The three rules of Ruby Q.:
Please do not post any solutions or spoiler discussion for this quiz
48 hours have passed from the time on this message.
Support Ruby Q. by submitting ideas as often as you can:
Suggestion: A [QUIZ] in the subject of emails about the problem helps
on Ruby T. follow the discussion.
by Matthew M.
You have a square sheet of grid paper, 16 cells across by 16 down. A
written in each cell, starting at 1 in the upper-left corner, going
line then down the paper, ending with 256 in the lower-right corner.
Your task is write a Ruby function to fold the paper in half repeatedly
the horizontal or vertical middle), until you are left with a single
layers thick, and report back on the order of those layers, top to
The input to the function is a string containing the characters “T” (the
edge folded down to the bottom edge), “B” (bottom up to top), “R” (right
left) and “L” (left to right). Not every combination of those will be
make sure you verify your input. Output will be an Array of Integers
from 1 to
256, arranged in the top-to-bottom layer order after all folds are done.
To help clarify, here’s a 2x2 example.
+-+-+ |1|2| +-+-+ |3|4| +-+-+ fold("RB") => [3, 4, 2, 1] fold("TL") => [3, 1, 2, 4] fold("LR") => raise exception for invalid input
Extra credit: Make your fold function take an additional input
the dimensions of the paper; dimensions should be power-of-2 in order to
down to one cell.
Extra extra credit: Write a method check_fold() that takes the
of Integers from the quiz and returns the transformation String argument
fold(check_fold(final_order)) == final_order).