puzzle.jl 528 B

123456789101112131415
  1. inputfile = joinpath(@__DIR__, "input.txt")
  2. input = readlines(inputfile)
  3. answer1 = (input .|> collect .|>
  4. x -> map(y -> islowercase(y) ? Int(y) - Int('a') + 1 : Int(y) - Int('A') + 27, x) |>
  5. x -> (x[begin:Int(length(x)/2)], x[Int(length(x)/2)+1:end]) |>
  6. x -> intersect(x...)) |> sum |> sum
  7. answer2 = ((input .|> collect .|>
  8. x -> map(y -> islowercase(y) ? Int(y) - Int('a') + 1 : Int(y) - Int('A') + 27, x)) |>
  9. x -> reshape(x, (3, :)) |> eachcol |> collect .|>
  10. x -> intersect(x...)) |> sum |> sum
  11. print((answer1, answer2))