This repository has been archived by the owner on Jul 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Euler001.fractran
134 lines (118 loc) · 3.31 KB
/
Euler001.fractran
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Project Euler 001 in FRACTRAN
## [The Problem](https://projecteuler.net/problem=1)
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.
[below 20: 3, 5, 6, 9, 10, 12, 15, 18] 15 is in both
Find the sum of all the multiples of 3 or 5 below 1000.
## The Program
INPUT (n): 13^State Alpha One
OUTPUT: 7^sum
r2: total
r3: three
r5: five
r7: sum
r11: temp
r13,r17: State Alpha One and Two
r19,r23,r29: State Beta Three, Five, and ThreeAndFive
r31,r37: State Gamma One and Two
r41,r43: State Delta One and Two
r47: end
### Pseudocode
while true {
if (total >= 1000 && State Alpha One >= 1) {
decrement total by 1000
decrement alphaA
increment end
// State Alpha
} else if (five >= 1 and three >= 1 and State Alpha One >= 1) {
decrement three, five, and State Alpha One
increment total and State Alpha Two
} else if (State Alpha Two >= 1) {
decrement State Alpha Two
increment State Alpha One
} else if (three >= 1 && State Alpha One >= 1) {
decrement three and State Alpha One
increment State Beta Three
} else if (five >= 1 && State Alpha One >= 1) {
decrement five and State Alpha One
increment State Beta Five
} else if (State Alpha One >= 1) {
decrement State Alpha One
State Beta ThreeAndFive
// State Beta Three
} else if (State Beta Three >= 1) {
decrement State Beta Three
increment five by 5
increment three and State Gamma One
// State Beta Five
} else if (State Beta Five >= 1) {
decrement State Beta Five
increment three by 3
increment five and State Gamma One
// State Beta ThreeAndFive
} else if (State Beta ThreeAndFive >= 1) {
decrement State Beta ThreeAndFive
increment three by 3
increment five by 5
increment State Gamma One
// State Gamma
} else if (total >= 1 && State Gamma One >= 1) {
decrement total and State Gamma One
increment sum, temp, and State Gamma Two
} else if (State Gamma Two >= 1) {
decrement State Gamma Two
increment State Gamma One
} else if (State Gamma One >= 1) {
decrement State Gamma One
increment State Delta One
// State Delta
} else if (temp >= 1 && State Delta One >= 1) {
decrement temp and State Delta One
increment total and State Delta Two++
} else if (State Delta Two >= 1) {
decrement State Delta Two
increment State Delta One
} else if (State Delta One >= 1) {
decrement State Delta One
increment State Alpha One
} else {
break
}
}
## FRACTRAN Pseudocode
(
47 / 2^1000 * 13,
17 / 3 * 5 * 13,
13 / 17,
19 / 3 * 13,
23 / 5 * 13,
29 / 13,
3 * 5^5 * 31 / 19,
3^3 * 5 * 31 / 23,
3^3 * 5^5 * 31 / 29,
7 * 11 * 37 / 2 * 31,
31 / 37,
41 / 31,
2 * 43 / 11 * 41,
41 / 43,
13 / 41
)
// Expanded
(
47 / 2^1000 * 13,
17 / 195,
13 / 17,
19 / 39,
23 / 65,
29 / 13,
290,625 / 19,
4185 / 23,
2,615,625 / 29,
2849 / 62,
31 / 37,
41 / 31,
86 / 451,
41 / 43,
13 / 41
)
## Possible Improvements