-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEuler_Problem-066 (annotated).b93
80 lines (65 loc) · 4.7 KB
/
Euler_Problem-066 (annotated).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
74
75
76
77
78
79
80
vYYY ################ // <-- N{-2} [0]
XBXX ################ // <-- N{-1} [1]
ZZZ ################ // <-- N{0} [2]
N
OOO ################ // <-- D{-2} [4]
################ // <-- D{-1} [5]
################ // <-- D{0} [6]
################ // <-- temp2 (N0 * N0) [7]
################ // <-- max [8]
################ // <-- temp (D0 * D0 * D + 1) [9]
v_v#!:-1p< // zero out max
> "@ ":*:** 21p 3 31p 013p 88 +>:8+0\8^
v $<
v _v# -*"}"8 p13:+1g13 < // Inc D
vp01g03_v#-g01:_v#- < v_v#!:-1p0\0+8:p1\0 < >11g.@
>31g 010p:20p>:30p:20 g\/+2/: 30g^ >88 +>:8+0\5p:8+0\4p:8+^
> >$30g:41p :*31g-| >$ 164*1p 164*4p 012p 122p v // Init D & N
^p13+1g13 <
v < <
> 41g12g+22g/32p 35*>:::9+0g\9+1g32g*+13g+ :21g/13p 21g%\9+2pv // Calculate N{0}
|\-1: <
>$35*>:::9+4g\9+5g32g*+13g+ :21g/13p 21g%\9+6pv // Calculate D{0}
|\-1: <
$
v $<
# |!\-1:g42$<
> 114p35 *>:9+0\ v|!-9g43-1p9g43%g12p41/g12:+g9g43< // Calculate temp1 (D0*D0*D+1)
>*>2 4p35* >::24g+6-34p9+6g24g9+6g31g**14g+^
|\-1:p9<
^53$<
v $<
# |!\-1:g42$<
>014p35 *>:9+0\ v|!-9g43-1p7g43%g12p41/g12:+g7g< // Calculate temp2 (N0*N0)
>*>2 4p35* >::24g+6-34p9+2g24g9+2g*14g+34^
|\-1:p7<
^53$<
$ // Solution not valid ... Calculate next fraction items
// test temp1 == temp2 |!\-1: <
>$ 32g22g*12g-12p 31g12g: *-22g/22p35*>::9+1g\9+0p ::9+2g\9+1p ::9+5g\9+4p ::9+6g\9+5p^
>35*>:: 9+7g \ 9+9g - |
|\-1: < // copy D --> max
// test if N_0 > max
>$ 31g11p 35*>:: 9+2g \ 9+8p v
>$ 0>:: 9+2g\ 9+ 8g - :!#v_0`| |\-1: < // <-- Solution found
| -8-9:+1$< > >$ ^
>$ ^
// solution <= max
[1,0] (isqrt) pxk
[2,0] (isqrt) n
[3,0] (isqrt) xk
[1,1] (main) max_index
[2,1] (main) base (const) = 67108864
[3,1] (main) D
[4,1] (main) isqrt(D)
[1,2] (cfrac) cf_add
[2,2] (cfrac) cf_div
[3,2] (cfrac) cf_frac_m
[1,3] (calc) carry
[1,4] (mul) carry
[2,4] (mul) digit pos
[3,4] (mul) target pos
2147483648 --> "@":::::+****
1073741824 --> "@"::::****
67108864 --> "@ ":*:**
1000 --> "}"8*