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

Commit 5e12499

Browse files
iambkscissorsneedfoodtoo
authored andcommitted
fix(challenges): added solutions to project euler problems 28, 31
Added solutions to Project Euler problems 28 and 31.
1 parent ddcc661 commit 5e12499

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,9 @@
17681768
"assert(spiralDiagonals(1001) == 669171001, '<code>spiralDiagonals(1001)</code> should return 669171001.');"
17691769
}
17701770
],
1771-
"solutions": [],
1771+
"solutions": [
1772+
"const spiralDiagonals = (n) => {\n const Sn2 = (n) => {\n return n*(n+1)*(2*n+1)/6;\n };\n const Sn = (n) => {\n return n*(n+1)/2;\n };\n let sum = (Sn2(n-1) + Sn(n-1) + n-1) + (Math.floor(n/2) + Sn2(n));\n return sum;\n};"
1773+
],
17721774
"translations": {},
17731775
"description": [
17741776
"Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:",
@@ -1937,7 +1939,9 @@
19371939
"assert(coinSums(200) == 73682, '<code>coinSums(200)</code> should return 73682.');"
19381940
}
19391941
],
1940-
"solutions": [],
1942+
"solutions": [
1943+
"const coinSums = (n) => {\n const getWays = (n, m=8, c=[1, 2, 5, 10, 20, 50, 100, 200]) => {\n if (n === 0) return 1;\n if (m === 0 || n < 0) return 0;\n return getWays(n - c[m - 1], m, c) + getWays(n, m - 1, c);\n };\n return getWays(n);\n};"
1944+
],
19411945
"translations": {},
19421946
"description": [
19431947
"In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:",

0 commit comments

Comments
 (0)