Skip to content

Instantly share code, notes, and snippets.

@tmn
Created December 20, 2014 18:25
Show Gist options
  • Save tmn/e86da4e2c1e12decb070 to your computer and use it in GitHub Desktop.
Save tmn/e86da4e2c1e12decb070 to your computer and use it in GitHub Desktop.
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