Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* Advent of code 2017, day 18, puzzle 1 in ANSI REXX */ | ||
numeric digits 20 | ||
r. = 0 | ||
r.1.p = 1 | ||
q.0.0 = 0 | ||
q.1.0 = 0 | ||
file = 'day18test.txt' | ||
file = 'day18test2.txt' | ||
file = 'day18.txt' | ||
do pc = 1 while lines(file) | ||
p.pc = linein(file) | ||
end | ||
p.max = pc | ||
say p.max | ||
say pc | ||
pc.0 = 1 ; pc.1 = 1 | ||
do forever | ||
lock = 0 | ||
do # = 0 to 1 | ||
pc = pc.# | ||
/* | ||
say #'.'pc':' p.pc | ||
*/ | ||
parse var p.pc op1 op2 op3 . | ||
interpret 'call' op1 op2 "'"op3"'" | ||
pc = pc + 1 | ||
pc.# = pc | ||
end | ||
if pc >= p.max then leave | ||
if lock = 2 then leave | ||
end | ||
say r.a | ||
exit | ||
|
||
add: | ||
arg dest operand | ||
r.#.dest = r.#.dest + getval(operand) | ||
return | ||
|
||
jgz: | ||
arg reg offset | ||
if r.#.reg = 0 then return | ||
offset = getval(offset) | ||
pc = pc + offset - 1 | ||
return | ||
|
||
mod: | ||
arg dest operand | ||
r.#.dest = getval(dest) // getval(operand) | ||
return | ||
|
||
mul: | ||
arg dest operand | ||
r.#.dest = r.#.dest * getval(operand) | ||
return | ||
|
||
rcv: | ||
arg dest . | ||
last = q.#.0 | ||
if last > 0 then do | ||
r.#.dest = q.#.last | ||
q.#.0 = last - 1 | ||
return | ||
end | ||
else do | ||
lock = lock + 1 | ||
pc = pc - 1 | ||
return | ||
end | ||
|
||
set: | ||
arg dest operand . | ||
r.#.dest = getval(operand) | ||
return | ||
|
||
snd: | ||
arg val . | ||
other = abs(# - 1) | ||
last = q.other.0 | ||
last = last + 1 | ||
q.other.last = getval(val) | ||
q.other.0 = last | ||
return | ||
|
||
getval: | ||
arg val . | ||
if datatype(val) == num then return val | ||
return r.#.val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
snd 1 | ||
snd 2 | ||
snd p | ||
rcv a | ||
rcv b | ||
rcv c | ||
rcv d |