Skip to content

Commit

Permalink
Dag 18 i REXX
Browse files Browse the repository at this point in the history
  • Loading branch information
idrougge committed Dec 21, 2017
1 parent 69f27e4 commit 2e98693
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 78 deletions.
41 changes: 0 additions & 41 deletions idrougge-rexx/day18.txt

This file was deleted.

41 changes: 21 additions & 20 deletions idrougge-rexx/day18_2.rexx
@@ -1,35 +1,31 @@
/* Advent of code 2017, day 18, puzzle 1 in ANSI REXX */
/* Advent of code 2017, day 18, puzzle 2 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
cycles = 0
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"'"
parse upper 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
cycles = cycles + 1
end
say r.a
say cycles
say r.1.sent
exit

add:
Expand All @@ -38,8 +34,9 @@ r.#.dest = r.#.dest + getval(operand)
return

jgz:
arg reg offset
if r.#.reg = 0 then return
arg addr offset
addr = getval(addr)
if addr <= 0 then return
offset = getval(offset)
pc = pc + offset - 1
return
Expand All @@ -59,14 +56,17 @@ arg dest .
last = q.#.0
if last > 0 then do
r.#.dest = q.#.last
r.#.dest = q.#.1
do i = 1 to last
j = i + 1
q.#.i = q.#.j
end
q.#.0 = last - 1
return
end
else do
lock = lock + 1
pc = pc - 1
return
end
lock = lock + 1
pc = pc - 1
return

set:
arg dest operand .
Expand All @@ -75,14 +75,15 @@ return

snd:
arg val .
other = abs(# - 1)
other = 1 - #
last = q.other.0
last = last + 1
q.other.last = getval(val)
q.other.0 = last
r.#.sent = r.#.sent + 1
return

getval:
arg val .
if datatype(val) == num then return val
return r.#.val
return r.#.val
10 changes: 0 additions & 10 deletions idrougge-rexx/day18test.txt

This file was deleted.

7 changes: 0 additions & 7 deletions idrougge-rexx/day18test2.txt

This file was deleted.

0 comments on commit 2e98693

Please sign in to comment.