aboutsummaryrefslogtreecommitdiff
path: root/2019/five.nim
diff options
context:
space:
mode:
authorj-james2022-12-12 02:15:44 +0000
committerj-james2022-12-12 02:18:55 +0000
commita7ba598a54a8883c83cb9ef2b04d653eecd92e28 (patch)
tree06d362d3a88c615d8747ddf9a961bf491a8575a5 /2019/five.nim
parent13007178188cd89b31e3e41090e8a8ed64867c13 (diff)
Reorganize 2019 solutions
Diffstat (limited to '2019/five.nim')
-rw-r--r--2019/five.nim63
1 files changed, 0 insertions, 63 deletions
diff --git a/2019/five.nim b/2019/five.nim
deleted file mode 100644
index 87c359e..0000000
--- a/2019/five.nim
+++ /dev/null
@@ -1,63 +0,0 @@
-# Day Five: Sunny with a Chance of Asteroids
-import os, strutils, sequtils
-
-let input: string = paramStr(1)
-var program: seq[int] = map(split(strip(readFile(input)), ','), parseInt)
-
-var i: int = 0
-while i < len(program):
- let opcode: int = program[i] mod 100
-
- var
- mode: int = program[i] div 100
- one: int = i+1
- two: int = i+2
- three: int = i+3
- if len(program)-i > 1 and mode mod 10 == 0:
- one = program[one]
- if len(program)-i > 2 and mode div 10 mod 10 == 0:
- two = program[two]
- if len(program)-i > 3 and mode div 100 == 0:
- three = program[three]
-
- case opcode
- of 1: # adds
- program[three] = program[one] + program[two]
- i += 4
- of 2: # multiplies
- program[three] = program[one] * program[two]
- i += 4
- of 3: # input
- write(stdout, "Input: ")
- program[one] = parseInt(readLine(stdin))
- i += 2
- of 4: # output
- echo program[one]
- i += 2
- of 5: # jump-if-true
- if program[one] != 0:
- i = program[two]
- else:
- i += 3
- of 6: # jump-if-false
- if program[one] == 0:
- i = program[two]
- else:
- i += 3
- of 7: # less than
- if program[one] < program[two]:
- program[three] = 1
- else:
- program[three] = 0
- i += 4
- of 8: # equals
- if program[one] == program[two]:
- program[three] = 1
- else:
- program[three] = 0
- i += 4
- of 99: # terminate
- break
- else:
- echo("Unsupported code ", program[i], " at ", i)
- quit(QuitFailure)