|
2895 | 2895 | "title": "Problem 53: Combinatoric selections",
|
2896 | 2896 | "tests": [
|
2897 | 2897 | {
|
2898 |
| - "text": "<code>euler53()</code> should return 4075.", |
| 2898 | + "text": |
| 2899 | + "<code>combinatoricSelections(1000)</code> should return 4626.", |
| 2900 | + "testString": |
| 2901 | + "assert.strictEqual(combinatoricSelections(1000), 4626, '<code>combinatoricSelections(1000)</code> should return 4626.');" |
| 2902 | + }, |
| 2903 | + { |
| 2904 | + "text": |
| 2905 | + "<code>combinatoricSelections(10000)</code> should return 4431.", |
| 2906 | + "testString": |
| 2907 | + "assert.strictEqual(combinatoricSelections(10000), 4431, '<code>combinatoricSelections(10000)</code> should return 4431.');" |
| 2908 | + }, |
| 2909 | + { |
| 2910 | + "text": |
| 2911 | + "<code>combinatoricSelections(100000)</code> should return 4255.", |
2899 | 2912 | "testString":
|
2900 |
| - "assert.strictEqual(euler53(), 4075, '<code>euler53()</code> should return 4075.');" |
| 2913 | + "assert.strictEqual(combinatoricSelections(100000), 4255, '<code>combinatoricSelections(100000)</code> should return 4255.');" |
| 2914 | + }, |
| 2915 | + { |
| 2916 | + "text": |
| 2917 | + "<code>combinatoricSelections(1000000)</code> should return 4075.", |
| 2918 | + "testString": |
| 2919 | + "assert.strictEqual(combinatoricSelections(1000000), 4075, '<code>combinatoricSelections(1000000)</code> should return 4075.');" |
2901 | 2920 | }
|
2902 | 2921 | ],
|
2903 |
| - "solutions": [], |
| 2922 | + "solutions": [ |
| 2923 | + "function combinatoricSelections(limit) {\n const factorial = n => \n Array.apply(null, { length: n })\n .map((_, i) => i + 1)\n .reduce((p, c) => p * c, 1);\n\n let result = 0;\n const nMax = 100;\n\n for (let n = 1; n <= nMax; n++) {\n for (let r = 0; r <= n; r++) {\n if (factorial(n) / (factorial(r) * factorial(n - r)) >= limit)\n result++;\n }\n }\n\n return result;\n}" |
| 2924 | + ], |
2904 | 2925 | "translations": {},
|
2905 | 2926 | "description": [
|
2906 | 2927 | "There are exactly ten ways of selecting three from five, 12345:",
|
|
2921 | 2942 | "ext": "js",
|
2922 | 2943 | "name": "index",
|
2923 | 2944 | "contents": [
|
2924 |
| - "function euler53() {", |
| 2945 | + "function combinatoricSelections(limit) {", |
2925 | 2946 | " // Good luck!",
|
2926 |
| - " return true;", |
| 2947 | + " return 1;", |
2927 | 2948 | "}",
|
2928 | 2949 | "",
|
2929 |
| - "euler53();" |
| 2950 | + "combinatoricSelections(1000000);" |
2930 | 2951 | ],
|
2931 | 2952 | "head": [],
|
2932 | 2953 | "tail": []
|
|
0 commit comments