R
Ruby Quiz
The three rules of Ruby Quiz:
1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.
2. Support Ruby Quiz by submitting ideas as often as you can:
http://www.rubyquiz.com/
3. Enjoy!
Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
on Ruby Talk follow the discussion. Please reply to the original quiz message,
if you can.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
This week's Ruby Quiz is in pop quiz format. For each of the scenarios below,
send in a one line (80 characters or less) solution that performs the task. You
may use any legal Ruby syntax including require statements and semicolons, but
the goal in finesse more than golfing.
Any input described in the problem is in a local variable called quiz.
Assigning to this variable is assumed to have happened earlier in the program
and is not part of your submitted solution.
Your line just needs to evaluate to the expected result. You do not have to
store the result in a variable or create any output.
Any edge cases not covered by the provided examples are left to your best
judgement.
* Given a Numeric, provide a String representation with commas inserted between
each set of three digits in front of the decimal. For example, 1999995.99
should become "1,999,995.99".
* Given a nested Array of Arrays, perform a flatten()-like operation that
removes only the top level of nesting. For example, [1, [2, [3]]] would become
[1, 2, [3]].
* Shuffle the contents of a provided Array.
* Given a Ruby class name in String form (like
"GhostWheel::Expression::LookAhead"), fetch the actual class object.
* Insert newlines into a paragraph of prose (provided in a String) so lines will
wrap at 40 characters.
* Given an Array of String words, build an Array of only those words that are
anagrams of the first word in the Array.
* Convert a ThinkGeek t-shirt slogan (in String form) into a binary
representation (still a String). For example, the popular shirt "you are dumb"
is actually printed as:
111100111011111110101
110000111100101100101
1100100111010111011011100010
* Provided with an open File object, select a random line of content.
* Given a wondrous number Integer, produce the sequence (in an Array). A
wondrous number is a number that eventually reaches one, if you apply the
following rules to build a sequence from it. If the current number in the
sequence is even, the next number is that number divided by two. When the
current number is odd, multiply that number by three and add one to get the next
number in the sequence. Therefore, if we start with the wondrous number 15, the
sequence is [15, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2,
1].
* Convert an Array of objects to nested Hashes such that %w[one two three four
five] becomes {"one" => {"two" => {"three" => {"four" => "five"}}}}.
1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.
2. Support Ruby Quiz by submitting ideas as often as you can:
http://www.rubyquiz.com/
3. Enjoy!
Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
on Ruby Talk follow the discussion. Please reply to the original quiz message,
if you can.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
This week's Ruby Quiz is in pop quiz format. For each of the scenarios below,
send in a one line (80 characters or less) solution that performs the task. You
may use any legal Ruby syntax including require statements and semicolons, but
the goal in finesse more than golfing.
Any input described in the problem is in a local variable called quiz.
Assigning to this variable is assumed to have happened earlier in the program
and is not part of your submitted solution.
Your line just needs to evaluate to the expected result. You do not have to
store the result in a variable or create any output.
Any edge cases not covered by the provided examples are left to your best
judgement.
* Given a Numeric, provide a String representation with commas inserted between
each set of three digits in front of the decimal. For example, 1999995.99
should become "1,999,995.99".
* Given a nested Array of Arrays, perform a flatten()-like operation that
removes only the top level of nesting. For example, [1, [2, [3]]] would become
[1, 2, [3]].
* Shuffle the contents of a provided Array.
* Given a Ruby class name in String form (like
"GhostWheel::Expression::LookAhead"), fetch the actual class object.
* Insert newlines into a paragraph of prose (provided in a String) so lines will
wrap at 40 characters.
* Given an Array of String words, build an Array of only those words that are
anagrams of the first word in the Array.
* Convert a ThinkGeek t-shirt slogan (in String form) into a binary
representation (still a String). For example, the popular shirt "you are dumb"
is actually printed as:
111100111011111110101
110000111100101100101
1100100111010111011011100010
* Provided with an open File object, select a random line of content.
* Given a wondrous number Integer, produce the sequence (in an Array). A
wondrous number is a number that eventually reaches one, if you apply the
following rules to build a sequence from it. If the current number in the
sequence is even, the next number is that number divided by two. When the
current number is odd, multiply that number by three and add one to get the next
number in the sequence. Therefore, if we start with the wondrous number 15, the
sequence is [15, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2,
1].
* Convert an Array of objects to nested Hashes such that %w[one two three four
five] becomes {"one" => {"two" => {"three" => {"four" => "five"}}}}.