Skip to content
This repository was archived by the owner on Sep 25, 2019. It is now read-only.

Commit 56d7caf

Browse files
alvinklscissorsneedfoodtoo
authored andcommitted
fix(challenges): add solution to project euler 53
1 parent cfa99ef commit 56d7caf

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

challenges/08-coding-interview-prep/project-euler.json

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2895,12 +2895,33 @@
28952895
"title": "Problem 53: Combinatoric selections",
28962896
"tests": [
28972897
{
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.",
28992912
"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.');"
29012920
}
29022921
],
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+
],
29042925
"translations": {},
29052926
"description": [
29062927
"There are exactly ten ways of selecting three from five, 12345:",
@@ -2921,12 +2942,12 @@
29212942
"ext": "js",
29222943
"name": "index",
29232944
"contents": [
2924-
"function euler53() {",
2945+
"function combinatoricSelections(limit) {",
29252946
" // Good luck!",
2926-
" return true;",
2947+
" return 1;",
29272948
"}",
29282949
"",
2929-
"euler53();"
2950+
"combinatoricSelections(1000000);"
29302951
],
29312952
"head": [],
29322953
"tail": []

0 commit comments

Comments
 (0)