Last active
December 10, 2025 03:34
-
-
Save mythicalprogrammer/2734322b44a9005d610c230349045120 to your computer and use it in GitHub Desktop.
Advent of Code 2025 - Day 2 - Part 1 - Elixir
This file contains hidden or 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
| defmodule DAY02 do | |
| @moduledoc """ | |
| Documentation for `Advent of Code 2025 Day 02 - module DAY02`. | |
| """ | |
| @doc """ | |
| ## Examples | |
| iex> DAY02.hello() | |
| :world | |
| """ | |
| def part1(input) do | |
| input | |
| |> String.split(",") | |
| |> Enum.reduce([], fn range, acc -> | |
| range_split = range |> id_range | |
| range_split ++ acc | |
| end) | |
| |> Enum.reduce(0, fn curr_id, acc -> | |
| result = curr_id |> id_pattern() | |
| if result, do: acc + String.to_integer(curr_id), else: acc | |
| end) | |
| end | |
| def id_range(range) do | |
| [id_start, id_end] = range |> String.split("-") | |
| id_start = String.to_integer(id_start) | |
| id_end = String.to_integer(id_end) | |
| id_start..id_end | |
| |> Enum.to_list() | |
| |> Enum.map(&to_string/1) | |
| end | |
| def id_pattern(id) do | |
| len = id |> String.length() | |
| mid = len |> div(2) | |
| first_half = id |> String.slice(0, mid) | |
| second_half = id |> String.slice(mid, len - mid) | |
| first_half == second_half | |
| end | |
| def solve do | |
| read_input() | |
| |> part1 | |
| # IO.puts("--- Part One ---") | |
| # IO.puts("Result: #{part1(input)}") | |
| end | |
| defp read_input do | |
| File.read!("./inputs/input.txt") | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment