Skip to content

Instantly share code, notes, and snippets.

@benmccormick
Created April 14, 2013 17:40
Show Gist options
  • Save benmccormick/5383550 to your computer and use it in GitHub Desktop.
Save benmccormick/5383550 to your computer and use it in GitHub Desktop.
Submission for Problem C of google code jam Qualification Round 2013 https://code.google.com/codejam/contest/2270488/dashboard#s=p2
fs = require('fs')
writevalue = (i, val)->
output += "Case #"+i+": "+val+"\n"
# is a palindrome (expects a string)
isPalindrome = (num) ->
reversed = (num).split("").reverse().join("")
num is reversed
findNums = (a,b) ->
count = 0
x = Math.ceil Math.sqrt a
y = Math.floor Math.sqrt b
for num in [x..y]
if isPalindrome (num+"")
count += if isPalindrome (num*num+"") then 1 else 0
count
text = fs.readFileSync("test.txt","utf8")
lines = text.split "\n"
output = ""
numtests = lines[0]
lines.splice 0, 1
for line , i in lines
[a,b] = line.split(" ")
val = findNums a, b
writevalue i+1, val
fs.writeFileSync("output.txt",output,"utf8")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment