diff --git a/d06/main.odin b/d06/main.odin new file mode 100644 index 0000000..a808cf6 --- /dev/null +++ b/d06/main.odin @@ -0,0 +1,79 @@ +package main + +import "core:math" +import "core:slice" +import "core:strconv" +import "core:strings" +import "core:bytes" +import "core:fmt" +import "core:os" + +import "../util" + +part_1 :: proc(lines: []string) { + result: = 0 + + batches := make([dynamic]map[rune]bool) + batch := make(map[rune]bool) + + for line, idx in lines { + if len(line) == 0 { + append(&batches, batch) + batch = make(map[rune]bool) + } + + for letter in line { + batch[letter] = true + } + } + + for answers in batches { + result += len(answers) + } + + fmt.printfln("Part 1: %d", result) +} + +Batch :: struct { + amount: int, + answers: map[rune]int +} + +part_2 :: proc(lines: []string) { + result: = 0 + + batches := make([dynamic]Batch) + batch := Batch{} + + for line, idx in lines { + if len(line) == 0 { + append(&batches, batch) + batch = Batch{} + } else { + for letter in line { + batch.answers[letter] += 1 + } + batch.amount += 1 + } + } + + for batch in batches { + for _, num_answers in batch.answers { + if batch.amount == num_answers do result += 1 + } + } + + fmt.printfln("Part 2: %d", result) +} + +main :: proc() { + context.allocator = context.temp_allocator + defer free_all(context.temp_allocator) + + INPUT :: #load("input.txt", string) + lines := strings.split(INPUT, "\n") + lines = lines[:len(lines)-1] + + part_1(lines) + part_2(lines) +}