Skip to content

Instantly share code, notes, and snippets.

@tfwright

tfwright/1.exs Secret

Last active December 5, 2022 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfwright/86cbe0cdac20bc90e67fa488ce855b01 to your computer and use it in GitHub Desktop.
Save tfwright/86cbe0cdac20bc90e67fa488ce855b01 to your computer and use it in GitHub Desktop.
System.argv()
|> List.first()
|> File.stream!()
|> Enum.count(fn pair ->
[[section_1_start, section_1_end], [section_2_start, section_2_end]] =
pair
|> String.trim()
|> String.split(",")
|> Enum.map(fn assignment -> assignment |> String.split("-") |> Enum.map(&String.to_integer/1) end)
(section_1_start >= section_2_start && section_1_end <= section_2_end) ||
(section_2_start >= section_1_start && section_2_end <= section_1_end)
end)
|> IO.inspect
System.argv()
|> List.first()
|> File.stream!()
|> Enum.count(fn pair ->
pair
|> String.trim()
|> String.split(",")
|> Enum.map(fn assignment ->
assignment
|> String.split("-")
|> Enum.map(& String.to_integer/1)
|> then(fn bounds -> apply(Range, :new, bounds) end)
end)
|> then(fn assignments -> !apply(Range, :disjoint?, assignments) end)
end)
|> IO.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment