-
Notifications
You must be signed in to change notification settings - Fork 1
/
Euler_Problem-028.b93
37 lines (24 loc) · 809 Bytes
/
Euler_Problem-028.b93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
0"d"55+*1+::1-01p*>:01g-:01g-:01g-:01g-:1-#v_>\# :#+_+.@
X ^p10-2g10 <
// SUM
>+\:#<_$ @
"d"55+*1+ => 1001
---------------------------------------
Let's look ate the diagonal numbers of our 5x5 grid:
|n |info |
|--|---------------|
|25|starting number|
|21| = 25 - **4** |
|17| = 21 - **4** |
|13| = 17 - **4** |
|9 | = 13 - **4** |
|7 | = 9 - **2** |
|5 | = 7 - **2** |
|3 | = 5 - **2** |
|1 | = 3 - **2** |
You can probably see the pattern here. The rest of the algorithm is simply loop from 1001^2 to 1, subtracting the right amount each round and in the end summing up all numbers.
I have this little code to calculate the sum of stack values until a zero is encountered:
```befunge
>\# :#+_+.
```
Perhaps it's useful for someone else.