Using a combination of black square tiles and oblong tiles chosen from: red tiles measuring two units, green tiles measuring three units, and blue tiles measuring four units, it is possible to tile a row measuring five units in length in exactly fifteen different ways.
|
|
|
|
||||||||||||||||||||
|
|
|
|
||||||||||||||||||||
|
|
|
|
||||||||||||||||||||
|
|
|
How many ways can a row measuring fifty units in length be tiled?
NOTE: This is related to problem 116.
def p117recur(l) return 1 if l==0 memoize=$p117[l] return memoize if memoize tot=1 (2..4).each do |tile| (0..(l-tile)).each do |space| tot+=p117recur(space) end end $p117[l]=tot end def p117 $p117={} puts p117recur(50) end