-
Notifications
You must be signed in to change notification settings - Fork 1
/
Euler_Problem-032.b93
59 lines (42 loc) · 3.55 KB
/
Euler_Problem-032.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
v
$$$$$$$$$
###############################
vp2\0:<
>" "> 1-:|
v < *"ce"<
v p01 1$< vp1\0:< >v >v >$v >v >v >$v >v >v >$v v\g1:< >10g:1+10p2pv
>9"ec"*>80p:80g55+> 1-:| >:55+%:|>:1g!|>1\1p55+/:!| >\:>:55+%:|>:1g!|>1\1p55+/:!| >*:>:55+%:|>:1g!|>1\1p55+/:!| >55+> 1-:|>| >80g1-:5558***-#^_$1-:1-|
>$:^ $# $# < ^ $# $# < ^ $# $# <v++++++++$< >$ ^v $<
v < > > > > $> >$ $00>9-! ^ 1
| <0 <*9*3+1*94<
vp1\0:< >v >v >$v >v >v >$v >v >v >$v v\g1:< >10g:1+10p2pv
>"c"49*1+3*9*>80p:80g55+> 1-:| >:55+%:|>:1g!|>1\1p55+/:!| >\:>:55+%:|>:1g!|>1\1p55+/:!| >*:>:55+%:|>:1g!|>1\1p55+/:!| >55+> 1-:|>| >80g1-:"d"-#^_$1-:55+-|
>$:^ $# $# < ^ $# $# < ^ $# $# <v++++++++$< >$ ^ $
> >#v ># ># #< $> >$ $00>9-! ^
v < v\< ^ <
v -1< v< |:g2:<
v ># $# ># v# -1< ^$<
>" ">80p80g1->70p80g2g:!|>70g2g -| > 70g:1-#^_$80g:2-#^_$0>" "> 1-:| >+#<\:#<_+.@
>^ >070g2p^ >$^
[10] position resultarr
[70] temp
[80] temp
// Clear digit row
vp1\0:<
55+> 1-:#^_$
// Is Pandigital (A B -> stack)
vp1\0:< >v >v >$v >v >v >$v >v >v >$v v\g1:<
55+> 1-:| >:55+%:|>:1g!|>1\1p55+/:!| >\:>:55+%:|>:1g!|>1\1p55+/:!| >*>:55+%:|>:1g!|>1\1p55+/:!| >55+> 1-:|
$>$:^ $# $# < ^ $# $# < ^ $# $# <v++++++++$<
> > > > $$> > $0>9-! @
// Is Pandigital (stack -> {} ) and insert in resultarr
vp1\0:< >v >v >$v >v >v >$v >v >v >$v v\g1:< >10g:1+10p2pv
55+> 1-:| >:55+%:|>:1g!|>1\1p55+/:!| >\:>:55+%:|>:1g!|>1\1p55+/:!| >*:>:55+%:|>:1g!|>1\1p55+/:!| >55+> 1-:|>| >
$>$:^ $# $# < ^ $# $# < ^ $# $# <v++++++++$< >$ ^
> > > > $> >$ $0>9-! ^
---------------------------------------
The main focus here was optimizing the pandigital testing. The rest is just looping over every possible number.
We can optimize the outer loop a little bit if we look at the possible multiplicands.
There are only 2 possibilities if we need 9 digits in our calculation:
- 1-digit number * 4-digit number = 4-digit number
- 2-digit number * 3-digit number = 4-digit number