-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCCC18J1.bf
156 lines (133 loc) · 5.51 KB
/
CCC18J1.bf
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
Now at cell 0
>, Read first digit into cell 1
>,[-] Move to cell 2 and consume newline
, Read second digit into cell 2
>,[-] Move to cell 3 and consume newline
, Read third digit into cell 3
>,[-] Move to cell 4 and consume newline
, Read fourth digit into cell 4
>+ Set cell 5 to 1
<<<< Go to cell 1
MMMMMMMMMMMMM CASE 1 MMMMMMMMMMMMM
First we check if cell 1 is equal to 56
Because if it is then the first digit is an 8
Now at cell 1
<+++++++[>--------<-]> Subtract 56 from cell 1
The code within these brackets only runs if the first digit was not 8
[
>>>>- Set cell 5 to 0 to end loop
]
<[<]>>>>> Go to cell 5
Now at cell 5
The code within these brackets only runs if the first digit was 8
[
>+ Increment cell 6
<- Set cell 5 to 0 to end loop
]
+ Set cell 5 to 1
<<<< Go to cell 1
And then check if cell 1 is equal to 57
Because that means the first digit is a 9
Now at cell 1
- Subtract 1 from cell 1
The code within these brackets only runs if the first digit was not 9
[
>>>>- Set cell 5 to 0 to end loop
]
<[<]>>>>> Go to cell 5
Now at cell 5
The code within these brackets only runs if the first digit was 9
[
>+ Increment cell 6
<- Set cell 5 to 0 to end loop
]
+ Set cell 5 to 1
<<<<[+] Set cell 1 to 0
>>> Go to cell 4
MMMMMMMMMMMMM CASE 2 MMMMMMMMMMMMM
Now we check if cell 4 is equal to 56
Because that means the fourth digit is an 8
Now at cell 4
>>>+++++++[<<<-------->>>-]<<< Subtract 56 from cell 4
The code within these brackets only runs if the fourth digit was not 8
[
>- Set cell 5 to 0 to end loop
]
<[<]>>>> Go to cell 5
Now at cell 5
The code within these brackets only runs if the first digit was 8
[
>+ Increment cell 6
<- Set cell 5 to 0 to end loop
]
+ Set cell 5 to 1
< Go to cell 4
And then check if cell 4 is equal to 57
Because that means the fourth digit is a 9
Now at cell 4
- Subtract 1 from cell 4
The code within these brackets only runs if the fourth digit was not 9
[
>- Set cell 5 to 0 to end loop
]
<[<]>>>> Go to cell 5
Now at cell 5
The code within these brackets only runs if the first digit was 9
[
>+ Increment cell 6
<- Set cell 5 to 0 to end loop
]
+ Set cell 5 to 1
<[+] Set cell 4 to 0
<< Go to cell 2
MMMMMMMMMMMMM CASE 3 MMMMMMMMMMMMM
Finally we check if the second and the third digits are the same
We do this by checking cells 2 and 3 for equality
Now at cell 2
[->-<] Subtract from cells 2 and 3 until cell 2 is 0
> Go to cell 3
The code within these brackets only runs if the digits were unequal
That is if cell 3 is nonzero after the subtraction
[
>>- Set cell 5 to 0
<<[-] Set cell 3 to 0 to end loop
]
>> Go to cell 5
Now at cell 5
The code within these brackets only runs if the digits were equal
[
>+ Increment cell 6
<- Set cell 5 to 0 to end loop
]
+ Set cell 5 to 1
> Go to cell 6
MMMMMMMMMMMMM FINAL STEP MMMMMMMMMMMMM
Now we just have to check if all 3 cases were met
This is done by checking if the value of cell 6 is equal to 3
Now at cell 6
--- Subtract 3 from cell 6
The code within these brackets only runs if not all 3 cases were met
[
<- Set cell 5 to 0
>> Go to cell 7
Print "answer" (Ends at cell 9)
--[----->+<]>-----.+++++++++++++.+++++.++++.[->+++<]>.+++++++++++++.
<<<[+] Set cell 6 to 0 to end loop
]
< Go to cell 5
Now at cell 5
The code within these brackets only runs if all 3 cases were met
[
> Go to cell 6
Print "ignore" (Ends at cell 7)
+[----->+++<]>++.--.+++++++.+.+++.-------------.
<<- Set cell 5 to 0 to end loop
]
MINIFIED CODE:
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
>,>,[-],>,[-],>,[-],>+<<<<<+++++++[>--------<-]>[>>>>-]<[<]>>>>>[>+<-]+<<<<-[>>>
>-]<[<]>>>>>[>+<-]+<<<<[+]>>>>>>+++++++[<<<-------->>>-]<<<[>-]<[<]>>>>[>+<-]+<-
[>-]<[<]>>>>[>+<-]+<[+]<<[->-<]>[>>-<<[-]]>>[>+<-]+>---[<->>--[----->+<]>-----.+
++++++++++++.+++++.++++.[->+++<]>.+++++++++++++.<<<[+]]<[>+[----->+++<]>++.--.++
+++++.+.+++.-------------.<<-]
]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]