diff options
author | j-james | 2020-12-08 23:28:23 +0000 |
---|---|---|
committer | j-james | 2020-12-08 23:28:23 +0000 |
commit | d5fc9f859b9cc03d8d4f75c1c77561734bf62635 (patch) | |
tree | 3ad32e2045dd27f64a092a44483eeaf3c76dbb48 /2020 | |
parent | 206d076e8169c50081f908e0be23fcf65461d63e (diff) |
Day Eight: Keep lines under 80 characters
Diffstat (limited to '2020')
-rw-r--r-- | 2020/eight.nim | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/2020/eight.nim b/2020/eight.nim index a7b40f2..b923f76 100644 --- a/2020/eight.nim +++ b/2020/eight.nim @@ -1,12 +1,12 @@ # Day Eight: Handheld Halting -import os, strutils, sequtils +import os, strutils, sequtils, sugar let input: string = paramStr(1) var program: seq[tuple[op: string, arg: int]] = map(split(strip(readFile(input)), '\n'), - func (instr: string): (string, int) = return (instr[0..2], parseInt(instr[4..^1]))) + instruction => (instruction[0..2], parseInt(instruction[4..^1]))) -func execute(program: seq[tuple[op: string, arg: int]]): tuple[status: bool, acc: int] = +func execute(program: seq[tuple[op: string, arg: int]]): (bool, int) = var executed = newSeq[bool](len(program)) var i, acc: int = 0 while i < len(program): @@ -26,9 +26,11 @@ func execute(program: seq[tuple[op: string, arg: int]]): tuple[status: bool, acc discard return (true, acc) -echo execute(program).acc +let result: tuple[status: bool, acc: int] = execute(program) +echo result.acc for i, instruction in program: var program = program program[i].op = if program[i].op == "nop": "jmp" else: "nop" - if execute(program).status: echo execute(program).acc + let result: tuple[status: bool, acc: int] = execute(program) + if result.status: echo result.acc |