Last active
December 24, 2015 03:39
-
-
Save poochin/6739279 to your computer and use it in GitHub Desktop.
numdot 解答
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
var result = "", | |
l = [0,0,0,0,0], | |
i = 0, | |
f; | |
function carry (l) { | |
if (l.length <= 1) { | |
return l; | |
} | |
var f = l.slice(1).some(function(v) { | |
return v == l[0] || v == l[0] - 1 | |
}); | |
var m = Math.max.apply(null, l.slice(1)); | |
if (f == false) { | |
l[0] = 0; | |
l[1]++; | |
} | |
return l.slice(0,1).concat(carry(l.slice(1))); | |
} | |
function tostr(l) { | |
var l2 = l.slice().reverse(); | |
var results = ["", "", "", "", ""]; | |
l2.map(function(v, i) {results[v] += (i+1)}); | |
return results.join('.').replace(/\.*$/, ''); | |
} | |
while (l[0]<4) { | |
console.log(tostr(l)); | |
l[0]++; | |
l = carry(l); | |
} | |
console.log(tostr(l)); |
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
https://gist.github.com/poochin/6681807 |
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
var l = [[[1]]], l2, l3, i, j, k; | |
function copy_r(list) { | |
return list.map(function(v){ | |
if (v.map) { | |
return copy_r(v); | |
} | |
return v; | |
}); | |
} | |
for (i = 2; i <= 5; ++i) { | |
l2 = []; | |
for (j = 0; j < l.length; ++j) { | |
l3 = []; | |
for (k = 0; k < l[j].length; ++k) { | |
l3 = copy_r(l[j]); | |
l3[k].push(i); | |
l2.push(l3); | |
} | |
l3 = copy_r(l[j]); | |
l3.push([i]); | |
l2.push(l3); | |
} | |
l = l2; | |
} | |
for (i = 0; i < l.length; ++i) { | |
console.log(l[i].map(function(v){return v.join('')}).join('.')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment