statics data
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 1,
|
||||
'title' => 'Multiples of 3 and 5',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_001_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_001_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_001_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=001',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-001.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 47624,
|
||||
'time' => 62,
|
||||
'width' => 30,
|
||||
'height' => 5,
|
||||
'value' => 233168,
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
vvv: < <
|
||||
1> 1+:::3/3*-!#^_>::5/5*-!#^_v
|
||||
1$v ># v# ># v#<
|
||||
1 >:5558***-!|v$<>+\:1-!|v$<
|
||||
>^ <>$$^\ <>.@
|
||||
@@ -0,0 +1,3 @@
|
||||
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.
|
||||
|
||||
Find the sum of all the multiples of 3 or 5 below 1000.
|
||||
@@ -0,0 +1 @@
|
||||
The solution here is pretty straight-forward, going through all numbers from 1-1000 and adding all multiples of 3 and 5 together.
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 2,
|
||||
'title' => 'Even Fibonacci numbers',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_002_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_002_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_002_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=002',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-002.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 1669,
|
||||
'time' => 62,
|
||||
'width' => 26,
|
||||
'height' => 5,
|
||||
'value' => 4613732,
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
v>v>ppp 0>>$ 10g20g:10p+:v
|
||||
202 >00p0^|-*2/2::< vp02<
|
||||
0::0^+ g00<v**"}P ":<
|
||||
:1>^@$.g00<>*` #v_^
|
||||
>^ ^ <
|
||||
@@ -0,0 +1,8 @@
|
||||
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, ...
|
||||
~~~
|
||||
|
||||
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
|
||||
@@ -0,0 +1 @@
|
||||
Also the problem here was not the algorithm, but writing and compressing it in Befunge. The code calculates the Fibonacci sequence one after each other and remembers the sum while iterating.
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 3,
|
||||
'title' => 'Largest prime factor',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_003_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_003_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_003_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=003',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-003.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 31579516,
|
||||
'time' => 9547,
|
||||
'width' => 55,
|
||||
'height' => 4,
|
||||
'value' => 6857,
|
||||
];
|
||||
@@ -0,0 +1,4 @@
|
||||
89197939490919v >00g10g1-:10p%#v_10g:30p1-40pv
|
||||
v+*29191929891< ^ < <_v#! %g04g03<
|
||||
>*+*+*+*+*+*+*v >"{.i "+**10p#^ #p #0 #0 <>40g:1-40p2-|
|
||||
>#^ +# *# +# *# +# *# +# *# +# <@.g03<
|
||||
@@ -0,0 +1,3 @@
|
||||
The prime factors of 13195 are 5, 7, 13 and 29.
|
||||
|
||||
What is the largest prime factor of the number 600851475143 ?
|
||||
@@ -0,0 +1,3 @@
|
||||
This problem is the reason why I changed the internals of my interpreter to int64 (because the numbers are too big for int32).
|
||||
|
||||
Fortunately the number is still small enough to brute-force the prime factors, going from the biggest factor to the smallest, the first factor (that is also a prime) that my code finds is the solution.
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 4,
|
||||
'title' => 'Largest palindrome product',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_004_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_004_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_004_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=004',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-004.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 230611114,
|
||||
'time' => 77813,
|
||||
'width' => 71,
|
||||
'height' => 6,
|
||||
'value' => 906609,
|
||||
];
|
||||
@@ -0,0 +1,6 @@
|
||||
1:010:pp5558***04p>10g1+::10p04g-00g \#v_1+:00p\$1:10p\:04g- #v_$$03g.@
|
||||
^ v $< >1# 0# 1# p# *# :# v# <
|
||||
v_v#-g1-g20g10g 1g20<p201<v_^#:/+55p10+1g10p1g10%+55: <
|
||||
$ >02g1+:02p 01 g - | > ^
|
||||
> ^ >:03g\`#v_03pv
|
||||
^ $< 0<
|
||||
@@ -0,0 +1,3 @@
|
||||
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
|
||||
|
||||
Find the largest palindrome made from the product of two 3-digit numbers.
|
||||
@@ -0,0 +1 @@
|
||||
Again we can write our program fast enough to brute-force the solution. So we iterate through every possible 3-digit product and check if its a palindrom.
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 5,
|
||||
'title' => 'Smallest multiple',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_005_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_005_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_005_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=005',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-005.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 50166,
|
||||
'time' => 47,
|
||||
'width' => 73,
|
||||
'height' => 6,
|
||||
'value' => 232792560,
|
||||
];
|
||||
@@ -0,0 +1,6 @@
|
||||
45*00p110p120p >10g20g*10p00g20g1+:20p`#v_10g.@
|
||||
^_v#`g00p03+1:g03 <p031< v <
|
||||
>10g30g% |1 <^ p01/g03g01<
|
||||
>10g30g/40p150p > 20g50g1+:50p` #v_^
|
||||
^ < |!%g05g04 <
|
||||
^<
|
||||
@@ -0,0 +1,3 @@
|
||||
2520 is the smallest number that can be divided by each of the numbers 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?
|
||||
@@ -0,0 +1,11 @@
|
||||
We start with a value of `1`.
|
||||
Then we multiply one after another the numbers from `1` to `20` to our value (We call these `multiplicand` in the loop).
|
||||
|
||||
After each multiplications we search go through the numbers from `2` to `value` and search for a number `divisor` where
|
||||
|
||||
- `value % divisor == 0`
|
||||
- `(value / divisor) % {0, multiplicand} == 0`
|
||||
|
||||
Then (after we found such a number) we can reduce the value with it (`value /= divisor`).
|
||||
|
||||
The reduction steps guarantees us that we find the **smallest** number and it prevents our *Int64* numbers from overflowing
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 6,
|
||||
'title' => 'Sum square difference',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_006_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_006_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_006_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=006',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-006.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 18897151,
|
||||
'time' => 7347,
|
||||
'width' => 72,
|
||||
'height' => 16,
|
||||
'value' => 25164150,
|
||||
];
|
||||
@@ -0,0 +1,16 @@
|
||||
"d"10p000p>10g:00g+00p1-:#v_$010p>"c"10g::1+:*\:5:+%\5:+/6+p`#v_ v
|
||||
>$.@ ^ p01< ^ p01+1g01 < 0
|
||||
> v
|
||||
|!:\<|p01-1:g01<$$_v#!:g+6/+:5\%+:5:g01 :< p01"c"+<_v#!p01:-1g01<p01:g0<
|
||||
\ ^< >` > #v_v
|
||||
> v v-g+6/+:5\%+:5:g01< >00g ^
|
||||
##########> ^
|
||||
########## >010g:5:+%\5:+/6+pv
|
||||
##########
|
||||
########## ^ < <
|
||||
##########
|
||||
##########
|
||||
##########
|
||||
##########
|
||||
##########
|
||||
##########
|
||||
@@ -0,0 +1,9 @@
|
||||
The sum of the squares of the first ten natural numbers is,
|
||||
`1^2 + 2^2 + ... + 10^2 = 385`
|
||||
|
||||
The square of the sum of the first ten natural numbers is,
|
||||
`(1 + 2 + ... + 10)^2 = 552 = 3025`
|
||||
|
||||
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`.
|
||||
|
||||
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
|
||||
@@ -0,0 +1,7 @@
|
||||
My solution here is *far* more complex than necessary, mostly because I thought the temporary numbers would get too big for int32 to handle (especially sum(1,100)^2).
|
||||
Later I found out I could just calculate the sum of the squares and the square of the sum and subtract them ...
|
||||
|
||||
But I like my solution so I'll leave it here.
|
||||
While I calculate the the second value (using the distributive property), I subtract in every step as much parts of the first value (the single elements of the addition) as I can (without going negative).
|
||||
|
||||
That way my temporary values never greatly exceed the final result.
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 7,
|
||||
'title' => '10001st prime',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_007_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_007_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_007_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=007',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-007.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => true,
|
||||
'steps' => 21915385,
|
||||
'time' => 7628,
|
||||
'width' => 1000,
|
||||
'height' => 156,
|
||||
'value' => 104743,
|
||||
];
|
||||
@@ -0,0 +1,11 @@
|
||||
v
|
||||
# ... #
|
||||
. . . .
|
||||
. . .
|
||||
. . . .
|
||||
# ... #
|
||||
v <
|
||||
>"d"55+*:10p3"2"*:20p*00p230p" ":01p11p10g5:+*1+50pv > 030p 040p>30g1+:30p:10g%\10g/1+g"X"- |
|
||||
v < _^#`g03g00 <|p+1/g01\%g01:g03"0"-p04:+1g04g05<
|
||||
> "X" 30g:10g%\10g/1+p30g >30g+ : 00g\` #v_$>30g1+:30p:10g%\10g/1+g" "- |>30g.@
|
||||
^p+1/g01\%g01:\" ":< ^ <
|
||||
@@ -0,0 +1,3 @@
|
||||
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?
|
||||
@@ -0,0 +1 @@
|
||||
Finally a opportunity to use my favorite algorithm: [The sieve of Eratosthenes.](http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes)
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 8,
|
||||
'title' => 'Largest product in a series',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_008_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_008_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_008_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=008',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-008.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 614295,
|
||||
'time' => 234,
|
||||
'width' => 116,
|
||||
'height' => 29,
|
||||
'value' => 23514624000,
|
||||
];
|
||||
@@ -0,0 +1,29 @@
|
||||
"v"00p54*:10p552**:20p*30p85+40p050p060p070p080p v
|
||||
>150g60p>60g:20g%\20g/9+g"0"-*60g1+:60p50g-40g-#v_:80g`#v_$>50g1+:50p30g-#v_ 970p >70g0g.70g8-40g-#v_"=",80g.@
|
||||
^ < $ ^ <
|
||||
>80p060p>60g50g+:2 0g%\20g /9+g"0"-60g9+0p6 0g1+:60p40g-#v_^
|
||||
^ < < ^p07+1g07 <
|
||||
^ <
|
||||
|
||||
|
||||
|
||||
73167176531330624919225119674426574742355349194934
|
||||
96983520312774506326239578318016984801869478851843
|
||||
85861560789112949495459501737958331952853208805511
|
||||
12540698747158523863050715693290963295227443043557
|
||||
66896648950445244523161731856403098711121722383113
|
||||
62229893423380308135336276614282806444486645238749
|
||||
30358907296290491560440772390713810515859307960866
|
||||
70172427121883998797908792274921901699720888093776
|
||||
65727333001053367881220235421809751254540594752243
|
||||
52584907711670556013604839586446706324415722155397
|
||||
53697817977846174064955149290862569321978468622482
|
||||
83972241375657056057490261407972968652414535100474
|
||||
82166370484403199890008895243450658541227588666881
|
||||
16427171479924442928230863465674813919123162824586
|
||||
17866458359124566529476545682848912883142607690042
|
||||
24219022671055626321111109370544217506941658960408
|
||||
07198403850962455444362981230987879927244284909188
|
||||
84580156166097919133875499200524063689912560717606
|
||||
05886116467109405077541002256983155200055935729725
|
||||
71636269561882670428252483600823257530420752963450
|
||||
@@ -0,0 +1,7 @@
|
||||
The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832.
|
||||
|
||||
```
|
||||
...
|
||||
```
|
||||
|
||||
Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?
|
||||
@@ -0,0 +1 @@
|
||||
These kinds of problems are fun in Befunge because you can just copy the input into your program and it becomes a part of your source code.
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 9,
|
||||
'title' => 'Special Pythagorean triplet',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_009_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_009_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_009_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=009',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-009.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 1397212134,
|
||||
'time' => 394277,
|
||||
'width' => 79,
|
||||
'height' => 7,
|
||||
'value' => 31875000,
|
||||
];
|
||||
@@ -0,0 +1,7 @@
|
||||
"d"5:+*00p210p> 120p>v >20g1+:20p10g-#v_10g1+:10p00g-#v_ @
|
||||
^ <
|
||||
^ <
|
||||
v <
|
||||
>20g:*10g:*+:30p0>::*30g-#v_:30p20g10g++ 00g-#v_20g:." ",10g:." ",30g:."=",**.@
|
||||
|-g00 :+1<
|
||||
>$$ ^ $<
|
||||
@@ -0,0 +1,7 @@
|
||||
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
|
||||
`a^2 + b^2 = c^2`
|
||||
|
||||
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.
|
||||
@@ -0,0 +1 @@
|
||||
The brute-force approach is here taking quite a long time - but I think it's good enough - perhaps I will make an optimized version later
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 10,
|
||||
'title' => 'Summation of primes',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_010_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_010_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_010_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=010',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-010.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => true,
|
||||
'steps' => 416776174,
|
||||
'time' => 67127,
|
||||
'width' => 2000,
|
||||
'height' => 1007,
|
||||
'value' => 142913828922,
|
||||
];
|
||||
@@ -0,0 +1,12 @@
|
||||
v
|
||||
# ... #
|
||||
. . . .
|
||||
. . .
|
||||
. . . .
|
||||
# ... #
|
||||
>"d"55+*:2**1- >:"#"\:"d"55+2**%\"d"55+2**/1+p:#v_ "d"55+*:2*:10p v
|
||||
^ ^ -1< v p05+1*+:5g01p11p10:" "p032p00*p02: <v <
|
||||
> 030p 040p>30g1+:30p:10g% \10g/1+g"X"-|
|
||||
v < _^#`g03g00 <| - g03g00 < p04+g04 g03<
|
||||
> "X" 30g:10g%\10g/1+p30g >30g+ : 00g\` #v_$>30g1+:30p:10g%\10g/1+g" "- |>40g.@
|
||||
^p+1/g01\%g01:\" ":< ^ <
|
||||
@@ -0,0 +1,3 @@
|
||||
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
|
||||
|
||||
Find the sum of all the primes below two million.
|
||||
@@ -0,0 +1 @@
|
||||
And again a sieve of Eratosthenes (see Problem 7), but this time a lot bigger.
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 11,
|
||||
'title' => 'Largest product in a grid',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_011_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_011_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_011_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=011',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-011.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 323945,
|
||||
'time' => 78,
|
||||
'width' => 151,
|
||||
'height' => 31,
|
||||
'value' => 70600674,
|
||||
];
|
||||
@@ -0,0 +1,31 @@
|
||||
v v <
|
||||
>"4"2/:*1-00p > 000g: "4"2/ %"?"+\ "4"2/ /1+ p 00g:1-00p #^_v++++++++++++++++++++++++++
|
||||
++++++++++++++++++++++++++
|
||||
++++++++++++++++++++++++++
|
||||
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 | +++####################+++
|
||||
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 | +++####################+++
|
||||
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65 | +++####################+++
|
||||
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91 | +++####################+++
|
||||
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80 | +++####################+++
|
||||
24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50 | +++####################+++
|
||||
32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70 | +++####################+++
|
||||
67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21 | +++####################+++
|
||||
24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72 | +++####################+++
|
||||
21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95 | +++####################+++
|
||||
78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92 | +++####################+++
|
||||
16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57 | +++####################+++
|
||||
86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58 | +++####################+++
|
||||
19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40 | +++####################+++
|
||||
04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66 | +++####################+++
|
||||
88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69 | +++####################+++
|
||||
04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36 | +++####################+++
|
||||
20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16 | +++####################+++
|
||||
20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54 | +++####################+++
|
||||
01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48 | +++####################+++
|
||||
vp00-1*:*45 p1++1550p0++1551p1+55-10p0+551p19-10p090 p010<++++++++++++++++++++++++++ >10pv
|
||||
>00g:54*%3*1+\54*/4+g"0"-52**00g:54*%3*2+\54*/4+g"0"-+00g:54*%v++++++++++++++++++++++++++ >$> v
|
||||
| p00-1:g00p+4/*45\+"B"<++++++++++++++++++++++++++ ^_^#`g01:< v <
|
||||
>54*:*1-00p>220p>20g9+:0g30p1g40p00g:54*%50p54*/60p50g"B"+60g4+g50g30g+50p60g40g+60p>50g"B"+60g4+g50g30g+50p60g40g+60pv >20g:1-20p#v_00g:1-00p#^_10g. @
|
||||
^ _^# <vp06+g04g06p05+g03g05g+4g06+"B"g05<^ < v 0<
|
||||
>50g"B"+60g4+g50g30g+50p60g40g+60p***^
|
||||
^ <<
|
||||
@@ -0,0 +1,9 @@
|
||||
In the 20×20 grid below, four numbers along a diagonal line have been marked in red.
|
||||
|
||||
```
|
||||
...
|
||||
```
|
||||
|
||||
The product of these numbers is 26 × 63 × 78 × 14 = 1788696.
|
||||
|
||||
What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?
|
||||
@@ -0,0 +1 @@
|
||||
The idea here was to first move the numbers into a *real* 20x20 grid where every field represents a single number, the rest was not that hard.
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 12,
|
||||
'title' => 'Highly divisible triangular number',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_012_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_012_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_012_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=012',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-012.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => true,
|
||||
'steps' => 38855123,
|
||||
'time' => 7566,
|
||||
'width' => 1000,
|
||||
'height' => 170,
|
||||
'value' => 76576500,
|
||||
];
|
||||
@@ -0,0 +1,22 @@
|
||||
# ... #
|
||||
. . . .
|
||||
. . .
|
||||
. . . .
|
||||
# ... #
|
||||
|
||||
v p03+1g03 p04+1g04 p +3/g01\%g01:g04 g03 <
|
||||
>"d"55+*:10p3"2"*:20p*00p230p" ":03p13p v >130p040p > 30g:10g%\10g/3+g" "- 00g30g` !#v_ |
|
||||
v < _^#`g03g00 <^ p03+1g03 <
|
||||
> "X" 30g:10g%\10g/3+p30g >30g+ : 00g\` #v_$>30g1+:30p:10g%\10g/3+g" "- |
|
||||
^p+3/g01\%g01:\" ":< ^ <
|
||||
v +1$<
|
||||
>:1+2/>:01p31p111p0>::10g%\10g/3+g::*01g`#v_121p>:31g\% !#v_11g21g*11p31g1-|
|
||||
v < ^p13/\g13:p12+1g12<
|
||||
v < vp21<*2g11$$<^g11$$ <
|
||||
>2 212p222p >:2%| >12g22g*"d"5*` #v_1+ 1v
|
||||
| < 0+1$<
|
||||
>:1+ >:01p31p111p0>::10g%\10g/3+g::*01g`#v_121p>:31g\% !#v_11g21g*11p31g1-|
|
||||
# v < v ^p13/\g13:p12+1g12<
|
||||
^p22<*2g11$$<^g11$$ <
|
||||
>$$:1+*2/.@
|
||||
^ $p05-1g04<
|
||||
@@ -0,0 +1,17 @@
|
||||
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:
|
||||
|
||||
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
|
||||
|
||||
Let us list the factors of the first seven triangle numbers:
|
||||
|
||||
1: 1
|
||||
3: 1,3
|
||||
6: 1,2,3,6
|
||||
10: 1,2,5,10
|
||||
15: 1,3,5,15
|
||||
21: 1,3,7,21
|
||||
28: 1,2,4,7,14,28
|
||||
|
||||
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?
|
||||
@@ -0,0 +1 @@
|
||||
Here I was desperately in need of an efficient algorithm. So I copied [this](http://www.mathblog.dk/triangle-number-with-more-than-500-divisors/) one from mathblog.dk and translated it into befunge. And I have to say it's amazingly fast.
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 13,
|
||||
'title' => 'Large sum',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_013_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_013_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_013_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=013',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-013.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => true,
|
||||
'steps' => 244792,
|
||||
'time' => 78,
|
||||
'width' => 59,
|
||||
'height' => 113,
|
||||
'value' => 5537376230,
|
||||
];
|
||||
@@ -0,0 +1,16 @@
|
||||
v // Project Euler - Problem 13
|
||||
37107287533902102798797998220837590246510135740250
|
||||
...
|
||||
# 53503534226472524250874054075591789781264330331690
|
||||
=
|
||||
|
||||
v_v# < <1<
|
||||
>510p"d"20p>"0"10g20gp10g1-:10p#^_510p20g1-:20p#^_^
|
||||
v $<
|
||||
>"7"10pv>10g20gg" "-!#v_ >10g20gg"0"-00g+00p v
|
||||
v30p021< >10g1-10p55+/00p v |-" "gg02g01p02+1g02<
|
||||
>0p0::p ^^p021pg02g01+"0"%+55:<>0v
|
||||
^ "# $< ^g0<
|
||||
v p02"e"p010$<
|
||||
>10g1+:10p20gg"0"-!#v_55+00p>00g:1-00p!#@_54+00g-10g+20gg,v
|
||||
^ < ^ <
|
||||
@@ -0,0 +1,5 @@
|
||||
Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.
|
||||
|
||||
```
|
||||
...
|
||||
```
|
||||
@@ -0,0 +1 @@
|
||||
Here I do simply do a column addition. After the sum is calculated, we take the first 10 digits and print them
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 14,
|
||||
'title' => 'Longest Collatz sequence',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_014_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_014_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_014_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=014',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-014.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 3877209672,
|
||||
'time' => 717713,
|
||||
'width' => 51,
|
||||
'height' => 5,
|
||||
'value' => 837799,
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
v >3*1+v
|
||||
>0::p3>1+:1\>:2%| >\1+\:1- #v_$:00g\`#v_00p:10pv
|
||||
v:0.g0 1< ^ $># 2/^#1 < $
|
||||
g ^_^#!` **"}}@": < <
|
||||
>": ",,.@
|
||||
@@ -0,0 +1,13 @@
|
||||
The following iterative sequence is defined for the set of positive integers:
|
||||
|
||||
n -> n/2 (n is even)
|
||||
n -> 3n + 1 (n is odd)
|
||||
|
||||
Using the rule above and starting with 13, we generate the following sequence:
|
||||
13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1
|
||||
|
||||
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.
|
||||
|
||||
Which starting number, under one million, produces the longest chain?
|
||||
|
||||
NOTE: Once the chain starts the terms are allowed to go above one million.
|
||||
@@ -0,0 +1 @@
|
||||
Again a simple problem, we get the length of every sequence (= until they reach `1`) and print the highest.
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 15,
|
||||
'title' => 'Lattice paths',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_015_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_015_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_015_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=015',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-015.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 61202,
|
||||
'time' => 47,
|
||||
'width' => 78,
|
||||
'height' => 27,
|
||||
'value' => 137846528820,
|
||||
];
|
||||
@@ -0,0 +1,27 @@
|
||||
v
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000
|
||||
000000000000000000000 > v
|
||||
>v >00g1-10gg00g10g1-g+00g10gpv
|
||||
>100p110p> 00g492*+10g-*|>00g392*+`#^_>00g1-10g1-*| vp01+1g01p00-1g00<
|
||||
^p011p00+g01g00< >100g10gp ^
|
||||
|! `+2*58+g00g01 <
|
||||
@.g:*73<
|
||||
@@ -0,0 +1,5 @@
|
||||
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.
|
||||
|
||||

|
||||
|
||||
How many such routes are there through a 20×20 grid?
|
||||
@@ -0,0 +1,3 @@
|
||||
We create a 21x21 grid of the edges in our graph, then we set the value on each edge to the number of possible paths to (0|0).
|
||||
For the top-left edge this is `1`. For the edges in the first row/column it is also `1`. For every other edge it is the above edge + the left edge.
|
||||
And in the end we are only interested in the value of the bottom-right edge - this value is our result.
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 16,
|
||||
'title' => 'Power digit sum',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_016_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_016_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_016_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=016',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-016.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 27332672,
|
||||
'time' => 4228,
|
||||
'width' => 60,
|
||||
'height' => 14,
|
||||
'value' => 1366,
|
||||
];
|
||||
@@ -0,0 +1,14 @@
|
||||
v00000000000000000000000000000000000000000000000000000000000
|
||||
v00000000000000000000000000000000000000000000000000000000000
|
||||
v00000000000000000000000000000000000000000000000000000000000
|
||||
v00000000000000000000000000000000000000000000000000000000000
|
||||
v00000000000000000000000000000000000000000000000000000000000
|
||||
v00000000000000000000000000000000000000000000000000000000001
|
||||
|
||||
> "0":::::00p01p02p03p04p05p v // INIT
|
||||
v p64*8"}"p60*p62:6p61:"<" <v p66-1g66 <
|
||||
>06g1-66p 0> 66g16g%66g16g/g"0"-+ 66g|
|
||||
v $# < .
|
||||
>46g:!#^_ 1-46p 06g1-66p 076p > 66g!#^_ v @
|
||||
v61g66+"0"%+55:+g67*2-"0"g/g61 g66%g61g66<
|
||||
>g%66g16g/p55+/76p 66g1-66p ^
|
||||
@@ -0,0 +1,3 @@
|
||||
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?
|
||||
@@ -0,0 +1 @@
|
||||
Here I implemented a long multiplication algorithm. Then I took the value `1` and doubled it 1000 times. The calculation of the digit sum was then easy.
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 17,
|
||||
'title' => 'Number letter counts',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_017_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_017_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_017_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=017',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-017.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 179076,
|
||||
'time' => 47,
|
||||
'width' => 48,
|
||||
'height' => 15,
|
||||
'value' => 21124,
|
||||
];
|
||||
@@ -0,0 +1,15 @@
|
||||
v
|
||||
033544355436688779886
|
||||
0366555766
|
||||
$
|
||||
$ v-1 < v-1 <
|
||||
>54*>:::1g"0"-\1p#^_54*>:::2g"0"-\2p|
|
||||
v **25"d" 0 $$<
|
||||
v <
|
||||
v $< >:55+/2g\55+% v
|
||||
: >:54*`| >"d"/1g70 v
|
||||
>0\>:!#v_:"d"\`| ^0g1< >:"d"%!| v <
|
||||
v < >:"}"8*-#^_$380v>:"d"/1g\ "d"%v
|
||||
^ < <\3\7<
|
||||
>+# \:# _+ \ 1- :|
|
||||
@.+_ #! #:\ #+<
|
||||
@@ -0,0 +1,5 @@
|
||||
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
|
||||
|
||||
If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
|
||||
|
||||
*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.*
|
||||
@@ -0,0 +1,8 @@
|
||||
There are only `N` kinds of numbers:
|
||||
|
||||
- `0` - `20`: Get the length from a precomputed list
|
||||
- `20` - `99`: Get the length of the first word from a precomputed list and the length of the second word (second digit) from the previous point
|
||||
- `100` - `999`: Get the length of the first word from a precomputed list and the length of the second and third word (second digit) from the previous point
|
||||
- `1000`: Get the hard coded value
|
||||
|
||||
*Note*: Interestingly this program operates completely on the stack - only the initializing method sets a few "constant fields" to per-definied values
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 18,
|
||||
'title' => 'Maximum path sum I',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_018_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_018_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_018_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=018',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-018.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 15048,
|
||||
'time' => 16,
|
||||
'width' => 120,
|
||||
'height' => 16,
|
||||
'value' => 1074,
|
||||
];
|
||||
@@ -0,0 +1,16 @@
|
||||
$$>53* 00p00g1-20p010p>10g3*:20g1+g"0"-55+*\1+20g1+g"0"-+10g20g1+p10g1+:10p20g-1-#v_20g:1-20p010p#v_v
|
||||
75 ^ < < v
|
||||
95 64 v <
|
||||
17 47 82 > $v
|
||||
18 35 87 10 >00g2-:10p20p>10g20g1+g10g20g2+g:10g1+20g2+g -:0`>#^_->+10g20g1+p10g:1-10p#v_20g:1-:20p10p#v_01g.@
|
||||
20 04 82 47 65 ^ < <
|
||||
19 01 23 75 03 34
|
||||
88 02 77 73 07 63 67
|
||||
99 65 04 28 06 16 70 92
|
||||
41 41 26 56 83 40 80 70 33
|
||||
41 48 72 33 47 32 37 16 94 29
|
||||
53 71 44 65 25 43 91 52 97 51 14
|
||||
70 11 33 28 77 73 17 78 39 68 17 57
|
||||
91 71 52 38 17 14 91 43 58 50 27 29 48
|
||||
63 66 04 68 89 53 67 30 73 16 69 87 40 31
|
||||
04 62 98 27 23 09 70 98 73 93 38 53 60 04 23
|
||||
@@ -0,0 +1,18 @@
|
||||
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
|
||||
~~~
|
||||
|
||||
That is, 3 + 7 + 4 + 9 = 23.
|
||||
|
||||
Find the maximum total from top to bottom of the triangle below:
|
||||
|
||||
~~~
|
||||
...
|
||||
~~~
|
||||
|
||||
*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)*
|
||||
@@ -0,0 +1,5 @@
|
||||
Step 1: Convert the numbers so that 1 field = 1 number
|
||||
|
||||
Step 2: Set every field to `value` + max(`value-left`, `value-right`)
|
||||
|
||||
Step 3: The solution is the value of the top-most field
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 19,
|
||||
'title' => 'Counting Sundays',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_019_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_019_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_019_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=019',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-019.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 3197878,
|
||||
'time' => 546,
|
||||
'width' => 72,
|
||||
'height' => 12,
|
||||
'value' => 171,
|
||||
];
|
||||
@@ -0,0 +1,12 @@
|
||||
v303232332323
|
||||
v313232332323
|
||||
6
|
||||
>2*>::0g"0"-47*+\0p::v
|
||||
|:-1p1\+*74-"0"g1 <
|
||||
v $<
|
||||
>202p112p122p"2&"*1+32p092pv
|
||||
v20+1g20p29+g29!+-1g21%7g20<># 0# v# < > >v
|
||||
>p12g1+12p32g4% | >1 >>22g\g12g1--|
|
||||
>32g"d"%| 0^ < # >112p22g:1+22p66+-|
|
||||
v%*4"d"g23<>#^_1^ |-+1*"(2"g23<p23+1g23p221<
|
||||
> ^>1^ >92g.@ ^ <
|
||||
@@ -0,0 +1,12 @@
|
||||
You are given the following information, but you may prefer to do some research for yourself.
|
||||
|
||||
- 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.
|
||||
|
||||
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
|
||||
@@ -0,0 +1,3 @@
|
||||
In the first two rows we remember the day-count of each month.
|
||||
First row is normal years, second row leap years.
|
||||
Then we just enumerate through all days and test if its a Sunday and the first of month.
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 20,
|
||||
'title' => 'Factorial digit sum',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_020_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_020_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_020_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=020',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-020.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => true,
|
||||
'steps' => 1546679,
|
||||
'time' => 265,
|
||||
'width' => 101,
|
||||
'height' => 6,
|
||||
'value' => 648,
|
||||
];
|
||||
@@ -0,0 +1,6 @@
|
||||
v00 ... 00
|
||||
v00 ... 01
|
||||
>"d">1-:!#v_:03p013p"~I"+23p>23g"d"%1+23g"d"/g"0"-03g*13g+:55+%68 v
|
||||
^ $# _^#!p32:-1g32p31/+55p/"d"g32+1%"d"g32+*<
|
||||
>"~I"+33p0>33g"d"%1+33g"d"/g"0"-+ 33g:1-33p v
|
||||
@._^#! <
|
||||
@@ -0,0 +1,6 @@
|
||||
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!
|
||||
@@ -0,0 +1,2 @@
|
||||
The approach is similar to problem 16 - the main task was implementing a long multiplication algorithm in Befunge.
|
||||
Then, after 100! is calculated we only need to sum the individual digits.
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 21,
|
||||
'title' => 'Amicable numbers',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_021_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_021_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_021_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=021',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-021.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => true,
|
||||
'steps' => 601124986,
|
||||
'time' => 102399,
|
||||
'width' => 400,
|
||||
'height' => 33,
|
||||
'value' => 31626,
|
||||
];
|
||||
@@ -0,0 +1,13 @@
|
||||
v
|
||||
# ... #
|
||||
. . . .
|
||||
. . .
|
||||
. . . .
|
||||
# ... #
|
||||
v ># v# <
|
||||
>"d"4*:10p55**00p00g>1-::20p0\2/>:20g\%#^_:30p+30g>1-:#^_$v
|
||||
|: p+1/g01g02%g01g02<
|
||||
v$$ p100<
|
||||
>00g1-20p090p>20g10g%20g10g/1+g40p40g10g%40g10g/1+g50p 20g50g-#v_20g40g`!#v_20g." - ",,,40g.55+,v
|
||||
|p02-1:g02 < < p09++g04g02g09<
|
||||
@.g09<
|
||||
@@ -0,0 +1,6 @@
|
||||
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 1, 2, 4, 71 and 142; so d(284) = 220.
|
||||
|
||||
Evaluate the sum of all the amicable numbers under 10000.
|
||||
@@ -0,0 +1,2 @@
|
||||
Most of the time is here spent in the NumberOfDivisors function. So we first cache every possible result of this function (from 0 to 10000).
|
||||
The rest is simple searching for numbers where a == D(D(a)) and a != D(a).
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 22,
|
||||
'title' => 'Names scores',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_022_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_022_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_022_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=022',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-022.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => true,
|
||||
'steps' => 4703607994,
|
||||
'time' => 961793,
|
||||
'width' => 109,
|
||||
'height' => 5164,
|
||||
'value' => 871198282,
|
||||
];
|
||||
@@ -0,0 +1,13 @@
|
||||
> v // Calc ordered index > v
|
||||
MARY >"??IE"*++:20p00p>010p0 >:00gg"@"-:0`#^_$0>10g74**+10pv
|
||||
PATRICIA > ^ ^ _v# -+66:+1<
|
||||
LINDA v _^#!p00:-1g00pg000g01$< >v // Bubblesort it
|
||||
BARBARA >20g30p> 040p> 040g1+g 040g2+g`|>40g:1+>60p70p66+:80p>:60g1+g\70g1+g80g60g1+v
|
||||
ELIZABETH |`\-1g03 p04:+1g04< $<|\p08:-1:g08p+1g07g08p <
|
||||
JENNIFER |-2p03-1:g03< // Sum the values ^<
|
||||
MARIA v <v+1p09+g09*g05-"@"<
|
||||
SUSAN >090p20g50p>1>:50gg:" " -|
|
||||
MARGARET |p05:-1g05 $$$<
|
||||
DOROTHY @.g09<
|
||||
...
|
||||
...
|
||||
@@ -0,0 +1,5 @@
|
||||
Using 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.
|
||||
|
||||
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.
|
||||
|
||||
What is the total of all the name scores in the file?
|
||||
@@ -0,0 +1,2 @@
|
||||
The main thing here was sorting the list. I used [bubble sort](http://en.wikipedia.org/wiki/Bubble_sort), which is not the fastest algorithm but was pretty easy to implement in befunge.
|
||||
The rest is just calculating the single scores.
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 23,
|
||||
'title' => 'Non-abundant sums',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_023_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_023_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_023_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=023',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-023.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => true,
|
||||
'steps' => 10667174483,
|
||||
'time' => 1967688,
|
||||
'width' => 400,
|
||||
'height' => 88,
|
||||
'value' => 4179871,
|
||||
];
|
||||
@@ -0,0 +1,18 @@
|
||||
v
|
||||
# ... #
|
||||
. . . .
|
||||
. . .
|
||||
. . . .
|
||||
# ... #
|
||||
|
||||
v ># v# <
|
||||
>"d"4*:10p355***00p00g>1-::20p0\2/>:20g\%#^_:30p+30g>1-:#^_$v
|
||||
|:p +1/g01g02%g01g02`g02<
|
||||
v $p100< vp+1/g01+g05g04%g01+g05g04+2%2g+1/g01+g05g04%g01+<
|
||||
$ >v >v >v >v v < g
|
||||
>00g40p>40g1-:40p|>40g10g%40g10g/1+g2%|>40g1+50p>50g1-:50p|>50g10g%50g10g/1+g2%|>40g50g+00g`| 0
|
||||
^ < ^ < $< >40g5^
|
||||
v < ^ <
|
||||
>080p00g20p>20g1-20p20g10g%20g10g/1+g2/#v_v
|
||||
|g02 <p08+g02g0 8<
|
||||
>80g.@ ^ <
|
||||
@@ -0,0 +1,7 @@
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.
|
||||
@@ -0,0 +1,2 @@
|
||||
The algorithm here is pretty ineffecient. First I brute force all the abundent numbers and then calculate every possible product of these numbers.
|
||||
I used a little trick to store 2 boolean values per grid cell: The lowest bit represents if the value is abundent and the second-lowest if it can be written as two abundent numbers
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 24,
|
||||
'title' => 'Lexicographic permutations',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_024_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_024_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_024_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=024',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-024.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 3499,
|
||||
'time' => 31,
|
||||
'width' => 61,
|
||||
'height' => 8,
|
||||
'value' => 2783915460,
|
||||
];
|
||||
@@ -0,0 +1,8 @@
|
||||
v0123456789
|
||||
>"ddd"**1v
|
||||
vp129p11-<
|
||||
>v>v v < v < > v >\1-\vv p14+1g14<
|
||||
>21g:1+|>|>21g0\>:1-:#^_$>*\:#^_$:| >31p 141p >31g41g*11g`!|
|
||||
$ >$1^ |-"x" g0:\<\1<g14 <
|
||||
@ > v> >1+\:| 1
|
||||
^p12-1g12p11-*-1g14g13g11.p0\"x"\-"0"g0:>#- #1 #$ #< ^
|
||||
@@ -0,0 +1,5 @@
|
||||
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:
|
||||
|
||||
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,0 +1,11 @@
|
||||
This is a really nice problem - and I kinda like the solution.
|
||||
|
||||
If we think about the ordered numbers we can see that the first few start with `0`, the next with `1` and so on ...
|
||||
We can also see that there are `8!` possible numbers that start with `0` (or any other digit).
|
||||
So if `1 * 8! <= (1000000 - 0)` the result starts with `0`. Otherwise if `2 * 8! <= (1000000 - 0)`, etc.
|
||||
Then after we got our first digit (`2`) we can similar calculate the second with `1 * 7! <= (1000000 - 2 * 8!)`, `2 * 7! <= (1000000 - 2 * 8!)` ...
|
||||
The last thing we have to be aware of is that this method yields us to the "n-th digit of the remaining digits". So if we got the 6th digit for our second calculation its in fact `7`, because we already used `2`.
|
||||
|
||||
The program now does exactly these calculations, you can see in the top row the already used digits (they are crossed out).
|
||||
|
||||
All in all this program pretty fast - they could really do another version of this problem with bigger numbers.
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return
|
||||
[
|
||||
'number' => 25,
|
||||
'title' => '1000-digit Fibonacci number',
|
||||
'description' => function(){ return file_get_contents(__DIR__ . '/euler_025_description.md'); },
|
||||
'code' => function(){ return file_get_contents(__DIR__ . '/euler_025_code.txt'); },
|
||||
'explanation' => function(){ return file_get_contents(__DIR__ . '/euler_025_explanation.md'); },
|
||||
'url_euler' => 'http://projecteuler.net/problem=025',
|
||||
'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-025.b93',
|
||||
'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge',
|
||||
'abbreviated' => false,
|
||||
'steps' => 745055403,
|
||||
'time' => 116938,
|
||||
'width' => 123,
|
||||
'height' => 28,
|
||||
'value' => 4782,
|
||||
];
|
||||
@@ -0,0 +1,28 @@
|
||||
v
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000001 00000000000000000000000000000000000000000000000001
|
||||
|
||||
>5567***00p"2"10p 230p>v
|
||||
> > 00g40p050p>40g1-40p40g10g%"4"+40g10g/1+g"0"-:40g10g%1+40g10g/1+g"0"-50g++ v
|
||||
v< v< |g04p+1/g01g04+1%g01g04+"0"p+1/g01g04+"4"%g01g04+"0"%+55p05/+55:<
|
||||
^<|-*+55"d"-g07g00<|-"0"g+1/g01g07+"4"%g01g07<p070p03+1g03<
|
||||
>30g.@ >70g1+70p ^
|
||||
@@ -0,0 +1,22 @@
|
||||
The Fibonacci sequence is defined by the recurrence relation:
|
||||
|
||||
Fn = Fn?1 + Fn?2, where F1 = 1 and F2 = 1.
|
||||
|
||||
Hence the first 12 terms will be:
|
||||
|
||||
F1 = 1
|
||||
F2 = 1
|
||||
F3 = 2
|
||||
F4 = 3
|
||||
F5 = 5
|
||||
F6 = 8
|
||||
F7 = 13
|
||||
F8 = 21
|
||||
F9 = 34
|
||||
F10 = 55
|
||||
F11 = 89
|
||||
F12 = 144
|
||||
|
||||
The 12th term, F12, is the first term to contain three digits.
|
||||
|
||||
What is the first term in the Fibonacci sequence to contain 1000 digits?
|
||||
@@ -0,0 +1,2 @@
|
||||
And for like the 5th time i implement an long addition algorithm. On the right side is the current number and on the left side the last number.
|
||||
The only interesting thing here is probably that I calculate the next number and move the current to the left in a single cycle.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user