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
let primes = 2; | |
const isPrime = n => { | |
const half = Math.ceil(n / 2); | |
for (let i = 2; i <= half; i++) { | |
if (n % i === 0) { | |
return false; | |
} | |
} | |
return true; |
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
const str = [ | |
"08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08", | |
"49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00", | |
"81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65", | |
"52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91", | |
"22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80", | |
"24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50", | |
"32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70", | |
"67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21", | |
"24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72", |
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
function divisor(n) { | |
let sum = 0; | |
const sq = Math.round(Math.sqrt(n)); | |
for (let i = 0; i <= sq; i++) { | |
if (n % i === 0) { | |
sum += 2; | |
} | |
} | |
if (sq * sq === 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
arr = [ | |
37107287533902102798797998220837590246510135740250, | |
46376937677490009712648124896970078050417018260538, | |
74324986199524741059474233309513058123726617309629, | |
91942213363574161572522430563301811072406154908250, | |
23067588207539346171171980310421047513778063246676, | |
89261670696623633820136378418383684178734361726757, | |
28112879812849979408065481931592621691275889832738, | |
44274228917432520321923589422876796487670272189318, | |
47451445736001306439091167216856844588711603153276, |
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
function collatz(n, times = 1) { | |
while (n > 1) { | |
times += 1; | |
if (n % 2 === 0) { | |
n = n / 2; | |
} else { | |
n = 3 * n + 1; | |
} | |
} | |
return times; |
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
#include <stdio.h> | |
int main() { | |
const int grid = 20; | |
long ways = 1; | |
for (int i = 0; i < grid; i++) { | |
ways *= (2 * grid) - i; | |
ways /= i + 1; | |
} | |
printf("%ld\n", ways); |
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
result = sum(list(map(int, list(str(2 ** 1000))))) | |
print(result) |
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
const letters = { | |
'1': 'one', | |
'2': 'two', | |
'3': 'three', | |
'4': 'four', | |
'5': 'five', | |
'6': 'six', | |
'7': 'seven', | |
'8': 'eight', | |
'9': 'nine', |
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
const nums = [ | |
[75], | |
[95, 64], | |
[17, 47, 82], | |
[18, 35, 87, 10], | |
[20, 04, 82, 47, 65], | |
[19, 01, 23, 75, 03, 34], | |
[88, 02, 77, 73, 07, 63, 67], | |
[99, 65, 04, 28, 06, 16, 70, 92], | |
[41, 41, 26, 56, 83, 40, 80, 70, 33], |
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
def fac(n): | |
product = 1; | |
for i in range(1, n + 1): | |
product *= i | |
return product | |
def sumLen(n): | |
return sum(list(map(int, list(str(n))))) | |
print(sumLen(fac(100))) |