Pythagorean quadruples: Difference between revisions

m (added a Wikipedia link.)
Line 1,812:
puts (1..n).reject{|x| l[x]}.join(" ")
</lang>
{{outOut}}
<pre>1 2 4 5 8 10 16 20 32 40 64 80 128 160 256 320 512 640 1024 1280 2048
</pre>
Considering the observations in the Rust and Sidef sections and toying with Enumerators :
<lang Ruby>squares = Enumerator.new{|y| (0..).each{|n| y << 2**n} }
squares5 = Enumerator.new{|y| (0..).each{|n| y << 2**n*5} }
 
pyth_quad = Enumerator.new do |y|
n = squares.next
m = squares5.next
loop do
if n < m
y << n
n = squares.next
else
y << m
m = squares5.next
end
end
end
# this takes less than a millisecond
puts pyth_quad.take_while{|n| n <= 1000000000}.join(" ")
{{Out}}1 2 4 5 8 10 16 20 32 40 64 80 128 160 256 320 512 640 1024 1280 2048 2560 4096 5120 8192 10240 16384 20480 32768 40960 65536 81920 131072 163840 262144 327680 524288 655360 1048576 1310720 2097152 2621440 4194304 5242880 8388608 10485760 16777216 20971520 33554432 41943040 67108864 83886080 134217728 167772160 268435456 335544320 536870912 671088640
 
=={{header|Rust}}==
1,149

edits