# Advent of Code 2023 - Day 6

**URL:** <https://erlangforums.com/t/advent-of-code-2023-day-6/3084>\
**Category:** Coding Challenges\
**Tags:** advent-of-code\
**Created:** [December 6, 2023, 10:46am UTC](https://erlangforums.com/t/advent-of-code-2023-day-6/3084 "2023-12-06T10:46:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vkatsuba](https://erlangforums.com/user_avatar/erlangforums.com/vkatsuba/32/314_2.png) [@vkatsuba](https://erlangforums.com/u/vkatsuba)\
**Post date:** [December 6, 2023, 10:46am UTC](https://erlangforums.com/t/advent-of-code-2023-day-6/3084/1 "2023-12-06T10:46:04Z")

</div>

Greetings, everyone! **Ukrainian Erlanger** is here to check in 🤘! I hope you’re all enjoying the thrill of puzzle-solving. As we find ourselves in the midst of the week, it’s time for [Day 6](https://adventofcode.com/2023/day/6) of [Advent of Code](https://adventofcode.com)! A new puzzle challenge awaits, so don’t miss out on this opportunity. Embrace the challenge and, of course, happy coding 😊!

---

<div class="post-metadata">

**Author:** ![danilagamma](https://erlangforums.com/user_avatar/erlangforums.com/danilagamma/32/342_2.png) [@danilagamma](https://erlangforums.com/u/danilagamma)\
**Post date:** [December 6, 2023, 10:07pm UTC](https://erlangforums.com/t/advent-of-code-2023-day-6/3084/2 "2023-12-06T22:07:55Z")

</div>

Here is my day 6 solution:

```elixir
defmodule Aoc.Six do
  def parse(string) do
    string
    |> String.split("\n", trim: true)
    |> Enum.map(fn line ->
      line
      |> String.split(" ", trim: true)
      |> tl()
      |> Enum.map(&String.to_integer/1)
    end)
  end

  def part_one(input) do
    input
    |> Enum.zip()
    |> Enum.map(&math/1)
    |> Enum.product()
  end

  def part_two(input) do
    input
    |> Enum.map(fn line ->
      line |> Enum.map(&Integer.to_string/1) |> Enum.join() |> String.to_integer()
    end)
    |> List.to_tuple()
    |> math()
  end

  def math({time, distance}) do
    sqrt = :math.sqrt(time ** 2 - 4 * distance)
    a = (time - sqrt) / 2
    b = (time + sqrt) / 2
    ceil(a)..floor(b) |> Enum.count()
  end
end

input = File.read!("priv/6.txt") |> Aoc.Six.parse()

input |> Aoc.Six.part_one() |> IO.inspect(label: "part 1")
input |> Aoc.Six.part_two() |> IO.inspect(label: "part 2")

```
