Created
December 7, 2020 11:18
-
-
Save oem/6c17a43796b93a42112043f78df949d5 to your computer and use it in GitHub Desktop.
day 6, advent of code 2020, using Pipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Pipe: @pipe | |
getdata(file) = open(joinpath(@__DIR__, file)) do f read(f, String) end | |
part1(data) = @pipe data |> | |
split(_, "\n\n") |> | |
map(l -> replace(l, "\n" => ""), _) |> | |
map(l -> split(l, ""), _) |> | |
map(l -> unique(l), _) |> | |
map(l -> length(l), _) |> | |
sum | |
part2(data) = @pipe data |> | |
split(_, "\n\n") |> | |
map(l -> replace(l, r"\s*$" => ""), _) |> | |
map(l -> split(l, "\n"), _) |> | |
map(l -> reduce(intersect, l), _) |> | |
map(length, _) |> | |
sum | |
using Test | |
@test getdata("day_6_test.txt") |> part1 == 11 | |
@test getdata("day_6_puzzle.txt") |> part1 == 6930 | |
@test getdata("day_6_puzzle_2.txt") |> part2 == 6 | |
@test getdata("day_6_puzzle.txt") |> part2 == 3585 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment