Skip to content

Instantly share code, notes, and snippets.

@DiegoSalazar
Created July 15, 2013 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DiegoSalazar/c34bd6a4c138e02a0589 to your computer and use it in GitHub Desktop.
Save DiegoSalazar/c34bd6a4c138e02a0589 to your computer and use it in GitHub Desktop.
exact squares
# A program that takes any single number (max) and returns all the numbers below (max) that is an exact square
def exact_squares(max)
s = []
while max > 0
s << max if is_exact_square? max
max -= 1
end
s
end
def is_exact_square?(max)
sqr = Math.sqrt max
sqr == sqr.to_i
end
p exact_squares(200)
@datasieve
Copy link

def prog(max)
results = .each do |x|
results << x if is_valid?(x)
end
results
end

def is_valid?(num)
((num % 5) == 0 || (num % 2) == 0) && ((num % 5) != 0 || (num % 2) != 0)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment