Skip to content

Instantly share code, notes, and snippets.

@erikaderstedt
Created December 5, 2019 17:37
Show Gist options
  • Save erikaderstedt/959c327fcac0b57cd8dbf3383ff9f45e to your computer and use it in GitHub Desktop.
Save erikaderstedt/959c327fcac0b57cd8dbf3383ff9f45e to your computer and use it in GitHub Desktop.
// Input: 1 - pt 1, 2 - pt 2
3,PROGRAM_MODE
1001,PROGRAM_MODE,-1,PROGRAM_MODE
1101,DATA_START,-1,DATA_INDEX
1101,0,0,TOTAL_MASS
// Get next mass value
NEXT_MASS:
1001,DATA_INDEX,1,DATA_INDEX
// Check if data is -1
1008,
DATA_INDEX:
0,-1,SLASK1
1005,SLASK1,END_PROGRAM
1001,DATA_INDEX,0,ARGUMENT1
1001,DATA_INDEX,0,ARGUMENT2
1105,1,SINGLE_MASS_START,
BACK_FROM_MASS:
0001,TOTAL_MASS,SLASK2,TOTAL_MASS
1105,1,NEXT_MASS
// Calculates a single mass value.
// Input: ARGUMENT1 & 2.
SINGLE_MASS_START:
1101,0,0,SLASK2
SINGLE_MASS:
1101,0,0,SUM
1101,0,0,COUNTER
LOOP1:
1001,COUNTER,1,COUNTER
1001,SUM,3,SUM
0007,SUM,
ARGUMENT1:
0,SLASK1
1005,SLASK1,LOOP1
// If we are above ARGUMENT, we need to decrement COUNTER
0008,
ARGUMENT2:
0,SUM,SLASK1
1005,SLASK1,FINISHED_LOOP
1001,COUNTER,-1,COUNTER
FINISHED_LOOP:
1001,COUNTER,-2,COUNTER
// Are we below zero:
1007,COUNTER,0,SLASK1
1006,SLASK1,WAS_NOT_BELOW_ZERO
1101,0,0,COUNTER
WAS_NOT_BELOW_ZERO:
0001,COUNTER,SLASK2,SLASK2
// Counter is now >= 0.
1006,COUNTER,WAS_ZERO
// Prepare for recursion (only when PROGRAM_MODE != 0)
1001,COUNTER,0,SLASK3
1101,SLASK3,0,ARGUMENT1
1101,SLASK3,0,ARGUMENT2
1005,PROGRAM_MODE,SINGLE_MASS
WAS_ZERO:
// Done. Result is in SLASK2.
1105,1,BACK_FROM_MASS
END_PROGRAM:
4,TOTAL_MASS
99
TOTAL_MASS:
0
PROGRAM_MODE:
0
FUEL_REQ:
0
RETURN_INDEX:
0
SUM:
0
COUNTER:
0
SLASK1:
0
SLASK2:
0,
SLASK3:
0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
DATA_START:
70219
93253
79077
75104
142278
65798
148578
136159
60033
51629
57239
77808
142016
92225
136933
95933
109170
83012
135771
59064
101361
86997
79026
50825
79671
143898
65548
84651
53043
84997
87226
65816
81088
143976
109917
103744
131433
81899
80901
146112
65084
84439
73939
102337
99794
107113
62081
98484
55246
131950
129633
98380
118568
100632
127493
90804
120735
124932
115165
73091
77960
67435
63132
114453
104379
82371
51259
104055
127984
108215
53174
139459
58530
86994
149064
90062
139593
128406
136288
140669
125298
144444
80296
135065
121641
108842
59336
64720
121706
78017
142674
89214
100171
80836
110919
102218
54834
104544
81501
128610
-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment