Skip to content

Instantly share code, notes, and snippets.

@luc4leone
Created May 30, 2014 20:04
Show Gist options
  • Save luc4leone/b938520b7d76addcb11a to your computer and use it in GitHub Desktop.
Save luc4leone/b938520b7d76addcb11a to your computer and use it in GitHub Desktop.
Given an array of numbers, which are perfect squares?
def get_squares(n)
n.to_a
squares = []
n.each do |i|
if (i ** 0.5).to_s[-2..-1] == ".0"
if squares.include? i
squares
else
squares.push(i)
end
end
end
squares.sort
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment