Last active
March 29, 2016 14:42
-
-
Save ikr7/8b8398dbfd4f31553b50 to your computer and use it in GitHub Desktop.
n次元九九
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
nku :: Integer -> [Integer] | |
nku 0 = [1] | |
nku n = concat (map (\x -> map (*x) [1..9]) (nku (n - 1))) |
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
'use strict'; | |
const nku = function (n) { | |
const res = []; | |
if (n === 0) { | |
res.push(1); | |
} else { | |
nku(n - 1).forEach((x) => { | |
[1, 2, 3, 4, 5, 6, 7 ,8, 9].forEach((e) => { | |
res.push(e * x); | |
}) | |
}); | |
} | |
return res; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment