Created
December 20, 2014 18:25
-
-
Save tmn/e86da4e2c1e12decb070 to your computer and use it in GitHub Desktop.
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
console.time('luke20') | |
var sets = {}, size = 0 | |
var sum = function (x, y) { | |
var num = Math.abs(x).toString() + Math.abs(y) | |
return parseInt(eval(num.replace(/(\d)(?=\d)/g, '$1+'))) | |
} | |
var check = function (x, y) { | |
if (sets[x+','+y] || sum(x, y) > 19) { | |
return | |
} | |
sets[x+','+y] = 1 | |
check(x + 1, y) | |
check(x - 1, y) | |
check(x, y + 1) | |
check(x, y - 1) | |
} | |
check(0, 0) | |
for (var key in sets) { | |
if (sets.hasOwnProperty(key)) size++; | |
} | |
console.log(size) | |
console.timeEnd('luke20') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment