Created
June 20, 2013 03:50
-
-
Save mythicalprogrammer/5820186 to your computer and use it in GitHub Desktop.
Given an integer input, return the total number of all perfect square square. Note 2^2+3^2 and 3^2+2^2 is counted as one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'set' | |
number = gets | |
number = number.to_i | |
max = Math.sqrt(number).to_i | |
set = Set.new | |
n_perf = 0 | |
for i in 0..max | |
for j in 0..max | |
#puts "#{i}^2 + #{j}^2" | |
#puts i*i + j*j | |
if number == (i*i+j*j) | |
set.add(Set.new [i,j]) | |
n_perf = n_perf+1 | |
end | |
end | |
end | |
puts set.length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment