-
Notifications
You must be signed in to change notification settings - Fork 1
/
Euler_Problem-043.b93
73 lines (54 loc) · 2.77 KB
/
Euler_Problem-043.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
vXXXXXXXXX
vXXXXXXXXX
>902p012p9>:0\1pv
|\-1: <
>12g55+, #$ " =",, . @ vp20<
|`9g20 < < <
>$0v > v >002g0g"0"-1p v
>02g0g"0"-:9`| >:22p55+-| >22g1g #v_ 02g0g"9"`!#^_ ## v
>1+^ >0|-9p22+1:g22<vp20-1g20p0g20+"0"g22p1g221<
v!`g200 < p20+1g20< ##
> 02g0g"9"`!#v_ ^ +
>002g0g"0"-1p"X"02g0p^ 1
>#v_002p 032p0>:0g"0"-32g55v>12p> ^g
>02g9-!02g8-!02g7-!++v |-9\+1:p23+*+<+ 2
v < >$32g:.55+,12g^ 0
>02g6-70g"0"-55+*80g"0"-+55+*90g"0"-+89+%+!v>++#^_02g0g"9"`!#v_^
v!+%+58+-"0"g08*+55+-"0"g07*+55-"0"g06-5g20<+v"X"p1-"0"g0g200<#
>02g4-50g"0"-55+*60g"0"-+55+*70g"0"-+47+%+!v+>02g0p02g1+02p ^
v!+%+70+-"0"g06*+55+-"0"g05*+55-"0"g04-3g20<+
>02g2-30g"0"-55+*40g"0"-+55+*50g"0"-+05+%+!v+
v!+%+30+-"0"g04*+55+-"0"g03*+55-"0"g02-1g20<+
>02g0-10g"0"-55+*20g"0"-+55+*30g"0"-+02+%+!>^
[?0] perm : nums
[?1] digits : bool
[02] position
[12] sum
[22] digitsearch / i
[32] tmp sum
// dec
02g0g"9"`!#v_ >02g1+02p
>002g0g"0"-1p "X"02g0p^
// switch or (do we need to dec)
>02g9-!02g8-!02g7-!++v
v <
>02g6-70g"0"-55+*80g"0"-+55+*90g"0"-+89+%+!v>++
v!+%+58+-"0"g08*+55+-"0"g07*+55-"0"g06-5g20<+
>02g4-50g"0"-55+*60g"0"-+55+*70g"0"-+47+%+!v+
v!+%+70+-"0"g06*+55+-"0"g05*+55-"0"g04-3g20<+
>02g2-30g"0"-55+*40g"0"-+55+*50g"0"-+05+%+!v+
v!+%+30+-"0"g04*+55+-"0"g03*+55-"0"g02-1g20<+
>02g0-10g"0"-55+*20g"0"-+55+*30g"0"-+02+%+!>^
// get current number
032p0>:0g"0"-32g55v>
|-\+1:p23+*+ <
> ^
---------------------------------------
While trying to optimize this problem I found that you don't even need a program to solve this.
You can easily get the result by calculating it on paper.
I have documented my calculations in my [Github repo](https://github.com/Mikescher/Project-Euler_Befunge).
But I wanted an program to do this (where you could for example change the constraints), so I wrote this.
The code here was a tight fit into the Befunge-93 80x25 grid, not because of some big data structures but because of a lot of code.
Here we generate all combinations from the last digit to the first, we significantly limit the amount of possible combinations by checking the constraints for every number.
For example we are at `???????410`, we then don't need to evaluate the first 7 digits because constraint 7 is violated (divisibility of d_789 by 17).
This way instead of evaluating `3,628,800` possibilities we only have to look at `1702`.