Brute force day 2 that will never finish

This commit is contained in:
Daniel Flanagan 2021-12-14 15:53:55 -06:00
parent 942a6dd897
commit 653b8d55dd
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
2 changed files with 27 additions and 10 deletions

View file

@ -38,14 +38,14 @@ template time*(i: string, body: untyped): untyped =
when not defined(release):
echo "NOTE: This is not a real measurement of performance. Compile in release mode with -d:release for best performance."
proc doDay*[T](
proc doDay*[T, X](
day: int,
inputLoader: int -> T,
part1: T -> int,
part2: T -> int,
part1: T -> X,
part2: T -> X,
testInput: T,
expectedPart1: int,
expectedPart2: int): void =
expectedPart1: X,
expectedPart2: X): void =
when not defined(release):
var p1 = testInput.part1()
@ -61,6 +61,15 @@ proc doDay*[T](
time(&"Day {day} Part 2"): echo day.inputLoader().part2()
proc doDayX*[T, X](
day: int,
inputLoader: int -> T,
part1: T -> X,
part2: T -> X,
testTuple: (T, X, X)): void =
let (tin, expectedPart1, expectedPart2) = testTuple
doDay(day, inputLoader, part1, part2, tin, expectedPart1, expectedPart2)
proc doDay*[T](
day: int,
inputLoader: int -> T,

View file

@ -15,15 +15,23 @@ proc stepPolymer(polymer: string, combis: Table[(char, char), char]): string =
result.add polymer[i]
i += 1
proc p1(input: Lines): int =
proc p1(input: Lines): uint64 =
var (polymer, combis) = input.parse
for i in 1..10:
polymer = polymer.stepPolymer combis
var pps = polymer.toCountTable.values.toSeq
max(pps) - min(pps)
uint64(max(pps) - min(pps))
proc p2(input: Lines): int =
return 0
proc p2(input: Lines): uint64 =
var (polymer, combis) = input.parse
for i in 1..40:
echo &"Step {i}"
polymer = polymer.stepPolymer combis
var t = initTable[char, uint64]()
for c in polymer:
inc t[c]
var pps = t.values.toSeq
max(pps) - min(pps)
const input = """
NNCB
@ -45,4 +53,4 @@ BC -> B
CC -> N
CN -> C
""".strip().split('\n').mapIt(it.strip)
doDay 14, n => n.loadInput, p1, p2, (input, 1588, 0)
doDayX 14, n => n.loadInput, p1, p2, (input, 1588'u64, 2188189693529'u64)