{"id":15833721,"url":"https://github.com/itzmeanjan/project-euler","last_synced_at":"2025-04-01T12:26:41.816Z","repository":{"id":106438361,"uuid":"232326056","full_name":"itzmeanjan/project-euler","owner":"itzmeanjan","description":"Another implementation of Project Euler Problems :wink: #ProjectEuler100","archived":false,"fork":false,"pushed_at":"2020-12-20T17:16:38.000Z","size":869,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-04T12:13:09.356Z","etag":null,"topics":["golang","projecteuler","projecteuler-go","projecteuler100"],"latest_commit_sha":null,"homepage":"https://itzmeanjan.github.io/project-euler/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itzmeanjan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-07T13:04:16.000Z","updated_at":"2024-06-19T06:30:21.102Z","dependencies_parsed_at":null,"dependency_job_id":"1edad265-74d4-4441-8553-9081a432b19d","html_url":"https://github.com/itzmeanjan/project-euler","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzmeanjan%2Fproject-euler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzmeanjan%2Fproject-euler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzmeanjan%2Fproject-euler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzmeanjan%2Fproject-euler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itzmeanjan","download_url":"https://codeload.github.com/itzmeanjan/project-euler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246637919,"owners_count":20809702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","projecteuler","projecteuler-go","projecteuler100"],"created_at":"2024-10-05T13:41:45.350Z","updated_at":"2025-04-01T12:26:41.775Z","avatar_url":"https://github.com/itzmeanjan.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# project-euler\nAnother implementation of Project Euler Problems :wink: #ProjectEuler100\n\n## motivation\n\nI just came across one freecodecamp [post](https://www.freecodecamp.org/news/projecteuler100-coding-challenge-competitive-programming/), which tempted me to accept _#ProjectEuler100_ challenge. It's not like that prior to this I never thought of solving these beautiful mathematical problems, but I never opensourced it. So it looks like a great opportunity to me, where I can challenge my thinking and problem solving capability again.\n\n## solutions\n\nI'm planning to stick to _GoLang_ as language of implementation. All solutions will stay in this [directory](./projecteuler/).\n\n### [problem 1](./projecteuler/problem1.go)\n\n#### statement\n\n_If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23._\n\n_Find the sum of all the multiples of 3 or 5 below 1000._\n\n#### solution\n\n233168 in 7.325µs\n\n#### explanation\n\nIterating using a simple for loop _( starting from 3 )_, upto _(X -  1)_, where _X_ is given, and checking divisibility of current number by either 3 or 5. If it's divisible, then we add it up to _sum_ variable. And finally return _sum_, holding expected output.\n\n### [problem 2](./projecteuler/problem2.go)\n\n#### statement\n\n_Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:_\n\n_1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ..._\n\n_By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms._\n\n#### solution\n\n4613732 in 2.752µs\n\n#### explanation\n\nUsing dynamic programming style, for calculating fibonacci terms, recursive strategy will be straightforward but run slow ( and no doubt very expensive ). Starting with a slice of two elements `{1, 2}`, we'll keep calculating next fibonacci term until most recently computed term crosses _4,000,000_. And in each iteration, it'll check whether this term is even or not. If even, we'll add it up to _sum_ variable, which is initialized with _2_ ( because at very beginning _fibArr_, was only holding _2_ as even number )\n\n### [problem 3](./projecteuler/problem3.go)\n\n#### statement\n\n_The prime factors of 13195 are 5, 7, 13 and 29._\n\n_What is the largest prime factor of the number 600851475143 ?_\n\n#### solution\n\n6857 in 171.188338ms\n\n#### explanation\n\nFirst calculates square root of given number, and find out all primes which are under or equals to that sqrt value. Now we'll simply iterate over that prime holder slice, from last to first, i.e. from higher value prime to lower value prime, cause finally, we need to find out maximum prime factor of _num_. That'll allow us to perform lesser number of checkings.\n\nGeneration of primes under _X_, is done using dynamic programming strategy, by updating a slice holding primes, on runtime. Because we know any composite number must have prime factor, lesser than square root of that number. So we'll perform check with prime numbers only, which will save a lot of computation too.\n\n### [problem 4](./projecteuler/problem4.go)\n\n#### statement\n\n_A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99._\n\n_Find the largest palindrome made from the product of two 3-digit numbers._\n\n#### solution\n\n906609 in 172.4µs\n\n#### explanation\n\nWe'll start from end i.e. for finding largest possible palindrome number under _1000_, we'll start checking from _999_ \u0026 keep multiplying two numbers _( \u003c 1000 )_, until I reach _1_. But that'll be brute-force, which is why we'd prefer breaking out of current iteration, as soon as current product _( product in this iteration )_ goes below `largestPalim` _( which is largest palindrome computed upto this point )_.\n\n### [problem 5](./projecteuler/problem5.go)\n\n#### statement\n\n_2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder._\n\n_What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?_\n\n#### solution\n\n232792560 in 1.664408611s\n\n#### explanation\n\nWe'll start finding smallest number divisible by all numbers from _1_ to _20_, at 10, because for any number to be divisible by _10_, it must end with round figure. And keep incrementing number under lens by _10_ ( after each iteration ), which will eventually reduce #-of computational steps required for finding result.\n\n### [problem 6](./projecteuler/problem6.go)\n\n#### statement\n\n_The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385_\n\n_The square of the sum of the first ten natural numbers is,(1 + 2 + ... + 10)2 = 552 = 3025_\n\n_Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640._\n\n_Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum._\n\n#### solution\n\n25164150 in 275ns\n\n#### explanation\n\nWe'll calculate square of sum of {1..100} ( used _n*(n+1)/2_, for finding sum of first _n_ natural numbers ) \u0026 square of each natural number {1..100}, while accumulating them up in a single variable. Finally a simple absolute substraction of those two, will get us desired result.\n\n### [problem 7](./projecteuler/problem7.go)\n\n#### statement\n\n_By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13._\n\n_What is the 10,001st prime number?_\n\n#### solution\n\n104743 in 14.523821ms\n\n#### explanation\n\nWe'll buffer all primes calculated uptil now, and check a certain odd number's _( for reducing number of steps, we're skipping even numbers, cause they are definitely composite )_ divisibility using primes _( buffered )_ under square root of `num`. Finally we return _(x-1)_ indexed term from buffer.\n\n### [problem 8](./projecteuler/problem8.go)\n\n#### statement\n\n_The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832._\n\n_73167176531330624919225119674426574742355349194934_\n_96983520312774506326239578318016984801869478851843_\n_85861560789112949495459501737958331952853208805511_\n_12540698747158523863050715693290963295227443043557_\n_66896648950445244523161731856403098711121722383113_\n_62229893423380308135336276614282806444486645238749_\n_30358907296290491560440772390713810515859307960866_\n_70172427121883998797908792274921901699720888093776_\n_65727333001053367881220235421809751254540594752243_\n_52584907711670556013604839586446706324415722155397_\n_53697817977846174064955149290862569321978468622482_\n_83972241375657056057490261407972968652414535100474_\n_82166370484403199890008895243450658541227588666881_\n_16427171479924442928230863465674813919123162824586_\n_17866458359124566529476545682848912883142607690042_\n_24219022671055626321111109370544217506941658960408_\n_07198403850962455444362981230987879927244284909188_\n_84580156166097919133875499200524063689912560717606_\n_05886116467109405077541002256983155200055935729725_\n_71636269561882670428252483600823257530420752963450_\n\n_Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?_\n\n#### solution\n\n23514624000 in 36.693µs\n\n#### explanation\n\nGiven a _1000_ digit number _( as a string )_, we'll iterate over all indices of this string _( from 0 to 999 )_, so that we can consider all possible consequtive substrings of fixed length. Then we keep multiplying all digits present in each sub-sequence and take max of it. That'll satisfy our need, but multiplication of digits in subsequences is overlapping problem. So, we won't recompute, but use previous iterations cached value _( with care )_, if and only if it's not initial iteration \u0026 first digit of previous subsequence isn't _0_.\n\n### [problem 9](./projecteuler/problem9.go)\n\n#### statement\n\n_A Pythagorean triplet is a set of three natural numbers, a \u003c b \u003c c, for which,_\n_a^2 + b^2 = c^2_\n\n_For example, 32 + 42 = 9 + 16 = 25 = 52._\n\n_There exists exactly one Pythagorean triplet for which a + b + c = 1000._\n_Find the product abc._\n\n#### solution\n\n31875000 in 145.78477ms\n\n#### explanation\n\nWe start iterating from c=999 ( outer loop ), b=998 ( mid loop ), a=997 ( inner most loop ), satisfying a \u003c b \u003c c always. Now we need to check whether a+b+c == 1000 or not, if it's lesser than so, we need to break out of loop, avoiding unnecessary computation. If previous condition and Pythagorean Triplet condition is met, we calculate product of a, b, c, which is our desired result.\n\n### [problem 10](./projecteuler/problem10.go)\n\n#### statement\n\n_The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17._\n\n_Find the sum of all the primes below two million._\n\n#### solution\n\n142913828922 in 585.534206ms\n\n#### explanation\n\nFirst we'll start generating all primes under given number _X_, and then simply summing them up, will get us our desired result. For generating primes, we're going to make use of one method _( GeneratePrimesUnderX )_ written during solving _Problem 3_.\n\n### [problem 11](./projecteuler/problem11.go)\n\n#### statement\n\n_In the 20×20 grid below, four numbers along a diagonal line have been marked in red._\n\n[ 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08\n\n49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00\n\n81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65\n\n52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91\n\n22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80\n\n24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50\n\n32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70\n\n67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21\n\n24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72\n\n21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95\n\n78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92\n\n16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57\n\n86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58\n\n19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40\n\n04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66\n\n88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69\n\n04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36\n\n20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16\n\n20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54\n\n01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48 ]\n\n_The product of these numbers is 26 × 63 × 78 × 14 = 1788696._\n\n_What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?_\n\n#### solution\n\n70600674 in 776.735µs\n\n#### explanation\n\nFirst we go for exploring neighboring element sequences, for any given index in GRID. Now any index can have 8 directions _( at max )_ from it, i.e.\n\n- left\n- right\n- top\n- down\n- top-left\n- top-right\n- bottom-left\n- bottom-right\n\n, given that a certain index which is calculated to be present in neighbor _( along any possible direction )_, is valid, otherwise we don't explore elements along that direction. How many elements to be considered as neighbor, will be specified _( here it's 4 )_. Now we'll simply calculate product of neighboring elements, and get max one for all indices. So, currently we're left with, 400 _( 20x20 GRID, so 400 cells )_, products, all we've to do, is to pick up max number from that list, which is our desired result.\n\n### [problem 12](./projecteuler/problem12.go)\n\n#### statement\n\n_The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:_\n\n_1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ..._\n\n_Let us list the factors of the first seven triangle numbers:_\n\n     1: 1\n     3: 1,3\n     6: 1,2,3,6\n    10: 1,2,5,10\n    15: 1,3,5,15\n    21: 1,3,7,21\n    28: 1,2,4,7,14,28\n\n_We can see that 28 is the first triangle number to have over five divisors._\n\n_What is the value of the first triangle number to have over five hundred divisors?_\n\n#### solution\n\n![perf_stat](assets/ss.jpg)\n\n#### explanation\n\nThis problem is pretty straightforward, all we've to do, is to keep generating triangular numbers, until we find one, which possesses factors _\u003e= 500_. But if we plan to solve this problem deploying only one worker thread, it'll take a lot of time. So we're going to explore go-routines _( leveraging power of modern multi-core CPU architectures )_, that's why this implementation is a bit lengthy. Multi-threaded _( green threads )_ implementation details can be explored in source [code](./projecteuler/problem12.go).\n\n### [problem 13](./projecteuler/problem13.go)\n\n#### statement\n\n_Work out the first ten digits of the sum of the following one-hundred 50-digit numbers._\n\n37107287533902102798797998220837590246510135740250\n46376937677490009712648124896970078050417018260538\n74324986199524741059474233309513058123726617309629\n91942213363574161572522430563301811072406154908250\n23067588207539346171171980310421047513778063246676\n89261670696623633820136378418383684178734361726757\n28112879812849979408065481931592621691275889832738\n44274228917432520321923589422876796487670272189318\n47451445736001306439091167216856844588711603153276\n70386486105843025439939619828917593665686757934951\n62176457141856560629502157223196586755079324193331\n64906352462741904929101432445813822663347944758178\n92575867718337217661963751590579239728245598838407\n58203565325359399008402633568948830189458628227828\n80181199384826282014278194139940567587151170094390\n35398664372827112653829987240784473053190104293586\n86515506006295864861532075273371959191420517255829\n71693888707715466499115593487603532921714970056938\n54370070576826684624621495650076471787294438377604\n53282654108756828443191190634694037855217779295145\n36123272525000296071075082563815656710885258350721\n45876576172410976447339110607218265236877223636045\n17423706905851860660448207621209813287860733969412\n81142660418086830619328460811191061556940512689692\n51934325451728388641918047049293215058642563049483\n62467221648435076201727918039944693004732956340691\n15732444386908125794514089057706229429197107928209\n55037687525678773091862540744969844508330393682126\n18336384825330154686196124348767681297534375946515\n80386287592878490201521685554828717201219257766954\n78182833757993103614740356856449095527097864797581\n16726320100436897842553539920931837441497806860984\n48403098129077791799088218795327364475675590848030\n87086987551392711854517078544161852424320693150332\n59959406895756536782107074926966537676326235447210\n69793950679652694742597709739166693763042633987085\n41052684708299085211399427365734116182760315001271\n65378607361501080857009149939512557028198746004375\n35829035317434717326932123578154982629742552737307\n94953759765105305946966067683156574377167401875275\n88902802571733229619176668713819931811048770190271\n25267680276078003013678680992525463401061632866526\n36270218540497705585629946580636237993140746255962\n24074486908231174977792365466257246923322810917141\n91430288197103288597806669760892938638285025333403\n34413065578016127815921815005561868836468420090470\n23053081172816430487623791969842487255036638784583\n11487696932154902810424020138335124462181441773470\n63783299490636259666498587618221225225512486764533\n67720186971698544312419572409913959008952310058822\n95548255300263520781532296796249481641953868218774\n76085327132285723110424803456124867697064507995236\n37774242535411291684276865538926205024910326572967\n23701913275725675285653248258265463092207058596522\n29798860272258331913126375147341994889534765745501\n18495701454879288984856827726077713721403798879715\n38298203783031473527721580348144513491373226651381\n34829543829199918180278916522431027392251122869539\n40957953066405232632538044100059654939159879593635\n29746152185502371307642255121183693803580388584903\n41698116222072977186158236678424689157993532961922\n62467957194401269043877107275048102390895523597457\n23189706772547915061505504953922979530901129967519\n86188088225875314529584099251203829009407770775672\n11306739708304724483816533873502340845647058077308\n82959174767140363198008187129011875491310547126581\n97623331044818386269515456334926366572897563400500\n42846280183517070527831839425882145521227251250327\n55121603546981200581762165212827652751691296897789\n32238195734329339946437501907836945765883352399886\n75506164965184775180738168837861091527357929701337\n62177842752192623401942399639168044983993173312731\n32924185707147349566916674687634660915035914677504\n99518671430235219628894890102423325116913619626622\n73267460800591547471830798392868535206946944540724\n76841822524674417161514036427982273348055556214818\n97142617910342598647204516893989422179826088076852\n87783646182799346313767754307809363333018982642090\n10848802521674670883215120185883543223812876952786\n71329612474782464538636993009049310363619763878039\n62184073572399794223406235393808339651327408011116\n66627891981488087797941876876144230030984490851411\n60661826293682836764744779239180335110989069790714\n85786944089552990653640447425576083659976645795096\n66024396409905389607120198219976047599490197230297\n64913982680032973156037120041377903785566085089252\n16730939319872750275468906903707539413042652315011\n94809377245048795150954100921645863754710598436791\n78639167021187492431995700641917969777599028300699\n15368713711936614952811305876380278410754449733078\n40789923115535562561142322423255033685442488917353\n44889911501440648020369068063960672322193204149535\n41503128880339536053299340368006977710650566631954\n81234880673210146739058568557934581403627822703280\n82616570773948327592232845941706525094512325230608\n22918802058777319719839450180888072429661980811197\n77158542502016545090413245809786882778948721859617\n72107838435069186155435662884062257473692284509516\n20849603980134001723930671666823555245252804609722\n53503534226472524250874054075591789781264330331690\n\n#### solution\n\n5537376230 in 173.641µs\n\n#### explanation\n\nFor handling arbitrary precision numbers, Golang provides us with \"math/big\" package, which is pretty handy in manipulating big numbers. After summing these 100 big numbers, we'll simply convert it to string, so that slicing first 10 digits become easier.\n\n### [problem 14](./projecteuler/problem14.go)\n\n#### statement\n\n_The following iterative sequence is defined for the set of positive integers:_\n\n_n → n/2 (n is even)_\n_n → 3n + 1 (n is odd)_\n\n_Using the rule above and starting with 13, we generate the following sequence:_\n\n_13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1_\n\n_It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1._\n\n_Which starting number, under one million, produces the longest chain ?_\n\n_NOTE: Once the chain starts the terms are allowed to go above one million._\n\n#### solution\n\n837799 in 1.345537614s\n\n#### explanation\n\nFor finding longest collatz sequence, generated by which number under _10^6_, we're going to deploy _10^6_ number of light-weight go-routines, for sake of faster computation. Next term of collatz sequence is generated by following rule\n\n```golang\nif n%2 == 0 {\n\treturn n / 2\n}\nreturn 3*n + 1\n```\n\nWe need to keep computing until we reach 1 _( because it's thought that all collatz sequences end at 1 )_.\n\n### [problem 15](./projecteuler/problem15.go)\n\n#### statement\n\n_Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner._\n\n_How many such routes are there through a 20×20 grid?_\n\n#### solution\n\n137846528820 in 22m41.809635403s _( **using Recursion** )_\n\n137846528820 in 4.076µs _( **using Bottom-Up approach i.e. Dynamic Programming** )_\n\n#### explanation\n\nRecursively computes possible number of paths for reaching bottom-right cell, while starting at top-left cell (0, 0). We can think of it like we're splitting into two child _( at max )_ routes at every vertex, until we get to target vertex _(2, 2)_ for example case.\n\n![lattice_path](assets/lattice_path.jpg)\n\n**Improvement** - We can probably understand this problem is having following two properties\n\n- Optimal Substructure\n- Overlapping Subproblems\n\nwhich are enough to indicate that this one can be solved using Dynamic Programming. So we're going to use a two dimentional array to store number of possible paths which can be taken from a certain index _(i, j)_, to reach bottom-right most index _(20, 20)_.\n\n![lattice_path_dp](assets/lattice_path_dp.jpg)\n\n### [problem 16](./projecteuler/problem16.go)\n\n#### statement\n\n_2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26._\n\n_What is the sum of the digits of the number 2^1000?_\n\n#### solution\n\n1366 in 20.087µs\n\n#### explanation\n\nCalculates sum of digits of _base ^ pow_, using `math/big` package of go standard library.\n\n### [problem 18](./projecteuler/problem18.go)\n\n#### statement\n\n_By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23._\n\n3\n\n7 4\n\n2 4 6\n\n8 5 9 3\n\n_That is, 3 + 7 + 4 + 9 = 23._\n\n_Find the maximum total from top to bottom of the triangle below:_\n\n75\n\n95 64\n\n17 47 82\n\n18 35 87 10\n\n20 04 82 47 65\n\n19 01 23 75 03 34\n\n88 02 77 73 07 63 67\n\n99 65 04 28 06 16 70 92\n\n41 41 26 56 83 40 80 70 33\n\n41 48 72 33 47 32 37 16 94 29\n\n53 71 44 65 25 43 91 52 97 51 14\n\n70 11 33 28 77 73 17 78 39 68 17 57\n\n91 71 52 38 17 14 91 43 58 50 27 29 48\n\n63 66 04 68 89 53 67 30 73 16 69 87 40 31\n\n04 62 98 27 23 09 70 98 73 93 38 53 60 04 23\n\n_NOTE: As there are only 16384 routes, it is possible to solve this problem by trying every route. However, Problem 67, is the same challenge with a triangle containing one-hundred rows; it cannot be solved by brute force, and requires a clever method! ;o)_\n\n#### solution\n\n1074 in 16.624µs\n\n#### explanation\n\nI'll use following triangle for explanatory purpose.\n\n```\n3\n\n7 4\n\n2 4 6\n\n8 5 9 3\n```\nWe need to choose among _2^(n-1)_ = _2^3_ = _8_ paths from root to bottom level _( thinking of it as it's a binary tree )_. Bruteforce won't help for larger size triangle, so we'll start updating node value of level 1 by accumulating node value of previous level _( root level is kept unchanged )_, and continue this process. When we have multiple competiting values for a certain position, we'll choose max of it, cause our objective is to find max path value, running from top to bottom.\n\n![max_path_sum_1](assets/max_path_sum_1.jpg)\n\n![max_path_sum_2](assets/max_path_sum_2.jpg)\n\nThus _**23**_ is max cost path, from top to bottom level. Algorithm's time and space complexity ∈ _0(n^2)_, where n = # of rows in triangle.\n\n### [problem 19](./projecteuler/problem19.go)\n\n#### statement\n\n_You are given the following information, but you may prefer to do some research for yourself._\n\n_1 Jan 1900 was a Monday. Thirty days has September, April, June and November. All the rest have thirty-one, Saving February alone, Which has twenty-eight, rain or shine. And on leap years, twenty-nine. A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400._\n\n_How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?_\n\n#### solution\n\n171 in 57.092µs\n\n#### explanation\n\nStarts iteration from _31/ 11/ 1899_, which was _Sunday_ ( given ), keeps calculating next _Sunday_, until we reach _01/ 01/ 2001_. In each iteration we need to check, whether current date is within _01/01/1901 - 31/12/2000_ \u0026\u0026 it's first day of month or not.\n\n### [problem 20](./projecteuler/problem20.go)\n\n#### statement\n\n_n! means n × (n − 1) × ... × 3 × 2 × 1_\n\n_For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27._\n\n_Find the sum of the digits in the number 100!_\n\n#### solution\n\n648 in 25.651µs\n\n#### explanation\n\nFirst calculates factorial of any given number `n` as _big.Int_, after that we simply add digits up of that number, to get desired result.\n\n### [problem 21](./projecteuler/problem21.go)\n\n#### statement\n\n_Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n)._\n_If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b are called amicable numbers._\n\n_For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220._\n\n_Evaluate the sum of all the amicable numbers under 10000._\n\n#### solution\n\n31626 in 629.03783ms\n\n#### explanation\n\nWe start from 1 and go upto 9999, for checking whether that number is forming amicable pair or not. Using caching mechanism, will help us in halving number of checks to be performed.\n\n### [problem 22](./projecteuler/problem22.go)\n\n#### statement\n\n_Using [names.txt](assets/p022_names.txt) (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score._\n\n_For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 × 53 = 49714._\n\n_What is the total of all the name scores in the file?_\n\n#### solution\n\n871198282 in 216.833152ms\n\n#### explanation\n\nWe start by reading content of given data file, and converting it into a string slice _( slice holding names )_. After that we'll go for a ascending sort of names. Now we need to calculate namescore of each name, following given rule. Finally we'll return sum of those scores.\n\n### [problem 23](./projecteuler/problem23.go)\n\n#### statement\n\n_A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number._\n\n_A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n._\n\n_As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit._\n\n_Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers._\n\n#### solution\n\n4179871 in 17.033928895s\n\n#### explanation\n\nWe'll start by creating a cache of abundant numbers \u003c _28124_, which will be used for checking whether we can represent any +ve integer \u003c _28124_, as a sum of two abudant numbers or not. Finally we'll return sum of those numbers which can't be written as sum of two abundant numbers.\n\n### [problem 24](./projecteuler/problem24.go)\n\n#### statement\n\n_A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are:_\n\n012   021   102   120   201   210\n\n_What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?_\n\n#### solution\n\n2783915460 in 50.254669ms\n\n#### explanation\n\nGenerating next lexicographic permutation using Indian mathematician Narayana Pandita's [algorithm](https://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order). Assuming we're given with a permutation of _n_-elements in a[n] array, now next lexicographic permutation can be found using following algorithm.\n\n- Find the largest index _i_ such that a[i] \u003c a[i + 1]. If no such index exists, the permutation is the last permutation.\n- Find the largest index _j_ greater than _i_ such that a[i] \u003c a[j].\n- Swap the value of a[i] with that of a[j].\n- Reverse the sequence from a[i + 1] up to and including the final element a[n-1]\n\nWe'll keep generating next lexicographic permutation until we get to reach _10^6_-th permutation.\n\n### [problem 25](./projecteuler/problem25.go)\n\n#### statement\n\n_The Fibonacci sequence is defined by the recurrence relation:_\n\n_Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1._\n\n_Hence the first 12 terms will be:_\n\nF1 = 1\n\nF2 = 1\n\nF3 = 2\n\nF4 = 3\n\nF5 = 5\n\nF6 = 8\n\nF7 = 13\n\nF8 = 21\n\nF9 = 34\n\nF10 = 55\n\nF11 = 89\n\nF12 = 144\n\n_The 12th term, F12, is the first term to contain three digits._\n\n_What is the index of the first term in the Fibonacci sequence to contain 1000 digits?_\n\n#### solution\n\n4782 in 63.3032ms\n\n#### explanation\n\nWe'll keep generating fibonacci numbers, until we get first fibonacci term to have _1000_ digits, with help _\"math/big\"_ package. Index of that fibonacci term to be returned.\n\n### [problem 27](./projecteuler/problem27.go)\n\n#### statement\n\n_Euler discovered the remarkable quadratic formula:_\n\nn^2 + n + 41\n\n_It turns out that the formula will produce 40 primes for the consecutive integer values 0≤n≤39. However, when n=40,402+40+41=40(40+1)+41 is divisible by 41, and certainly when n=41,41^2+41+41 is clearly divisible by 41._\n\n_The incredible formula n^2−79n+1601 was discovered, which produces 80 primes for the consecutive values 0≤n≤79_\n\n_The product of the coefficients, −79 and 1601, is −126479._\n\n_Considering quadratics of the form: n^2+an+b, where |a|\u003c1000 and |b|≤1000 where |n| is the modulus/absolute value of `n` e.g. |11|=11 and |−4|=4_\n\n_Find the product of the coefficients, a and b, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n=0._\n\n#### solution\n\n-59231 in 4.852316977s\n\n#### explanation\n\nFor leveraging power of multiple CPU cores of modern computers, we'll be using go-routines, for computing how many consequtive primes can be generated by _( n^2 + a*n + b )_, for some given _a_ \u0026 _b_ combination. And we'll cache maximum value computed upto this point, which will be returned at end of computation.\n\n### [problem 28](./projecteuler/problem28.go)\n\n#### statement\n\n_Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:_\n\n21 22 23 24 25\n\n20  7  8  9 10\n\n19  6  1  2 11\n\n18  5  4  3 12\n\n17 16 15 14 13\n\n_It can be verified that the sum of the numbers on the diagonals is 101._\n\n_What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way?_\n\n#### solution\n\n669171001 in 26.457464ms\n\n#### explanation\n\nWe'll start by calculating field values of sub-matrix of size _3 x 3_, centered at intersection of two diagonals of matrix. Center field of matrix is holding _1_. We'll keep calculating these field values, upto size \u003c= _1001_, increasing size by 2 at each iteration. \n\n![spiral_diagonal](spiral_diagonal.jpg)\n\nAnd finally, sum of all values present on two diagonals of matrix, to be returned.\n\n### [problem 29](./projecteuler/problem29.go)\n\n#### statement\n\n_Consider all integer combinations of ab for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5:_\n\n2^2=4, 2^3=8, 2^4=16, 2^5=32\n\n3^2=9, 3^3=27, 3^4=81, 3^5=243\n\n4^2=16, 4^3=64, 4^4=256, 4^5=1024\n\n5^2=25, 5^3=125, 5^4=625, 5^5=3125\n\n_If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms:_\n\n_4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125_\n\n_How many distinct terms are in the sequence generated by ab for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100?_\n\n#### solution\n\n9183 in 32.185177ms\n\n#### explanation\n\nWe'll simply use one hash map to keep track of number unique terms generated by _a^b_, _2 \u003c= a \u003c= 100 \u0026 2 \u003c= b \u003c=100_, and cheers to _\"math/big\"_ package.\n\n### [problem 30](./projecteuler/problem30.go)\n\n#### statement\n\n_Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:_\n\n1634 = 1^4 + 6^4 + 3^4 + 4^4\n\n8208 = 8^4 + 2^4 + 0^4 + 8^4\n\n9474 = 9^4 + 4^4 + 7^4 + 4^4\n\n_As 1 = 1^4 is not a sum it is not included._\n\n_The sum of these numbers is 1634 + 8208 + 9474 = 19316._\n\n_Find the sum of all the numbers that can be written as the sum of fifth powers of their digits._\n\n#### solution\n\n443839 in 406.554596ms\n\n#### explanation\n\nWe'll start checking whether a certain number equals to sum of fifth power of their digits, from 10 and go upto 10^6, while keeping track of sum of numbers which are satisfying this criteria.\n\n### [problem 31](./projecteuler/problem31.go)\n\n#### statement\n\n_In the United Kingdom the currency is made up of pound (£) and pence (p). There are eight coins in general circulation:_\n\n_1p, 2p, 5p, 10p, 20p, 50p, £1 (100p), and £2 (200p)._\n\n_It is possible to make £2 in the following way:_\n\n_1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p_\n\n_How many different ways can £2 be made using any number of coins?_\n\n#### solution\n\n73682 in 3.532µs\n\n#### explanation\n\nWe can make 3p using _{ 1p }_ coins, only in one possible way i.e. _{ 1p + 1p + 1p }_. But when given with _{ 1p, 2p }_ coins, we'll have one more possible way _{ 1p + 2p }_ of making 3p. Now our target it to count £2 _( = 200p )_ using _1p, 2p, 5p, 10p, 20p, 50p, £1 (100p), and £2 (200p)_ coins, where it's clearly visible that multiple subproblems are overlapping, and it also has an optimal substructure property. So we'll prefer dynamic programming to recursion, for counting possible number of ways. We'll use one single dimentational array of length `(targetV + 1)` = `201`, where we'll store possible number of ways for making all values from _0p_ to _200p_, using given coins.\n\n### [problem 32](./projecteuler/problem32.go)\n\n#### statement\n\n_We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital._\n\n_The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital._\n\n_Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital._\n\n_HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum._\n\n#### solution\n\n45228 in 12.040034ms\n\n#### explanation\n\nWe'll iterate over a range _(2-9999)_, and explore all possible products of them, so that we don't miss any possible _multiplicand/ multiplier/ product_ combination, for which pandigital criteria gets satisfied. Now we need to also consider one matter that some products can be obtained in multiple ways, so we'll simply choose to use hash map for storing products, so that we don't count any certain product more than ones. For reducing number of checks being performed, we'll only check those combinations which will have 9 digits total i.e. _( digitCount(multiplicand) + digitCount(multiplier) + digitCount(product) ) == 9_, cause we're checking pandigital products from 1 through 9.\n\n### [problem 33](./projecteuler/problem33.go)\n\n#### statement\n\n_The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s._\n\n_We shall consider fractions like, 30/50 = 3/5, to be trivial examples._\n\n_There are exactly four non-trivial examples of this type of fraction, less than one in value, and containing two digits in the numerator and denominator._\n\n_If the product of these four fractions is given in its lowest common terms, find the value of the denominator._\n\n#### solution\n\n100 in 8.947783ms\n\n#### explanation\n\nFirst we'll generate all those fractions, having exactly two digits in both numerator \u0026 denominator, and not having _0_ as digit. In next step, we'll go for extracting curious fractions _( as per given definition )_. After that, we'll multiply those filtered out fractions, which will be represented in its lowest common terms. Finally we'll return denominator of fraction.\n\n### [problem 34](./projecteuler/problem34.go)\n\n#### statement\n\n_145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145._\n\n_Find the sum of all numbers which are equal to the sum of the factorial of their digits._\n\n_Note: as 1! = 1 and 2! = 2 are not sums they are not included._\n\n#### solution\n\n40730 in 13.280042ms\n\n#### explanation\n\nFirst we'll build a slice holding all digits _( 0 - 9 )_ of a given number, which will then be updated with each digits corresponding factorial values, _( which will stay precomputed in a buffer i.e. hash map )_. Then we'll sum up that slice and compare it with given number, if they are equal, it's curious number, which are searching for. We'll find all curious numbers, and sum them up. By the way, we've only two curious numbers _145_ \u0026 _40225_\n\n### [problem 35](./projecteuler/problem35.go)\n\n#### statement\n\n_The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime._\n\n_There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97._\n\n_How many circular primes are there below one million?_\n\n#### solution\n\n55 in 1.256801259s\n\n#### explanation\n\nWe'll keep one hash map holding all primes explored yet, because while checking _13_, which is a prime, we also check its rotated form i.e. _31_, which is also prime, so 13 and 31 both are circular primes. But in some future iteration, if we go for checking 31 again, that'll result into recomputation of precomputed values, wasting computational resources. Finally length of prime holder hash map to be returned.\n\n### [problem 36](./projecteuler/problem36.go)\n\n#### statement\n\n_The decimal number, 585 = 10010010012 (binary), is palindromic in both bases._\n\n_Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2._\n\n_(Please note that the palindromic number, in either base, may not include leading zeros.)_\n\n#### solution\n\n872187 in 26.343636ms\n\n#### explanation\n\nWe check all numbers _from 2 to 10^6_, whether they are palindrome or not, of yes, then we convert it into binary, which is then checked for palindrome nature; else we go for next decimal number. Finally we return sum of all numbers, which are palindrome in both bases _( 2 \u0026 10 )_.\n\n### [problem 37](./projecteuler/problem37.go)\n\n#### statement\n\n_The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3._\n\n_Find the sum of the only eleven primes that are both truncatable from left to right and right to left._\n\n_NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes._\n\n#### solution\n\n748317 in 583.690604ms\n\n#### explanation\n\nWe'll start checking from _10_, and keep moving forward until we get to explore _11_ fully truncatable primes. For each given number, we'll first check whether number is left truncatable. If yes, we go for right truncatability check, else we say it's not fully truncatable. Finally sum of those 11 numbers to be returned.\n\n### [problem 38](./projecteuler/problem38.go)\n\n#### statement\n\n_Take the number 192 and multiply it by each of 1, 2, and 3:_\n\n192 × 1 = 192\n\n192 × 2 = 384\n\n192 × 3 = 576\n\n_By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3)_\n\n_The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1,2,3,4,5)._\n\n_What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n \u003e 1?_\n\n#### solution\n\n932718654 in 10.566131ms\n\n#### explanation\n\nWe'll start from 2 and go upto 9876, for each number we'll keep it multiplying with numbers _{1, 2, .., n}_, where n \u003e 1 _( and to be incremented by 1 in each iteration )_, and their concatenated products to be checked for pandigital nature _from 1 though 9_. To reduce number of checks, we'll only consider those numbers having exactly 9 digits. For numbers having lesser digits, we'll skip to next iteration. And for numbers with digit count \u003e 9, we'll break out of this checking loop, and consider next multiplicand. Multiplicands to be considered are from 2 to 9876, due to the fact that, for any number greater than that, we'll always loose 9 digit lengthy concatenated product criteria. E.g. lets take _9877_, and products generated by multiplying _{1, 2}_, and after concatenation, it'll be _{9, 8, 7, 7, 1, 9, 7, 5, 4}_, which is 9 digit lengthy, but not pandigital, but when we try to multiply it with _{1, 2, 3}_, their concatenated products will make _{9, 8, 7, 7, 1, 9, 7, 5, 4, 2, 9, 6, 3, 1}_, which is definitely not 9 digit, so we don't need to check them at all.\n\n![pandigital_multiples](assets/pandigital_multiples.jpg)\n\nFinally we'll return maximum 1 though 9 pandigital number, that can be obtained this way.\n\n### [problem 39](./projecteuler/problem39.go)\n\n#### statement\n\n_If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120._\n\n_{20,48,52}, {24,45,51}, {30,40,50}_\n\n_For which value of p ≤ 1000, is the number of solutions maximised?_\n\n#### solution\n\n![interger_right_triangle](assets/interger_right_triangle.jpg)\n\n#### explanation\n\nWe need to ensure for some combination of _a, b, c_, `a + b + c == p \u0026\u0026 a^2 + b^2 == c^2` must be satisfied for that _a, b, c_ combination to be considered as valid. We'll try to find out how many number of ways we can form a right triangle, when `p` is given, by generating _a, b, c_. Our job is to find out maximum `p` _\u003c 1001_, so that number of right triangles generated is maximum.\n\n### [problem 40](./projecteuler/problem40.go)\n\n#### statement\n\n_An irrational decimal fraction is created by concatenating the positive integers:_\n\n_0.123456789101112131415161718192021..._\n\n_It can be seen that the 12th digit of the fractional part is 1._\n\n_If dn represents the nth digit of the fractional part, find the value of the following expression._\n\n_d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000_\n\n#### solution\n\n210 in 11.470216ms\n\n#### explanation\n\nWe'll not store all 10^6 digits in a slice, so that later we can compute required equation value by looking up values from slice positions, rather we'll choose one tricky way, in which only 1-5 digits ( at max ) will be kept at a time \u0026 `stopDigit` positions i.e. _1, 10, 100, 1000, 10000, 100000, 1000000_ will be kept track of, when close by we'll pick digit at corresponding `stopDigit` position in a hash map, which will be later used for generating result of given equation.\n\n### [problem 41](./projecteuler/problem41.go)\n\n#### statement\n\n_We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime._\n\n_What is the largest n-digit pandigital prime that exists?_\n\n#### solution\n\n7652413 in 2m33.647939438s\n\n#### explanation\n\nWe'll keep calculating maximum number that can be represented using `n`-digits, which is also pandigital \u0026 prime, in several go-routines. Each go-routine will report to listener. In hope of performing lesser number of computations, we'll start checking from _9999_ ( for 4 digit pandigital prime number ), and stop as soon as we find a single number satisfying both conditions, which is _4231_. Finally we'll return maximum `n`-digit pandigital prime number, it's pretty much understandable that maximum value of `n` can be _9_.\n\n### [problem 42](./projecteuler/problem42.go)\n\n#### statement\n\n_The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangle numbers are:_\n\n_1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ..._\n\n_By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value is a triangle number then we shall call the word a triangle word._\n\n_Using [words.txt](assets/p042_words.txt) (right click and 'Save Link/Target As...'), a 16K text file containing nearly two-thousand common English words, how many are triangle words?_\n\n#### solution\n\n162 in 2.508198ms\n\n#### explanation\n\nWe'll read given file content and obtain a slice of words, and each of them will be sent to one function for checking their triangle property. For each word, we'll compute its word value, and check whether that number is triangular or not. Finally number of triangle words to be returned.\n\n### [problem 43](./projecteuler/problem43.go)\n\n#### statement\n\n_The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a rather interesting sub-string divisibility property._\n\n_Let d1 be the 1st digit, d2 be the 2nd digit, and so on. In this way, we note the following:_\n\nd2d3d4=406 is divisible by 2\n\nd3d4d5=063 is divisible by 3\n\nd4d5d6=635 is divisible by 5\n\nd5d6d7=357 is divisible by 7\n\nd6d7d8=572 is divisible by 11\n\nd7d8d9=728 is divisible by 13\n\nd8d9d10=289 is divisible by 17\n\n_Find the sum of all 0 to 9 pandigital numbers with this property._\n\n#### solution\n\n16695334890 in 1.260754677s\n\n#### explanation\n\nWe need to keep checking all 0-9 pandigital numbers, which are satisfying criteria given in above question. We can do either of two things :\n\n- Start with first 10 digit number, and keep checking all 10 digit numbers, whether they are 0-9 pandigital and satisfying above given criteria\n- Or start with smallest 10 digit number that is 0-9 pandigital, and keep generating lexicographic permutations until we get _0_ as first digit of permutation i.e. _[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]_, and in each pass, we'll check whether that number satifies above given criterias or not.\n\nObviously second choice is better, as we're going to check lesser number and it's always guaranted that we're checking a number which is 0-9 pandigital i.e. we can simply skip pandigital check.\n\nLets take an example, _102_, which is 0-2 pandigital, can only generate 0-2 pandigital permutations, when we generate next term using lexicographic permutation generation rule i.e. _120, 201, 210_. And next term generated is _012_, which is very first term and having 0 at beginning, so it's not really a 0-2 pandigital number, rather it's a 1-2 pandigital number. Which is why we're checking until we get first digit as _0_ in case of 0-9 pandigital numbers.\n\nFinally we'll add those 0-9 pandigital numbers, which are satisfying above given criteria.\n\n### [problem 44](./projecteuler/problem44.go)\n\n#### statement\n\n_Pentagonal numbers are generated by the formula, Pn=n(3n−1)/2. The first ten pentagonal numbers are:_\n\n_1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ..._\n\n_It can be seen that P4 + P7 = 22 + 70 = 92 = P8. However, their difference, 70 − 22 = 48, is not pentagonal._\n\n_Find the pair of pentagonal numbers, Pj and Pk, for which their sum and difference are pentagonal and D = |Pk − Pj| is minimised; what is the value of D?_\n\n#### solution\n\n5482660 in 7.281894631s\n\n#### explanation\n\nWe'll keep track of all pentagonal numbers generated, and once a new pentagonal number is generated we'll combine it with all remaining elements; and that pair to be checked for following condition\n\n- Is a + b Pentagonal ?\n- Is |a - b| Pentagonal ?\n\nIf both of them are yes, only them, we can stop searching for desired pair, and return absolute difference of those two pentagonal numbers, which is also a pentagonal number.\n\n### [problem 45](./projecteuler/problem45.go)\n\n#### statement\n\n_Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:_\n\nTriangle \t  \tTn=n(n+1)/2 \t  \t1, 3, 6, 10, 15, ...\n\nPentagonal \t  \tPn=n(3n−1)/2 \t  \t1, 5, 12, 22, 35, ...\n\nHexagonal \t  \tHn=n(2n−1) \t  \t1, 6, 15, 28, 45, ...\n\n_It can be verified that T285 = P165 = H143 = 40755._\n\n_Find the next triangle number that is also pentagonal and hexagonal._\n\n#### solution\n\n1533776805 in 1.659591111s\n\n#### explanation\n\nWe'll keep computing next triangular number _( starting from 286-th triangular number )_\n, until we find one which is pentagonal and hexagonal too.\n\n### [problem 46](./projecteuler/problem46.go)\n\n#### statement\n\n_It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square._\n\n9 = 7 + 2×1^2\n\n15 = 7 + 2×2^2\n\n21 = 3 + 2×3^2\n\n25 = 7 + 2×3^2\n\n27 = 19 + 2×2^2\n\n33 = 31 + 2×1^2\n\n_It turns out that the conjecture was false._\n\n_What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?_\n\n#### solution\n\n5777 in 7.999267ms\n\n#### explanation\n\nWe'll keep a buffer of primes, which will be first filled up, by generating all primes under _100_. Now we'll start checking from 35 and keep checking all odd numbers, until we find one which doesn't satisfy Goldbach's Conjecture. To avoid huge recomputation of primes, we'll keep modifying that same slice of primes whenever we run out of sufficient number of primes.\n\n### [problem 47](./projecteuler/problem47.go)\n\n#### statement\n\n_The first two consecutive numbers to have two distinct prime factors are:_\n\n14 = 2 × 7\n15 = 3 × 5\n\n_The first three consecutive numbers to have three distinct prime factors are:_\n\n644 = 2² × 7 × 23\n\n645 = 3 × 5 × 43\n\n646 = 2 × 17 × 19.\n\n_Find the first four consecutive integers to have four distinct prime factors each. What is the first of these numbers?_\n\n#### solution\n\n134043 in 2.836098132s\n\n#### explanation\n\nWe'll start with _1, 2, 3, 4_, for each of them we'll find their unique prime factors and keep it in cache, if for each of them unique prime factor count satisfies given `count` value, then we've obtained our solution. Until we find such a solution we'll keep exploring next combinations. Now for avoiding huge recomputation of primes, we'll no doubt cache them and use it in successive computations. Another thing to be noticed, if we explore _1, 2, 3, 4_, in next iteration we'll explore _2, 3, 4, 5_ and next to that _3, 4, 5, 6_ i.e. in each iteration we need to only compute a single element's prime factors, others are precompted, which saves a lot of CPU cycles.\n\n### [problem 48](./projecteuler/problem48.go)\n\n#### statement\n\n_The series, 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317._\n\n_Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000._\n\n#### solution\n\n9110846700 in 6.437555ms\n\n#### explanation\n\nUsing help of _\"math/big\"_ of golang, we'll keep computing power of x^x \u0026 summing them up in an accumulator, as long as _x \u003c= 1000_. Finally returned last 10 digits of sum of series.\n\n### [problem 49](./projecteuler/problem49.go)\n\n#### statement\n\n_The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways:_\n\n(i) each of the three terms are prime, and, \n\n(ii) each of the 4-digit numbers are permutations of one another.\n\n_There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit increasing sequence._\n\n_What 12-digit number do you form by concatenating the three terms in this sequence?_\n\n#### solution\n\n296962999629 in 2m44.957077262s\n\n#### explanation\n\nFirst we'll generate all primes having four digits, now we'll keep choosing three primes _( from that set )_ in all possible ways. And each of them to validated against criterias given in question, if it satisfies so \u0026 other than _{ 1487, 4817, 8147 }_, then we've obtained our desired solution. Because it's already given that we've only two sequence such that.\n\n### [problem 50](./projecteuler/problem50.go)\n\n#### statement\n\n_The prime 41, can be written as the sum of six consecutive primes:_\n\n41 = 2 + 3 + 5 + 7 + 11 + 13\n\n_This is the longest sum of consecutive primes that adds to a prime below one-hundred._\n\n_The longest sum of consecutive primes below one-thousand that adds to a prime, contains 21 terms, and is equal to 953._\n\n_Which prime, below one-million, can be written as the sum of the most consecutive primes?_\n\n#### solution\n\n997651 in 7.538766769s\n\n#### explanation\n\nFirst we'll generate all primes under 10^6, and keep them in a given slice. Now we'll compute sum of those primes. Our objective is to find out longest consecutive prime sequence, which has sum _\u003c 10^6_. So we need two pointers, one pointing at beginning of sequence _( i.e. starting index of sequence under consideration )_ \u0026 another pointing at end of sequence, which is to be modified by inner loop index. And front index gets controlled by outer loop. For avoiding huge recomputation of primes, we'll cache previous iteration's sum, and substract last term of previous sequence, to get sum of current sequence, which is simply one lesser than previous iterations last index.\n\n![consecutive_prime_sum](assets/consecutive_prime_sum.jpg)\n\n### [problem 51](./projecteuler/problem51.go)\n\n#### statement\n\n_By replacing the 1st digit of the 2-digit number *3, it turns out that six of the nine possible values: 13, 23, 43, 53, 73, and 83, are all prime._\n\n_By replacing the 3rd and 4th digits of 56**3 with the same digit, this 5-digit number is the first example having seven primes among the ten generated numbers, yielding the family: 56003, 56113, 56333, 56443, 56663, 56773, and 56993. Consequently 56003, being the first member of this family, is the smallest prime with this property._\n\n_Find the smallest prime which, by replacing part of the number (not necessarily adjacent digits) with the same digit, is part of an eight prime value family._\n\n#### solution\n\n121313 in 4.654042749s\n\n#### explanation\n\nWe'll keep generating primes of certain length, starting from 2. For each of them, we'll try to replace _1 to len(prime)-1_, number of digits by _0-9_, which will eventually generate _\u003c= 10_ new numbers _( at min 9 )_. Now we'll check whether this series is having `x` number of primes or not. If yes, we'll return starting number of this prime series, else we'll go for exploring another prime.\n\n### [problem 52](./projecteuler/problem52.go)\n\n#### statement\n\n_It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order._\n\n_Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits._\n\n#### solution\n\n142857 in 206.462802ms\n\n#### explanation\n\nWe'll keep exploring _( starting with 1 )_ until we get one such number, which is when multplied with each of _{2, 3, 4, 5, 6}_, will be permutation of same digits\n\n### [problem 53](./projecteuler/problem53.go)\n\n#### statement\n\n_There are exactly ten ways of selecting three from five, 12345:_\n\n_123, 124, 125, 134, 135, 145, 234, 235, 245, and 345_\n\n_In combinatorics, we use the notation, (5C3)=10_\n\n_In general, (nr)=n!r!(n−r)!, where r≤n, n!=n×(n−1)×...×3×2×1, and 0!=1_\n\n_It is not until n=23, that a value exceeds one-million: (23C10)=1144066_\n\n_How many, not necessarily distinct, values of (nCr) for 1≤n≤100, are greater than one-million?_\n\n#### solution\n\n4075 in 60.199108ms\n\n#### explanation\n\nWe're going to leverage caching mechanism heavily, for choosing _r_ many elements from _n_ many elements, where _1 \u003c= r \u003c= n_, by building pascal triangle only once for a certain _n_. And we'll keep track of how many of those choice counts are _\u003e10^6_, which will be returned.\n\n### [problem 54](./projecteuler/problem54.go)\n\n#### statement\n\n_In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way:_\n\nHigh Card: Highest value card.\n\nOne Pair: Two cards of the same value.\n\nTwo Pairs: Two different pairs.\n\nThree of a Kind: Three cards of the same value.\n\nStraight: All cards are consecutive values.\n\nFlush: All cards of the same suit.\n\nFull House: Three of a kind and a pair.\n\nFour of a Kind: Four cards of the same value.\n\nStraight Flush: All cards are consecutive values of same suit.\n\nRoyal Flush: Ten, Jack, Queen, King, Ace, in same suit.\n\n_The cards are valued in the order:_\n\n_2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace._\n\n_If two players have the same ranked hands then the rank made up of the highest value wins; for example, a pair of eights beats a pair of fives (see example 1 below). But if two ranks tie, for example, both players have a pair of queens, then highest cards in each hand are compared (see example 4 below); if the highest cards tie then the next highest cards are compared, and so on._\n\n_Consider the following five hands dealt to two players:_\n\nHand | Player 1 | Player 2 | Winner\n--- | --- | --- | ---\n1 | 5H 5C 6S 7S KD | 2C 3S 8S 8D TD  | Player 2\n2 | 5D 8C 9S JS AC | 2C 5C 7D 8S QH | Player 1\n3 | 2D 9C AS AH AC | 3D 6D 7D TD QD | Player 2\n4 | 4D 6S 9H QH QC | 3D 6D 7H QD QS | Player 1\n5 | 2H 2D 4C 4D 4S | 3C 3D 3S 9S 9D | Player 1\n\n_The file, [poker.txt](assets/p054_poker.txt), contains one-thousand random hands dealt to two players. Each line of the file contains ten cards (separated by a single space): the first five are Player 1's cards and the last five are Player 2's cards. You can assume that all hands are valid (no invalid characters or repeated cards), each player's hand is in no specific order, and in each hand there is a clear winner._\n\n_How many hands does Player 1 win?_\n\n#### solution\n\n376 in 180.557576ms\n\n#### explanation\n\n*Coming soon*\n\n### [problem 55](./projecteuler/problem55.go)\n\n#### statement\n\n_If we take 47, reverse and add, 47 + 74 = 121, which is palindromic._\n\n_Not all numbers produce palindromes so quickly. For example,_\n\n349 + 943 = 1292\n\n1292 + 2921 = 4213\n\n4213 + 3124 = 7337\n\n_That is, 349 took three iterations to arrive at a palindrome._\n\n_Although no one has proved it yet, it is thought that some numbers, like 196, never produce a palindrome. A number that never forms a palindrome through the reverse and add process is called a Lychrel number. Due to the theoretical nature of these numbers, and for the purpose of this problem, we shall assume that a number is Lychrel until proven otherwise. In addition you are given that for every number below ten-thousand, it will either (i) become a palindrome in less than fifty iterations, or, (ii) no one, with all the computing power that exists, has managed so far to map it to a palindrome. In fact, 10677 is the first number to be shown to require over fifty iterations before producing a palindrome: 4668731596684224866951378664 (53 iterations, 28-digits)._\n\n_Surprisingly, there are palindromic numbers that are themselves Lychrel numbers; the first example is 4994._\n\n_How many Lychrel numbers are there below ten-thousand?_\n\n_NOTE: Wording was modified slightly on 24 April 2007 to emphasise the theoretical nature of Lychrel numbers._\n\n#### solution\n\n249 in 143.031404ms\n\n#### explanation\n\nWhile leveraging power of multicore CPU using go-routines, we'll parallelly compute how many numbers are lychrel under 10K. Thanks to `math/big` for handling big numbers efficiently.\n\n### [problem 56](./projecteuler/problem56.go)\n\n#### statement\n\n_A googol (10^100) is a massive number: one followed by one-hundred zeros; 100^100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1._\n\n_Considering natural numbers of the form, a^b, where a, b \u003c 100, what is the maximum digital sum?_\n\n#### solution\n\n972 in 26.468845ms\n\n#### explanation\n\nIteratively computes maximum sum of digits of natural number of form _a^b where a, b \u003c 100_.\n\n### [problem 57](./projecteuler/problem57.go)\n\n#### statement\n\n_It is possible to show that the square root of two can be expressed as an infinite continued fraction._\n\n√2 = 1+1/(2+1/(2+1/2+…\n\n_By expanding this for the first four iterations, we get:_\n\n1+1/2=3/2=1.5\n\n1+1/(2+1/2)=7/5=1.4\n\n1+1/(2+1/(2+1/2))=17/12=1.41666…\n\n1+1/(2+1/(2+1/(2+1/2)))=41/29=1.41379…\n\n\n\n_The next three expansions are 9970, 239169, and 577408, but the eighth expansion, 1393985, is the first example where the number of digits in the numerator exceeds the number of digits in the denominator._\n\n_In the first one-thousand expansions, how many fractions contain a numerator with more digits than the denominator_\n\n#### solution\n\n153 in 10.379267ms\n\n#### explanation\n\nWe can find a clear pattern in calculating next expanded form of √2, given intial form\n\n_p / q = (num(i-1)+ den(i-1)*2) / (num(i-1) + den(i-1))_\n\nNow it's very easy to count how many of these fractions having more digits in numerator than in denominator.\n\n### [problem 58](./projecteuler/problem58.go)\n\n#### statement\n\n_Starting with 1 and spiralling anticlockwise in the following way, a square spiral with side length 7 is formed._\n\n37 36 35 34 33 32 31\n\n38 17 16 15 14 13 30\n\n39 18  5  4  3 12 29\n\n40 19  6  1  2 11 28\n\n41 20  7  8  9 10 27\n\n42 21 22 23 24 25 26\n\n43 44 45 46 47 48 49\n\n_It is interesting to note that the odd squares lie along the bottom right diagonal, but what is more interesting is that 8 out of the 13 numbers lying along both diagonals are prime; that is, a ratio of 8/13 ≈ 62%._\n\n_If one complete new layer is wrapped around the spiral above, a square spiral with side length 9 will be formed. If this process is continued, what is the side length of the square spiral for which the ratio of primes along both diagonals first falls below 10%?_\n\n#### solution\n\n26241 in 1.652747178s\n\n#### explanation\n\nWe'll generate only diagonal elements of square matrix of certain order _( i.e. 1x1, 3x3, 5x5 ... )_ in clockwise spiral fashion. And we'll keep doing that thing until we get a prime ratio _\u003c 10%_. Now in each iteration we need to check how many of these diagonal elements are prime, to avoid checking all diagonal elements in each iteration, we'll cache prime count of previous iteration and only check newly generated four corner items. For reduing space complexity, we'll store only 4 corner elements of square matrix, in each iteration.\n\n**More coming soon ...** :wink:\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitzmeanjan%2Fproject-euler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitzmeanjan%2Fproject-euler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitzmeanjan%2Fproject-euler/lists"}