Skip to content

Instantly share code, notes, and snippets.

@hlfcoding
Last active August 29, 2015 14:02
Show Gist options
  • Save hlfcoding/82196bef00605ff1c6de to your computer and use it in GitHub Desktop.
Save hlfcoding/82196bef00605ff1c6de to your computer and use it in GitHub Desktop.
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