input = """
2494
8013
1055
5425
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/sequtils, std/strutils, std/strformat | |
type | |
Operation = enum AddX, Noop | |
Instruction = object | |
op: Operation | |
args: seq[int] | |
State = object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/strutils, std/sequtils, std/strformat, std/sets | |
type | |
Position = object | |
x: int | |
y: int | |
Move = Position | |
Rope = object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/sequtils, std/strutils, std/sets, std/sugar, std/strformat, std/tables, std/algorithm | |
proc countVisible*(input: seq[seq[int]]): int = | |
runnableExamples: | |
let input = @[@[2, 2, 1, 2], | |
@[2, 1, 3, 2], | |
@[2, 2, 5, 2]] | |
assert countVisible(input) == 11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/sequtils, std/strutils, std/sugar, std/strformat | |
type | |
NodeKind = enum File, Dir | |
Node = object | |
kind: NodeKind | |
name: string | |
size: int | |
children: seq[Node] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/strformat, std/sets | |
proc findMarker(input: string, length: int): int = | |
for idx in 0..<input.len: | |
if input[idx..<idx+length].toHashSet.len == length: | |
result = idx + length | |
break | |
proc findStartOfPacket*(input: string): int = | |
findMarker(input, 4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/strformat, std/sequtils, std/strscans, std/strutils, sugar | |
proc extractInput*(input: seq[string]): (seq[string], seq[string]) = | |
runnableExamples: | |
let (s, i) = extractInput(@["foo", "bar", "", "baz", "bax"]) | |
assert s == @["foo", "bar"] | |
assert i == @["baz", "bax"] | |
var storage: seq[string] | |
var instructions: seq[string] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/sequtils, std/os, std/strformat, std/strscans, std/sets, sugar | |
proc countPairs(input: seq[string], fun: (HashSet[int], HashSet[int]) -> bool): int = | |
var count = 0 | |
for line in input: | |
let (ok, lower1, upper1, lower2, upper2) = scanTuple( | |
line, "$i-$i,$i-$i") | |
if ok: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/sequtils, std/sets, std/tables, std/os, std/strformat | |
let priorities = concat( | |
zip(toSeq('a'..'z'), toSeq(1..26)), | |
zip(toSeq('A'..'Z'), toSeq(27..52)) | |
).toTable | |
iterator chunks[T](a: seq[T], size: int): seq[T] = | |
var chunk: seq[T] = @[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/tables | |
var points = 0 | |
let choicePoints = { | |
'R': 1, | |
'P': 2, | |
'S': 3 | |
}.toTable |