Disarium numbers: Difference between revisions
Content added Content deleted
m (→{{header|Free Pascal}}: correct by accident correct value for base 10.Now run correct in Base 11 too) |
(→{{header|Ruby}}: Rewrite, attempt to be more idiomatic) |
||
Line 2,679: | Line 2,679: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
<syntaxhighlight lang="ruby"> |
<syntaxhighlight lang="ruby">disariums = Enumerator.new do |y| |
||
(1..).each do |n| |
|||
n = num.to_s |
|||
i = 0 |
|||
y << n if n.digits.reverse.sum{|d| d ** (i+=1) } == n |
|||
for i in 1..(n.length) |
|||
⚫ | |||
sum += n[i-1].to_i**i |
|||
⚫ | |||
return sum == num |
|||
end |
end |
||
puts disariums.take(18).to_a.join(" ") |
|||
i = 0 |
|||
count = 0 |
|||
while count < 19 |
|||
if is_disarium(i) |
|||
printf("%d ", i) |
|||
count += 1 |
|||
end |
|||
i += 1 |
|||
end |
|||
print("\n") |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{out}} |
{{out}} |