This commit is contained in:
David Doblas Jiménez 2021-10-27 11:27:14 +02:00
parent 846a9343ae
commit d9c96f32cf
51 changed files with 315 additions and 366 deletions

1
.ignored_words.txt Normal file
View File

@ -0,0 +1 @@
ans

View File

@ -17,7 +17,7 @@ repos:
rev: 21.9b0
hooks:
- id: black
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
#- repo: https://github.com/codespell-project/codespell
# rev: v2.1.0
# hooks:
# - id: codespell -I .ignored_words.txt

View File

@ -17,14 +17,14 @@ function Problem1()
Find the sum of all the multiples of 3 or 5 below 1000.
=#
ans = sum(x for x in 0:999 if x%3==0 || x%5==0)
return ans
end
println("Time to evaluate Problem 1:")
println("Time to evaluate Problem $(lpad(1, 3, "0")):")
@btime Problem1()
println("")
println("Result for Problem 1: ", Problem1())
println("Result for Problem $(lpad(1, 3, "0")): ", Problem1())

View File

@ -1,25 +1,23 @@
#=
#=
Created on 08 Jun 2021
@author: David Doblas Jiménez
@email: daviddoji@pm.me
Solution for Problem 2 of Project Euler
https://projecteuler.net/problem=2
=#
https://projecteuler.net/problem=2 =#
using BenchmarkTools
function Problem2()
#=
#=
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:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Find the sum of all the even-valued terms in the sequence which do not
exceed four million.
=#
exceed four million. =#
ans = 0
limit = 4_000_000
@ -37,7 +35,7 @@ function Problem2()
end
println("Time to evaluate Problem 2:")
println("Time to evaluate Problem $(lpad(2, 3, "0")):")
@btime Problem2()
println("")
println("Result for Problem 2: ", Problem2())
println("Result for Problem $(lpad(2, 3, "0")): ", Problem2())

View File

@ -1,21 +1,19 @@
#=
#=
Created on 15 Jun 2021
@author: David Doblas Jiménez
@email: daviddoji@pm.me
Solution for Problem 3 of Project Euler
https://projecteuler.net/problem=3
=#
https://projecteuler.net/problem=3 =#
using BenchmarkTools
function Problem3()
#=
#=
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
=#
What is the largest prime factor of the number 600851475143 ? =#
ans = 600_851_475_143
factor = 2
@ -30,7 +28,7 @@ function Problem3()
end
println("Time to evaluate Problem 3:")
println("Time to evaluate Problem $(lpad(3, 3, "0")):")
@btime Problem3()
println("")
println("Result for Problem 3: ", Problem3())
println("Result for Problem $(lpad(3, 3, "0")): ", Problem3())

View File

@ -1,4 +1,4 @@
#=
#=
Created on 17 Jun 2021
@author: David Doblas Jiménez
@ -21,7 +21,7 @@ function ispalindrome(n::Int64)
end
function Problem4()
#=
#=
A palindromic number reads the same both ways. The largest palindrome made
from the product of two 2-digit numbers is 9009 = 91 x 99.
@ -39,7 +39,7 @@ function Problem4()
end
println("Time to evaluate Problem 4:")
println("Time to evaluate Problem $(lpad(4, 3, "0")):")
@btime Problem4()
println("")
println("Result for Problem 4: ", Problem4())
println("Result for Problem $(lpad(4, 3, "0")): ", Problem4())

View File

@ -5,8 +5,7 @@ Created on 20 Jun 2021
@email: daviddoji@pm.me
Solution for Problem 5 of Project Euler
https://projecteuler.net/problem=5
=#
https://projecteuler.net/problem=5 =#
#=
The LCM of two natural numbers x and y is given by:
@ -14,8 +13,7 @@ def lcm(x, y):
return x * y // math.gcd(x, y)
It is possible to compute the LCM of more than two numbers by iteratively
computing the LCM of two numbers, i.e. LCM(a, b, c) = LCM(a, LCM(b, c))
=#
computing the LCM of two numbers, i.e. LCM(a, b, c) = LCM(a, LCM(b, c)) =#
using BenchmarkTools
@ -25,8 +23,7 @@ function Problem5()
from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of
the numbers from 1 to 20?
=#
the numbers from 1 to 20? =#
ans = 1
for i in 1:21
ans *= i ÷ gcd(i, ans)
@ -36,7 +33,7 @@ function Problem5()
end
println("Time to evaluate Problem 5:")
println("Time to evaluate Problem $(lpad(5, 3, "0")):")
@btime Problem5()
println("")
println("Result for Problem 5: ", Problem5())
println("Result for Problem $(lpad(5, 3, "0")): ", Problem5())

View File

@ -5,8 +5,9 @@ Created on 20 Jun 2021
@email: daviddoji@pm.me
Solution for Problem 6 of Project Euler
https://projecteuler.net/problem=6
=#
https://projecteuler.net/problem=6 =#
using BenchmarkTools
function Problem6()
#=
@ -20,8 +21,7 @@ function Problem6()
natural numbers and the square of the sum is 3025 385 = 2640.
Find the difference between the sum of the squares of the first one
hundred natural numbers and the square of the sum. Statement
=#
hundred natural numbers and the square of the sum. Statement =#
n = 100
square_of_sum = sum(i for i in (1:n))^2
sum_squares = sum(i^2 for i in 1:n)
@ -30,7 +30,7 @@ function Problem6()
end
println("Time to evaluate Problem 6:")
@time Problem6()
println("Time to evaluate Problem $(lpad(6, 3, "0")):")
@btime Problem6()
println("")
println("Result for Problem 6: ", Problem6())
println("Result for Problem $(lpad(6, 3, "0")): ", Problem6())

View File

@ -5,9 +5,9 @@ Created on 24 Jun 2021
@email: daviddoji@pm.me
Solution for Problem 7 of Project Euler
https://projecteuler.net/problem=7
=#
https://projecteuler.net/problem=7 =#
using BenchmarkTools
using Primes
function Problem7()
@ -15,13 +15,12 @@ function Problem7()
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13,
we can see that the 6th prime is 13.
What is the 10_001st prime number
=#
What is the 10_001st prime number =#
number = 2
primeList = Int[]
while length(primeList) < 10_001
if isprime(number)
append!(primeList,number)
append!(primeList, number)
end
number += 1
end
@ -30,7 +29,7 @@ function Problem7()
end
println("Time to evaluate Problem 7:")
@time Problem7()
println("Time to evaluate Problem $(lpad(7, 3, "0")):")
@btime Problem7()
println("")
println("Result for Problem 7: ", Problem7())
println("Result for Problem $(lpad(7, 3, "0")): ", Problem7())

View File

@ -5,8 +5,9 @@ Created on 29 Jun 2021
@email: daviddoji@pm.me
Solution for Problem 8 of Project Euler
https://projecteuler.net/problem=8
=#
https://projecteuler.net/problem=8 =#
using BenchmarkTools
function Problem8()
#=
@ -16,8 +17,7 @@ function Problem8()
731671...963450
Find the thirteen adjacent digits in the 1000-digit number that have
the greatest product. What is the value of this product?
=#
the greatest product. What is the value of this product? =#
NUM = """
73167176531330624919225119674426574742355349194934
@ -62,7 +62,7 @@ function Problem8()
end
println("Time to evaluate Problem 8:")
@time Problem8()
println("Time to evaluate Problem $(lpad(8, 3, "0")):")
@btime Problem8()
println("")
println("Result for Problem 8: ", Problem8())
println("Result for Problem $(lpad(8, 3, "0")): ", Problem8())

View File

@ -5,8 +5,9 @@ Created on 01 Jul 2021
@email: daviddoji@pm.me
Solution for Problem 9 of Project Euler
https://projecteuler.net/problem=9
=#
https://projecteuler.net/problem=9 =#
using BenchmarkTools
function Problem9()
#=
@ -16,8 +17,7 @@ function Problem9()
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
=#
Find the product abc. =#
upper_limit = 1000
for a in 1:upper_limit + 1
@ -32,7 +32,7 @@ function Problem9()
end
println("Time to evaluate Problem 9:")
@time Problem9()
println("Time to evaluate Problem $(lpad(9, 3, "0")):")
@btime Problem9()
println("")
println("Result for Problem 9: ", Problem9())
println("Result for Problem $(lpad(9, 3, "0")): ", Problem9())

View File

@ -5,23 +5,22 @@ Created on 03 Jul 2021
@email: daviddoji@pm.me
Solution for Problem 10 of Project Euler
https://projecteuler.net/problem=10
=#
https://projecteuler.net/problem=10 =#
using BenchmarkTools
using Primes
function Problem10()
#=
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
=#
Find the sum of all the primes below two million. =#
return sum(primes(1_999_999))
end
println("Time to evaluate Problem 10:")
@time Problem10()
println("Time to evaluate Problem $(lpad(10, 3, "0")):")
@btime Problem10()
println("")
println("Result for Problem 10: ", Problem10())
println("Result for Problem $(lpad(10, 3, "0")): ", Problem10())

View File

@ -5,10 +5,9 @@ Created on 21 Jul 2021
@email: daviddoji@pm.me
Solution for Problem 12 of Project Euler
https://projecteuler.net/problem=12
=#
https://projecteuler.net/problem=12 =#
using BenchmarkTools
function Problem12()
#=
@ -32,14 +31,13 @@ function Problem12()
We can see that 28 is the first triangle number to have over five divisors.
What is the value of the first triangle number to have over five hundred
divisors?
=#
divisors? =#
function num_divisors(n)
r = isqrt(n)
2 * count(n % i == 0 for i in 1:r) - (r^2 == n)
end
triangle = 0
for i in Iterators.countfrom(1)
@ -51,7 +49,7 @@ function Problem12()
end
println("Time to evaluate Problem 12:")
@time Problem12()
println("Time to evaluate Problem $(lpad(12, 3, "0")):")
@btime Problem12()
println("")
println("Result for Problem 12: ", Problem12())
println("Result for Problem $(lpad(12, 3, "0")): ", Problem12())

View File

@ -1,4 +1,4 @@
using Base: String
using Base:String
#=
Created on 22 Jul 2021
@ -6,22 +6,20 @@ Created on 22 Jul 2021
@email: daviddoji@pm.me
Solution for Problem 13 of Project Euler
https://projecteuler.net/problem=13
=#
https://projecteuler.net/problem=13 =#
using BenchmarkTools
using DoubleFloats
# using JSON
function Problem13()
#=
Work out the first ten digits of the sum of the following one-hundred
50-digit numbers
=#
return string(sum(parse.(BigInt,readlines("../files/Problem13.txt"))))[1:10]
50-digit numbers =#
return string(sum(parse.(BigInt, readlines("../files/Problem13.txt"))))[1:10]
end
println("Time to evaluate Problem 13:")
@time Problem13()
println("Time to evaluate Problem $(lpad(13, 3, "0")):")
@btime Problem13()
println("")
println("Result for Problem 13: ", Problem13())
println("Result for Problem $(lpad(13, 3, "0")): ", Problem13())

View File

@ -5,16 +5,17 @@ Created on 24 Jul 2021
@email: daviddoji@pm.me
Solution for Problem 14 of Project Euler
https://projecteuler.net/problem=14
=#
https://projecteuler.net/problem=14 =#
function chain_length(n)#, terms)
using BenchmarkTools
function chain_length(n)# , terms)
length = 0
while n > 1
n = iseven(n) ? n >> 1 : 3n + 1
length += 1
end
return length
return length
end
function Problem14()
@ -36,8 +37,7 @@ function Problem14()
Which starting number, under one million, produces the longest chain?
NOTE: Once the chain starts the terms are allowed to go above one million.
=#
NOTE: Once the chain starts the terms are allowed to go above one million. =#
ans = 0
limit = 1_000_000
@ -48,12 +48,12 @@ function Problem14()
score = longest
ans = i
end
end
end
return ans
end
println("Time to evaluate Problem 14:")
@time Problem14()
println("Time to evaluate Problem $(lpad(14, 3, "0")):")
@btime Problem14()
println("")
println("Result for Problem 14: ", Problem14())
println("Result for Problem $(lpad(14, 3, "0")): ", Problem14())

View File

@ -1,4 +1,4 @@
using Base: Integer
using Base:Integer
#=
Created on 25 Jul 2021
@ -6,8 +6,9 @@ Created on 25 Jul 2021
@email: daviddoji@pm.me
Solution for Problem 15 of Project Euler
https://projecteuler.net/problem=15
=#
https://projecteuler.net/problem=15 =#
using BenchmarkTools
function Problem15()
#=
@ -15,14 +16,13 @@ function Problem15()
move to the right and down, there are exactly 6 routes to the bottom
right corner.
How many such routes are there through a 20×20 grid?
=#
How many such routes are there through a 20×20 grid? =#
n = 20
return Integer(factorial(big(2n)) / (factorial(big(n)) * factorial(big(2n - n))))
end
println("Time to evaluate Problem 15:")
@time Problem15()
println("Time to evaluate Problem $(lpad(15, 3, "0")):")
@btime Problem15()
println("")
println("Result for Problem 15: ", Problem15())
println("Result for Problem $(lpad(15, 3, "0")): ", Problem15())

View File

@ -1,4 +1,4 @@
using Base: Integer
using Base:Integer
#=
Created on 26 Jul 2021
@ -6,21 +6,21 @@ Created on 26 Jul 2021
@email: daviddoji@pm.me
Solution for Problem 16 of Project Euler
https://projecteuler.net/problem=16
=#
https://projecteuler.net/problem=16 =#
using BenchmarkTools
function Problem16()
#=
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 2^1000?
=#
What is the sum of the digits of the number 2^1000? =#
n = 1000
return sum(parse(Int, d) for d in string(2^BigInt(n)))
end
println("Time to evaluate Problem 16:")
@time Problem16()
println("Time to evaluate Problem $(lpad(16, 3, "0")):")
@btime Problem16()
println("")
println("Result for Problem 16: ", Problem16())
println("Result for Problem $(lpad(16, 3, "0")): ", Problem16())

View File

@ -5,8 +5,9 @@ Created on 28 Jul 2021
@email: daviddoji@pm.me
Solution for Problem 17 of Project Euler
https://projecteuler.net/problem=17
=#
https://projecteuler.net/problem=17 =#
using BenchmarkTools
function num2letters(num, dic)
if num <= 20
@ -39,8 +40,7 @@ function Problem17()
NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and
forty-two) contains 23 letters and 115 (one hundred and fifteen) contains
20 letters. The use of "and" when writing out numbers is in compliance
with British usage.
=#
with British usage. =#
nums = Dict(
0 => "", 1 => "one", 2 => "two", 3 => "three", 4 => "four", 5 => "five",
6 => "six", 7 => "seven", 8 => "eight", 9 => "nine", 10 => "ten",
@ -60,7 +60,7 @@ function Problem17()
end
println("Time to evaluate Problem 17:")
@time Problem17()
println("Time to evaluate Problem $(lpad(17, 3, "0")):")
@btime Problem17()
println("")
println("Result for Problem 17: ", Problem17())
println("Result for Problem $(lpad(17, 3, "0")): ", Problem17())

View File

@ -1,4 +1,4 @@
#=
#=
Created on 01 Aug 2021
@author: David Doblas Jiménez
@ -7,18 +7,20 @@ Created on 01 Aug 2021
Solution for Problem 18 of Project Euler
https://projecteuler.net/problem=18 =#
using BenchmarkTools
function Problem18()
#=
By starting at the top of the triangle below and moving to adjacent
#=
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.
3
7 4
2 4 6
8 5 9 3
8 5 9 3
That is, 3 + 7 + 4 + 9 = 23.
Find the maximum total from top to bottom of the triangle above =#
triangle = [ # Mutable
[75],
@ -49,7 +51,7 @@ function Problem18()
end
println("Time to evaluate Problem 18:")
@time Problem18()
println("Time to evaluate Problem $(lpad(18, 3, "0")):")
@btime Problem18()
println("")
println("Result for Problem 18: ", Problem18())
println("Result for Problem $(lpad(18, 3, "0")): ", Problem18())

View File

@ -1,4 +1,4 @@
#=
#=
Created on 02 Aug 2021
@author: David Doblas Jiménez
@ -7,10 +7,11 @@ Created on 02 Aug 2021
Solution for Problem 19 of Project Euler
https://projecteuler.net/problem=19 =#
using BenchmarkTools
using Dates
function Problem19()
#=
#=
You are given the following information, but you may prefer to do some
research for yourself.
@ -37,7 +38,7 @@ function Problem19()
end
println("Time to evaluate Problem 19:")
@time Problem19()
println("Time to evaluate Problem $(lpad(19, 3, "0")):")
@btime Problem19()
println("")
println("Result for Problem 19: ", Problem19())
println("Result for Problem $(lpad(19, 3, "0")): ", Problem19())

View File

@ -1,4 +1,4 @@
#=
#=
Created on 03 Aug 2021
@author: David Doblas Jiménez
@ -7,21 +7,23 @@ Created on 03 Aug 2021
Solution for Problem 20 of Project Euler
https://projecteuler.net/problem=20 =#
using BenchmarkTools
function Problem20()
#=
#=
n! means n × (n 1) × ... × 3 × 2 × 1
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.
Find the sum of the digits in the number 100! =#
fact = factorial(big(100))
return sum(parse(Int, d) for d in string(fact))
end
println("Time to evaluate Problem 20:")
@time Problem20()
println("Time to evaluate Problem $(lpad(20, 3, "0")):")
@btime Problem20()
println("")
println("Result for Problem 20: ", Problem20())
println("Result for Problem $(lpad(20, 3, "0")): ", Problem20())

View File

@ -1,4 +1,4 @@
#=
#=
Created on 05 Aug 2021
@author: David Doblas Jiménez
@ -7,6 +7,7 @@ Created on 05 Aug 2021
Solution for Problem 21 of Project Euler
https://projecteuler.net/problem=21 =#
using BenchmarkTools
function divisors(n)
divisors = Int64[1]
@ -20,25 +21,25 @@ function divisors(n)
end
function Problem21()
#=
Let d(n) be defined as the sum of proper divisors of n (numbers
#=
Let d(n) be defined as the sum of proper divisors of n (numbers
less than n which divide evenly into 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.
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
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.
Evaluate the sum of all the amicable numbers under 10000 =#
n = 9999
s = zeros(Int, n)
amicable = Int64[]
for i in 2:n
s[i] = sum(divisors(i))
end
for i in 2:n
if s[i] <= n && i != s[i] && i == s[s[i]]
push!(amicable, i)
@ -49,7 +50,7 @@ function Problem21()
end
println("Time to evaluate Problem 21:")
@time Problem21()
println("Time to evaluate Problem $(lpad(21, 3, "0")):")
@btime Problem21()
println("")
println("Result for Problem 21: ", Problem21())
println("Result for Problem $(lpad(21, 3, "0")): ", Problem21())

View File

@ -5,9 +5,9 @@ Created on 08 Aug 2021
@email: daviddoji@pm.me
Solution for Problem 22 of Project Euler
https://projecteuler.net/problem=22
=#
https://projecteuler.net/problem=22 =#
using BenchmarkTools
using DelimitedFiles
function Problem22()
@ -21,20 +21,19 @@ function Problem22()
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.
What is the total of all the name scores in the file?
=#
What is the total of all the name scores in the file? =#
file = "/datos/Scripts/Gitea/Project_Euler/src/files/Problem22.txt"
names = sort(readdlm(file, ',', String)[:])
result = 0
for (idx,name) in enumerate(names)
for (idx, name) in enumerate(names)
result += sum(Int(c) - 64 for c in name) * idx
end
return result
end
println("Time to evaluate Problem 22:")
@time Problem22()
println("Time to evaluate Problem $(lpad(22, 3, "0")):")
@btime Problem22()
println("")
println("Result for Problem 22: ", Problem22())
println("Result for Problem $(lpad(22, 3, "0")): ", Problem22())

View File

@ -8,6 +8,8 @@ Solution for Problem 23 of Project Euler
https://projecteuler.net/problem=23
=#
using BenchmarkTools
function Problem23()
#=
A perfect number is a number for which the sum of its proper divisors is
@ -54,7 +56,7 @@ function Problem23()
end
println("Time to evaluate Problem 23:")
@time Problem23()
println("Time to evaluate Problem $(lpad(23, 3, "0")):")
@btime Problem23()
println("")
println("Result for Problem 23: ", Problem23())
println("Result for Problem $(lpad(23, 3, "0")): ", Problem23())

View File

@ -5,9 +5,9 @@ Created on 13 Aug 2021
@email: daviddoji@pm.me
Solution for Problem 24 of Project Euler
https://projecteuler.net/problem=24
=#
https://projecteuler.net/problem=24 =#
using BenchmarkTools
using Combinatorics
function Problem24()
@ -20,15 +20,14 @@ function Problem24()
012 021 102 120 201 210
What is the millionth lexicographic permutation of the digits
0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
=#
0, 1, 2, 3, 4, 5, 6, 7, 8 and 9? =#
digits = [0,1,2,3,4,5,6,7,8,9]
_permutations = nthperm(digits, 1_000_000)
return join(_permutations)
end
println("Time to evaluate Problem 24:")
@time Problem24()
println("Time to evaluate Problem $(lpad(24, 3, "0")):")
@btime Problem24()
println("")
println("Result for Problem 24: ", Problem24())
println("Result for Problem $(lpad(24, 3, "0")): ", Problem24())

View File

@ -5,8 +5,9 @@ Created on 15 Aug 2021
@email: daviddoji@pm.me
Solution for Problem 25 of Project Euler
https://projecteuler.net/problem=25
=#
https://projecteuler.net/problem=25 =#
using BenchmarkTools
function Problem25()
#=
@ -32,13 +33,12 @@ function Problem25()
The 12th term, F12, is the first term to contain three digits.
What is the index of the first term in the Fibonacci sequence to
contain 1000 digits?
=#
contain 1000 digits? =#
a, b = 1, 1
index = 2
while length(digits(b)) < 1000
a, b = big(b), big(b+a)
a, b = big(b), big(b + a)
index += 1
end
@ -46,7 +46,7 @@ function Problem25()
end
println("Time to evaluate Problem 25:")
@time Problem25()
println("Time to evaluate Problem $(lpad(25, 3, "0")):")
@btime Problem25()
println("")
println("Result for Problem 25: ", Problem25())
println("Result for Problem $(lpad(25, 3, "0")): ", Problem25())

View File

@ -5,8 +5,9 @@ Created on 16 Aug 2021
@email: daviddoji@pm.me
Solution for Problem 26 of Project Euler
https://projecteuler.net/problem=26
=#
https://projecteuler.net/problem=26 =#
using BenchmarkTools
function Problem26()
#=
@ -27,8 +28,7 @@ function Problem26()
It can be seen that 1/7 has a 6-digit recurring cycle.
Find the value of d < 1000 for which 1/d contains the longest recurring
cycle in its decimal fraction part.
=#
cycle in its decimal fraction part. =#
cycle_length = 0
number_d = 0
for number in 3:2:999
@ -47,7 +47,7 @@ function Problem26()
end
println("Time to evaluate Problem 26:")
@time Problem26()
println("Time to evaluate Problem $(lpad(26, 3, "0")):")
@btime Problem26()
println("")
println("Result for Problem 26: ", Problem26())
println("Result for Problem $(lpad(26, 3, "0")): ", Problem26())

View File

@ -5,9 +5,9 @@ Created on 19 Aug 2021
@email: daviddoji@pm.me
Solution for Problem 27 of Project Euler
https://projecteuler.net/problem=27
=#
https://projecteuler.net/problem=27 =#
using BenchmarkTools
using Primes
function Problem27()
@ -34,12 +34,11 @@ function Problem27()
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.
=#
starting with n=0. =#
LIMIT = 1000
consecutive_values = 0
c = 0
for a in -999:LIMIT-1
for a in -999:LIMIT - 1
for b in 0:LIMIT
n = 0
while isprime((n^2) + (a * n) + b)
@ -55,7 +54,7 @@ function Problem27()
end
println("Time to evaluate Problem 27:")
@time Problem27()
println("Time to evaluate Problem $(lpad(27, 3, "0")):")
@btime Problem27()
println("")
println("Result for Problem 27: ", Problem27())
println("Result for Problem $(lpad(27, 3, "0")): ", Problem27())

View File

@ -5,8 +5,7 @@ Created on 23 Aug 2021
@email: daviddoji@pm.me
Solution for Problem 28 of Project Euler
https://projecteuler.net/problem=28
=#
https://projecteuler.net/problem=28 =#
using BenchmarkTools
@ -24,13 +23,12 @@ function Problem28()
It can be verified that the sum of the numbers on the diagonals is 101.
What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral
formed in the same way?
=#
formed in the same way? =#
size = 1001 # Must be odd
ans = 1 # Special case for size 1
step = 0
i, cur = 1, 1
while step < size-1
while step < size - 1
step = i * 2
for j in 1:4
cur += step
@ -43,7 +41,7 @@ function Problem28()
end
println("Time to evaluate Problem 28:")
println("Time to evaluate Problem $(lpad(28, 3, "0")):")
@btime Problem28()
println("")
println("Result for Problem 28: ", Problem28())
println("Result for Problem $(lpad(28, 3, "0")): ", Problem28())

View File

@ -5,8 +5,7 @@ Created on 23 Aug 2021
@email: daviddoji@pm.me
Solution for Problem 29 of Project Euler
https://projecteuler.net/problem=29
=#
https://projecteuler.net/problem=29 =#
using BenchmarkTools
@ -25,14 +24,13 @@ function Problem29()
4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125
How many distinct terms are in the sequence generated by ab for 2a≤100
and 2b≤100?
=#
and 2b≤100? =#
terms = Set(big(a)^b for a in 2:100, b in 2:100)
return length(terms)
end
println("Time to evaluate Problem 29:")
println("Time to evaluate Problem $(lpad(29, 3, "0")):")
@btime Problem29()
println("")
println("Result for Problem 29: ", Problem29())
println("Result for Problem $(lpad(29, 3, "0")): ", Problem29())

View File

@ -41,7 +41,7 @@ function Problem30()
end
println("Time to evaluate Problem 30:")
println("Time to evaluate Problem $(lpad(30, 3, "0")):")
@btime Problem30()
println("")
println("Result for Problem 30: ", Problem30())
println("Result for Problem $(lpad(30, 3, "0")): ", Problem30())

View File

@ -5,8 +5,7 @@ Created on 27 Aug 2021
@email: daviddoji@pm.me
Solution for Problem 31 of Project Euler
https://projecteuler.net/problem=31
=#
https://projecteuler.net/problem=31 =#
using BenchmarkTools
using IterTools
@ -22,8 +21,7 @@ function Problem31()
1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
How many different ways can £2 be made using any number of coins?
=#
How many different ways can £2 be made using any number of coins? =#
no_ways = 0
coins = [2, 5, 10, 20, 50, 100]
@ -39,7 +37,7 @@ function Problem31()
end
println("Time to evaluate Problem 31:")
println("Time to evaluate Problem $(lpad(31, 3, "0")):")
@btime Problem31()
println("")
println("Result for Problem 31: ", Problem31())
println("Result for Problem $(lpad(31, 3, "0")): ", Problem31())

View File

@ -5,8 +5,7 @@ Created on 30 Aug 2021
@email: daviddoji@pm.me
Solution for Problem 32 of Project Euler
https://projecteuler.net/problem=32
=#
https://projecteuler.net/problem=32 =#
using BenchmarkTools
@ -22,8 +21,7 @@ function Problem32()
Find the sum of all products whose multiplicand/multiplier/product identity
can be written as a 1 through 9 pandigital.
HINT: Some products can be obtained in more than one way so be sure to only
include it once in your sum.
=#
include it once in your sum. =#
ans = Set()
pandigital = join(['1', '2', '3', '4', '5', '6', '7', '8', '9'])
@ -41,7 +39,7 @@ function Problem32()
end
println("Time to evaluate Problem 32:")
println("Time to evaluate Problem $(lpad(32, 3, "0")):")
@btime Problem32()
println("")
println("Result for Problem 32: ", Problem32())
println("Result for Problem $(lpad(32, 3, "0")): ", Problem32())

View File

@ -5,8 +5,7 @@ Created on 01 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 33 of Project Euler
https://projecteuler.net/problem=33
=#
https://projecteuler.net/problem=33 =#
using BenchmarkTools
@ -22,8 +21,7 @@ function Problem33()
than one in value, and containing two digits in the numerator and denominator.
If the product of these four fractions is given in its lowest common terms,
find the value of the denominator.
=#
find the value of the denominator. =#
numerator = 1
denominator = 1
for x in 10:99
@ -41,11 +39,11 @@ function Problem33()
end
end
return Int(denominator/numerator)
return Int(denominator / numerator)
end
println("Time to evaluate Problem 33:")
println("Time to evaluate Problem $(lpad(33, 3, "0")):")
@btime Problem33()
println("")
println("Result for Problem 33: ", Problem33())
println("Result for Problem $(lpad(33, 3, "0")): ", Problem33())

View File

@ -5,8 +5,7 @@ Created on 01 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 34 of Project Euler
https://projecteuler.net/problem=34
=#
https://projecteuler.net/problem=34 =#
using BenchmarkTools
@ -17,8 +16,7 @@ function Problem34()
Find the sum of all numbers which are equal to the sum of the factorial
of their digits.
Note: As 1! = 1 and 2! = 2 are not sums they are not included.
=#
Note: As 1! = 1 and 2! = 2 are not sums they are not included. =#
ans = 0
@ -36,7 +34,7 @@ function Problem34()
end
println("Time to evaluate Problem 34:")
println("Time to evaluate Problem $(lpad(34, 3, "0")):")
@btime Problem34()
println("")
println("Result for Problem 34: ", Problem34())
println("Result for Problem $(lpad(34, 3, "0")): ", Problem34())

View File

@ -5,8 +5,7 @@ Created on 02 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 35 of Project Euler
https://projecteuler.net/problem=35
=#
https://projecteuler.net/problem=35 =#
using BenchmarkTools
using Combinatorics
@ -22,15 +21,15 @@ using Primes
# end
function circular_number(n)
if n <10
if n < 10
return [n]
end
digs=digits(n)
d=length(digs)
cyc=zeros(Int,d)
x=[10^i for i in 0:d-1]
digs = digits(n)
d = length(digs)
cyc = zeros(Int, d)
x = [10^i for i in 0:d - 1]
for i in 1:d
cyc[i]=sum(x .* digs[vcat(i:d,1:i-1)])
cyc[i] = sum(x .* digs[vcat(i:d, 1:i - 1)])
end
return cyc
end
@ -43,8 +42,7 @@ function Problem35()
There are thirteen such primes below 100:
2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.
How many circular primes are there below one million?
=#
How many circular primes are there below one million? =#
circular_primes = []
cnt = 0
for i in 2:1_000_000
@ -57,16 +55,16 @@ function Problem35()
end
end
if all_primes
cnt +=1 #push!(circular_primes, i)
cnt += 1 # push!(circular_primes, i)
end
end
end
return cnt #length(circular_primes)
return cnt # length(circular_primes)
end
println("Time to evaluate Problem 35:")
println("Time to evaluate Problem $(lpad(35, 3, "0")):")
@btime Problem35()
println("")
println("Result for Problem 35: ", Problem35())
println("Result for Problem $(lpad(35, 3, "0")): ", Problem35())

View File

@ -5,8 +5,7 @@ Created on 04 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 36 of Project Euler
https://projecteuler.net/problem=36
=#
https://projecteuler.net/problem=36 =#
using BenchmarkTools
@ -20,11 +19,10 @@ function Problem36()
in both bases.
Find the sum of all numbers, less than one million, which are palindromic
in base 10 and base 2.
=#
in base 10 and base 2. =#
ans = 0
for n in 1:2:1_000_000
if is_palindrome(digits(n,base=10)) && is_palindrome(digits(n,base=2))
if is_palindrome(digits(n, base=10)) && is_palindrome(digits(n, base=2))
ans += n
end
end
@ -32,7 +30,7 @@ function Problem36()
end
println("Time to evaluate Problem 36:")
println("Time to evaluate Problem $(lpad(36, 3, "0")):")
@btime Problem36()
println("")
println("Result for Problem 36: ", Problem36())
println("Result for Problem $(lpad(36, 3, "0")): ", Problem36())

View File

@ -5,8 +5,7 @@ Created on 07 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 37 of Project Euler
https://projecteuler.net/problem=37
=#
https://projecteuler.net/problem=37 =#
using BenchmarkTools
using Primes
@ -14,9 +13,9 @@ using Primes
function is_truncatable_prime(number)
num_str_rev = reverse(digits(number))
for (idx,num) in enumerate(join(num_str_rev))
for (idx, num) in enumerate(join(num_str_rev))
if !isprime(parse(Int, join(num_str_rev[idx:end]))) ||
!isprime(parse(Int, join(num_str_rev[1:end-idx+1])))
!isprime(parse(Int, join(num_str_rev[1:end - idx + 1])))
return false
end
end
@ -47,7 +46,7 @@ function Problem37()
end
println("Time to evaluate Problem 37:")
println("Time to evaluate Problem $(lpad(37, 3, "0")):")
@btime Problem37()
println("")
println("Result for Problem 37: ", Problem37())
println("Result for Problem $(lpad(37, 3, "0")): ", Problem37())

View File

@ -5,8 +5,7 @@ Created on 08 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 38 of Project Euler
https://projecteuler.net/problem=38
=#
https://projecteuler.net/problem=38 =#
using BenchmarkTools
@ -28,8 +27,7 @@ function Problem38()
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 > 1?
=#
(1,2, ... , n) where n > 1? =#
results = []
pandigital = join(['1', '2', '3', '4', '5', '6', '7', '8', '9'])
@ -41,7 +39,7 @@ function Problem38()
while length(number) < 9
number *= string(integer * i)
if join(sort(collect(number))) == pandigital
push!(results,number)
push!(results, number)
end
integer += 1
end
@ -50,7 +48,7 @@ function Problem38()
end
println("Time to evaluate Problem 38:")
println("Time to evaluate Problem $(lpad(38, 3, "0")):")
@btime Problem38()
println("")
println("Result for Problem 38: ", Problem38())
println("Result for Problem $(lpad(38, 3, "0")): ", Problem38())

View File

@ -5,8 +5,7 @@ Created on 09 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 39 of Project Euler
https://projecteuler.net/problem=39
=#
https://projecteuler.net/problem=39 =#
using BenchmarkTools
@ -17,13 +16,12 @@ function Problem39()
{20,48,52}, {24,45,51}, {30,40,50}
For which value of p 1000, is the number of solutions maximised?
=#
For which value of p 1000, is the number of solutions maximised? =#
ans, val = 0, 0
for p in 2:2:1000
sol = 0
for a in 1:p
for b in a+1:p-2*a
for b in a + 1:p - 2 * a
c = p - (a + b)
if a^2 + b^2 == c^2
sol += 1
@ -43,7 +41,7 @@ function Problem39()
end
println("Time to evaluate Problem 39:")
println("Time to evaluate Problem $(lpad(39, 3, "0")):")
@btime Problem39()
println("")
println("Result for Problem 39: ", Problem39())
println("Result for Problem $(lpad(39, 3, "0")): ", Problem39())

View File

@ -5,8 +5,7 @@ Created on 10 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 40 of Project Euler
https://projecteuler.net/problem=40
=#
https://projecteuler.net/problem=40 =#
using BenchmarkTools
@ -20,21 +19,19 @@ function Problem40()
If d_n represents the n^th digit of the fractional part, find the value of the following expression.
d_1 × d_{10} × d_{100} × d_{1_000} × d_{10_000} × d_{100_000} × d_{1_000_000}
=#
d_1 × d_{10} × d_{100} × d_{1_000} × d_{10_000} × d_{100_000} × d_{1_000_000} =#
ans = 1
fraction = join([i for i in 1:1_000_000])
for i in 0:6
ans *= parse(Int, fraction[10^i])
ans *= parse(Int, fraction[10^i])
end
return ans
end
println("Time to evaluate Problem 40:")
println("Time to evaluate Problem $(lpad(40, 3, "0")):")
@btime Problem40()
println("")
println("Result for Problem 40: ", Problem40())
println("Result for Problem $(lpad(40, 3, "0")): ", Problem40())

View File

@ -5,8 +5,7 @@ Created on 11 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 41 of Project Euler
https://projecteuler.net/problem=41
=#
https://projecteuler.net/problem=41 =#
using BenchmarkTools
using Primes
@ -26,8 +25,7 @@ function Problem41()
use of all the digits 1 to n exactly once. For example, 2143 is
a 4-digit pandigital and is also prime.
What is the largest n-digit pandigital prime that exists?
=#
What is the largest n-digit pandigital prime that exists? =#
for ans in 7654321:-1:1
if is_pandigital(ans) & isprime(ans)
@ -37,7 +35,7 @@ function Problem41()
end
println("Time to evaluate Problem 41:")
println("Time to evaluate Problem $(lpad(41, 3, "0")):")
@btime Problem41()
println("")
println("Result for Problem 41: ", Problem41())
println("Result for Problem $(lpad(41, 3, "0")): ", Problem41())

View File

@ -5,18 +5,17 @@ Created on 12 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 42 of Project Euler
https://projecteuler.net/problem=42
=#
https://projecteuler.net/problem=42 =#
using BenchmarkTools
using DelimitedFiles
function triangle_number(num)
return Int(0.5*num*(num+1))
return Int(0.5 * num * (num + 1))
end
function word_to_value(word)
return sum(Int(letter)-64 for letter in word)
return sum(Int(letter) - 64 for letter in word)
end
function Problem42()
@ -32,12 +31,11 @@ function Problem42()
shall call the word a triangle word.
Using words.txt, a 16K text file containing nearly two-thousand common English words,
how many are triangle words?
=#
how many are triangle words? =#
triangular_numbers = [triangle_number(n) for n in 1:26]
ans = 0
file = "/datos/Scripts/Gitea/Project_Euler/src/files/Problem42.txt"
file = "../files/Problem42.txt"
words = sort(readdlm(file, ',', String)[:])
for word in words
@ -49,7 +47,7 @@ function Problem42()
end
println("Time to evaluate Problem 42:")
println("Time to evaluate Problem $(lpad(42, 3, "0")):")
@btime Problem42()
println("")
println("Result for Problem 42: ", Problem42())
println("Result for Problem $(lpad(42, 3, "0")): ", Problem42())

View File

@ -5,8 +5,7 @@ Created on 13 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 43 of Project Euler
https://projecteuler.net/problem=43
=#
https://projecteuler.net/problem=43 =#
using BenchmarkTools
using Combinatorics
@ -28,13 +27,12 @@ function Problem43()
d7d8d9=728 is divisible by 13
d8d9d10=289 is divisible by 17
Find the sum of all 0 to 9 pandigital numbers with this property.
=#
Find the sum of all 0 to 9 pandigital numbers with this property. =#
ans = []
pandigital = join(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
for n in permutations(pandigital)
n_ =join(n)
n_ = join(n)
if n_[1] != 0 && join(sort(n)) == pandigital
if parse(Int, n_[8:end]) % 17 == 0
if parse(Int, n_[7:9]) % 13 == 0
@ -58,7 +56,7 @@ function Problem43()
end
println("Time to evaluate Problem 43:")
println("Time to evaluate Problem $(lpad(43, 3, "0")):")
@btime Problem43()
println("")
println("Result for Problem 43: ", Problem43())
println("Result for Problem $(lpad(43, 3, "0")): ", Problem43())

View File

@ -5,14 +5,13 @@ Created on 14 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 44 of Project Euler
https://projecteuler.net/problem=44
=#
https://projecteuler.net/problem=44 =#
using BenchmarkTools
using Combinatorics
function pentagonal(n)
return Int(n*(3*n-1)/2)
return Int(n * (3 * n - 1) / 2)
end
function Problem44()
@ -28,14 +27,13 @@ function Problem44()
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?
=#
What is the value of D? =#
dif = 0
pentagonal_list = [pentagonal(n) for n in 1:2500]
pairs = combinations(pentagonal_list, 2)
for p in pairs
if reduce(+, p) in pentagonal_list && abs(reduce(-, p)) in pentagonal_list
dif = (abs(reduce(-,p)))
dif = (abs(reduce(-, p)))
# the first one found would be the smallest
break
end
@ -45,7 +43,7 @@ function Problem44()
end
println("Time to evaluate Problem 44:")
println("Time to evaluate Problem $(lpad(44, 3, "0")):")
@btime Problem44()
println("")
println("Result for Problem 44: ", Problem44())
println("Result for Problem $(lpad(44, 3, "0")): ", Problem44())

View File

@ -5,17 +5,16 @@ Created on 15 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 45 of Project Euler
https://projecteuler.net/problem=45
=#
https://projecteuler.net/problem=45 =#
using BenchmarkTools
function pentagonal(n)
return Int(n*(3*n-1)/2)
return Int(n * (3 * n - 1) / 2)
end
function hexagonal(n)
return Int(n*(2*n-1))
return Int(n * (2 * n - 1))
end
function Problem45()
@ -27,8 +26,7 @@ function Problem45()
It can be verified that T285 = P165 = H143 = 40755.
Find the next triangle number that is also pentagonal and hexagonal.
=#
Find the next triangle number that is also pentagonal and hexagonal. =#
pentagonal_list = Set(pentagonal(n) for n in 2:100_000)
# all hexagonal numbers are also triangle numbers!
hexagonal_list = Set(hexagonal(n) for n in 2:100_000)
@ -39,7 +37,7 @@ function Problem45()
end
println("Time to evaluate Problem 45:")
println("Time to evaluate Problem $(lpad(45, 3, "0")):")
@btime Problem45()
println("")
println("Result for Problem 45: ", Problem45())
println("Result for Problem $(lpad(45, 3, "0")): ", Problem45())

View File

@ -5,15 +5,14 @@ Created on 16 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 46 of Project Euler
https://projecteuler.net/problem=46
=#
https://projecteuler.net/problem=46 =#
using BenchmarkTools
using Primes
function is_goldbach(number)
for i in number - 1:-1:1
if isprime(i) & ((((number - i) / 2)^0.5)%1==0)
if isprime(i) & ((((number - i) / 2)^0.5) % 1 == 0)
return true
end
end
@ -22,7 +21,7 @@ end
function Problem46()
#=
It was proposed by Christian Goldbach that every odd composite number
It was proposed by Christian Goldbach that every odd composite number
can be written as the sum of a prime and twice a square.
9 = 7 + 2×1^2
@ -34,9 +33,8 @@ function Problem46()
It turns out that the conjecture was false.
What is the smallest odd composite that cannot be written as the sum
of a prime and twice a square?
=#
What is the smallest odd composite that cannot be written as the sum
of a prime and twice a square? =#
ans = 9
while true
ans += 2
@ -47,7 +45,7 @@ function Problem46()
end
println("Time to evaluate Problem 46:")
println("Time to evaluate Problem $(lpad(46, 3, "0")):")
@btime Problem46()
println("")
println("Result for Problem 46: ", Problem46())
println("Result for Problem $(lpad(46, 3, "0")): ", Problem46())

View File

@ -5,24 +5,23 @@ Created on 18 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 47 of Project Euler
https://projecteuler.net/problem=47
=#
https://projecteuler.net/problem=47 =#
using BenchmarkTools
function factor(n)
ans = []
d = 2
while d*d <= n
while d * d <= n
if n % d == 0
push!(ans,d)
push!(ans, d)
n = n ÷ d
else
d += 1
end
end
if n > 1
push!(ans,n)
push!(ans, n)
end
return ans
end
@ -41,15 +40,14 @@ function Problem47()
646 = 2 × 17 × 19.
Find the first four consecutive integers to have four distinct prime factors each.
What is the first of these numbers?
=#
What is the first of these numbers? =#
ans = []
for number in 1:1_000_000
if length(ans) == 4
break
elseif length(Set(factor(number))) == 4
push!(ans,number)
push!(ans, number)
else
ans = []
end
@ -59,7 +57,7 @@ function Problem47()
end
println("Time to evaluate Problem 47:")
println("Time to evaluate Problem $(lpad(47, 3, "0")):")
@btime Problem47()
println("")
println("Result for Problem 47: ", Problem47())
println("Result for Problem $(lpad(47, 3, "0")): ", Problem47())

View File

@ -5,8 +5,7 @@ Created on 18 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 48 of Project Euler
https://projecteuler.net/problem=48
=#
https://projecteuler.net/problem=48 =#
using BenchmarkTools
@ -14,14 +13,13 @@ function Problem48()
#=
The series, 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317.
Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000.
=#
Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000. =#
series = sum(big(i)^i for i in 1:1000)
return string(series)[end-9:end]
return string(series)[end - 9:end]
end
println("Time to evaluate Problem 48:")
println("Time to evaluate Problem $(lpad(48, 3, "0")):")
@btime Problem48()
println("")
println("Result for Problem 48: ", Problem48())
println("Result for Problem $(lpad(48, 3, "0")): ", Problem48())

View File

@ -5,8 +5,7 @@ Created on 19 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 49 of Project Euler
https://projecteuler.net/problem=49
=#
https://projecteuler.net/problem=49 =#
using BenchmarkTools
using Primes
@ -21,15 +20,14 @@ function Problem49()
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.
What 12-digit number do you form by concatenating the three terms in this sequence?
=#
What 12-digit number do you form by concatenating the three terms in this sequence? =#
ans = []
primes_list = primes(1_000, 10_000)
for number in primes_list
if sort(collect(digits(number))) == sort(collect(digits(number+3330))) == sort(collect(digits(number+6660)))
if number+3330 in primes_list && number+6660 in primes_list
push!(ans, (string(number)*string(number+3300)*string(number+6660)))
if sort(collect(digits(number))) == sort(collect(digits(number + 3330))) == sort(collect(digits(number + 6660)))
if number + 3330 in primes_list && number + 6660 in primes_list
push!(ans, (string(number) * string(number + 3300) * string(number + 6660)))
end
end
end
@ -38,7 +36,7 @@ function Problem49()
end
println("Time to evaluate Problem 49:")
println("Time to evaluate Problem $(lpad(49, 3, "0")):")
@btime Problem49()
println("")
println("Result for Problem 49: ", Problem49())
println("Result for Problem $(lpad(49, 3, "0")): ", Problem49())

View File

@ -5,8 +5,7 @@ Created on 20 Sep 2021
@email: daviddoji@pm.me
Solution for Problem 50 of Project Euler
https://projecteuler.net/problem=50
=#
https://projecteuler.net/problem=50 =#
using BenchmarkTools
using Primes
@ -19,11 +18,10 @@ function Problem50()
This is the longest sum of consecutive primes that adds to a prime below one-hundred.
The longest sum of consecutive primes below one-thousand that adds to a prime,
The longest sum of consecutive primes below one-thousand that adds to a prime,
contains 21 terms, and is equal to 953.
Which prime, below one-million, can be written as the sum of the most consecutive primes?
=#
Which prime, below one-million, can be written as the sum of the most consecutive primes? =#
ans = 0
result = 0
@ -48,7 +46,7 @@ function Problem50()
end
println("Time to evaluate Problem 50:")
println("Time to evaluate Problem $(lpad(50, 3, "0")):")
@btime Problem50()
println("")
println("Result for Problem 50: ", Problem50())
println("Result for Problem $(lpad(50, 3, "0")): ", Problem50())