advent_of_code_2022

My (attempted) solutions to the 2022 Advent of Code
git clone https://git.eamoncaddigan.net/advent_of_code_2022.git
Log | Files | Refs | README

commit 62beb1240c46404e269d0578a6ca4d317cf98c5d
parent 8003346de8b4da4cf289608d54f5d2c2e6fa9637
Author: Eamon Caddigan <eamon.caddigan@gmail.com>
Date:   Mon,  5 Dec 2022 21:47:07 -0800

Solution to day 6, part 2.

Rewrote part 1 solution so there would be less duplicated code.

Diffstat:
Msrc/day_6.jl | 15+++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/day_6.jl b/src/day_6.jl @@ -5,19 +5,22 @@ using AdventOfCode example = ["mjqjpqmgbljsphdztnvjfqwrcgsmlb"] input = readlines("data/day_6.txt") -function part_1(input) - transmission = first(input) - for i = 4:lastindex(transmission) - if allunique(transmission[i-3:i]) +function findmarker(transmission, markerlength) + for i = markerlength:lastindex(transmission) + if allunique(transmission[i-markerlength+1:i]) return i end end end + +function part_1(input) + findmarker(first(input), 4) +end @assert part_1(example) == 7 @info part_1(input) function part_2(input) - nothing + findmarker(first(input), 14) end -@assert part_2(example) == nothing +@assert part_2(example) == 19 @info part_2(input)