Skip to content

Instantly share code, notes, and snippets.

@ikr7
Last active March 29, 2016 14:42
Show Gist options
  • Save ikr7/8b8398dbfd4f31553b50 to your computer and use it in GitHub Desktop.
Save ikr7/8b8398dbfd4f31553b50 to your computer and use it in GitHub Desktop.
n次元九九
nku :: Integer -> [Integer]
nku 0 = [1]
nku n = concat (map (\x -> map (*x) [1..9]) (nku (n - 1)))
'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