├── Euler-001.js ├── Euler-002.js ├── Euler-003.js ├── Euler-004.js ├── Euler-005.js ├── Euler-006.js ├── Euler-007.js ├── Euler-008.js ├── Euler-009.js ├── Euler-010.js ├── Euler-011.js ├── Euler-012.js ├── Euler-013.js ├── Euler-014.js ├── Euler-015.js ├── Euler-016.js ├── Euler-017.js ├── Euler-018.js ├── Euler-019.js ├── Euler-020.js ├── Euler-021.js ├── Euler-022.js ├── Euler-023.js ├── Euler-024.js ├── Euler-025.js ├── Euler-026.js ├── Euler-027.js ├── Euler-028.js ├── Euler-029.js ├── Euler-030.js ├── Euler-031.js ├── Euler-032.js ├── Euler-033.js ├── Euler-034.js ├── Euler-035.js ├── Euler-036.js ├── Euler-037.js ├── Euler-038.js ├── Euler-039.js ├── Euler-040.js ├── Euler-041.js ├── Euler-042.js ├── Euler-043.js ├── Euler-044.js ├── Euler-045.js ├── Euler-046.js ├── Euler-047.js ├── Euler-048.js ├── Euler-049.js ├── Euler-050.js ├── Euler-051.js ├── Euler-052.js ├── Euler-053.js ├── Euler-054.js ├── Euler-055.js ├── Euler-056.js ├── Euler-057.js ├── Euler-058.js ├── Euler-059.py ├── Euler-060.js ├── Euler-061.js ├── Euler-062.js ├── Euler-063.js ├── Euler-064.js ├── Euler-065.js ├── LICENSE └── README.md /Euler-001.js: -------------------------------------------------------------------------------- 1 | /* 2 | Project Euler 3 | 4 | https://projecteuler.net/problem=1 5 | 6 | Multiples Of 3 & 5 7 | 8 | by : Pabitra Banerjee [https://pabitrabanerjee.newsgoogle.org] 9 | */ 10 | 11 | function solution(n) { 12 | 13 | var r = n / 3 | 0; 14 | var s = n / 5 | 0; 15 | var t = n / 15 | 0; 16 | 17 | return 3 * r * ++r + 5 * s * ++s - 15 * t * ++t >> 1; 18 | } 19 | console.log(solution(999)); 20 | 21 | 22 | // https://replit.com/@RockstarPabitra/Euler-001 23 | -------------------------------------------------------------------------------- /Euler-002.js: -------------------------------------------------------------------------------- 1 | var SR5 = Math.sqrt(5); 2 | var PHI = (1 + SR5) / 2; 3 | var PSI = (1 - SR5) / 2; 4 | 5 | function F(n) { 6 | return (Math.pow(PHI, n) - Math.pow(PSI, n)) / SR5; 7 | } 8 | 9 | function index(F) { 10 | return Math.floor(Math.log(F * SR5 + 0.5) / Math.log(PHI)); 11 | } 12 | 13 | function sum(n) { 14 | return F(n + 2) - 1; 15 | } 16 | 17 | function solution(n) { 18 | return Math.round(sum(index(n)) / 2); 19 | } 20 | console.log(solution(4e6)); 21 | 22 | // https://replit.com/@RockstarPabitra/Euler-002 23 | -------------------------------------------------------------------------------- /Euler-003.js: -------------------------------------------------------------------------------- 1 | function solution(n) { 2 | 3 | for (var i = 2; i * i <= n; i++) { 4 | while(n % i === 0 /* && i * i <= n */) { 5 | n/= i; 6 | } 7 | } 8 | return n; 9 | } 10 | console.log(solution(600851475143)); 11 | 12 | // https://replit.com/@RockstarPabitra/Euler-003 13 | -------------------------------------------------------------------------------- /Euler-004.js: -------------------------------------------------------------------------------- 1 | function isPalindrome(num) { 2 | const stringifiedNum = num.toString(); 3 | 4 | return ( 5 | Array.from(stringifiedNum).toString() === 6 | Array.from(stringifiedNum) 7 | .reverse() 8 | .toString() 9 | ); 10 | } 11 | 12 | function findLargestPalindrome() { 13 | const start = 100; 14 | const end = 999; 15 | 16 | let largestPalindrome = 0; 17 | 18 | for (let i = start; i <= end; i += 1) { 19 | for (let j = start; j <= end; j += 1) { 20 | const product = i * j; 21 | if (isPalindrome(product) && product > largestPalindrome) { 22 | largestPalindrome = product; 23 | } 24 | } 25 | } 26 | 27 | return largestPalindrome; 28 | } 29 | 30 | console.log(findLargestPalindrome()); 31 | -------------------------------------------------------------------------------- /Euler-005.js: -------------------------------------------------------------------------------- 1 | function smallestMult(n) { 2 | let inc = 2; 3 | let step = 2; 4 | let smallestNum = 2; 5 | while (smallestNum <= Number.MAX_SAFE_INTEGER) { 6 | for (let i = 2; i <= n; i++) { 7 | const divisible = smallestNum % i === 0; 8 | if (!divisible) { 9 | break; 10 | } 11 | if (i === inc) { 12 | step = smallestNum; 13 | inc++; 14 | } 15 | if (i === n) { 16 | return smallestNum; 17 | } 18 | } 19 | smallestNum += step; 20 | } 21 | } 22 | console.log(smallestMult(20)); 23 | -------------------------------------------------------------------------------- /Euler-006.js: -------------------------------------------------------------------------------- 1 | let n = 100; 2 | let answer = Math.pow((n * (n + 1)) / 2, 2) - (n * (n + 1) * (2 * n + 1)) / 6; 3 | console.log(answer); 4 | -------------------------------------------------------------------------------- /Euler-007.js: -------------------------------------------------------------------------------- 1 | function isPrime(n) { 2 | 3 | if (n <= 1) return false; 4 | if (n === 2) return true; 5 | for (let i = 2; i <= Math.sqrt(n); i++) { 6 | if (n % i === 0) return false; 7 | } 8 | return true; 9 | } 10 | 11 | let answer = 1; 12 | let n = 1; // Start counter 13 | while (n < 10001) { // Find 10001 prime numbers 14 | answer += 2; // Next number 15 | if (isPrime(answer)) { 16 | n++; // Increment counter 17 | } 18 | } 19 | 20 | console.log(answer); 21 | -------------------------------------------------------------------------------- /Euler-008.js: -------------------------------------------------------------------------------- 1 | function slice(str, i, n) { 2 | var prod = 1; 3 | for (var j = 0; j < n; j++) { 4 | prod*= str.charAt(i + j); 5 | } 6 | return prod; 7 | } 8 | 9 | function solution(str, n) { 10 | 11 | var prod = slice(str, 0, n); 12 | var maxp = prod; 13 | 14 | for (var i = n; i <= str.length - n; i++) { 15 | var pre = str.charAt(i - n); 16 | var cur = str.charAt(i); 17 | 18 | if (pre !== '0') 19 | prod = prod * cur / pre; 20 | else 21 | prod = slice(str, i - n + 1, n); 22 | 23 | maxp = Math.max(prod, maxp); 24 | } 25 | return maxp; 26 | } 27 | 28 | console.log(solution( 29 | "73167176531330624919225119674426574742355349194934" + 30 | "96983520312774506326239578318016984801869478851843" + 31 | "85861560789112949495459501737958331952853208805511" + 32 | "12540698747158523863050715693290963295227443043557" + 33 | "66896648950445244523161731856403098711121722383113" + 34 | "62229893423380308135336276614282806444486645238749" + 35 | "30358907296290491560440772390713810515859307960866" + 36 | "70172427121883998797908792274921901699720888093776" + 37 | "65727333001053367881220235421809751254540594752243" + 38 | "52584907711670556013604839586446706324415722155397" + 39 | "53697817977846174064955149290862569321978468622482" + 40 | "83972241375657056057490261407972968652414535100474" + 41 | "82166370484403199890008895243450658541227588666881" + 42 | "16427171479924442928230863465674813919123162824586" + 43 | "17866458359124566529476545682848912883142607690042" + 44 | "24219022671055626321111109370544217506941658960408" + 45 | "07198403850962455444362981230987879927244284909188" + 46 | "84580156166097919133875499200524063689912560717606" + 47 | "05886116467109405077541002256983155200055935729725" + 48 | "71636269561882670428252483600823257530420752963450", 13)); 49 | -------------------------------------------------------------------------------- /Euler-009.js: -------------------------------------------------------------------------------- 1 | function solution(n) { 2 | 3 | for (var c = Math.floor(n / 3 + 1); c < n / 2; c++) { 4 | var sqa_b = c * c - n * n + 2 * n * c 5 | var a_b = Math.floor(Math.sqrt(sqa_b)); 6 | 7 | if (a_b * a_b == sqa_b) { 8 | var b = (n - c + a_b) / 2; 9 | var a = n - b - c; 10 | return a * b * c; 11 | } 12 | } 13 | return -1 14 | } 15 | console.log(solution(1000)); 16 | -------------------------------------------------------------------------------- /Euler-010.js: -------------------------------------------------------------------------------- 1 | function solution(n) { 2 | 3 | var sum = 0; 4 | var bound = (Math.sqrt(n + 1) - 1) >> 1; 5 | n = n >> 1; 6 | var data = new Uint8Array(n + 1); 7 | 8 | for (var i = 1; i <= bound; i++) { 9 | 10 | for (var j = i * 2 * (i + 1); j <= n; j+= 2 * i + 1) { 11 | 12 | if (data[j] === 0) { 13 | data[j] = 1; 14 | sum+= j * 2 + 1; 15 | } 16 | } 17 | } 18 | return 2 + n * (n + 1) + n - sum; 19 | } 20 | console.log(solution(2e6 - 1)); 21 | -------------------------------------------------------------------------------- /Euler-011.js: -------------------------------------------------------------------------------- 1 | var arr = [ 2 | [08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 08], 3 | [49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 04, 56, 62, 00], 4 | [81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 03, 49, 13, 36, 65], 5 | [52, 70, 95, 23, 04, 60, 11, 42, 69, 24, 68, 56, 01, 32, 56, 71, 37, 02, 36, 91], 6 | [22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80], 7 | [24, 47, 32, 60, 99, 03, 45, 02, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50], 8 | [32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70], 9 | [67, 26, 20, 68, 02, 62, 12, 20, 95, 63, 94, 39, 63, 08, 40, 91, 66, 49, 94, 21], 10 | [24, 55, 58, 05, 66, 73, 99, 26, 97, 17, 78, 78, 96, 83, 14, 88, 34, 89, 63, 72], 11 | [21, 36, 23, 09, 75, 00, 76, 44, 20, 45, 35, 14, 00, 61, 33, 97, 34, 31, 33, 95], 12 | [78, 17, 53, 28, 22, 75, 31, 67, 15, 94, 03, 80, 04, 62, 16, 14, 09, 53, 56, 92], 13 | [16, 39, 05, 42, 96, 35, 31, 47, 55, 58, 88, 24, 00, 17, 54, 24, 36, 29, 85, 57], 14 | [86, 56, 00, 48, 35, 71, 89, 07, 05, 44, 44, 37, 44, 60, 21, 58, 51, 54, 17, 58], 15 | [19, 80, 81, 68, 05, 94, 47, 69, 28, 73, 92, 13, 86, 52, 17, 77, 04, 89, 55, 40], 16 | [04, 52, 08, 83, 97, 35, 99, 16, 07, 97, 57, 32, 16, 26, 26, 79, 33, 27, 98, 66], 17 | [88, 36, 68, 87, 57, 62, 20, 72, 03, 46, 33, 67, 46, 55, 12, 32, 63, 93, 53, 69], 18 | [04, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 08, 46, 29, 32, 40, 62, 76, 36], 19 | [20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 04, 36, 16], 20 | [20, 73, 35, 29, 78, 31, 90, 01, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 05, 54], 21 | [01, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 01, 89, 19, 67, 48] 22 | ]; 23 | 24 | 25 | function get(arr, y, x) { 26 | if (0 <= y && y < arr.length && 0 <= x && x < arr[y].length) { 27 | return arr[y][x]; 28 | } 29 | return 0; 30 | } 31 | 32 | function solution(arr, k) { 33 | var max = 0; 34 | var dx = [1, 0, 1,-1]; 35 | var dy = [0, 1, 1, 1]; 36 | 37 | for (var y = 0; y < arr.length; y++) { 38 | for (var x = 0; x < arr[y].length; x++) { 39 | for (var d = 0; d < 4; d++) { 40 | var p = 1; 41 | for (var i = 0; i < k; i++) { 42 | p*= get(arr, y + i * dy[d], x + i * dx[d]); 43 | } 44 | max = Math.max(p, max); 45 | } 46 | } 47 | } 48 | return max; 49 | } 50 | console.log(solution(arr, 4)); 51 | -------------------------------------------------------------------------------- /Euler-012.js: -------------------------------------------------------------------------------- 1 | function tau(num) { 2 | 3 | var n = num; 4 | var i = 2; 5 | var p = 1; 6 | 7 | if (num === 1) return 1; 8 | 9 | while (i * i <= n) { 10 | var c = 1; 11 | while (n % i === 0) { 12 | n/= i; 13 | c++; 14 | } 15 | i++; 16 | p*= c; 17 | } 18 | 19 | if (n === num || n > 1) 20 | p*= 1 + 1; 21 | 22 | return p; 23 | } 24 | function solution(x) { 25 | 26 | var n = 1; 27 | var d = 1; 28 | 29 | while (tau(d) <= x) { 30 | n++; 31 | d+= n; 32 | } 33 | return d; 34 | } 35 | console.log(solution(500)); 36 | -------------------------------------------------------------------------------- /Euler-013.js: -------------------------------------------------------------------------------- 1 | var nums = [ 2 | "37107287533902102798797998220837590246510135740250", 3 | "46376937677490009712648124896970078050417018260538", 4 | "74324986199524741059474233309513058123726617309629", 5 | "91942213363574161572522430563301811072406154908250", 6 | "23067588207539346171171980310421047513778063246676", 7 | "89261670696623633820136378418383684178734361726757", 8 | "28112879812849979408065481931592621691275889832738", 9 | "44274228917432520321923589422876796487670272189318", 10 | "47451445736001306439091167216856844588711603153276", 11 | "70386486105843025439939619828917593665686757934951", 12 | "62176457141856560629502157223196586755079324193331", 13 | "64906352462741904929101432445813822663347944758178", 14 | "92575867718337217661963751590579239728245598838407", 15 | "58203565325359399008402633568948830189458628227828", 16 | "80181199384826282014278194139940567587151170094390", 17 | "35398664372827112653829987240784473053190104293586", 18 | "86515506006295864861532075273371959191420517255829", 19 | "71693888707715466499115593487603532921714970056938", 20 | "54370070576826684624621495650076471787294438377604", 21 | "53282654108756828443191190634694037855217779295145", 22 | "36123272525000296071075082563815656710885258350721", 23 | "45876576172410976447339110607218265236877223636045", 24 | "17423706905851860660448207621209813287860733969412", 25 | "81142660418086830619328460811191061556940512689692", 26 | "51934325451728388641918047049293215058642563049483", 27 | "62467221648435076201727918039944693004732956340691", 28 | "15732444386908125794514089057706229429197107928209", 29 | "55037687525678773091862540744969844508330393682126", 30 | "18336384825330154686196124348767681297534375946515", 31 | "80386287592878490201521685554828717201219257766954", 32 | "78182833757993103614740356856449095527097864797581", 33 | "16726320100436897842553539920931837441497806860984", 34 | "48403098129077791799088218795327364475675590848030", 35 | "87086987551392711854517078544161852424320693150332", 36 | "59959406895756536782107074926966537676326235447210", 37 | "69793950679652694742597709739166693763042633987085", 38 | "41052684708299085211399427365734116182760315001271", 39 | "65378607361501080857009149939512557028198746004375", 40 | "35829035317434717326932123578154982629742552737307", 41 | "94953759765105305946966067683156574377167401875275", 42 | "88902802571733229619176668713819931811048770190271", 43 | "25267680276078003013678680992525463401061632866526", 44 | "36270218540497705585629946580636237993140746255962", 45 | "24074486908231174977792365466257246923322810917141", 46 | "91430288197103288597806669760892938638285025333403", 47 | "34413065578016127815921815005561868836468420090470", 48 | "23053081172816430487623791969842487255036638784583", 49 | "11487696932154902810424020138335124462181441773470", 50 | "63783299490636259666498587618221225225512486764533", 51 | "67720186971698544312419572409913959008952310058822", 52 | "95548255300263520781532296796249481641953868218774", 53 | "76085327132285723110424803456124867697064507995236", 54 | "37774242535411291684276865538926205024910326572967", 55 | "23701913275725675285653248258265463092207058596522", 56 | "29798860272258331913126375147341994889534765745501", 57 | "18495701454879288984856827726077713721403798879715", 58 | "38298203783031473527721580348144513491373226651381", 59 | "34829543829199918180278916522431027392251122869539", 60 | "40957953066405232632538044100059654939159879593635", 61 | "29746152185502371307642255121183693803580388584903", 62 | "41698116222072977186158236678424689157993532961922", 63 | "62467957194401269043877107275048102390895523597457", 64 | "23189706772547915061505504953922979530901129967519", 65 | "86188088225875314529584099251203829009407770775672", 66 | "11306739708304724483816533873502340845647058077308", 67 | "82959174767140363198008187129011875491310547126581", 68 | "97623331044818386269515456334926366572897563400500", 69 | "42846280183517070527831839425882145521227251250327", 70 | "55121603546981200581762165212827652751691296897789", 71 | "32238195734329339946437501907836945765883352399886", 72 | "75506164965184775180738168837861091527357929701337", 73 | "62177842752192623401942399639168044983993173312731", 74 | "32924185707147349566916674687634660915035914677504", 75 | "99518671430235219628894890102423325116913619626622", 76 | "73267460800591547471830798392868535206946944540724", 77 | "76841822524674417161514036427982273348055556214818", 78 | "97142617910342598647204516893989422179826088076852", 79 | "87783646182799346313767754307809363333018982642090", 80 | "10848802521674670883215120185883543223812876952786", 81 | "71329612474782464538636993009049310363619763878039", 82 | "62184073572399794223406235393808339651327408011116", 83 | "66627891981488087797941876876144230030984490851411", 84 | "60661826293682836764744779239180335110989069790714", 85 | "85786944089552990653640447425576083659976645795096", 86 | "66024396409905389607120198219976047599490197230297", 87 | "64913982680032973156037120041377903785566085089252", 88 | "16730939319872750275468906903707539413042652315011", 89 | "94809377245048795150954100921645863754710598436791", 90 | "78639167021187492431995700641917969777599028300699", 91 | "15368713711936614952811305876380278410754449733078", 92 | "40789923115535562561142322423255033685442488917353", 93 | "44889911501440648020369068063960672322193204149535", 94 | "41503128880339536053299340368006977710650566631954", 95 | "81234880673210146739058568557934581403627822703280", 96 | "82616570773948327592232845941706525094512325230608", 97 | "22918802058777319719839450180888072429661980811197", 98 | "77158542502016545090413245809786882778948721859617", 99 | "72107838435069186155435662884062257473692284509516", 100 | "20849603980134001723930671666823555245252804609722", 101 | "53503534226472524250874054075591789781264330331690" 102 | ]; 103 | 104 | function solution(nums) { 105 | 106 | var pos = nums[0].length; 107 | var ret = ""; 108 | var num = 0; 109 | 110 | while (pos--) { 111 | 112 | for (var i = nums.length; i--; ) { 113 | num+= +nums[i].charAt(pos); 114 | } 115 | ret = num % 10 + ret; 116 | num = num / 10 | 0; 117 | } 118 | 119 | if (num > 0) { 120 | ret = num + ret; 121 | } 122 | return ret.slice(0, 10); 123 | } 124 | 125 | console.log(solution(nums)); 126 | -------------------------------------------------------------------------------- /Euler-014.js: -------------------------------------------------------------------------------- 1 | let longestCollatzSequence = (limit) => { 2 | let longestSequence = 1 3 | let longestValue = 1 4 | let startValue 5 | for(startValue = 2; startValue < limit; startValue ++){ 6 | let numberOfTerms = 1 7 | let currentTerm = startValue 8 | while(currentTerm != 1){ 9 | if(currentTerm % 2 === 0){ 10 | currentTerm = currentTerm / 2 11 | }else{ 12 | currentTerm = ((3 * currentTerm) + 1) 13 | } 14 | numberOfTerms = numberOfTerms + 1 15 | } 16 | if(numberOfTerms > longestSequence){ 17 | console.log('Number of terms for ' + startValue + ' is ' + numberOfTerms) 18 | longestSequence = numberOfTerms 19 | longestValue = startValue 20 | } 21 | 22 | } 23 | return longestValue 24 | } 25 | console.log('Result is ' + longestCollatzSequence(1000000)) 26 | -------------------------------------------------------------------------------- /Euler-015.js: -------------------------------------------------------------------------------- 1 | function noverk(n, k) { 2 | 3 | if (n < k || k < 0) 4 | return 0; 5 | 6 | k = Math.min(k, n - k); 7 | n = n - k; 8 | 9 | for (var i = 1, c = 1; i <= k; i++) 10 | c = c * (n + i) / i; 11 | 12 | return c; 13 | } 14 | function solution(n) { 15 | 16 | for (var i = 1, c = 1; i <= n; i++) 17 | c = c * (n + i) / i; 18 | return c; 19 | } 20 | console.log(solution(20)); 21 | -------------------------------------------------------------------------------- /Euler-016.js: -------------------------------------------------------------------------------- 1 | function solution(exp) { 2 | var order = 0; 3 | var digits = Math.floor(1 + exp * Math.LN2 / Math.LN10); 4 | var number = new Uint8Array(digits); 5 | 6 | number[0] = 1; 7 | 8 | for (var i = 0; i < exp; i++) { 9 | 10 | var carry = 0; 11 | 12 | for (var j = 0; j <= order; j++) { 13 | 14 | var product = 2 * number[j] + carry; 15 | number[j] = product % 10; 16 | carry = product / 10 | 0; 17 | 18 | if (j === order && carry > 0) { 19 | order++; 20 | } 21 | } 22 | } 23 | return number.reduce((p, x) => x + p, 0); 24 | } 25 | console.log(solution(1000)); 26 | -------------------------------------------------------------------------------- /Euler-017.js: -------------------------------------------------------------------------------- 1 | var proper = [ 2 | 0, 3 | "one".length, 4 | "two".length, 5 | "three".length, 6 | "four".length, 7 | "five".length, 8 | "six".length, 9 | "seven".length, 10 | "eight".length, 11 | "nine".length, 12 | "ten".length, 13 | "eleven".length, 14 | "twelve".length, 15 | "thirteen".length, 16 | "fourteen".length, 17 | "fifteen".length, 18 | "sixteen".length, 19 | "seventeen".length, 20 | "eighteen".length, 21 | "nineteen".length 22 | ]; 23 | 24 | // tenth prefixes 25 | var tenth = [ 26 | "twenty".length, 27 | "thirty".length, 28 | "forty".length, 29 | "fifty".length, 30 | "sixty".length, 31 | "seventy".length, 32 | "eighty".length, 33 | "ninety".length 34 | ]; 35 | 36 | // Returns the length of the numbers between 0 and 99 37 | function below100(n) { 38 | 39 | if (n < 20) 40 | return proper[n]; 41 | 42 | return tenth[n / 10 - 2 | 0] + proper[n % 10]; 43 | } 44 | 45 | function numberLength(n) { 46 | if (n < 100) 47 | return below100(n); 48 | 49 | var res = 0; 50 | var h = Math.floor(n / 100) % 10; 51 | var t = Math.floor(n / 1000); 52 | var s = n % 100; 53 | 54 | if (n > 999) 55 | res+= below100(t) + "thousand".length; 56 | if (h !== 0) 57 | res+= proper[h] + "hundred".length; 58 | if (s !== 0) 59 | res+= "and".length + below100(s); 60 | return res; 61 | } 62 | 63 | function solution(n) { 64 | var num = 0; 65 | for (var i = 1; i <= n; i++) { 66 | num+= numberLength(i); 67 | } 68 | return num; 69 | } 70 | console.log(solution(1000)); 71 | -------------------------------------------------------------------------------- /Euler-018.js: -------------------------------------------------------------------------------- 1 | var triangle = [ 2 | [75], 3 | [95, 64], 4 | [17, 47, 82], 5 | [18, 35, 87, 10], 6 | [20, 04, 82, 47, 65], 7 | [19, 01, 23, 75, 03, 34], 8 | [88, 02, 77, 73, 07, 63, 67], 9 | [99, 65, 04, 28, 06, 16, 70, 92], 10 | [41, 41, 26, 56, 83, 40, 80, 70, 33], 11 | [41, 48, 72, 33, 47, 32, 37, 16, 94, 29], 12 | [53, 71, 44, 65, 25, 43, 91, 52, 97, 51, 14], 13 | [70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57], 14 | [91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48], 15 | [63, 66, 04, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31], 16 | [04, 62, 98, 27, 23, 09, 70, 98, 73, 93, 38, 53, 60, 04, 23], 17 | ]; 18 | 19 | function solution(t) { 20 | for (let i = t.length - 2; i >= 0; i--) 21 | for (let j = 0; j <= i; j++) 22 | t[i][j]+= Math.max(t[i + 1][j], t[i + 1][j + 1]); 23 | return triangle[0][0]; 24 | } 25 | console.log(solution(triangle)); 26 | -------------------------------------------------------------------------------- /Euler-019.js: -------------------------------------------------------------------------------- 1 | let yearid = 1900; 2 | let monthid = 1; 3 | let dayofmonth = 7; 4 | let sunonfirst = 0; 5 | 6 | function daysinmonth(year, month) { 7 | if ([4, 6, 9, 11].includes(month)) return 30; 8 | if (month == 2) { 9 | if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) return 29; 10 | else return 28; 11 | } 12 | return 31; 13 | } 14 | 15 | while (yearid <= 2000 && monthid <= 12 && dayofmonth <= 31) { 16 | const dim = daysinmonth(yearid, monthid); 17 | if (dayofmonth == 1 && yearid > 1900) sunonfirst += 1; 18 | dayofmonth += 7; 19 | if (dayofmonth > dim) { 20 | dayofmonth -= dim; 21 | monthid += 1; 22 | if (monthid == 13) { 23 | monthid = 1; 24 | yearid += 1; 25 | } 26 | 27 | } 28 | 29 | } 30 | console.log(sunonfirst); 31 | -------------------------------------------------------------------------------- /Euler-020.js: -------------------------------------------------------------------------------- 1 | let n = 100; 2 | let fact = BigInt(1); 3 | for(let i = 2; i <= n; i++) { 4 | fact *= BigInt(i); 5 | } 6 | let result = 0; 7 | for(let digit of fact.toString()) { 8 | result += parseInt(digit); 9 | } 10 | console.log(result); 11 | -------------------------------------------------------------------------------- /Euler-021.js: -------------------------------------------------------------------------------- 1 | function divisors(x) { 2 | let divisors = []; 3 | let d = 0; 4 | for (let i = 1; i <= Math.floor(Math.sqrt(x)); i++) { 5 | if (x % i == 0) { 6 | divisors[d] = i; 7 | if (i != x / i) { 8 | d += 1; 9 | divisors[d] = x / i; 10 | } 11 | d += 1; 12 | 13 | } 14 | 15 | } 16 | return divisors; 17 | } 18 | 19 | let answer = 0; 20 | let n = 220; 21 | while (n <= 10000) { 22 | let divSum = divisors(n).reduce((a, b) => a + b) - n; 23 | if (n == divisors(divSum).reduce((a, b) => a + b) - divSum && n != divSum) { 24 | answer += n; 25 | console.log(`(${n}, ${divSum})`); 26 | } 27 | n += 1; 28 | 29 | } 30 | console.log(answer); 31 | -------------------------------------------------------------------------------- /Euler-022.js: -------------------------------------------------------------------------------- 1 | const https = require('https'); 2 | 3 | https.get("https://projecteuler.net/project/resources/p022_names.txt", (res) => { 4 | let data = ''; 5 | 6 | res.on('data', (chunk) => { 7 | data += chunk; 8 | }); 9 | 10 | res.on('end', () => { 11 | let names = data.split(','); 12 | names = names.map(name => name.replace(/[^\w\s]|_/g, "").toUpperCase()).sort(); 13 | let answer = 0; 14 | for (let i = 0; i < names.length; i++) { 15 | let value = names[i].split('').reduce((sum, char) => sum + char.charCodeAt(0) - 64, 0); 16 | value *= (i + 1); 17 | answer += value; 18 | } 19 | console.log(answer); 20 | }); 21 | 22 | }).on("error", (err) => { 23 | console.log("Error: " + err.message); 24 | }); 25 | -------------------------------------------------------------------------------- /Euler-023.js: -------------------------------------------------------------------------------- 1 | function sieve(n) { 2 | let prime = [2, 3]; 3 | let i = 3; 4 | 5 | while (true) { 6 | i += 2; 7 | if (i * i > n) break; 8 | for (let j of prime) { 9 | if (j * j > i) { 10 | prime.push(i); 11 | break; 12 | } else if (i % j == 0) { 13 | break; 14 | } else if (j == prime[prime.length - 1]) { 15 | prime.push(i); 16 | break; 17 | } 18 | } 19 | } 20 | return prime; 21 | } 22 | function sumdiv(n) { 23 | let s = 1; 24 | for (let div = 2; div < n; div++) { 25 | if (div ** 2 > n) break; 26 | if (div ** 2 == n) return s + div; 27 | if (n % div == 0) { 28 | s += div; 29 | s += n / div; 30 | } 31 | } 32 | return s; 33 | } 34 | 35 | let primes = sieve(28123); 36 | let abundant = []; 37 | let ab_sums = []; 38 | for (let i = 12; i <= 28123 - 11; i++) { 39 | if (sumdiv(i) > i) abundant.push(i); 40 | } 41 | 42 | for (let ab1 = 0; ab1 < abundant.length; ab1++) { 43 | for (let ab2 = ab1; ab2 < abundant.length; ab2++) { 44 | let value = abundant[ab1] + abundant[ab2]; 45 | if (value > 28123) break; 46 | ab_sums.push(value); 47 | } 48 | } 49 | ab_sums = [...new Set(ab_sums)]; 50 | console.log(28123 * 28124 / 2 - ab_sums.reduce((a, b) => a + b, 0)); 51 | -------------------------------------------------------------------------------- /Euler-024.js: -------------------------------------------------------------------------------- 1 | function nextPerm(a) { 2 | let i = a.length; 3 | while (i > 1 && a[i - 2] >= a[i - 1]) i--; 4 | if (i <= 1) return null; 5 | let j = a.length; 6 | while (a[j - 1] <= a[i - 2]) j--; 7 | let temp = a[i - 2]; 8 | a[i - 2] = a[j - 1]; 9 | a[j - 1] = temp; 10 | let suffix = a.slice(i - 1); 11 | suffix.reverse(); 12 | a.splice(i - 1, a.length - i + 1, ...suffix); 13 | return a; 14 | } 15 | 16 | let numbers = [...Array(10).keys()]; 17 | for (let i = 1; i < 1000000; i++) { 18 | numbers = nextPerm(numbers); 19 | } 20 | let answer = numbers.join(""); 21 | console.log(answer); 22 | 23 | let n = 10; 24 | let remain = 999999; 25 | let numbers2 = [...Array(n).keys()]; 26 | let answer2 = Array(n); 27 | for (let i = 1; i <= n; i++) { 28 | let j = Math.floor(remain / factorial(n - i)); 29 | answer2[i - 1] = numbers2[j]; 30 | remain = remain % factorial(n - i); 31 | numbers2.splice(j, 1); 32 | } 33 | answer2 = answer2.join(""); 34 | console.log(answer2); 35 | 36 | function factorial(num) { 37 | if (num === 0 || num === 1) return 1; 38 | else return num * factorial(num - 1); 39 | } 40 | -------------------------------------------------------------------------------- /Euler-025.js: -------------------------------------------------------------------------------- 1 | function solution(n) { 2 | return Math.ceil(4.78497 * n - 3.1127); 3 | } 4 | 5 | console.log(solution(1000)); 6 | -------------------------------------------------------------------------------- /Euler-026.js: -------------------------------------------------------------------------------- 1 | function recur(x, output = "") { 2 | if (x == 0) return NaN; 3 | if (x == 1) return 0; 4 | x = Math.floor(Math.abs(x)); 5 | let dec = []; 6 | let rem = []; 7 | let i = 1; 8 | let r = 10; 9 | rem[0] = r; 10 | while (true) { 11 | dec[i] = Math.floor(r / x); 12 | r = 10 * (r % x); 13 | if (r == 0 || rem.indexOf(r) !== -1) break; 14 | rem[i] = r; 15 | i++; 16 | } 17 | let rep = r != 0 ? rem.length - rem.indexOf(r) + 1 : 0; 18 | if (output == "len") { 19 | return rep; 20 | } else { 21 | if (rep != 0) { 22 | let l = rep == dec.length ? "(" : dec.slice(0, dec.length - rep).concat("("); 23 | dec = l.concat(dec.slice(dec.length - rep, dec.length), ")"); 24 | } 25 | return "0." + dec.join(""); 26 | } 27 | } 28 | let A051626 = Array.from({length: 1000}, (_, i) => recur(i + 1, "len")); 29 | let answer = A051626.indexOf(Math.max(...A051626)) + 1; 30 | console.log(answer); 31 | -------------------------------------------------------------------------------- /Euler-027.js: -------------------------------------------------------------------------------- 1 | let start_time = Date.now(); 2 | 3 | function sieve(n, prime) { 4 | let i = prime[prime.length - 1]; 5 | while (prime[prime.length - 1] < n) { 6 | i += 2; 7 | if (i > n) break; 8 | let isPrime = true; 9 | for (let j of prime) { 10 | if (j * j > i) { 11 | prime.push(i); 12 | break; 13 | } else if (i % j == 0) { 14 | isPrime = false; 15 | break; 16 | } 17 | } 18 | if (isPrime) prime.push(i); 19 | } 20 | return 0; 21 | } 22 | 23 | function inprimes(n, a, b, primes) { 24 | let test = n * n + a * n + b; 25 | if (test > primes[primes.length - 1]) sieve(test, primes); 26 | return primes.includes(test); 27 | } 28 | 29 | let primes = [2, 3]; 30 | sieve(1000, primes); 31 | let maxconsec = 0; 32 | let maxprod = 0; 33 | 34 | for (let a = -999; a <= 999; a++) { 35 | for (let b of primes.filter(p => p < 1000)) { 36 | let n = 1; 37 | let consec = 1; 38 | while (inprimes(n, a, b, primes)) { 39 | consec++; 40 | n++; 41 | } 42 | if (consec > maxconsec) { 43 | maxconsec = consec; 44 | maxprod = a * b; 45 | } 46 | } 47 | } 48 | console.log(maxprod); 49 | 50 | console.log(`--- ${Date.now() - start_time} milliseconds ---`); 51 | -------------------------------------------------------------------------------- /Euler-028.js: -------------------------------------------------------------------------------- 1 | function solution(n) { 2 | return (n * (n * (4 * n + 3) + 8) - 9) / 6; 3 | } 4 | 5 | console.log(solution(1001)); 6 | -------------------------------------------------------------------------------- /Euler-029.js: -------------------------------------------------------------------------------- 1 | console.time('timer'); 2 | 3 | // Initialisation 4 | const target = 100; 5 | const terms = []; 6 | let i = 0; 7 | 8 | // Loop through values of a and b and store powers in vector 9 | for (let a = 2; a <= target; a++) { 10 | for (let b = 2; b <= target; b++) { 11 | terms[i] = Math.pow(a, b); 12 | i++; 13 | } 14 | } 15 | 16 | // Determine the number of distinct powers 17 | const answer = [...new Set(terms)].length; 18 | console.log(answer); 19 | console.timeEnd('timer'); 20 | 21 | 22 | console.time('timer'); 23 | const answer2 = [...new Set([...Array(99)].map((_, i) => { 24 | return [...Array(99)].map((_, j) => { 25 | return Math.pow(i + 2, j + 2); 26 | }); 27 | }).flat())].length; 28 | 29 | console.log(answer2); 30 | console.timeEnd('timer'); 31 | -------------------------------------------------------------------------------- /Euler-030.js: -------------------------------------------------------------------------------- 1 | function build_number(a) { 2 | let output = 0; 3 | let zeros = 0; 4 | for (let i = 0; i < a.length; i++) { 5 | const digit = a[i]; 6 | if (digit === 0) zeros += 1; 7 | else if (digit > -1) { 8 | output *= 10; 9 | output += digit; 10 | } 11 | } 12 | return output * 10 ** zeros; 13 | } 14 | 15 | function increase_array(a) { 16 | let d = 1; 17 | for (d = 1; d <= a.length; d++) { 18 | if (a[a.length - d] < 9) { 19 | if (a[a.length - d] === -1) a[a.length - d] = 0; 20 | else a[a.length - d] += 1; 21 | break; 22 | } 23 | } 24 | for (let i = 1; i < d; i++) { 25 | a[a.length - (d - i)] = a[a.length - d]; 26 | } 27 | return 0; 28 | } 29 | 30 | function compare(n1, n2) { 31 | if (n1.toString().split('').sort().join() === n2.toString().split('').sort().join()) { 32 | return true; 33 | } 34 | return false; 35 | } 36 | 37 | function sumpow(a) { 38 | let s = 0; 39 | for (let i = 0; i < a.length; i++) { 40 | const digit = a[i]; 41 | if (digit === -1) continue; 42 | s += digit ** 5; 43 | } 44 | return s; 45 | } 46 | 47 | let s = 0; 48 | const numbers = [-1, -1, -1, -1, -1, 2]; 49 | while (!numbers.every((digit, i) => digit === [2, 3, 4, 4, 5, 9][i])) { 50 | increase_array(numbers); 51 | if (compare(build_number(numbers), sumpow(numbers))) { 52 | s += sumpow(numbers); 53 | } 54 | } 55 | console.log(s); 56 | -------------------------------------------------------------------------------- /Euler-031.js: -------------------------------------------------------------------------------- 1 | // the total and available coins 2 | let total = 200; 3 | let coins = [1, 2, 5, 10, 20, 50, 100, 200]; 4 | 5 | // implement the coin change algorithm 6 | function count(n, m) { 7 | if (n === 0) { 8 | return 1; 9 | } else if (n < 0) { 10 | return 0; 11 | } else if (m <= 0 && n >= 1) { 12 | return 0; 13 | } else { 14 | return count(n, m - 1) + count(n - coins[m - 1], m); 15 | } 16 | } 17 | 18 | let answer = count(total, coins.length); 19 | 20 | console.log(answer); 21 | -------------------------------------------------------------------------------- /Euler-032.js: -------------------------------------------------------------------------------- 1 | class EulerSolution { 2 | run() {} 3 | } 4 | 5 | class P032 extends EulerSolution { 6 | run() { 7 | let sum = 0; 8 | for (let i = 1; i < 10000; i++) { 9 | if (this.hasPandigitalProduct(i)) { 10 | sum += i; 11 | } 12 | } 13 | return sum.toString(); 14 | } 15 | 16 | hasPandigitalProduct(n) { 17 | // Find and examine all factors of n 18 | for (let i = 1; i <= n; i++) { 19 | if (n % i === 0 && this.isPandigital("" + n + i + n / i)) { 20 | return true; 21 | } 22 | } 23 | return false; 24 | } 25 | 26 | isPandigital(s) { 27 | if (s.length !== 9) { 28 | return false; 29 | } 30 | const temp = s.split("").sort(); 31 | return temp.join("") === "123456789"; 32 | } 33 | } 34 | 35 | console.log(new P032().run()); 36 | -------------------------------------------------------------------------------- /Euler-033.js: -------------------------------------------------------------------------------- 1 | function compute() { 2 | let numer = 1; 3 | let denom = 1; 4 | for (let d = 10; d < 100; d++) { 5 | for (let n = 10; n < d; n++) { 6 | let n0 = n % 10; 7 | let n1 = Math.floor(n / 10); 8 | let d0 = d % 10; 9 | let d1 = Math.floor(d / 10); 10 | if ((n1 === d0 && n0 * d === n * d1) || (n0 === d1 && n1 * d === n * d0)) { 11 | numer *= n; 12 | denom *= d; 13 | } 14 | } 15 | } 16 | 17 | return String(Math.floor(denom / gcd(numer, denom))); 18 | } 19 | 20 | function gcd(a, b) { 21 | if (b === 0) return a; 22 | return gcd(b, a % b); 23 | } 24 | 25 | console.log(compute()); 26 | -------------------------------------------------------------------------------- /Euler-034.js: -------------------------------------------------------------------------------- 1 | function compute() { 2 | const factorials = [1]; 3 | for (let i = 1; i <= 9; i++) { 4 | factorials.push(factorials[i - 1] * i); 5 | } 6 | let sum = 0; 7 | for (let n = 10; n < 1000000; n++) { 8 | let digitFactorialSum = 0; 9 | let x = n; 10 | while (x > 0) { 11 | digitFactorialSum += factorials[x % 10]; 12 | x = Math.floor(x / 10); 13 | } 14 | if (digitFactorialSum === n) { 15 | sum += n; 16 | } 17 | } 18 | return sum; 19 | } 20 | console.log(compute()); 21 | -------------------------------------------------------------------------------- /Euler-035.js: -------------------------------------------------------------------------------- 1 | function isPrime(num) { 2 | if (num < 2) { 3 | return false; 4 | } 5 | for (let i = 2; i <= Math.sqrt(num); i++) { 6 | if (num % i === 0) { 7 | return false; 8 | } 9 | } 10 | return true; 11 | } 12 | 13 | function getCircularPermutations(num) { 14 | const digits = num.toString().split(''); 15 | const result = []; 16 | for (let i = 0; i < digits.length; i++) { 17 | const permutation = parseInt(digits.slice(i).concat(digits.slice(0, i)).join('')); 18 | result.push(permutation); 19 | } 20 | return result; 21 | } 22 | 23 | function countCircularPrimesBelow(limit) { 24 | let count = 0; 25 | for (let i = 2; i < limit; i++) { 26 | const circularPermutations = getCircularPermutations(i); 27 | const isCircularPrime = circularPermutations.every(num => isPrime(num)); 28 | if (isCircularPrime) { 29 | count++; 30 | } 31 | } 32 | return count; 33 | } 34 | 35 | console.log(countCircularPrimesBelow(1000000)); 36 | -------------------------------------------------------------------------------- /Euler-036.js: -------------------------------------------------------------------------------- 1 | function isPalindrome(num, base) { 2 | var numString = num.toString(base); 3 | return numString === numString.split("").reverse().join(""); 4 | } 5 | var sum = 0; 6 | for (var i = 1; i < 1000000; i++) { 7 | if (isPalindrome(i, 10) && isPalindrome(i, 2)) { 8 | sum += i; 9 | } 10 | } 11 | console.log(sum); 12 | -------------------------------------------------------------------------------- /Euler-037.js: -------------------------------------------------------------------------------- 1 | function isPrime(num) { 2 | if (num < 2) { 3 | return false; 4 | } 5 | for (let i = 2; i <= Math.sqrt(num); i++) { 6 | if (num % i === 0) { 7 | return false; 8 | } 9 | } 10 | return true; 11 | } 12 | 13 | function isTruncatablePrime(num) { 14 | let digits = num.toString().split(''); 15 | for (let i = 1; i < digits.length; i++) { 16 | let leftTruncation = parseInt(digits.slice(i).join('')); 17 | let rightTruncation = parseInt(digits.slice(0, digits.length - i).join('')); 18 | if (!isPrime(leftTruncation) || !isPrime(rightTruncation)) { 19 | return false; 20 | } 21 | } 22 | return true; 23 | } 24 | 25 | let sum = 0; 26 | let count = 0; 27 | let num = 11; 28 | while (count < 11) { 29 | if (isPrime(num) && isTruncatablePrime(num)) { 30 | sum += num; 31 | count++; 32 | } 33 | num++; 34 | } 35 | console.log(sum); 36 | -------------------------------------------------------------------------------- /Euler-038.js: -------------------------------------------------------------------------------- 1 | function isPandigital(num) { 2 | const digits = num.toString().split(''); 3 | return digits.length === 9 && !digits.includes('0') && new Set(digits).size === 9; 4 | } 5 | function largestPandigitalConcatenatedProduct() { 6 | let largestPandigital = 0; 7 | for (let i = 1; i <= 9876; i++) { 8 | let concatenatedProduct = ''; 9 | for (let n = 1; ; n++) { 10 | concatenatedProduct += (i * n).toString(); 11 | if (concatenatedProduct.length > 9) break; 12 | if (concatenatedProduct.length === 9 && isPandigital(concatenatedProduct)) { 13 | largestPandigital = Math.max(largestPandigital, parseInt(concatenatedProduct)); 14 | } 15 | } 16 | } 17 | return largestPandigital; 18 | } 19 | 20 | console.log(largestPandigitalConcatenatedProduct()); 21 | -------------------------------------------------------------------------------- /Euler-039.js: -------------------------------------------------------------------------------- 1 | let maxSolutions = 0; 2 | let maxP = 0; 3 | for (let p = 1; p <= 1000; p++) { 4 | let solutions = 0; 5 | for (let a = 1; a < p/2; a++) { 6 | for (let b = a; b < p/2; b++) { 7 | const c = p - a - b; 8 | if (a*a + b*b === c*c) { 9 | solutions++; 10 | } 11 | } 12 | } 13 | 14 | if (solutions > maxSolutions) { 15 | maxSolutions = solutions; 16 | maxP = p; 17 | } 18 | } 19 | 20 | console.log(maxP); 21 | -------------------------------------------------------------------------------- /Euler-040.js: -------------------------------------------------------------------------------- 1 | function irrationalFraction(digits) { 2 | let num = ''; 3 | let i = 1; 4 | while (num.length < digits) { 5 | num += i.toString(); 6 | i++; 7 | } 8 | return num; 9 | } 10 | const fraction = irrationalFraction(1000000); 11 | const d1 = parseInt(fraction.charAt(0)); 12 | const d10 = parseInt(fraction.charAt(9)); 13 | const d100 = parseInt(fraction.charAt(99)); 14 | const d1000 = parseInt(fraction.charAt(999)); 15 | const d10000 = parseInt(fraction.charAt(9999)); 16 | const d100000 = parseInt(fraction.charAt(99999)); 17 | const d1000000 = parseInt(fraction.charAt(999999)); 18 | const result = d1 * d10 * d100 * d1000 * d10000 * d100000 * d1000000; 19 | 20 | console.log(result); 21 | -------------------------------------------------------------------------------- /Euler-041.js: -------------------------------------------------------------------------------- 1 | function isPandigital(n) { 2 | let digits = 0; 3 | let count = 0; 4 | while (n > 0) { 5 | let tmp = digits; 6 | digits = digits | 1 << ((n % 10) - 1); 7 | if (tmp == digits) { 8 | return false; 9 | } 10 | count++; 11 | n = Math.floor(n / 10); 12 | } 13 | return digits == (1 << count) - 1; 14 | } 15 | 16 | function isPrime(n) { 17 | if (n <= 1) { 18 | return false; 19 | } 20 | if (n <= 3) { 21 | return true; 22 | } 23 | if (n % 2 == 0 || n % 3 == 0) { 24 | return false; 25 | } 26 | for (let i = 5; i * i <= n; i += 6) { 27 | if (n % i == 0 || n % (i + 2) == 0) { 28 | return false; 29 | } 30 | } 31 | return true; 32 | } 33 | 34 | function largestPandigitalPrime() { 35 | let largest = 0; 36 | for (let n = 7654321; n >= 1234567; n -= 2) { 37 | if (isPandigital(n) && isPrime(n)) { 38 | largest = n; 39 | break; 40 | } 41 | } 42 | return largest; 43 | } 44 | 45 | console.log(largestPandigitalPrime()); 46 | -------------------------------------------------------------------------------- /Euler-042.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | 3 | const mp = new Map(); 4 | function triangle() { 5 | for (let i = 1; i < 10000; i++) { 6 | mp.set(i * (i + 1) / 2, 1); 7 | } 8 | } 9 | 10 | triangle(); 11 | 12 | const fileContent = fs.readFileSync('words.txt', 'utf8'); 13 | const words = fileContent.split(','); 14 | 15 | const name = []; 16 | let tm = ''; 17 | for (let i = 0; i < words.length; i++) { 18 | const word = words[i].replace(/"/g, ''); 19 | name.push(word); 20 | } 21 | 22 | let ans = 0; 23 | for (let i = 0; i < name.length; i++) { 24 | let sum = 0; 25 | for (let j = 0; j < name[i].length; j++) { 26 | sum += name[i].charCodeAt(j) - 64; 27 | } 28 | if (mp.has(sum)) { 29 | ans++; 30 | } 31 | } 32 | 33 | console.log(ans); 34 | 35 | 36 | 37 | 38 | 39 | 40 | /* 41 | 42 | words.txt ::=> 43 | 44 | "A","ABILITY","ABLE","ABOUT","ABOVE","ABSENCE","ABSOLUTELY","ACADEMIC","ACCEPT","ACCESS","ACCIDENT","ACCOMPANY","ACCORDING","ACCOUNT","ACHIEVE","ACHIEVEMENT","ACID","ACQUIRE","ACROSS","ACT","ACTION","ACTIVE","ACTIVITY","ACTUAL","ACTUALLY","ADD","ADDITION","ADDITIONAL","ADDRESS","ADMINISTRATION","ADMIT","ADOPT","ADULT","ADVANCE","ADVANTAGE","ADVICE","ADVISE","AFFAIR","AFFECT","AFFORD","AFRAID","AFTER","AFTERNOON","AFTERWARDS","AGAIN","AGAINST","AGE","AGENCY","AGENT","AGO","AGREE","AGREEMENT","AHEAD","AID","AIM","AIR","AIRCRAFT","ALL","ALLOW","ALMOST","ALONE","ALONG","ALREADY","ALRIGHT","ALSO","ALTERNATIVE","ALTHOUGH","ALWAYS","AMONG","AMONGST","AMOUNT","AN","ANALYSIS","ANCIENT","AND","ANIMAL","ANNOUNCE","ANNUAL","ANOTHER","ANSWER","ANY","ANYBODY","ANYONE","ANYTHING","ANYWAY","APART","APPARENT","APPARENTLY","APPEAL","APPEAR","APPEARANCE","APPLICATION","APPLY","APPOINT","APPOINTMENT","APPROACH","APPROPRIATE","APPROVE","AREA","ARGUE","ARGUMENT","ARISE","ARM","ARMY","AROUND","ARRANGE","ARRANGEMENT","ARRIVE","ART","ARTICLE","ARTIST","AS","ASK","ASPECT","ASSEMBLY","ASSESS","ASSESSMENT","ASSET","ASSOCIATE","ASSOCIATION","ASSUME","ASSUMPTION","AT","ATMOSPHERE","ATTACH","ATTACK","ATTEMPT","ATTEND","ATTENTION","ATTITUDE","ATTRACT","ATTRACTIVE","AUDIENCE","AUTHOR","AUTHORITY","AVAILABLE","AVERAGE","AVOID","AWARD","AWARE","AWAY","AYE","BABY","BACK","BACKGROUND","BAD","BAG","BALANCE","BALL","BAND","BANK","BAR","BASE","BASIC","BASIS","BATTLE","BE","BEAR","BEAT","BEAUTIFUL","BECAUSE","BECOME","BED","BEDROOM","BEFORE","BEGIN","BEGINNING","BEHAVIOUR","BEHIND","BELIEF","BELIEVE","BELONG","BELOW","BENEATH","BENEFIT","BESIDE","BEST","BETTER","BETWEEN","BEYOND","BIG","BILL","BIND","BIRD","BIRTH","BIT","BLACK","BLOCK","BLOOD","BLOODY","BLOW","BLUE","BOARD","BOAT","BODY","BONE","BOOK","BORDER","BOTH","BOTTLE","BOTTOM","BOX","BOY","BRAIN","BRANCH","BREAK","BREATH","BRIDGE","BRIEF","BRIGHT","BRING","BROAD","BROTHER","BUDGET","BUILD","BUILDING","BURN","BUS","BUSINESS","BUSY","BUT","BUY","BY","CABINET","CALL","CAMPAIGN","CAN","CANDIDATE","CAPABLE","CAPACITY","CAPITAL","CAR","CARD","CARE","CAREER","CAREFUL","CAREFULLY","CARRY","CASE","CASH","CAT","CATCH","CATEGORY","CAUSE","CELL","CENTRAL","CENTRE","CENTURY","CERTAIN","CERTAINLY","CHAIN","CHAIR","CHAIRMAN","CHALLENGE","CHANCE","CHANGE","CHANNEL","CHAPTER","CHARACTER","CHARACTERISTIC","CHARGE","CHEAP","CHECK","CHEMICAL","CHIEF","CHILD","CHOICE","CHOOSE","CHURCH","CIRCLE","CIRCUMSTANCE","CITIZEN","CITY","CIVIL","CLAIM","CLASS","CLEAN","CLEAR","CLEARLY","CLIENT","CLIMB","CLOSE","CLOSELY","CLOTHES","CLUB","COAL","CODE","COFFEE","COLD","COLLEAGUE","COLLECT","COLLECTION","COLLEGE","COLOUR","COMBINATION","COMBINE","COME","COMMENT","COMMERCIAL","COMMISSION","COMMIT","COMMITMENT","COMMITTEE","COMMON","COMMUNICATION","COMMUNITY","COMPANY","COMPARE","COMPARISON","COMPETITION","COMPLETE","COMPLETELY","COMPLEX","COMPONENT","COMPUTER","CONCENTRATE","CONCENTRATION","CONCEPT","CONCERN","CONCERNED","CONCLUDE","CONCLUSION","CONDITION","CONDUCT","CONFERENCE","CONFIDENCE","CONFIRM","CONFLICT","CONGRESS","CONNECT","CONNECTION","CONSEQUENCE","CONSERVATIVE","CONSIDER","CONSIDERABLE","CONSIDERATION","CONSIST","CONSTANT","CONSTRUCTION","CONSUMER","CONTACT","CONTAIN","CONTENT","CONTEXT","CONTINUE","CONTRACT","CONTRAST","CONTRIBUTE","CONTRIBUTION","CONTROL","CONVENTION","CONVERSATION","COPY","CORNER","CORPORATE","CORRECT","COS","COST","COULD","COUNCIL","COUNT","COUNTRY","COUNTY","COUPLE","COURSE","COURT","COVER","CREATE","CREATION","CREDIT","CRIME","CRIMINAL","CRISIS","CRITERION","CRITICAL","CRITICISM","CROSS","CROWD","CRY","CULTURAL","CULTURE","CUP","CURRENT","CURRENTLY","CURRICULUM","CUSTOMER","CUT","DAMAGE","DANGER","DANGEROUS","DARK","DATA","DATE","DAUGHTER","DAY","DEAD","DEAL","DEATH","DEBATE","DEBT","DECADE","DECIDE","DECISION","DECLARE","DEEP","DEFENCE","DEFENDANT","DEFINE","DEFINITION","DEGREE","DELIVER","DEMAND","DEMOCRATIC","DEMONSTRATE","DENY","DEPARTMENT","DEPEND","DEPUTY","DERIVE","DESCRIBE","DESCRIPTION","DESIGN","DESIRE","DESK","DESPITE","DESTROY","DETAIL","DETAILED","DETERMINE","DEVELOP","DEVELOPMENT","DEVICE","DIE","DIFFERENCE","DIFFERENT","DIFFICULT","DIFFICULTY","DINNER","DIRECT","DIRECTION","DIRECTLY","DIRECTOR","DISAPPEAR","DISCIPLINE","DISCOVER","DISCUSS","DISCUSSION","DISEASE","DISPLAY","DISTANCE","DISTINCTION","DISTRIBUTION","DISTRICT","DIVIDE","DIVISION","DO","DOCTOR","DOCUMENT","DOG","DOMESTIC","DOOR","DOUBLE","DOUBT","DOWN","DRAW","DRAWING","DREAM","DRESS","DRINK","DRIVE","DRIVER","DROP","DRUG","DRY","DUE","DURING","DUTY","EACH","EAR","EARLY","EARN","EARTH","EASILY","EAST","EASY","EAT","ECONOMIC","ECONOMY","EDGE","EDITOR","EDUCATION","EDUCATIONAL","EFFECT","EFFECTIVE","EFFECTIVELY","EFFORT","EGG","EITHER","ELDERLY","ELECTION","ELEMENT","ELSE","ELSEWHERE","EMERGE","EMPHASIS","EMPLOY","EMPLOYEE","EMPLOYER","EMPLOYMENT","EMPTY","ENABLE","ENCOURAGE","END","ENEMY","ENERGY","ENGINE","ENGINEERING","ENJOY","ENOUGH","ENSURE","ENTER","ENTERPRISE","ENTIRE","ENTIRELY","ENTITLE","ENTRY","ENVIRONMENT","ENVIRONMENTAL","EQUAL","EQUALLY","EQUIPMENT","ERROR","ESCAPE","ESPECIALLY","ESSENTIAL","ESTABLISH","ESTABLISHMENT","ESTATE","ESTIMATE","EVEN","EVENING","EVENT","EVENTUALLY","EVER","EVERY","EVERYBODY","EVERYONE","EVERYTHING","EVIDENCE","EXACTLY","EXAMINATION","EXAMINE","EXAMPLE","EXCELLENT","EXCEPT","EXCHANGE","EXECUTIVE","EXERCISE","EXHIBITION","EXIST","EXISTENCE","EXISTING","EXPECT","EXPECTATION","EXPENDITURE","EXPENSE","EXPENSIVE","EXPERIENCE","EXPERIMENT","EXPERT","EXPLAIN","EXPLANATION","EXPLORE","EXPRESS","EXPRESSION","EXTEND","EXTENT","EXTERNAL","EXTRA","EXTREMELY","EYE","FACE","FACILITY","FACT","FACTOR","FACTORY","FAIL","FAILURE","FAIR","FAIRLY","FAITH","FALL","FAMILIAR","FAMILY","FAMOUS","FAR","FARM","FARMER","FASHION","FAST","FATHER","FAVOUR","FEAR","FEATURE","FEE","FEEL","FEELING","FEMALE","FEW","FIELD","FIGHT","FIGURE","FILE","FILL","FILM","FINAL","FINALLY","FINANCE","FINANCIAL","FIND","FINDING","FINE","FINGER","FINISH","FIRE","FIRM","FIRST","FISH","FIT","FIX","FLAT","FLIGHT","FLOOR","FLOW","FLOWER","FLY","FOCUS","FOLLOW","FOLLOWING","FOOD","FOOT","FOOTBALL","FOR","FORCE","FOREIGN","FOREST","FORGET","FORM","FORMAL","FORMER","FORWARD","FOUNDATION","FREE","FREEDOM","FREQUENTLY","FRESH","FRIEND","FROM","FRONT","FRUIT","FUEL","FULL","FULLY","FUNCTION","FUND","FUNNY","FURTHER","FUTURE","GAIN","GAME","GARDEN","GAS","GATE","GATHER","GENERAL","GENERALLY","GENERATE","GENERATION","GENTLEMAN","GET","GIRL","GIVE","GLASS","GO","GOAL","GOD","GOLD","GOOD","GOVERNMENT","GRANT","GREAT","GREEN","GREY","GROUND","GROUP","GROW","GROWING","GROWTH","GUEST","GUIDE","GUN","HAIR","HALF","HALL","HAND","HANDLE","HANG","HAPPEN","HAPPY","HARD","HARDLY","HATE","HAVE","HE","HEAD","HEALTH","HEAR","HEART","HEAT","HEAVY","HELL","HELP","HENCE","HER","HERE","HERSELF","HIDE","HIGH","HIGHLY","HILL","HIM","HIMSELF","HIS","HISTORICAL","HISTORY","HIT","HOLD","HOLE","HOLIDAY","HOME","HOPE","HORSE","HOSPITAL","HOT","HOTEL","HOUR","HOUSE","HOUSEHOLD","HOUSING","HOW","HOWEVER","HUGE","HUMAN","HURT","HUSBAND","I","IDEA","IDENTIFY","IF","IGNORE","ILLUSTRATE","IMAGE","IMAGINE","IMMEDIATE","IMMEDIATELY","IMPACT","IMPLICATION","IMPLY","IMPORTANCE","IMPORTANT","IMPOSE","IMPOSSIBLE","IMPRESSION","IMPROVE","IMPROVEMENT","IN","INCIDENT","INCLUDE","INCLUDING","INCOME","INCREASE","INCREASED","INCREASINGLY","INDEED","INDEPENDENT","INDEX","INDICATE","INDIVIDUAL","INDUSTRIAL","INDUSTRY","INFLUENCE","INFORM","INFORMATION","INITIAL","INITIATIVE","INJURY","INSIDE","INSIST","INSTANCE","INSTEAD","INSTITUTE","INSTITUTION","INSTRUCTION","INSTRUMENT","INSURANCE","INTEND","INTENTION","INTEREST","INTERESTED","INTERESTING","INTERNAL","INTERNATIONAL","INTERPRETATION","INTERVIEW","INTO","INTRODUCE","INTRODUCTION","INVESTIGATE","INVESTIGATION","INVESTMENT","INVITE","INVOLVE","IRON","IS","ISLAND","ISSUE","IT","ITEM","ITS","ITSELF","JOB","JOIN","JOINT","JOURNEY","JUDGE","JUMP","JUST","JUSTICE","KEEP","KEY","KID","KILL","KIND","KING","KITCHEN","KNEE","KNOW","KNOWLEDGE","LABOUR","LACK","LADY","LAND","LANGUAGE","LARGE","LARGELY","LAST","LATE","LATER","LATTER","LAUGH","LAUNCH","LAW","LAWYER","LAY","LEAD","LEADER","LEADERSHIP","LEADING","LEAF","LEAGUE","LEAN","LEARN","LEAST","LEAVE","LEFT","LEG","LEGAL","LEGISLATION","LENGTH","LESS","LET","LETTER","LEVEL","LIABILITY","LIBERAL","LIBRARY","LIE","LIFE","LIFT","LIGHT","LIKE","LIKELY","LIMIT","LIMITED","LINE","LINK","LIP","LIST","LISTEN","LITERATURE","LITTLE","LIVE","LIVING","LOAN","LOCAL","LOCATION","LONG","LOOK","LORD","LOSE","LOSS","LOT","LOVE","LOVELY","LOW","LUNCH","MACHINE","MAGAZINE","MAIN","MAINLY","MAINTAIN","MAJOR","MAJORITY","MAKE","MALE","MAN","MANAGE","MANAGEMENT","MANAGER","MANNER","MANY","MAP","MARK","MARKET","MARRIAGE","MARRIED","MARRY","MASS","MASTER","MATCH","MATERIAL","MATTER","MAY","MAYBE","ME","MEAL","MEAN","MEANING","MEANS","MEANWHILE","MEASURE","MECHANISM","MEDIA","MEDICAL","MEET","MEETING","MEMBER","MEMBERSHIP","MEMORY","MENTAL","MENTION","MERELY","MESSAGE","METAL","METHOD","MIDDLE","MIGHT","MILE","MILITARY","MILK","MIND","MINE","MINISTER","MINISTRY","MINUTE","MISS","MISTAKE","MODEL","MODERN","MODULE","MOMENT","MONEY","MONTH","MORE","MORNING","MOST","MOTHER","MOTION","MOTOR","MOUNTAIN","MOUTH","MOVE","MOVEMENT","MUCH","MURDER","MUSEUM","MUSIC","MUST","MY","MYSELF","NAME","NARROW","NATION","NATIONAL","NATURAL","NATURE","NEAR","NEARLY","NECESSARILY","NECESSARY","NECK","NEED","NEGOTIATION","NEIGHBOUR","NEITHER","NETWORK","NEVER","NEVERTHELESS","NEW","NEWS","NEWSPAPER","NEXT","NICE","NIGHT","NO","NOBODY","NOD","NOISE","NONE","NOR","NORMAL","NORMALLY","NORTH","NORTHERN","NOSE","NOT","NOTE","NOTHING","NOTICE","NOTION","NOW","NUCLEAR","NUMBER","NURSE","OBJECT","OBJECTIVE","OBSERVATION","OBSERVE","OBTAIN","OBVIOUS","OBVIOUSLY","OCCASION","OCCUR","ODD","OF","OFF","OFFENCE","OFFER","OFFICE","OFFICER","OFFICIAL","OFTEN","OIL","OKAY","OLD","ON","ONCE","ONE","ONLY","ONTO","OPEN","OPERATE","OPERATION","OPINION","OPPORTUNITY","OPPOSITION","OPTION","OR","ORDER","ORDINARY","ORGANISATION","ORGANISE","ORGANIZATION","ORIGIN","ORIGINAL","OTHER","OTHERWISE","OUGHT","OUR","OURSELVES","OUT","OUTCOME","OUTPUT","OUTSIDE","OVER","OVERALL","OWN","OWNER","PACKAGE","PAGE","PAIN","PAINT","PAINTING","PAIR","PANEL","PAPER","PARENT","PARK","PARLIAMENT","PART","PARTICULAR","PARTICULARLY","PARTLY","PARTNER","PARTY","PASS","PASSAGE","PAST","PATH","PATIENT","PATTERN","PAY","PAYMENT","PEACE","PENSION","PEOPLE","PER","PERCENT","PERFECT","PERFORM","PERFORMANCE","PERHAPS","PERIOD","PERMANENT","PERSON","PERSONAL","PERSUADE","PHASE","PHONE","PHOTOGRAPH","PHYSICAL","PICK","PICTURE","PIECE","PLACE","PLAN","PLANNING","PLANT","PLASTIC","PLATE","PLAY","PLAYER","PLEASE","PLEASURE","PLENTY","PLUS","POCKET","POINT","POLICE","POLICY","POLITICAL","POLITICS","POOL","POOR","POPULAR","POPULATION","POSITION","POSITIVE","POSSIBILITY","POSSIBLE","POSSIBLY","POST","POTENTIAL","POUND","POWER","POWERFUL","PRACTICAL","PRACTICE","PREFER","PREPARE","PRESENCE","PRESENT","PRESIDENT","PRESS","PRESSURE","PRETTY","PREVENT","PREVIOUS","PREVIOUSLY","PRICE","PRIMARY","PRIME","PRINCIPLE","PRIORITY","PRISON","PRISONER","PRIVATE","PROBABLY","PROBLEM","PROCEDURE","PROCESS","PRODUCE","PRODUCT","PRODUCTION","PROFESSIONAL","PROFIT","PROGRAM","PROGRAMME","PROGRESS","PROJECT","PROMISE","PROMOTE","PROPER","PROPERLY","PROPERTY","PROPORTION","PROPOSE","PROPOSAL","PROSPECT","PROTECT","PROTECTION","PROVE","PROVIDE","PROVIDED","PROVISION","PUB","PUBLIC","PUBLICATION","PUBLISH","PULL","PUPIL","PURPOSE","PUSH","PUT","QUALITY","QUARTER","QUESTION","QUICK","QUICKLY","QUIET","QUITE","RACE","RADIO","RAILWAY","RAIN","RAISE","RANGE","RAPIDLY","RARE","RATE","RATHER","REACH","REACTION","READ","READER","READING","READY","REAL","REALISE","REALITY","REALIZE","REALLY","REASON","REASONABLE","RECALL","RECEIVE","RECENT","RECENTLY","RECOGNISE","RECOGNITION","RECOGNIZE","RECOMMEND","RECORD","RECOVER","RED","REDUCE","REDUCTION","REFER","REFERENCE","REFLECT","REFORM","REFUSE","REGARD","REGION","REGIONAL","REGULAR","REGULATION","REJECT","RELATE","RELATION","RELATIONSHIP","RELATIVE","RELATIVELY","RELEASE","RELEVANT","RELIEF","RELIGION","RELIGIOUS","RELY","REMAIN","REMEMBER","REMIND","REMOVE","REPEAT","REPLACE","REPLY","REPORT","REPRESENT","REPRESENTATION","REPRESENTATIVE","REQUEST","REQUIRE","REQUIREMENT","RESEARCH","RESOURCE","RESPECT","RESPOND","RESPONSE","RESPONSIBILITY","RESPONSIBLE","REST","RESTAURANT","RESULT","RETAIN","RETURN","REVEAL","REVENUE","REVIEW","REVOLUTION","RICH","RIDE","RIGHT","RING","RISE","RISK","RIVER","ROAD","ROCK","ROLE","ROLL","ROOF","ROOM","ROUND","ROUTE","ROW","ROYAL","RULE","RUN","RURAL","SAFE","SAFETY","SALE","SAME","SAMPLE","SATISFY","SAVE","SAY","SCALE","SCENE","SCHEME","SCHOOL","SCIENCE","SCIENTIFIC","SCIENTIST","SCORE","SCREEN","SEA","SEARCH","SEASON","SEAT","SECOND","SECONDARY","SECRETARY","SECTION","SECTOR","SECURE","SECURITY","SEE","SEEK","SEEM","SELECT","SELECTION","SELL","SEND","SENIOR","SENSE","SENTENCE","SEPARATE","SEQUENCE","SERIES","SERIOUS","SERIOUSLY","SERVANT","SERVE","SERVICE","SESSION","SET","SETTLE","SETTLEMENT","SEVERAL","SEVERE","SEX","SEXUAL","SHAKE","SHALL","SHAPE","SHARE","SHE","SHEET","SHIP","SHOE","SHOOT","SHOP","SHORT","SHOT","SHOULD","SHOULDER","SHOUT","SHOW","SHUT","SIDE","SIGHT","SIGN","SIGNAL","SIGNIFICANCE","SIGNIFICANT","SILENCE","SIMILAR","SIMPLE","SIMPLY","SINCE","SING","SINGLE","SIR","SISTER","SIT","SITE","SITUATION","SIZE","SKILL","SKIN","SKY","SLEEP","SLIGHTLY","SLIP","SLOW","SLOWLY","SMALL","SMILE","SO","SOCIAL","SOCIETY","SOFT","SOFTWARE","SOIL","SOLDIER","SOLICITOR","SOLUTION","SOME","SOMEBODY","SOMEONE","SOMETHING","SOMETIMES","SOMEWHAT","SOMEWHERE","SON","SONG","SOON","SORRY","SORT","SOUND","SOURCE","SOUTH","SOUTHERN","SPACE","SPEAK","SPEAKER","SPECIAL","SPECIES","SPECIFIC","SPEECH","SPEED","SPEND","SPIRIT","SPORT","SPOT","SPREAD","SPRING","STAFF","STAGE","STAND","STANDARD","STAR","START","STATE","STATEMENT","STATION","STATUS","STAY","STEAL","STEP","STICK","STILL","STOCK","STONE","STOP","STORE","STORY","STRAIGHT","STRANGE","STRATEGY","STREET","STRENGTH","STRIKE","STRONG","STRONGLY","STRUCTURE","STUDENT","STUDIO","STUDY","STUFF","STYLE","SUBJECT","SUBSTANTIAL","SUCCEED","SUCCESS","SUCCESSFUL","SUCH","SUDDENLY","SUFFER","SUFFICIENT","SUGGEST","SUGGESTION","SUITABLE","SUM","SUMMER","SUN","SUPPLY","SUPPORT","SUPPOSE","SURE","SURELY","SURFACE","SURPRISE","SURROUND","SURVEY","SURVIVE","SWITCH","SYSTEM","TABLE","TAKE","TALK","TALL","TAPE","TARGET","TASK","TAX","TEA","TEACH","TEACHER","TEACHING","TEAM","TEAR","TECHNICAL","TECHNIQUE","TECHNOLOGY","TELEPHONE","TELEVISION","TELL","TEMPERATURE","TEND","TERM","TERMS","TERRIBLE","TEST","TEXT","THAN","THANK","THANKS","THAT","THE","THEATRE","THEIR","THEM","THEME","THEMSELVES","THEN","THEORY","THERE","THEREFORE","THESE","THEY","THIN","THING","THINK","THIS","THOSE","THOUGH","THOUGHT","THREAT","THREATEN","THROUGH","THROUGHOUT","THROW","THUS","TICKET","TIME","TINY","TITLE","TO","TODAY","TOGETHER","TOMORROW","TONE","TONIGHT","TOO","TOOL","TOOTH","TOP","TOTAL","TOTALLY","TOUCH","TOUR","TOWARDS","TOWN","TRACK","TRADE","TRADITION","TRADITIONAL","TRAFFIC","TRAIN","TRAINING","TRANSFER","TRANSPORT","TRAVEL","TREAT","TREATMENT","TREATY","TREE","TREND","TRIAL","TRIP","TROOP","TROUBLE","TRUE","TRUST","TRUTH","TRY","TURN","TWICE","TYPE","TYPICAL","UNABLE","UNDER","UNDERSTAND","UNDERSTANDING","UNDERTAKE","UNEMPLOYMENT","UNFORTUNATELY","UNION","UNIT","UNITED","UNIVERSITY","UNLESS","UNLIKELY","UNTIL","UP","UPON","UPPER","URBAN","US","USE","USED","USEFUL","USER","USUAL","USUALLY","VALUE","VARIATION","VARIETY","VARIOUS","VARY","VAST","VEHICLE","VERSION","VERY","VIA","VICTIM","VICTORY","VIDEO","VIEW","VILLAGE","VIOLENCE","VISION","VISIT","VISITOR","VITAL","VOICE","VOLUME","VOTE","WAGE","WAIT","WALK","WALL","WANT","WAR","WARM","WARN","WASH","WATCH","WATER","WAVE","WAY","WE","WEAK","WEAPON","WEAR","WEATHER","WEEK","WEEKEND","WEIGHT","WELCOME","WELFARE","WELL","WEST","WESTERN","WHAT","WHATEVER","WHEN","WHERE","WHEREAS","WHETHER","WHICH","WHILE","WHILST","WHITE","WHO","WHOLE","WHOM","WHOSE","WHY","WIDE","WIDELY","WIFE","WILD","WILL","WIN","WIND","WINDOW","WINE","WING","WINNER","WINTER","WISH","WITH","WITHDRAW","WITHIN","WITHOUT","WOMAN","WONDER","WONDERFUL","WOOD","WORD","WORK","WORKER","WORKING","WORKS","WORLD","WORRY","WORTH","WOULD","WRITE","WRITER","WRITING","WRONG","YARD","YEAH","YEAR","YES","YESTERDAY","YET","YOU","YOUNG","YOUR","YOURSELF","YOUTH" 45 | 46 | */ 47 | -------------------------------------------------------------------------------- /Euler-043.js: -------------------------------------------------------------------------------- 1 | const start = Date.now(); 2 | 3 | // variable to store the value of sum 4 | let solution = 0; 5 | 6 | // function to generate permutations 7 | function* permutations(string) { 8 | if (string.length <= 1) yield string; 9 | else 10 | for (let i = 0; i < string.length; i++) { 11 | const chr = string[i]; 12 | const remainder = string.slice(0, i) + string.slice(i + 1); 13 | for (const permutation of permutations(remainder)) 14 | yield chr + permutation; 15 | } 16 | } 17 | 18 | // generator for 0-9 pandigital permutations 19 | const pandigitals = permutations("0123456789"); 20 | 21 | // loop through permutations and check for sub-string divisibility property 22 | for (const pandigital of pandigitals) { 23 | if ( 24 | parseInt(pandigital.slice(7, 10)) % 17 === 0 && 25 | parseInt(pandigital.slice(6, 9)) % 13 === 0 && 26 | parseInt(pandigital.slice(5, 8)) % 11 === 0 && 27 | parseInt(pandigital.slice(4, 7)) % 7 === 0 && 28 | parseInt(pandigital.slice(3, 6)) % 5 === 0 && 29 | parseInt(pandigital.slice(2, 5)) % 3 === 0 && 30 | parseInt(pandigital.slice(1, 4)) % 2 === 0 31 | ) { 32 | solution += parseInt(pandigital); 33 | } 34 | } 35 | console.log(solution); 36 | -------------------------------------------------------------------------------- /Euler-044.js: -------------------------------------------------------------------------------- 1 | function isPentagonal(num) { 2 | return (1 + Math.sqrt(1 + 24*num)) % 6 === 0; 3 | } 4 | let flag = true; 5 | let i = 1; 6 | const start = Date.now(); 7 | while (flag) { 8 | for (let j = 1; j < i; j++) { 9 | const a = i * (3*i - 1) / 2; 10 | const b = j * (3*j - 1) / 2; 11 | if (isPentagonal(a + b) && isPentagonal(a - b)) { 12 | console.log(a - b); 13 | flag = false; 14 | break; 15 | } 16 | } 17 | i++; 18 | } 19 | -------------------------------------------------------------------------------- /Euler-045.js: -------------------------------------------------------------------------------- 1 | function triangle(n) { 2 | return n * (n + 1) / 2; 3 | } 4 | 5 | function pentagonal(n) { 6 | return n * (3 * n - 1) / 2; 7 | } 8 | 9 | function hexagonal(n) { 10 | return n * (2 * n - 1); 11 | } 12 | 13 | let t = 286; 14 | let p = 166; 15 | let h = 144; 16 | let nextNumber = 0; 17 | 18 | while (!nextNumber) { 19 | let T = triangle(t); 20 | let P = pentagonal(p); 21 | let H = hexagonal(h); 22 | 23 | if (T === P && P === H) { 24 | nextNumber = T; 25 | } else if (T <= P && T <= H) { 26 | t++; 27 | } else if (P <= T && P <= H) { 28 | p++; 29 | } else { 30 | h++; 31 | } 32 | 33 | } 34 | 35 | console.log(nextNumber); 36 | -------------------------------------------------------------------------------- /Euler-046.js: -------------------------------------------------------------------------------- 1 | function isPrime(n) { 2 | if (n <= 1) { 3 | return false; 4 | } 5 | for (let i = 2; i <= Math.sqrt(n); i++) { 6 | if (n % i === 0) { 7 | return false; 8 | } 9 | } 10 | return true; 11 | } 12 | function isGoldbach(n) { 13 | for (let i = 1; 2 * i * i < n; i++) { 14 | if (isPrime(n - 2 * i * i)) { 15 | return true; 16 | } 17 | } 18 | return false; 19 | } 20 | function findSmallestOddComposite() { 21 | let n = 9; 22 | while (true) { 23 | if (!isPrime(n) && !isGoldbach(n)) { 24 | return n; 25 | } 26 | n += 2; 27 | } 28 | } 29 | 30 | console.log(findSmallestOddComposite()); 31 | -------------------------------------------------------------------------------- /Euler-047.js: -------------------------------------------------------------------------------- 1 | function countDistinctPrimeFactors(n) { 2 | let count = 0; 3 | for (let i = 2; i <= Math.sqrt(n); i++) { 4 | if (n % i === 0) { 5 | count++; 6 | while (n % i === 0) { 7 | n /= i; 8 | } 9 | } 10 | } 11 | if (n > 1) { 12 | count++; 13 | } 14 | return count; 15 | } 16 | 17 | let numConsecutive = 0; 18 | let n = 1; 19 | 20 | while (numConsecutive < 4) { 21 | if ( 22 | countDistinctPrimeFactors(n) === 4 && 23 | countDistinctPrimeFactors(n + 1) === 4 && 24 | countDistinctPrimeFactors(n + 2) === 4 && 25 | countDistinctPrimeFactors(n + 3) === 4 26 | ) { 27 | numConsecutive = 4; 28 | console.log(n); 29 | } else { 30 | n++; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Euler-048.js: -------------------------------------------------------------------------------- 1 | function modpow(b, e, m) { 2 | let r = 1n; 3 | while (e > 0n) { 4 | if (e & 1n) { 5 | r = (r * b) % m; 6 | } 7 | b = (b * b) % m; 8 | e = e >> 1n; 9 | } 10 | return r; 11 | } 12 | function powersum(n, m) { 13 | let s = 0n; 14 | for (let i = 1n; i <= n; i++) { 15 | s += modpow(i, i, m); 16 | s %= m; 17 | } 18 | return s; 19 | } 20 | console.log(powersum(1000n, 10000000000n)); 21 | -------------------------------------------------------------------------------- /Euler-049.js: -------------------------------------------------------------------------------- 1 | function isPrime(n) { 2 | if (n <= 1) return false; 3 | if (n <= 3) return true; 4 | if (n % 2 == 0 || n % 3 == 0) return false; 5 | for (let i = 5; i * i <= n; i += 6) { 6 | if (n % i == 0 || n % (i + 2) == 0) { 7 | return false; 8 | } 9 | } 10 | return true; 11 | } 12 | 13 | function permutations(str) { 14 | if (str.length <= 1) return [str]; 15 | let perms = []; 16 | for (let i = 0; i < str.length; i++) { 17 | let char = str[i]; 18 | let remaining = str.slice(0, i) + str.slice(i + 1); 19 | let subperms = permutations(remaining); 20 | for (let j = 0; j < subperms.length; j++) { 21 | perms.push(char + subperms[j]); 22 | } 23 | } 24 | return perms; 25 | } 26 | 27 | function findSequence() { 28 | for (let n = 1000; n <= 9999; n++) { 29 | if (!isPrime(n)) continue; 30 | let perms = permutations(n.toString()); 31 | for (let i = 0; i < perms.length; i++) { 32 | let p1 = parseInt(perms[i]); 33 | if (p1 <= 1487 || !isPrime(p1)) continue; 34 | for (let j = i + 1; j < perms.length; j++) { 35 | let p2 = parseInt(perms[j]); 36 | if (p2 <= p1 || !isPrime(p2)) continue; 37 | let diff = p2 - p1; 38 | let p3 = p2 + diff; 39 | if (p3 > 9999 || !isPrime(p3)) continue; 40 | let p3perms = permutations(p3.toString()); 41 | if (p3perms.includes(perms[i]) && p3perms.includes(perms[j])) { 42 | return "" + p1 + p2 + p3; 43 | } 44 | } 45 | } 46 | } 47 | return "No sequence found"; 48 | } 49 | 50 | console.log(findSequence()); 51 | -------------------------------------------------------------------------------- /Euler-050.js: -------------------------------------------------------------------------------- 1 | function isPrime(num) { 2 | if (num < 2) { 3 | return false; 4 | } 5 | for (let i = 2; i <= Math.sqrt(num); i++) { 6 | if (num % i === 0) { 7 | return false; 8 | } 9 | } 10 | return true; 11 | } 12 | 13 | function getPrimes(limit) { 14 | const primes = []; 15 | for (let num = 2; num < limit; num++) { 16 | if (isPrime(num)) { 17 | primes.push(num); 18 | } 19 | } 20 | return primes; 21 | } 22 | 23 | function getLongestSumOfConsecutivePrimes(limit) { 24 | const primes = getPrimes(limit); 25 | let maxLength = 0; 26 | let maxSum = 0; 27 | for (let i = 0; i < primes.length; i++) { 28 | let sum = primes[i]; 29 | let length = 1; 30 | for (let j = i + 1; j < primes.length; j++) { 31 | sum += primes[j]; 32 | length++; 33 | if (sum >= limit) { 34 | break; 35 | } 36 | if (isPrime(sum) && length > maxLength) { 37 | maxLength = length; 38 | maxSum = sum; 39 | } 40 | } 41 | } 42 | return maxSum; 43 | } 44 | 45 | console.log(getLongestSumOfConsecutivePrimes(1000000)); 46 | -------------------------------------------------------------------------------- /Euler-051.js: -------------------------------------------------------------------------------- 1 | class PrimeSeive { 2 | constructor(num) { 3 | const seive = Array(Math.floor((num - 1) / 2)).fill(true); 4 | const upper = Math.floor((num - 1) / 2); 5 | const sqrtUpper = Math.floor((Math.sqrt(num) - 1) / 2); 6 | 7 | for (let i = 0; i <= sqrtUpper; i++) { 8 | if (seive[i]) { 9 | // Mark value in seive array 10 | const prime = 2 * i + 3; 11 | // Mark all multiples of this number as false (not prime) 12 | const primeSqaredIndex = 2 * i ** 2 + 6 * i + 3; 13 | for (let j = primeSqaredIndex; j < upper; j += prime) { 14 | seive[j] = false; 15 | } 16 | } 17 | } 18 | 19 | this._seive = seive; 20 | } 21 | 22 | isPrime(num) { 23 | return num === 2 24 | ? true 25 | : num % 2 === 0 26 | ? false 27 | : this.isOddPrime(num); 28 | } 29 | 30 | isOddPrime(num) { 31 | return this._seive[(num - 3) / 2]; 32 | } 33 | }; 34 | 35 | function primeDigitReplacements(n) { 36 | const primeSeive = new PrimeSeive(n * n * n * 2000); 37 | 38 | function isNFamily(number, n) { 39 | const prime = number.toString(); 40 | const lastDigit = prime[prime.length - 1]; 41 | return doesReplacingMakeFamily(prime, '0', n) || 42 | doesReplacingMakeFamily(prime, '2', n) || 43 | (lastDigit !== '1' && doesReplacingMakeFamily(prime, '1', n)); 44 | } 45 | 46 | function doesReplacingMakeFamily(prime, digitToReplace, family) { 47 | let miss = 0; 48 | const base = parseInt( 49 | prime 50 | .split('') 51 | .map(digit => digit == digitToReplace ? '0' : digit) 52 | .join('') 53 | ); 54 | const replacements = parseInt( 55 | prime 56 | .split('') 57 | .map(digit => digit === digitToReplace ? '1' : '0') 58 | .join('') 59 | ); 60 | const start = prime[0] === digitToReplace ? 1 : 0; 61 | for (let i = start; i < 10; i++) { 62 | const nextNumber = base + i * replacements; 63 | if (!isPartOfFamily(nextNumber, prime)) miss++; 64 | if (10 - start - miss < family) break; 65 | } 66 | return 10 - start - miss === family; 67 | } 68 | 69 | function isPartOfFamily(number, prime) { 70 | return ( 71 | primeSeive.isPrime(number) && number.toString().length === prime.length 72 | ); 73 | } 74 | 75 | for (let number = 1; number < 125000; number++) { 76 | if (primeSeive.isPrime(number) && isNFamily(number, n)) { 77 | return number; 78 | } 79 | } 80 | return -1; 81 | } 82 | console.log(primeDigitReplacements()); 83 | -------------------------------------------------------------------------------- /Euler-052.js: -------------------------------------------------------------------------------- 1 | function arePermutations(a, b) { 2 | // Convert both numbers to strings and sort their characters 3 | const sortedA = a.toString().split('').sort().join(''); 4 | const sortedB = b.toString().split('').sort().join(''); 5 | 6 | // Compare the sorted strings 7 | return sortedA === sortedB; 8 | } 9 | 10 | function findSmallest() { 11 | let x = 1; 12 | 13 | while (true) { 14 | // Check if all multiples of x have the same digits 15 | if ( 16 | arePermutations(x, 2 * x) && 17 | arePermutations(x, 3 * x) && 18 | arePermutations(x, 4 * x) && 19 | arePermutations(x, 5 * x) && 20 | arePermutations(x, 6 * x) 21 | ) { 22 | return x; 23 | } 24 | 25 | x++; 26 | } 27 | 28 | } 29 | 30 | console.log(findSmallest()); 31 | -------------------------------------------------------------------------------- /Euler-053.js: -------------------------------------------------------------------------------- 1 | function factorial(n, memo = {}) { 2 | if (n === 0 || n === 1) { 3 | return 1; 4 | } 5 | if (memo[n]) { 6 | return memo[n]; 7 | } 8 | memo[n] = n * factorial(n-1, memo); 9 | return memo[n]; 10 | } 11 | 12 | function countValues(limit) { 13 | let count = 0; 14 | for (let n = 1; n <= 100; n++) { 15 | for (let r = 0; r <= n; r++) { 16 | const nCr = factorial(n) / (factorial(r) * factorial(n-r)); 17 | if (nCr > limit) { 18 | count++; 19 | } 20 | } 21 | } 22 | return count; 23 | } 24 | 25 | console.log(countValues(1000000)); 26 | -------------------------------------------------------------------------------- /Euler-054.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | 3 | function countP1Wins() { 4 | const hands = fs.readFileSync('poker.txt', 'utf8').trim().split('\n').map(line => line.trim().split(' ')); 5 | 6 | const values = {'2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, 'T': 10, 'J': 11, 'Q': 12, 'K': 13, 'A': 14}; 7 | const straights = [[14, 5, 4, 3, 2], [13, 12, 11, 10, 9], [12, 11, 10, 9, 8], [11, 10, 9, 8, 7], [10, 9, 8, 7, 6], [9, 8, 7, 6, 5], [8, 7, 6, 5, 4], [7, 6, 5, 4, 3], [6, 5, 4, 3, 2]]; 8 | const ranks = [[1, 1, 1, 1, 1], [2, 1, 1, 1], [2, 2, 1], [3, 1, 1], [3, 2], [4, 1]]; 9 | 10 | function calculateRank(hand) { 11 | const cardValues = hand.map(card => values[card[0]]); 12 | const valueCount = {}; 13 | for (const cardValue of cardValues) { 14 | valueCount[cardValue] = (valueCount[cardValue] || 0) + 1; 15 | } 16 | const sortedValues = cardValues.sort((a, b) => b - a); 17 | const rankIndex = ranks.findIndex(rank => rank.every(count => sortedValues.slice(0, count).filter(v => v === sortedValues[0]).length === count)); 18 | const score = [rankIndex, ...sortedValues]; 19 | if (hand.every(card => card[1] === hand[0][1])) { 20 | score[0] = 5; // flush 21 | } 22 | if (straights.some(straight => straight.every(value => sortedValues.includes(value)))) { 23 | score[0] = 4; // straight 24 | } 25 | return score; 26 | } 27 | 28 | const p1Wins = hands.filter(hand => calculateRank(hand.slice(0, 5)).join('').localeCompare(calculateRank(hand.slice(5)).join('')) > 0).length; 29 | 30 | return p1Wins; 31 | } 32 | 33 | console.log(countP1Wins()); // should output 376 34 | -------------------------------------------------------------------------------- /Euler-055.js: -------------------------------------------------------------------------------- 1 | function isPalindrome(num) { 2 | const str = String(num); 3 | return str === str.split('').reverse().join(''); 4 | } 5 | 6 | function isLychrel(num, maxIterations = 50) { 7 | let result = num; 8 | for (let i = 0; i < maxIterations; i++) { 9 | result += Number(result.toString().split('').reverse().join('')); 10 | if (isPalindrome(result)) { 11 | return false; 12 | } 13 | } 14 | return true; 15 | } 16 | 17 | let count = 0; 18 | for (let num = 1; num < 10000; num++) { 19 | if (isLychrel(num)) { 20 | count++; 21 | } 22 | 23 | } 24 | 25 | console.log(count); 26 | -------------------------------------------------------------------------------- /Euler-056.js: -------------------------------------------------------------------------------- 1 | let maxSum = 0; 2 | 3 | for (let a = 0; a < 100; a++) { 4 | for (let b = 0; b < 100; b++) { 5 | let num = BigInt(Math.pow(a, b)).toString(); 6 | let sum = -2; 7 | for (let i = 2; i < num.length; i++) { 8 | sum += parseInt(num.charAt(i)); 9 | } 10 | if (sum > maxSum) { 11 | maxSum = sum; 12 | } 13 | } 14 | } 15 | console.log(maxSum); 16 | -------------------------------------------------------------------------------- /Euler-057.js: -------------------------------------------------------------------------------- 1 | function squareRootConvergents(n) { 2 | function countDigits(number) { 3 | let counter = 0; 4 | while (number > 0) { 5 | counter++; 6 | number = number / 10n; 7 | } 8 | return counter; 9 | } 10 | 11 | // Use BigInt as integer won't handle all cases 12 | let numerator = 3n; 13 | let denominator = 2n; 14 | let moreDigitsInNumerator = 0; 15 | 16 | for (let i = 2; i <= n; i++) { 17 | [numerator, denominator] = [ 18 | numerator + 2n * denominator, 19 | denominator + numerator 20 | ]; 21 | 22 | if (countDigits(numerator) > countDigits(denominator)) { 23 | moreDigitsInNumerator++; 24 | } 25 | } 26 | return moreDigitsInNumerator; 27 | } 28 | 29 | 30 | console.log(squareRootConvergents(1000)); 31 | -------------------------------------------------------------------------------- /Euler-058.js: -------------------------------------------------------------------------------- 1 | function spiralPrimes(percent) { 2 | function isPrime(n) { 3 | if (n <= 3) { 4 | return n > 1; 5 | } else if (n % 2 === 0 || n % 3 === 0) { 6 | return false; 7 | } 8 | 9 | for (let i = 5; i * i <= n; i += 6) { 10 | if (n % i === 0 || n % (i + 2) === 0) { 11 | return false; 12 | } 13 | } 14 | return true; 15 | } 16 | 17 | let totalCount = 1; 18 | let primesCount = 0; 19 | let curNumber = 1; 20 | let curSideLength = 1; 21 | let ratio = 1; 22 | const wantedRatio = percent / 100; 23 | 24 | while (ratio >= wantedRatio) { 25 | curSideLength += 2; 26 | for (let i = 0; i < 4; i++) { 27 | curNumber += curSideLength - 1; 28 | totalCount++; 29 | if (i !== 3 && isPrime(curNumber)) { 30 | primesCount++; 31 | } 32 | } 33 | ratio = primesCount / totalCount; 34 | } 35 | return curSideLength; 36 | } 37 | console.log(spiralPrimes(10)); 38 | -------------------------------------------------------------------------------- /Euler-059.py: -------------------------------------------------------------------------------- 1 | def compute(): 2 | bestkey = max(((x, y, z) 3 | for x in range(97, 123) # ASCII lowercase 'a' to 'z' 4 | for y in range(97, 123) 5 | for z in range(97, 123)), 6 | key=lambda key: get_score(decrypt(CIPHERTEXT, key))) 7 | ans = sum(decrypt(CIPHERTEXT, bestkey)) 8 | return str(ans) 9 | 10 | 11 | # Heuristical function that returns a penalty score, where lower is better. 12 | def get_score(plaintext): 13 | result = 0 14 | for c in plaintext: 15 | if 65 <= c <= 90: # ASCII uppercase 'A' to 'Z', good 16 | result += 1 17 | elif 97 <= c <= 122: # ASCII lowercase 'a' to 'z', excellent 18 | result += 2 19 | elif c < 0x20 or c == 0x7F: # ASCII control characters, very bad 20 | result -= 10 21 | return result 22 | 23 | 24 | # Takes two sequences of integers and returns a list of integers. 25 | def decrypt(ciphertext, key): 26 | return [(c ^ key[i % len(key)]) for (i, c) in enumerate(ciphertext)] 27 | 28 | 29 | CIPHERTEXT = [ 30 | 36, 22, 80, 0, 0, 4, 23, 25, 19, 17, 88, 4, 4, 19, 21, 11, 88, 22, 23, 23, 31 | 29, 69, 12, 24, 0, 88, 25, 11, 12, 2, 10, 28, 5, 6, 12, 25, 10, 22, 80, 10, 32 | 30, 80, 10, 22, 21, 69, 23, 22, 69, 61, 5, 9, 29, 2, 66, 11, 80, 8, 23, 3, 33 | 17, 88, 19, 0, 20, 21, 7, 10, 17, 17, 29, 20, 69, 8, 17, 21, 29, 2, 22, 84, 34 | 80, 71, 60, 21, 69, 11, 5, 8, 21, 25, 22, 88, 3, 0, 10, 25, 0, 10, 5, 8, 35 | 88, 2, 0, 27, 25, 21, 10, 31, 6, 25, 2, 16, 21, 82, 69, 35, 63, 11, 88, 4, 36 | 13, 29, 80, 22, 13, 29, 22, 88, 31, 3, 88, 3, 0, 10, 25, 0, 11, 80, 10, 30, 37 | 80, 23, 29, 19, 12, 8, 2, 10, 27, 17, 9, 11, 45, 95, 88, 57, 69, 16, 17, 19, 38 | 29, 80, 23, 29, 19, 0, 22, 4, 9, 1, 80, 3, 23, 5, 11, 28, 92, 69, 9, 5, 39 | 12, 12, 21, 69, 13, 30, 0, 0, 0, 0, 27, 4, 0, 28, 28, 28, 84, 80, 4, 22, 40 | 80, 0, 20, 21, 2, 25, 30, 17, 88, 21, 29, 8, 2, 0, 11, 3, 12, 23, 30, 69, 41 | 30, 31, 23, 88, 4, 13, 29, 80, 0, 22, 4, 12, 10, 21, 69, 11, 5, 8, 88, 31, 42 | 3, 88, 4, 13, 17, 3, 69, 11, 21, 23, 17, 21, 22, 88, 65, 69, 83, 80, 84, 87, 43 | 68, 69, 83, 80, 84, 87, 73, 69, 83, 80, 84, 87, 65, 83, 88, 91, 69, 29, 4, 6, 44 | 86, 92, 69, 15, 24, 12, 27, 24, 69, 28, 21, 21, 29, 30, 1, 11, 80, 10, 22, 80, 45 | 17, 16, 21, 69, 9, 5, 4, 28, 2, 4, 12, 5, 23, 29, 80, 10, 30, 80, 17, 16, 46 | 21, 69, 27, 25, 23, 27, 28, 0, 84, 80, 22, 23, 80, 17, 16, 17, 17, 88, 25, 3, 47 | 88, 4, 13, 29, 80, 17, 10, 5, 0, 88, 3, 16, 21, 80, 10, 30, 80, 17, 16, 25, 48 | 22, 88, 3, 0, 10, 25, 0, 11, 80, 12, 11, 80, 10, 26, 4, 4, 17, 30, 0, 28, 49 | 92, 69, 30, 2, 10, 21, 80, 12, 12, 80, 4, 12, 80, 10, 22, 19, 0, 88, 4, 13, 50 | 29, 80, 20, 13, 17, 1, 10, 17, 17, 13, 2, 0, 88, 31, 3, 88, 4, 13, 29, 80, 51 | 6, 17, 2, 6, 20, 21, 69, 30, 31, 9, 20, 31, 18, 11, 94, 69, 54, 17, 8, 29, 52 | 28, 28, 84, 80, 44, 88, 24, 4, 14, 21, 69, 30, 31, 16, 22, 20, 69, 12, 24, 4, 53 | 12, 80, 17, 16, 21, 69, 11, 5, 8, 88, 31, 3, 88, 4, 13, 17, 3, 69, 11, 21, 54 | 23, 17, 21, 22, 88, 25, 22, 88, 17, 69, 11, 25, 29, 12, 24, 69, 8, 17, 23, 12, 55 | 80, 10, 30, 80, 17, 16, 21, 69, 11, 1, 16, 25, 2, 0, 88, 31, 3, 88, 4, 13, 56 | 29, 80, 21, 29, 2, 12, 21, 21, 17, 29, 2, 69, 23, 22, 69, 12, 24, 0, 88, 19, 57 | 12, 10, 19, 9, 29, 80, 18, 16, 31, 22, 29, 80, 1, 17, 17, 8, 29, 4, 0, 10, 58 | 80, 12, 11, 80, 84, 67, 80, 10, 10, 80, 7, 1, 80, 21, 13, 4, 17, 17, 30, 2, 59 | 88, 4, 13, 29, 80, 22, 13, 29, 69, 23, 22, 69, 12, 24, 12, 11, 80, 22, 29, 2, 60 | 12, 29, 3, 69, 29, 1, 16, 25, 28, 69, 12, 31, 69, 11, 92, 69, 17, 4, 69, 16, 61 | 17, 22, 88, 4, 13, 29, 80, 23, 25, 4, 12, 23, 80, 22, 9, 2, 17, 80, 70, 76, 62 | 88, 29, 16, 20, 4, 12, 8, 28, 12, 29, 20, 69, 26, 9, 69, 11, 80, 17, 23, 80, 63 | 84, 88, 31, 3, 88, 4, 13, 29, 80, 21, 29, 2, 12, 21, 21, 17, 29, 2, 69, 12, 64 | 31, 69, 12, 24, 0, 88, 20, 12, 25, 29, 0, 12, 21, 23, 86, 80, 44, 88, 7, 12, 65 | 20, 28, 69, 11, 31, 10, 22, 80, 22, 16, 31, 18, 88, 4, 13, 25, 4, 69, 12, 24, 66 | 0, 88, 3, 16, 21, 80, 10, 30, 80, 17, 16, 25, 22, 88, 3, 0, 10, 25, 0, 11, 67 | 80, 17, 23, 80, 7, 29, 80, 4, 8, 0, 23, 23, 8, 12, 21, 17, 17, 29, 28, 28, 68 | 88, 65, 75, 78, 68, 81, 65, 67, 81, 72, 70, 83, 64, 68, 87, 74, 70, 81, 75, 70, 69 | 81, 67, 80, 4, 22, 20, 69, 30, 2, 10, 21, 80, 8, 13, 28, 17, 17, 0, 9, 1, 70 | 25, 11, 31, 80, 17, 16, 25, 22, 88, 30, 16, 21, 18, 0, 10, 80, 7, 1, 80, 22, 71 | 17, 8, 73, 88, 17, 11, 28, 80, 17, 16, 21, 11, 88, 4, 4, 19, 25, 11, 31, 80, 72 | 17, 16, 21, 69, 11, 1, 16, 25, 2, 0, 88, 2, 10, 23, 4, 73, 88, 4, 13, 29, 73 | 80, 11, 13, 29, 7, 29, 2, 69, 75, 94, 84, 76, 65, 80, 65, 66, 83, 77, 67, 80, 74 | 64, 73, 82, 65, 67, 87, 75, 72, 69, 17, 3, 69, 17, 30, 1, 29, 21, 1, 88, 0, 75 | 23, 23, 20, 16, 27, 21, 1, 84, 80, 18, 16, 25, 6, 16, 80, 0, 0, 0, 23, 29, 76 | 3, 22, 29, 3, 69, 12, 24, 0, 88, 0, 0, 10, 25, 8, 29, 4, 0, 10, 80, 10, 77 | 30, 80, 4, 88, 19, 12, 10, 19, 9, 29, 80, 18, 16, 31, 22, 29, 80, 1, 17, 17, 78 | 8, 29, 4, 0, 10, 80, 12, 11, 80, 84, 86, 80, 35, 23, 28, 9, 23, 7, 12, 22, 79 | 23, 69, 25, 23, 4, 17, 30, 69, 12, 24, 0, 88, 3, 4, 21, 21, 69, 11, 4, 0, 80 | 8, 3, 69, 26, 9, 69, 15, 24, 12, 27, 24, 69, 49, 80, 13, 25, 20, 69, 25, 2, 81 | 23, 17, 6, 0, 28, 80, 4, 12, 80, 17, 16, 25, 22, 88, 3, 16, 21, 92, 69, 49, 82 | 80, 13, 25, 6, 0, 88, 20, 12, 11, 19, 10, 14, 21, 23, 29, 20, 69, 12, 24, 4, 83 | 12, 80, 17, 16, 21, 69, 11, 5, 8, 88, 31, 3, 88, 4, 13, 29, 80, 22, 29, 2, 84 | 12, 29, 3, 69, 73, 80, 78, 88, 65, 74, 73, 70, 69, 83, 80, 84, 87, 72, 84, 88, 85 | 91, 69, 73, 95, 87, 77, 70, 69, 83, 80, 84, 87, 70, 87, 77, 80, 78, 88, 21, 17, 86 | 27, 94, 69, 25, 28, 22, 23, 80, 1, 29, 0, 0, 22, 20, 22, 88, 31, 11, 88, 4, 87 | 13, 29, 80, 20, 13, 17, 1, 10, 17, 17, 13, 2, 0, 88, 31, 3, 88, 4, 13, 29, 88 | 80, 6, 17, 2, 6, 20, 21, 75, 88, 62, 4, 21, 21, 9, 1, 92, 69, 12, 24, 0, 89 | 88, 3, 16, 21, 80, 10, 30, 80, 17, 16, 25, 22, 88, 29, 16, 20, 4, 12, 8, 28, 90 | 12, 29, 20, 69, 26, 9, 69, 65, 64, 69, 31, 25, 19, 29, 3, 69, 12, 24, 0, 88, 91 | 18, 12, 9, 5, 4, 28, 2, 4, 12, 21, 69, 80, 22, 10, 13, 2, 17, 16, 80, 21, 92 | 23, 7, 0, 10, 89, 69, 23, 22, 69, 12, 24, 0, 88, 19, 12, 10, 19, 16, 21, 22, 93 | 0, 10, 21, 11, 27, 21, 69, 23, 22, 69, 12, 24, 0, 88, 0, 0, 10, 25, 8, 29, 94 | 4, 0, 10, 80, 10, 30, 80, 4, 88, 19, 12, 10, 19, 9, 29, 80, 18, 16, 31, 22, 95 | 29, 80, 1, 17, 17, 8, 29, 4, 0, 10, 80, 12, 11, 80, 84, 86, 80, 36, 22, 20, 96 | 69, 26, 9, 69, 11, 25, 8, 17, 28, 4, 10, 80, 23, 29, 17, 22, 23, 30, 12, 22, 97 | 23, 69, 49, 80, 13, 25, 6, 0, 88, 28, 12, 19, 21, 18, 17, 3, 0, 88, 18, 0, 98 | 29, 30, 69, 25, 18, 9, 29, 80, 17, 23, 80, 1, 29, 4, 0, 10, 29, 12, 22, 21, 99 | 69, 12, 24, 0, 88, 3, 16, 21, 3, 69, 23, 22, 69, 12, 24, 0, 88, 3, 16, 26, 100 | 3, 0, 9, 5, 0, 22, 4, 69, 11, 21, 23, 17, 21, 22, 88, 25, 11, 88, 7, 13, 101 | 17, 19, 13, 88, 4, 13, 29, 80, 0, 0, 0, 10, 22, 21, 11, 12, 3, 69, 25, 2, 102 | 0, 88, 21, 19, 29, 30, 69, 22, 5, 8, 26, 21, 23, 11, 94, 103 | ] 104 | 105 | 106 | if __name__ == "__main__": 107 | print(compute()) 108 | -------------------------------------------------------------------------------- /Euler-060.js: -------------------------------------------------------------------------------- 1 | const max = 1000000; 2 | const arr = new Array(max).fill(0); 3 | 4 | function set_arr() { 5 | for (let i = 2; i < max; i++) { 6 | if (is_prime(i)) { 7 | arr[i] = 1; 8 | } 9 | } 10 | } 11 | 12 | function is_prime(n) { 13 | if (n === 1) { 14 | return 0; 15 | } 16 | if (n === 2) { 17 | return 1; 18 | } 19 | if (n % 2 === 0) { 20 | return 0; 21 | } 22 | for (let i = 3; i * i <= n; i += 2) { 23 | if (n % i === 0) { 24 | return 0; 25 | } 26 | } 27 | return 1; 28 | } 29 | 30 | function count_digits(n) { 31 | let counter = 0; 32 | while (n) { 33 | counter++; 34 | n = Math.floor(n / 10); 35 | } 36 | return counter; 37 | } 38 | 39 | function is_conPrime(a, b) { 40 | const num1 = a + b * 10 ** count_digits(a); 41 | const num2 = b + a * 10 ** count_digits(b); 42 | if (is_prime(num1) && is_prime(num2)) { 43 | return 1; 44 | } 45 | return 0; 46 | } 47 | 48 | function main() { 49 | let sum = 0; 50 | let min = 2147483647; 51 | set_arr(); 52 | for (let a = 3; a < 10000; a += 2) { 53 | if (arr[a]) { 54 | for (let b = 3; b < 10000; b += 2) { 55 | if (arr[b] && is_conPrime(a, b)) { 56 | for (let c = 3; c < 10000; c += 2) { 57 | if (arr[c] && is_conPrime(a, c) && is_conPrime(b, c)) { 58 | for (let d = 3; d < 10000; d += 2) { 59 | if ( 60 | arr[d] && 61 | is_conPrime(a, d) && 62 | is_conPrime(b, d) && 63 | is_conPrime(c, d) 64 | ) { 65 | for (let e = 3; e < 10000; e += 2) { 66 | if ( 67 | arr[e] && 68 | is_conPrime(a, e) && 69 | is_conPrime(b, e) && 70 | is_conPrime(c, e) && 71 | is_conPrime(d, e) 72 | ) { 73 | console.log( 74 | `${ 75 | a + b + c + d + e 76 | }` 77 | ); 78 | process.exit(1); 79 | } 80 | } 81 | } 82 | } 83 | } 84 | } 85 | } 86 | } 87 | } 88 | } 89 | } 90 | 91 | main(); 92 | -------------------------------------------------------------------------------- /Euler-061.js: -------------------------------------------------------------------------------- 1 | function cyclicalFigurateNums(n) { 2 | function getChains(chain, n, numberTypes, numsExcludingLastNeededType) { 3 | if (chain.length === n) { 4 | return [chain]; 5 | } 6 | 7 | const nextNumbers = getNextNumbersInChain( 8 | chain[chain.length - 1], 9 | numsExcludingLastNeededType 10 | ); 11 | 12 | const chains = []; 13 | for (let j = 0; j < nextNumbers.length; j++) { 14 | const nextNumber = nextNumbers[j]; 15 | if (chain.indexOf(nextNumber) === -1) { 16 | const nextChain = [...chain, nextNumber]; 17 | chains.push( 18 | ...getChains(nextChain, n, numberTypes, numsExcludingLastNeededType) 19 | ); 20 | } 21 | } 22 | return chains; 23 | } 24 | 25 | function getNextNumbersInChain(num, numsExcludingLastNeededType) { 26 | const results = []; 27 | const beginning = num % 100; 28 | numsExcludingLastNeededType.forEach(number => { 29 | if (Math.floor(number / 100) === beginning) { 30 | results.push(number); 31 | } 32 | }); 33 | return results; 34 | } 35 | 36 | function fillNumberTypes(n, numberTypes, numsExcludingLastNeededType) { 37 | const [, lastTypeCheck, lastTypeArr] = numberTypes[n - 1]; 38 | 39 | for (let i = 1000; i <= 9999; i++) { 40 | for (let j = 0; j < n - 1; j++) { 41 | const [, typeCheck, typeArr] = numberTypes[j]; 42 | if (typeCheck(i)) { 43 | typeArr.push(i); 44 | numsExcludingLastNeededType.add(i); 45 | } 46 | } 47 | 48 | if (lastTypeCheck(i)) { 49 | lastTypeArr.push(i); 50 | } 51 | } 52 | } 53 | 54 | function isCyclicalChain(chain, n, numberTypes) { 55 | const numberTypesInChain = getNumberTypesInChain(chain, numberTypes); 56 | 57 | if (!isChainAllowed(numberTypesInChain, n)) { 58 | return false; 59 | } 60 | 61 | const isChainCyclic = 62 | Math.floor(chain[0] / 100) === chain[chain.length - 1] % 100; 63 | return isChainCyclic; 64 | } 65 | 66 | function getNumberTypesInChain(chain, numberTypes) { 67 | const numbersInChain = {}; 68 | for (let i = 0; i < numberTypes.length; i++) { 69 | const numberTypeName = numberTypes[i][0]; 70 | numbersInChain[numberTypeName] = []; 71 | } 72 | 73 | for (let i = 0; i < chain.length; i++) { 74 | for (let j = 0; j < n; j++) { 75 | const [typeName, , typeNumbers] = numberTypes[j]; 76 | const typeNumbersInChain = numbersInChain[typeName]; 77 | if (typeNumbers.indexOf(chain[i]) !== -1) { 78 | typeNumbersInChain.push(chain[i]); 79 | } 80 | } 81 | } 82 | return numbersInChain; 83 | } 84 | 85 | function isChainAllowed(numberTypesInChain, n) { 86 | for (let i = 0; i < n; i++) { 87 | const typeName = numberTypes[i][0]; 88 | const isNumberWithTypeInChain = numberTypesInChain[typeName].length > 0; 89 | if (!isNumberWithTypeInChain) { 90 | return false; 91 | } 92 | 93 | for (let j = i + 1; j < n; j++) { 94 | const otherTypeName = numberTypes[j][0]; 95 | if ( 96 | isNumberRepeatedAsOnlyNumberInTwoTypes( 97 | numberTypesInChain[typeName], 98 | numberTypesInChain[otherTypeName] 99 | ) 100 | ) { 101 | return false; 102 | } 103 | } 104 | } 105 | return true; 106 | } 107 | 108 | function isNumberRepeatedAsOnlyNumberInTwoTypes( 109 | typeNumbers, 110 | otherTypeNumbers 111 | ) { 112 | return ( 113 | typeNumbers.length === 1 && 114 | otherTypeNumbers.length === 1 && 115 | typeNumbers[0] === otherTypeNumbers[0] 116 | ); 117 | } 118 | 119 | function isTriangle(num) { 120 | return ((8 * num + 1) ** 0.5 - 1) % 2 === 0; 121 | } 122 | 123 | function isSquare(num) { 124 | return num ** 0.5 === parseInt(num ** 0.5, 10); 125 | } 126 | 127 | function isPentagonal(num) { 128 | return ((24 * num + 1) ** 0.5 + 1) % 6 === 0; 129 | } 130 | 131 | function isHexagonal(num) { 132 | return ((8 * num + 1) ** 0.5 + 1) % 4 === 0; 133 | } 134 | 135 | function isHeptagonal(num) { 136 | return ((40 * num + 9) ** 0.5 + 3) % 10 === 0; 137 | } 138 | 139 | function isOctagonal(num) { 140 | return ((3 * num + 1) ** 0.5 + 1) % 3 === 0; 141 | } 142 | 143 | const numberTypes = [ 144 | ['triangle', isTriangle, []], 145 | ['square', isSquare, []], 146 | ['pentagonal', isPentagonal, []], 147 | ['hexagonal', isHexagonal, []], 148 | ['heptagonal', isHeptagonal, []], 149 | ['octagonal', isOctagonal, []] 150 | ]; 151 | const numsExcludingLastNeededType = new Set(); 152 | fillNumberTypes(n, numberTypes, numsExcludingLastNeededType); 153 | 154 | const nNumberChains = []; 155 | const [, , lastType] = numberTypes[n - 1]; 156 | for (let i = 0; i < lastType.length; i++) { 157 | const startOfChain = lastType[i]; 158 | nNumberChains.push( 159 | ...getChains([startOfChain], n, numberTypes, numsExcludingLastNeededType) 160 | ); 161 | } 162 | 163 | const cyclicalChains = nNumberChains.filter(chain => 164 | isCyclicalChain(chain, n, numberTypes) 165 | ); 166 | 167 | let sum = 0; 168 | for (let i = 0; i < cyclicalChains.length; i++) { 169 | for (let j = 0; j < cyclicalChains[0].length; j++) { 170 | sum += cyclicalChains[i][j]; 171 | } 172 | } 173 | return sum; 174 | } 175 | 176 | console.log(cyclicalFigurateNums(6)); 177 | -------------------------------------------------------------------------------- /Euler-062.js: -------------------------------------------------------------------------------- 1 | function cubicPermutations(n) { 2 | function getDigits(num) { 3 | const digits = []; 4 | while (num > 0) { 5 | digits.push(num % 10); 6 | num = Math.floor(num / 10); 7 | } 8 | return digits; 9 | } 10 | 11 | function getCube(num) { 12 | return num ** 3; 13 | } 14 | 15 | const digitsToCubeCounts = {}; 16 | let curNum = 1; 17 | let digits; 18 | 19 | while (!digitsToCubeCounts[digits] || digitsToCubeCounts[digits].count < n) { 20 | const cube = getCube(curNum); 21 | digits = getDigits(cube).sort().join(); 22 | if (!digitsToCubeCounts[digits]) { 23 | digitsToCubeCounts[digits] = { 24 | count: 1, 25 | smallestCube: cube 26 | }; 27 | } else { 28 | digitsToCubeCounts[digits].count += 1; 29 | } 30 | 31 | curNum++; 32 | } 33 | return digitsToCubeCounts[digits].smallestCube; 34 | } 35 | console.log(cubicPermutations(5)); 36 | -------------------------------------------------------------------------------- /Euler-063.js: -------------------------------------------------------------------------------- 1 | function powerfulDigitCounts(n) { 2 | function countDigits(num) { 3 | let counter = 0; 4 | while (num > 0) { 5 | num = Math.floor(num / 10); 6 | counter++; 7 | } 8 | return counter; 9 | } 10 | 11 | let numbersCount = 0; 12 | 13 | let curNum = 1; 14 | while (curNum < 10) { 15 | let power = n; 16 | if (power === countDigits(curNum ** power)) { 17 | numbersCount++; 18 | } 19 | curNum++; 20 | } 21 | 22 | return numbersCount; 23 | } 24 | 25 | console.log("4"+powerfulDigitCounts(1)); 26 | -------------------------------------------------------------------------------- /Euler-064.js: -------------------------------------------------------------------------------- 1 | function oddPeriodSqrts(n) { 2 | function getPeriod(num) { 3 | let period = 0; 4 | let m = 0; 5 | let d = 1; 6 | let a = Math.floor(Math.sqrt(num)); 7 | const a0 = a; 8 | while (2 * a0 !== a) { 9 | m = d * a - m; 10 | d = Math.floor((num - m ** 2) / d); 11 | a = Math.floor((Math.sqrt(num) + m) / d); 12 | period++; 13 | } 14 | return period; 15 | } 16 | 17 | function isPerfectSquare(num) { 18 | return Number.isInteger(Math.sqrt(num)); 19 | } 20 | 21 | let counter = 0; 22 | for (let i = 2; i <= n; i++) { 23 | if (!isPerfectSquare(i)) { 24 | if (getPeriod(i) % 2 !== 0) { 25 | counter++; 26 | } 27 | } 28 | } 29 | return counter; 30 | } 31 | 32 | console.log(oddPeriodSqrts(10000)); 33 | -------------------------------------------------------------------------------- /Euler-065.js: -------------------------------------------------------------------------------- 1 | function convergentsOfE(n) { 2 | function sumDigits(num) { 3 | let sum = 0n; 4 | while (num > 0) { 5 | sum += num % 10n; 6 | num = num / 10n; 7 | } 8 | return parseInt(sum); 9 | } 10 | 11 | // BigInt is needed for high convergents 12 | let convergents = [ 13 | [2n, 1n], 14 | [3n, 1n] 15 | ]; 16 | const multipliers = [1n, 1n, 2n]; 17 | for (let i = 2; i < n; i++) { 18 | const [secondLastConvergent, lastConvergent] = convergents; 19 | const [secondLastNumerator, secondLastDenominator] = secondLastConvergent; 20 | const [lastNumerator, lastDenominator] = lastConvergent; 21 | const curMultiplier = multipliers[i % 3]; 22 | 23 | const numerator = secondLastNumerator + curMultiplier * lastNumerator; 24 | const denominator = secondLastDenominator + curMultiplier * lastDenominator; 25 | 26 | convergents = [lastConvergent, [numerator, denominator]] 27 | if (i % 3 === 2) { 28 | multipliers[2] += 2n; 29 | } 30 | } 31 | return sumDigits(convergents[1][0]); 32 | } 33 | 34 | 35 | console.log(convergentsOfE(100)); 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Project-Euler 2 | Solutions Of Project Euler's Problem Using JavaScript 3 | 4 | Problem Website : https://projecteuler.net 5 | Solution Website : https://pabitrabanerjee.newsgoogle.org 6 | --------------------------------------------------------------------------------