diff options
author | j-james | 2020-12-09 11:39:49 +0000 |
---|---|---|
committer | j-james | 2020-12-09 11:39:49 +0000 |
commit | 3a5bc1757d077c75ecce78800372895d668f7d42 (patch) | |
tree | ca8e834b364b7c4a7f39ec2358a6a6569dced356 /2019/eight.nim | |
parent | c651051cf36e95c5603cd3f7aef2e6d278809333 (diff) |
Implement current 2019 AoC solutions in Nim
Diffstat (limited to '2019/eight.nim')
-rw-r--r-- | 2019/eight.nim | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/2019/eight.nim b/2019/eight.nim new file mode 100644 index 0000000..ecf291e --- /dev/null +++ b/2019/eight.nim @@ -0,0 +1,30 @@ +# Day Eight: Space Image Format +import os, strutils, sequtils + +let + input: string = paramStr(1) + digits: string = strip(readFile(input)) + width: int = 25 + height: int = 6 + depth: int = len(digits) div (width * height) + +var min, product: int = width * height +for layer in distribute(@digits, depth): + if count(layer, '0') < min: + min = count(layer, '0') + product = count(layer, '1') * count(layer, '2') +echo product + +for column in 0 ..< height: + for row in 0 ..< width: + for layer in 0 ..< depth: + case digits[(layer * height * width) + (column * width) + row] + of '0': + write(stdout, ' ') + break + of '1': + write(stdout, 'X') + break + else: + discard + write(stdout, '\n') |