Last active
August 29, 2015 14:26
-
-
Save endaaman/8fdffa310dbd6ec567e0 to your computer and use it in GitHub Desktop.
This file contains 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://twitter.com/runa1210248/status/628554882966945795 | |
all = [] | |
gen = (tree, list)-> | |
if tree.length is 0 | |
all.push list.concat() | |
return | |
[0..tree.length-1].forEach (v, i)-> | |
nextList = list.concat() | |
nextTree = tree.concat() | |
nextList.push tree[i] | |
nextTree.splice i, 1 | |
gen nextTree, nextList | |
gen [1..9], [] | |
check = (arr)-> | |
arr[0] / (arr[1] * 10 + arr[2]) + arr[3] / (arr[4] * 10 + arr[5]) + arr[6] / (arr[7] * 10 + arr[8]) | |
for i in all | |
v = check i | |
if 0.999 < v < 1.0001 | |
console.log i, v | |
# A B C D E F G H I: RESULT | |
# 5 3 4 9 1 2 7 6 8: 1 | |
# 5 8 7 6 2 4 9 1 3: 0.9997789566755084 | |
# 7 5 2 9 1 4 8 3 6: 0.9996947496947497 | |
# 5 6 3 8 4 7 9 1 2: 0.9995778453225261 | |
# 6 3 8 7 1 5 9 2 4: 0.9995614035087719 | |
# 5 2 6 8 1 3 9 4 7: 0.9991816693944353 | |
# 7 1 3 8 2 5 9 6 4: 0.9990865384615384 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment