Upside-down numbers: Difference between revisions

(Created Nim solution.)
Line 1,137:
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">DIGITS =(1..9).to_a
 
updowns = Enumerator.new do |y|
y << 5
(1..).each do |s|
perms = DIGITS.repeated_permutation(s)
perms.each{|perm| y << (perm + perm.reverse.map{|n| 10-n}).join.to_i }
perms.each{|perm| y << (perm + [5] + perm.reverse.map{|n| 10-n}).join.to_i }
end
end
 
res = updowns.take(5000000)
res.first(50).each_slice(10){|slice| puts "%6d"*slice.size % slice}
 
puts
n = 500
5.times do
puts "%8d: %-10d" % [n, res[n-1]]
n *= 10
end
</syntaxhighlight>
{{out}}
<pre> 5 19 28 37 46 55 64 73 82 91
159 258 357 456 555 654 753 852 951 1199
1289 1379 1469 1559 1649 1739 1829 1919 2198 2288
2378 2468 2558 2648 2738 2828 2918 3197 3287 3377
3467 3557 3647 3737 3827 3917 4196 4286 4376 4466
 
500th : 494616
5000th : 56546545
50000th : 6441469664
500000th : 729664644183
5000000th : 82485246852682
</pre>
=={{header|Wren}}==
{{trans|Python}}
1,149

edits