/
Euler1.b
76 lines (60 loc) · 2.93 KB
/
Euler1.b
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
// The first chunk is just something to print the heading text
++++++++++[>+++++++++++>++++++++++>+++>++++++++++++>+++++>+>++++++++>+++
+>+++++++>++++++<<<<<<<<<<-]>>>>>>>.<<<<<<++++.---.-----.>+.--.>>----.<+
+.>>>>>>-.<<<<<+.<<<++.>++.<++++++.>>.>>----.<<<<----.>.>>-.<.>>>>.<<<<<
<++++.---.>---.<---.>+++.<+.>>.>>+++.>..>---.<<<+.<<<-.>>>-.<<<---.+++++
++.----.>.>>-.<.<<+++.>+.>.>>++.<<.<-----.<-.>+++.>.>>++.>.>>>++++.<<<<<
<<++.>.>++++.<<-.>.<<--.---.>>>----.+.<.<----.<+++..>>.>.<<+++++++.---.>
.<<++.>----.>>.+.<<<++++.>.<------.>>.<<++.>>>.<<<-.>+.+++.<+++++.>>>--.
<.<---.+++.<------.+++.>>>++++.<.>>----.-.<<.>---.<<+++.-------.>>.<.<.<
+++.>++++.>.<<-----.>>>+.<<<-.>>>-.<<<---.+++++++.----.>.>>-.<.<<+++.>+.
>.>>+++.<<.<<.+++.>>.>>++.>>>++++.<<.<<++++.<<-.>.<++.--.>>---.<.>>--.>>
>.<<<<<.>>++.>>>.<<<<<.>>+.<<.<----.<----.>+++.>.>>>>>>>---.<<<<<-------
-.<<.>>>>+++++++.<<<<<++++.---.>.>-.++.<<<-.>>.<<++.>+.>.>-.<<++.---.>>-
.<<.>.<<--.>>>++.<<<-.>>>-.<<<---.+++++++.----.>.>>-.<.<<---.>>>.<.>>+++
+.+.-----.>..>>>---.<<<<<<<<.+++++.>-.>.>+.<<++++.---.>.>-.++.<<<-.>>.<<
++.>+.>.<-----.<---..>>.>-.<<+++++++.---.>.<<+.>>>+.<<<-.>>>-.<<<---.+++
++++.----.>.>>-.<.<<+++.>+.>.>>+++++.<<.<<.+++.>>.>>++.<<.<----.+++.<---
---.+++.>>>++++.<.>>----.-...--.>.<...>..>>>>[-]<[-]<[-]<[-]<[-]<[-]<[-]
<[-]<[-]<[-]<
Project Euler Problem 1 by James Stanley
Generate 1000
++++++++++[>++++++++++[>++++++++++<-]<-]>>
Take it down to 995
-----
Memory now: === 0 0 (995) result=0 ===
repeatedly add the number at 995 to our result and then take 5 off 995
[[->+>+<<] >>[-<<+>>]<< -----]
Move back to address 0
<<
Memory now: === (0) 0 0 result=99500 ===
Generate 1000
++++++++++[>++++++++++[>++++++++++<-]<-]>>
Take it down to 999
-
Memory now: === 0 0 (999) result=99500 ===
for 3's we do the same as the loop above for 5's but remember to ignore the
ones that were counted for 5 and basically unroll the loop and only count it on
the ones that aren't divisible by 15
also we quit looping when the outer loop should end
[
<[-]<[-]>> [-<+<+>>] <<[->>+<<]>> < [[->>+>+<<<] >>>[-<<<+>>>]<< --- < [-]] >
<[-]<[-]>> [-<+<+>>] <<[->>+<<]>> < [[->>+>+<<<] >>>[-<<<+>>>]<< --- < [-]] >
<[-]<[-]>> [-<+<+>>] <<[->>+<<]>> < [[->>+>+<<<] >>>[-<<<+>>>]<< --- < [-]] >
<[-]<[-]>> [-<+<+>>] <<[->>+<<]>> < [> --- < [-]] >
<[-]<[-]>> [-<+<+>>] <<[->>+<<]>> < [[->>+>+<<<] >>>[-<<<+>>>]<< --- < [-]] >
]
Memory now: === 0 0 (0) result=233168 0 ===
[
Print overall result
>.
]
////////////////////////////////////////////////////////////////////////////////
> Move to result cell and print as a number
>[-]>[-]>[-]>[-]>[-]>[-]+>[-]+>[-]+>[-]+<<<<<<<<<[->>+>+<<<]>>>[-<<<+>>>
]<[>[-]>[-]<<[>+>+<<-]>>[<<+>>-]+++++++++<[>>>[-]+<<[>+>[-]<<-]>[<+>-]>[
<<++++++++++>>-]<<-<-]+++++++++>[<->-]<[>+<-]<[>+<-]<[>+<-]>>>[<<<+>>>-]
>>>[-]<<<+++++++++<[>>>[-]+<<[>+>[-]<<-]>[<+>-]>[<<++++++++++>>>+<-]<<-<
-]>>>>[<<<<+>>>>-]<<<[-]<<+>]<[>[-]<[>+<-]+++++++[<+++++++>-]<-.[-]>>[<<
+>>-]<<-]<
<++++++++++.