Anonymous user
Damm algorithm: Difference between revisions
→{{header|Ruby}}: made Ruby example more like other examples (test return boolean) and more idiomatic to Ruby (function name, brackets, single statement trailing if)
(→{{header|Quackery}}: tweak) |
(→{{header|Ruby}}: made Ruby example more like other examples (test return boolean) and more idiomatic to Ruby (function name, brackets, single statement trailing if)) |
||
Line 1,996:
=={{header|Ruby}}==
<lang ruby>def
idx = 0
for i in 0 .. nbr.length - 1
a = nbr[i].to_i
return false if a == nil
idx = @table[idx][a]
end
idx == 0
print( "this number is " )▼
end▼
puts▼
end
@table = Array.new
]
▲ [9,4,3,8,6,1,7,2,0,5], [2,5,8,1,4,3,6,7,9,0]
while true
print
puts "this number is invalid!"
▲ end
end</lang>
{{out}}<pre>Number to check: 5724
|