Skip to content

Commit 5f45b54

Browse files
committed
Remove live code & console.log, leave examples as comments (ProjectEuler, Recursive).
1 parent 9212e6d commit 5f45b54

17 files changed

+48
-98
lines changed

Project-Euler/Problem013.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,11 @@ const numbers = [
107107
53503534226472524250874054075591789781264330331690
108108
]
109109

110-
const findFirstTenDigitsOfSum = () => {
111-
const sum = numbers.reduce((prev, current) => {
110+
export const findFirstTenDigitsOfSum = (N = numbers) => {
111+
const sum = N.reduce((prev, current) => {
112112
current += prev
113113
return current
114114
}, 0)
115115

116116
return sum.toLocaleString('fullwide', { useGrouping: false }).split('').slice(0, 10).join('')
117117
}
118-
119-
console.log(findFirstTenDigitsOfSum())

Project-Euler/Problem014.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ const getCollatzSequenceLength = (num, seqLength) => {
3131
}
3232
}
3333

34-
const findLongestCollatzSequence = () => {
34+
export const findLongestCollatzSequence = (limit = 1_000_000) => {
3535
let startingPointForLargestSequence = 1
3636
let largestSequenceLength = 1
37-
for (let i = 2; i < 1000000; i++) {
37+
for (let i = 2; i < limit; i++) {
3838
const currentSequenceLength = getCollatzSequenceLength(i, 1)
3939
if (currentSequenceLength > largestSequenceLength) {
4040
startingPointForLargestSequence = i
@@ -43,5 +43,3 @@ const findLongestCollatzSequence = () => {
4343
}
4444
return startingPointForLargestSequence
4545
}
46-
47-
console.log(findLongestCollatzSequence())

Project-Euler/Problem015.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ How many such routes are there through a 20×20 grid?
66

77
// A lattice path is composed of horizontal and vertical lines that pass through lattice points.
88

9-
const latticePath = (gridSize) => {
9+
export const latticePath = (gridSize) => {
1010
let paths
1111
for (let i = 1, paths = 1; i <= gridSize; i++) {
1212
paths = paths * (gridSize + i) / i
1313
}
1414
// The total number of paths can be found using the binomial coefficient (b+a)/a.
1515
return paths
1616
}
17-
console.log(latticePath(20)) // output = 137846528820
17+
18+
// > latticePath(20))
19+
// 137846528820

Project-Euler/Problem2.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ const PHI = (1 + SQ5) / 2 // definition of PHI
44

55
// theoretically it should take O(1) constant amount of time as long
66
// arithmetic calculations are considered to be in constant amount of time
7-
const EvenFibonacci = (limit) => {
7+
export const EvenFibonacci = (limit) => {
88
const highestIndex = Math.floor(Math.log(limit * SQ5) / Math.log(PHI))
99
const n = Math.floor(highestIndex / 3)
1010
return ((PHI ** (3 * n + 3) - 1) / (PHI ** 3 - 1) -
1111
((1 - PHI) ** (3 * n + 3) - 1) / ((1 - PHI) ** 3 - 1)) / SQ5
1212
}
13-
console.log(EvenFibonacci(4e6)) // Sum of even Fibonacci upto 4 Million

Project-Euler/Problem4.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
33
Find the largest palindrome made from the product of two 3-digit numbers.
44
*/
5-
const largestPalindromic = (digits) => {
5+
export const largestPalindromic = (digits) => {
66
let i
77
let n
88
let m
@@ -43,4 +43,4 @@ const largestPalindromic = (digits) => {
4343
return NaN // returning not a number, if any such case arise
4444
}
4545

46-
console.log(largestPalindromic(3))
46+

Project-Euler/Problem5.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Smallest multiple
55
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
66
*/
77

8-
const findSmallestMultiple = () => {
8+
export const findSmallestMultiple = () => {
99
const divisors = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]
1010
let num = 21
1111
let result
@@ -18,5 +18,3 @@ const findSmallestMultiple = () => {
1818

1919
return result
2020
}
21-
22-
console.log(findSmallestMultiple())

Project-Euler/Problem6.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// https://projecteuler.net/problem=6
22

3-
const num = 100 // number we are checking; change to 10 to check 10 from example
4-
5-
const squareDifference = (num) => {
3+
export const squareDifference = (num = 100) => {
64
let sumOfSquares = 0
75
let sums = 0
86
for (let i = 1; i <= num; i++) {
@@ -11,5 +9,3 @@ const squareDifference = (num) => {
119
}
1210
return (sums ** 2) - sumOfSquares // difference of square of the total sum and sum of squares
1311
}
14-
15-
console.log(squareDifference(num))

Project-Euler/Problem7.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// https://projecteuler.net/problem=7
22
// My approach does not use the Sieve of Eratosthenes but that is another common way to approach this problem. Sieve of Atkin is another possibility as well.
33

4-
const num = 10001
5-
const primes = [2, 3, 5, 7, 11, 13] // given list of primes you start with
6-
7-
const calculatePrime = (num) => {
4+
export const calculatePrime = (num = 10001, primes = [2, 3, 5, 7, 11, 13]) => {
85
// Calculate each next prime by checking each number to see what it's divisible by
96
let count = primes.length // count number of primes calculated
107
let current = primes[count - 1] + 1 // current number being assessed if prime
@@ -27,5 +24,3 @@ const calculatePrime = (num) => {
2724
}
2825
return primes[num - 1]
2926
}
30-
31-
console.log(calculatePrime(num))

Project-Euler/Problem9.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Find the product abc.
1212

1313
const isPythagoreanTriplet = (a, b, c) => Math.pow(a, 2) + Math.pow(b, 2) === Math.pow(c, 2)
1414

15-
const findSpecialPythagoreanTriplet = () => {
15+
export const findSpecialPythagoreanTriplet = () => {
1616
for (let a = 0; a < 1000; a++) {
1717
for (let b = a + 1; b < 1000; b++) {
1818
for (let c = b + 1; c < 1000; c++) {
@@ -23,5 +23,3 @@ const findSpecialPythagoreanTriplet = () => {
2323
}
2424
}
2525
}
26-
27-
console.log(findSpecialPythagoreanTriplet())

Recursive/BinaryEquivalent.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@
1313
*
1414
*/
1515

16-
const binaryEquivalent = (num) => {
16+
export const binaryEquivalent = (num) => {
1717
if (num === 0 || num === 1) {
1818
return String(num)
1919
}
2020
return binaryEquivalent(Math.floor(num / 2)) + String(num % 2)
2121
}
22-
23-
// Driver Code
24-
const num = 6
25-
const ans = binaryEquivalent(num)
26-
console.log(ans)

0 commit comments

Comments
 (0)