Last active
August 29, 2015 14:02
-
-
Save hlfcoding/82196bef00605ff1c6de to your computer and use it in GitHub Desktop.
CodeWars Kata: Sum of (Two) Squares (http://www.codewars.com/kata/reviews/52265c169f283a9789000036/groups/538a92da7a4ba8cde8000103)
This file contains 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
allSquaredPairs = (num) -> | |
isInt = (num) -> num % 1 is 0 | |
pairs = [] | |
floor = 0 | |
ceiling = Math.ceil Math.sqrt(num) | |
for x in [floor...ceiling] | |
numX = Math.pow x, 2 | |
numY = num - numX | |
y = Math.sqrt numY | |
if y >= x and isInt(y) | |
pairs.push [x, y] | |
if num is 0 then pairs.push [0, 0] | |
pairs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment