Day 6
This commit is contained in:
parent
5952e4cf89
commit
be683c3993
1 changed files with 79 additions and 0 deletions
79
d06/main.odin
Normal file
79
d06/main.odin
Normal file
|
|
@ -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)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue