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

day_6.jl (574B)


      1 #!/usr/bin/env julia
      2 # https://adventofcode.com/2022/day/6
      3 using AdventOfCode
      4 
      5 example = ["mjqjpqmgbljsphdztnvjfqwrcgsmlb"]
      6 input = readlines("data/day_6.txt")
      7 
      8 function findmarker(transmission, markerlength)
      9     findfirst(i->allunique(transmission[i-markerlength+1:i]),
     10               markerlength:lastindex(transmission)) +
     11         markerlength - 1
     12 end
     13 
     14 function part_1(input)
     15     findmarker(first(input), 4)
     16 end
     17 @assert part_1(example) == 7
     18 @info part_1(input)
     19 
     20 function part_2(input)
     21     findmarker(first(input), 14)
     22 end
     23 @assert part_2(example) == 19
     24 @info part_2(input)