This commit is contained in:
parent
9ada5bb7cd
commit
4b4045c9f0
|
@ -0,0 +1,8 @@
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
|
||||||
|
[*.nim]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
|
@ -1,4 +0,0 @@
|
||||||
# Do not edit this file. To specify the files to encrypt, create your own
|
|
||||||
# .gitattributes file in the directory where your files are.
|
|
||||||
* !filter !diff
|
|
||||||
*.gpg binary
|
|
Binary file not shown.
|
@ -1 +0,0 @@
|
||||||
session.key filter=git-crypt diff=git-crypt
|
|
|
@ -1,7 +1,13 @@
|
||||||
# binaries
|
# binaries
|
||||||
**/first
|
**/first
|
||||||
|
**/first.exe
|
||||||
**/second
|
**/second
|
||||||
|
**/second.exe
|
||||||
**/both
|
**/both
|
||||||
|
**/both.exe
|
||||||
|
|
||||||
# input files
|
# input files
|
||||||
**/input.txt
|
**/input.txt
|
||||||
|
|
||||||
|
# session.key
|
||||||
|
session.key
|
|
@ -0,0 +1,39 @@
|
||||||
|
import
|
||||||
|
std/strformat,
|
||||||
|
std/strutils
|
||||||
|
|
||||||
|
import
|
||||||
|
../../adventofcode
|
||||||
|
|
||||||
|
let input = adventofcode.getInput()
|
||||||
|
var sum = 0
|
||||||
|
|
||||||
|
for line in input.splitLines():
|
||||||
|
var digitsInLine: seq[char] = @[]
|
||||||
|
for i in 0 .. line.high:
|
||||||
|
if line[i].isDigit():
|
||||||
|
digitsInLine.add line[i]
|
||||||
|
when defined(second):
|
||||||
|
# We can't use multiReplace() as numbers can overlap
|
||||||
|
# e.g.: eighthree, twone, ...
|
||||||
|
proc matches(pattern: string): bool =
|
||||||
|
if i + pattern.high <= line.high:
|
||||||
|
return line[i .. i + pattern.high] == pattern
|
||||||
|
for (a, b) in [
|
||||||
|
("one", '1'),
|
||||||
|
("two", '2'),
|
||||||
|
("three", '3'),
|
||||||
|
("four", '4'),
|
||||||
|
("five", '5'),
|
||||||
|
("six", '6'),
|
||||||
|
("seven", '7'),
|
||||||
|
("eight", '8'),
|
||||||
|
("nine", '9'),
|
||||||
|
]:
|
||||||
|
if matches a:
|
||||||
|
digitsInLine.add b
|
||||||
|
|
||||||
|
# Take the first and the last digits of the current line
|
||||||
|
sum += parseInt(digitsInLine[0] & digitsInLine[^1])
|
||||||
|
|
||||||
|
echo fmt"Answer: {sum}"
|
|
@ -0,0 +1,39 @@
|
||||||
|
import
|
||||||
|
std/strformat,
|
||||||
|
std/strutils
|
||||||
|
|
||||||
|
import
|
||||||
|
../../adventofcode
|
||||||
|
|
||||||
|
const maxRedCubes = 12
|
||||||
|
const maxGreenCubes = 13
|
||||||
|
const maxBlueCubes = 14
|
||||||
|
|
||||||
|
let input = adventofcode.getInput()
|
||||||
|
var sum = 0
|
||||||
|
|
||||||
|
for line in input.splitLines():
|
||||||
|
let colonIdx = line.find(':')
|
||||||
|
let gameID = parseInt line[len("Game ") ..< colonIdx]
|
||||||
|
let gameSets = line[colonIdx + 2 .. ^1].split("; ")
|
||||||
|
block verifyGameSet:
|
||||||
|
for gameSet in gameSets:
|
||||||
|
for cubeTypeAndCount in gameSet.split(", "):
|
||||||
|
let cubeCountAndTypeSplit = cubeTypeAndCount.split(' ')
|
||||||
|
let cubeCount = parseInt cubeCountAndTypeSplit[0]
|
||||||
|
let cubeType = cubeCountAndTypeSplit[1]
|
||||||
|
case cubeType:
|
||||||
|
of "red":
|
||||||
|
if cubeCount > maxRedCubes:
|
||||||
|
break verifyGameSet
|
||||||
|
of "green":
|
||||||
|
if cubeCount > maxGreenCubes:
|
||||||
|
break verifyGameSet
|
||||||
|
of "blue":
|
||||||
|
if cubeCount > maxBlueCubes:
|
||||||
|
break verifyGameSet
|
||||||
|
else:
|
||||||
|
discard
|
||||||
|
sum += gameID
|
||||||
|
|
||||||
|
echo fmt"Answer: {sum}"
|
|
@ -0,0 +1 @@
|
||||||
|
Rename this file to `session.key` and put your session key in it.
|
BIN
session.key
BIN
session.key
Binary file not shown.
Loading…
Reference in New Issue