Skip to content

Commit

Permalink
18:2 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
idrougge committed Dec 19, 2017
1 parent 70568e9 commit 69f27e4
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
88 changes: 88 additions & 0 deletions idrougge-rexx/day18_2.rexx
@@ -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
7 changes: 7 additions & 0 deletions idrougge-rexx/day18test2.txt
@@ -0,0 +1,7 @@
snd 1
snd 2
snd p
rcv a
rcv b
rcv c
rcv d

0 comments on commit 69f27e4

Please sign in to comment.