Run this notebook

Use Livebook to open this notebook and explore new ideas.

It is easy to get started, on your machine or the cloud.

Click below to open and run it in your Livebook at .

(or change your Livebook location)

# Day 4: Camp Cleanup ```elixir Mix.install([:kino]) input = Kino.Input.textarea("Please paste your input:") ``` ## Part 1 [![Run in Livebook](https://livebook.dev/badge/v1/blue.svg)](https://livebook.dev/run?url=https%3A%2F%2Fgithub.com%2Fnallwhy%2Fadvent-of-code%2Fblob%2Fmain%2F2022%2Fday_04.livemd) https://adventofcode.com/2022/day/4 ```elixir data = input |> Kino.Input.read() |> String.split("\n", trim: true) |> Enum.map(&(&1 |> String.split(","))) |> Enum.map(fn pair -> pair |> Enum.map(fn range -> range |> String.split("-") |> Enum.map(fn integer_str -> String.to_integer(integer_str) end) end) end) ``` ```elixir _answer1 = data |> Enum.filter(fn [range0, range1] -> [{range0, range1}, {range1, range0}] |> Enum.any?(fn {[start_a, end_a], [start_b, end_b]} -> start_a >= start_b and end_a <= end_b end) end) |> Enum.count() ``` ## Part 2 https://adventofcode.com/2022/day/4#part2 ```elixir _answer2 = data |> Enum.reject(fn [[start_a, end_a], [start_b, end_b]] -> start_a > end_b or start_b > end_a end) |> Enum.count() ```
See source

Have you already installed Livebook?

If you already installed Livebook, you can configure the default Livebook location where you want to open notebooks.
Livebook up Checking status We can't reach this Livebook (but we saved your preference anyway)
Run notebook

Not yet? Install Livebook in just a minute

Livebook is open source, free, and ready to run anywhere.

Run in the cloud

on select platforms

To run on Linux, Docker, embedded devices, or Elixir’s Mix, check our README.

PLATINUM SPONSORS
SPONSORS
Code navigation with go to definition of modules and functions Read More