diff --git a/assets/euler.png b/assets/euler.png new file mode 100644 index 0000000..d19e14a Binary files /dev/null and b/assets/euler.png differ diff --git a/euler/readme.md b/euler/readme.md new file mode 100644 index 0000000..b23f697 --- /dev/null +++ b/euler/readme.md @@ -0,0 +1,114 @@ +
+ +

euler

+
+ +> My solutions to many of Project Euler's problems. + +The source code can be found in the [src](src) directory. My thoughts about some puzzles may also be found in the [thoughts](thoughts) directory, showing my thought process or providing some mathematical insight. As per the rules of the challenge, I may only publish the solutions to the first 100 problems here, so I will stop after that but still continue the challenge. + +### Checklist + +- [x] [1 - Multiples of 3 or 5](src/1%20-%20Multiples%20of%203%20or%205.ts) +- [x] [2 - Even Fibonacci numbers](src/2%20-%20Even%20Fibonacci%20numbers.ts) +- [x] [3 - Largest prime factor](src/3%20-%20Largest%20prime%20factor.ts) +- [x] [4 - Largest palindrome product](src/4%20-%20Largest%20palindrome%20product.ts) +- [x] [5 - Smallest multiple](src/5%20-%20Smallest%20multiple.ts) +- [x] [6 - Sum square difference](src/6%20-%20Sum%20square%20difference.ts) +- [x] [7 - 10001st prime](src/7%20-%2010001st%20prime.ts) +- [x] [8 - Largest product in a series](src/8%20-%20Largest%20product%20in%20a%20series.ts) +- [x] [9 - Special Pythagorean triplet](src/9%20-%20Special%20Pythagorean%20triplet.ts) + - [Thoughts](thoughts/9%20-%20Special%20Pythagorean%20triplet.md) +- [x] [10 - Summation of primes](src/10%20-%20Summation%20of%20primes.ts) + - [Thoughts](thoughts/10%20-%20Summation%20of%20primes.md) +- [x] [11 - Largest product in a grid](src/11%20-%20Largest%20product%20in%20a%20grid.ts) +- [x] [12 - Highly divisible triangular number](src/12%20-%20Highly%20divisible%20triangular%20number.ts) +- [x] [13 - Large sum](src/13%20-%20Large%20sum.ts) +- [x] [14 - Longest Collatz sequence](src/14%20-%20Longest%20Collatz%20sequence.ts) +- [x] [15 - Lattice paths](src/15%20-%20Lattice%20paths.ts) + - [Thoughts](thoughts/15%20-%20Lattice%20paths.md) +- [ ] 16 - Power digit sum +- [ ] 17 - Number letter counts +- [ ] 18 - Maximum path sum I +- [ ] 19 - Counting Sundays +- [ ] 20 - Factorial digit sum +- [ ] 21 - Amicable numbers +- [ ] 22 - Names scores +- [ ] 23 - Non-abundant sums +- [ ] 24 - Lexicographic permutations +- [ ] 25 - 1000-digit Fibonacci number +- [ ] 26 - Reciprocal cycles +- [ ] 27 - Quadratic primes +- [ ] 28 - Number spiral diagonals +- [ ] 29 - Distinct powers +- [ ] 30 - Digit fifth powers +- [ ] 31 - Coin sums +- [ ] 32 - Pandigital products +- [ ] 33 - Digit cancelling fractions +- [ ] 34 - Digit factorials +- [ ] 35 - Circular primes +- [ ] 36 - Double-base palindromes +- [ ] 37 - Truncatable primes +- [ ] 38 - Pandigital multiples +- [ ] 39 - Integer right triangles +- [ ] 40 - Champernowne's constant +- [ ] 41 - Pandigital prime +- [ ] 42 - Coded triangle numbers +- [ ] 43 - Sub-string divisibility +- [ ] 44 - Pentagon numbers +- [ ] 45 - Triangular, pentagonal, and hexagonal +- [ ] 46 - Goldbach's other conjecture +- [ ] 47 - Distinct primes factors +- [ ] 48 - Self powers +- [ ] 49 - Prime permutations +- [ ] 50 - Consecutive prime sum +- [ ] 51 - Prime digit replacements +- [ ] 52 - Permuted multiples +- [ ] 53 - Combinatoric selections +- [ ] 54 - Poker hands +- [ ] 55 - Lychrel numbers +- [ ] 56 - Powerful digit sum +- [ ] 57 - Square root convergents +- [ ] 58 - Spiral primes +- [ ] 59 - XOR decryption +- [ ] 60 - Prime pair sets +- [ ] 61 - Cyclical figurate numbers +- [ ] 62 - Cubic permutations +- [ ] 63 - Powerful digit counts +- [ ] 64 - Odd period square roots +- [ ] 65 - Convergents of e +- [ ] 66 - Diophantine equation +- [ ] 67 - Maximum path sum II +- [ ] 68 - Magic 5-gon ring +- [ ] 69 - Totient maximum +- [ ] 70 - Totient permutation +- [ ] 71 - Ordered fractions +- [ ] 72 - Counting fractions +- [ ] 73 - Counting fractions in a range +- [ ] 74 - Digit factorial chains +- [ ] 75 - Singular integer right triangles +- [ ] 76 - Counting summations +- [ ] 77 - Prime summations +- [ ] 78 - Coin partitions +- [ ] 79 - Passcode derivation +- [ ] 80 - Square root digital expansion +- [ ] 81 - Path sum: two ways +- [ ] 82 - Path sum: three ways +- [ ] 83 - Path sum: four ways +- [ ] 84 - Monopoly odds +- [ ] 85 - Counting rectangles +- [ ] 86 - Cuboid route +- [ ] 87 - Prime power triples +- [ ] 88 - Product-sum numbers +- [ ] 89 - Roman numerals +- [ ] 90 - Cube digit pairs +- [ ] 91 - Right triangles with integer coordinates +- [ ] 92 - Square digit chains +- [ ] 93 - Arithmetic expressions +- [ ] 94 - Almost equilateral triangles +- [ ] 95 - Amicable chains +- [ ] 96 - Su Doku +- [ ] 97 - Large non-Mersenne prime +- [ ] 98 - Anagramic squares +- [ ] 99 - Largest exponential +- [ ] 100 - Arranged probability diff --git a/euler/src/10 - Sumation of Primes.ts b/euler/src/10 - Sumation of primes.ts similarity index 100% rename from euler/src/10 - Sumation of Primes.ts rename to euler/src/10 - Sumation of primes.ts diff --git a/euler/src/11 - Largest Product in a Grid.ts b/euler/src/11 - Largest product in a grid.ts similarity index 100% rename from euler/src/11 - Largest Product in a Grid.ts rename to euler/src/11 - Largest product in a grid.ts diff --git a/euler/src/12 - Highly Divisible Triangular Number.ts b/euler/src/12 - Highly divisible triangular number.ts similarity index 100% rename from euler/src/12 - Highly Divisible Triangular Number.ts rename to euler/src/12 - Highly divisible triangular number.ts diff --git a/euler/src/13 - Large Sum.ts b/euler/src/13 - Large sum.ts similarity index 100% rename from euler/src/13 - Large Sum.ts rename to euler/src/13 - Large sum.ts diff --git a/euler/src/2 - Even Fibonacci Numbers.ts b/euler/src/2 - Even Fibonacci numbers.ts similarity index 100% rename from euler/src/2 - Even Fibonacci Numbers.ts rename to euler/src/2 - Even Fibonacci numbers.ts diff --git a/euler/src/3 - Largest Prime Factor.ts b/euler/src/3 - Largest prime factor.ts similarity index 100% rename from euler/src/3 - Largest Prime Factor.ts rename to euler/src/3 - Largest prime factor.ts diff --git a/euler/src/4 - Largest Palindrome Number.ts b/euler/src/4 - Largest pallindrome product.ts similarity index 100% rename from euler/src/4 - Largest Palindrome Number.ts rename to euler/src/4 - Largest pallindrome product.ts diff --git a/euler/src/5 - Smallest Number.ts b/euler/src/5 - Smallest multiple.ts similarity index 100% rename from euler/src/5 - Smallest Number.ts rename to euler/src/5 - Smallest multiple.ts diff --git a/euler/src/6 - Sum Square Difference.ts b/euler/src/6 - Sum square difference.ts similarity index 100% rename from euler/src/6 - Sum Square Difference.ts rename to euler/src/6 - Sum square difference.ts diff --git a/euler/src/8 - Largest Product in a Series.ts b/euler/src/8 - Largest product in a series.ts similarity index 100% rename from euler/src/8 - Largest Product in a Series.ts rename to euler/src/8 - Largest product in a series.ts diff --git a/euler/src/9 - Special Pythagorean Triplet.ts b/euler/src/9 - Special Pythagorean Triplet.ts deleted file mode 100644 index c6e3983..0000000 --- a/euler/src/9 - Special Pythagorean Triplet.ts +++ /dev/null @@ -1,38 +0,0 @@ -export {}; - -// a + b + c = 1000 -// we need a * b * c -// pythagorean triplet: a < b < c -// a^2 + b^2 = c^2 - -const pythagoreanTriplet = (sum: number) => { - let a: number, - b = 1, - c: number; - - for (; b < sum; b++) { - // let x = sum - - // c = x - (a + b) - // a^2 + b^2 = (x - (a + b))^2 - // a^2 + b^2 = a^2 + 2ab - 2ax + b^2 - 2bx + x^2 - // 0 = 2ab - 2ax - 2bx + x^2 - - // 2bx - 2ab = x^2 - 2ax - // (x^2 / x) - 2a = 2b - (2ab / x) - // -2a = 2b - (2ab / x) - (x^2 / x) - // a = - (((x * 2b) - (x * x)) / ((2 * x) - (2 * b))) - a = -((sum * (2 * b) - sum * sum) / (2 * sum - 2 * b)); - - if (Math.floor(a) === a) { - c = sum - a - b; - break; - } - } - - return { a, b, c }; -}; - -const triplet = pythagoreanTriplet(1000); -console.log(triplet); -console.log(triplet.a * triplet.b * triplet.c); diff --git a/euler/src/9 - Special Pythagorean triplet.ts b/euler/src/9 - Special Pythagorean triplet.ts new file mode 100644 index 0000000..056c19e --- /dev/null +++ b/euler/src/9 - Special Pythagorean triplet.ts @@ -0,0 +1,22 @@ +export {}; + +const pythagoreanTriplet = (sum: number) => { + let a: number, + b = 1, + c: number; + + for (; b < sum; b++) { + a = -((sum * (2 * b) - sum * sum) / (2 * sum - 2 * b)); + + if (Math.floor(a) === a) { + c = sum - a - b; + break; + } + } + + return { a, b, c }; +}; + +const triplet = pythagoreanTriplet(1000); +console.log(triplet); +console.log(triplet.a * triplet.b * triplet.c); diff --git a/euler/thoughts/10 - Summation of primes.md b/euler/thoughts/10 - Summation of primes.md new file mode 100644 index 0000000..a33a6a8 --- /dev/null +++ b/euler/thoughts/10 - Summation of primes.md @@ -0,0 +1,19 @@ +### Sieve of Eratosthenes Psuedocode + +[Source](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes#Pseudocode) + +``` +algorithm Sieve of Eratosthenes is + input: an integer n > 1. + output: all prime numbers from 2 through n. + + let A be an array of Boolean values, indexed by integers 2 to n, + initially all set to true. + + for i = 2, 3, 4, ..., not exceeding √n do + if A[i] is true + for j = i2, i2+i, i2+2i, i2+3i, ..., not exceeding n do + A[j] := false + + return all i such that A[i] is true. +``` diff --git a/euler/thoughts/9 - Special Pythagorean triplet.md b/euler/thoughts/9 - Special Pythagorean triplet.md new file mode 100644 index 0000000..edfb935 --- /dev/null +++ b/euler/thoughts/9 - Special Pythagorean triplet.md @@ -0,0 +1,26 @@ +a + b + c = 1000, so what is abc? + +a pythagorean triplet must make a < b < c + +we know that: + +![](assets/pythagoras.svg) + +let x be the sum + +![](assets/9.svg) + +### LaTeX + +``` +c = x - (a + b) \newline +a^2 + b^2 = (x - (a + b))^2 \newline +a^2 + b^2 = a^2 + 2ab - 2ax + b^2 - 2bx + x^2 \newline +2ab - 2ax - 2bx + x^2 = 0 \newline +\newline +2bx - 2ab = x^2 - 2ax \newline +(\frac{x^2}{x}) - 2a = 2b - (\frac{2ab}{x}) \newline +-2a = 2b - (\frac{2ab}{x}) - (\frac{x^2}{x}) \newline +\newline +a = \frac{2bx - x^2}{2x - 2b} +``` diff --git a/euler/thoughts/assets/15.svg b/euler/thoughts/assets/15.svg new file mode 100644 index 0000000..1b5cb3e --- /dev/null +++ b/euler/thoughts/assets/15.svg @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/euler/thoughts/assets/9.svg b/euler/thoughts/assets/9.svg new file mode 100644 index 0000000..85e95d1 --- /dev/null +++ b/euler/thoughts/assets/9.svg @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/euler/thoughts/assets/pythagoras.svg b/euler/thoughts/assets/pythagoras.svg new file mode 100644 index 0000000..634753a --- /dev/null +++ b/euler/thoughts/assets/pythagoras.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file