diff --git a/challenges/2022/05-supplyStacks/benchmark.json b/challenges/2022/05-supplyStacks/benchmark.json index 051e855..14513d0 100644 --- a/challenges/2022/05-supplyStacks/benchmark.json +++ b/challenges/2022/05-supplyStacks/benchmark.json @@ -2,13 +2,21 @@ "day": 5, "dir": "challenges/2022/05-supplyStacks", "implementations": { + "Nim": { + "part.1.avg": 0.0011273949949999996, + "part.1.max": 0.006086964, + "part.1.min": 0.000284679, + "part.2.avg": 0.0012850724640000013, + "part.2.max": 0.006825169, + "part.2.min": 0.000331679 + }, "Python": { - "part.1.avg": 0.0073598167896270755, - "part.1.max": 0.03172612190246582, - "part.1.min": 0.005206584930419922, - "part.2.avg": 0.00753035569190979, - "part.2.max": 0.04000711441040039, - "part.2.min": 0.005285978317260742 + "part.1.avg": 0.007537457227706909, + "part.1.max": 0.030069828033447266, + "part.1.min": 0.005114555358886719, + "part.2.avg": 0.007375564098358154, + "part.2.max": 0.0339961051940918, + "part.2.min": 0.0051727294921875 } }, "numRuns": 1000 diff --git a/challenges/2022/05-supplyStacks/nim/challenge.nim b/challenges/2022/05-supplyStacks/nim/challenge.nim new file mode 100644 index 0000000..6d5e541 --- /dev/null +++ b/challenges/2022/05-supplyStacks/nim/challenge.nim @@ -0,0 +1,85 @@ +import std/deques +import std/strutils +import std/sequtils +import std/re + +type + MoveInstruction = object + n: int + source: int + destination: int + + Stack[T] = Deque[T] + +let instructionRe = re(r"move (\d+) from (\d+) to (\d+)") + +proc parse(instr: string): (seq[Stack[char]], seq[MoveInstruction]) = + let + x = instr.split("\n\n") + rawInitialState = x[0] + rawInstructions = x[1] + + var stateLines = rawInitialState.splitlines() + stateLines = stateLines[0.. int: + for i in range(len(instr) - length): + if len(set(instr[i : i + length])) == length: + return i + length + raise ValueError("cannot solve") + + +class Challenge(BaseChallenge): + @staticmethod + def one(instr: str) -> int: + return find_unique_sequence(instr, 4) + + @staticmethod + def two(instr: str) -> int: + return find_unique_sequence(instr, 14) diff --git a/challenges/2022/README.md b/challenges/2022/README.md index 7fa59a7..ac3e486 100644 --- a/challenges/2022/README.md +++ b/challenges/2022/README.md @@ -14,7 +14,8 @@ Solutions to the [2022 Advent of Code](https://adventofcode.com/2022). | 02 - Rock Paper Scissors | ★ ★ | [Python](02-rockPaperScissors/py), [Nim](02-rockPaperScissors/nim) | Programmatically playing Rock Paper Scissors | | 03 - Rucksack Reorganization | ★ ★ | [Python](03-rucksackReorganization/py), [Nim](03-rucksackReorganization/nim) | Sets and intersections | | 04 - Camp Cleanup | ★ ★ | [Python](04-campCleanup/py), [Nim](04-campCleanup/nim) | More sets and more intersections! | -| 05 - Supply Stacks | ★ ★ | [Python](05-supplyStacks/py) | Believe it or not, this one involved stacks. | +| 05 - Supply Stacks | ★ ★ | [Python](05-supplyStacks/py), [Nim](05-supplyStacks/nim) | Believe it or not, this one involved stacks. | +| 05 - Tuning Trouble | ★ ★ | [Python](06-tuningTrouble/py), [Nim](06-tuningTrouble/nim) | This is the first year I've not repeatedly forgotten about the existence of sets, and it's coming in quite handy. | diff --git a/challenges/2022/running-times.png b/challenges/2022/running-times.png index 148c949..c4a3c6d 100644 Binary files a/challenges/2022/running-times.png and b/challenges/2022/running-times.png differ