Anonymous user
Nonoblock: Difference between revisions
→{{header|Ruby}}: It moves a change method to the cell form to the String class.
(→{{header|Ruby}}: add Class version) |
(→{{header|Ruby}}: It moves a change method to the cell form to the String class.) |
||
Line 353:
<lang ruby>def nonoblocks(cell, blocks)
raise 'Those blocks will not fit in those cells' if cell < blocks.inject(0,:+) + blocks.size - 1
▲ nblock(cell, blocks, '', result)
end
Line 366 ⟶ 364:
rest = cell - blocks.inject(:+) - blocks.size + 2
bl, brest = blocks[0], blocks.drop(1)
rest.times.inject(result) do |res, i|
nblock(cell-i-bl-1, brest, position + '.'*i + '#'*bl + '.',
end
end
Line 427 ⟶ 425:
</pre>
The output form consulted the one of the python.▼
<lang ruby>class NonoBlock
end▼
def initialize(cell, blocks)
raise 'Those blocks will not fit in those cells' if cell < blocks.inject(0,:+) + blocks.size - 1
Line 440 ⟶ 435:
def result(correct=true)
correct ? @result.map
end
Line 457 ⟶ 452:
end
end
def str2cell(str) # "##.###..##" -> "|A|A|_|B|B|B|_|_|C|C|"▼
class String
chr = ('A'..'Z').each
s =
"|#{s.chars.join('|')}|"
end
Line 470 ⟶ 467:
[10, [8]],
[15, [2, 3, 2, 3]],
[ 5, [2, 3]]
conf.each do |cell, blocks|
begin
puts "Configuration:",
"#{
"Possibilities:"
result = NonoBlock.new(cell, blocks).result
Line 484 ⟶ 481:
end
end</lang>
▲The output form consulted the one of the python.
{{out}}
<pre style="height: 64ex; overflow: scroll">
Configuration:
|_|_|_|_|_| # 5 cells and [2, 1] blocks
|