Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [q] sX
- z 2/ d se sf # get deck sizes (assuming half of input each), set end ptrs
- 0 sp # set the start ptr (next card to be played)
- # initialize arrays with input (S macro parameter to set array)
- [
- li 1- dsi lSx
- li 0=X
- lIx
- ] sI
- # S macros to parameterize the above I macro
- [:a]sS le si lIx
- [:b]sS lf si lIx
- # Macro to calculate score (R macro parameter to read array)
- [
- le 1- d lRx li * r se + # top += read_array( --end_ptr ) * i
- le lp =X # check if (end == start)
- li 1+ si # inc i
- lVx # loop
- ] sV
- # R macros to parameterize the above V macro
- [ [;a]sR 1 si 0 lVx q ] sP
- [ [;b]sR lf se 1 si 0 lVx q ] sQ # parameterize the end_pointer by setting e = f
- # Handle case where player 1 wins hand
- [
- lp d;a le:a
- d;b le 1+:a 1+ sp
- le 2+ se
- s.0 # replace the -1 on the stack with a 0
- ] sA
- # Handle case where player 2 wins hand
- [
- lp d;b lf:b
- d;a lf 1+:b 1+ sp
- lf 2+ sf
- ] sB
- [
- _1 # push -1 to signal when A macro doesn't run
- lp ddd le =Q lf =P # check end of game, leaving two copies of ptr
- ;b r ;a >A # compare a(p) > b(p)
- _1 =B # if -1 left on stack, do else B macro
- lLx
- ] sL
- lLx
- [Part 1: ]np
Add Comment
Please, Sign In to add comment