RosettaCodeData/Task/Square-but-not-cube/Ruby/square-but-not-cube-2.rb

5 lines
165 B
Ruby
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
squares = Enumerator.new {|y| 1.step{|n| y << n*n} }
puts "Square cubes: %p
Square non-cubes: %p" % squares.take(33).partition{|sq| Math.cbrt(sq).to_i ** 3 == sq }