aboutsummaryrefslogtreecommitdiff
path: root/aoc-2019-elixir/lib/util.ex
diff options
context:
space:
mode:
authorTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2023-01-27 15:00:57 +0100
committerTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2023-01-27 15:00:57 +0100
commit29c49417f89169c03ca05724da3c88880d3a1a17 (patch)
treea2105c4a8e1da21b617035dda3d695560578e0d7 /aoc-2019-elixir/lib/util.ex
parent6c747854c00b5f96038a726a90a7201fefd626bb (diff)
downloadgleam_aoc2020-29c49417f89169c03ca05724da3c88880d3a1a17.tar.gz
gleam_aoc2020-29c49417f89169c03ca05724da3c88880d3a1a17.zip
Solve first two days of 2019 in Elixir
Diffstat (limited to 'aoc-2019-elixir/lib/util.ex')
-rw-r--r--aoc-2019-elixir/lib/util.ex26
1 files changed, 26 insertions, 0 deletions
diff --git a/aoc-2019-elixir/lib/util.ex b/aoc-2019-elixir/lib/util.ex
new file mode 100644
index 0000000..ada31be
--- /dev/null
+++ b/aoc-2019-elixir/lib/util.ex
@@ -0,0 +1,26 @@
+defmodule Util.Integer do
+ @spec parse!(binary) :: integer
+ def parse!(binary) do
+ {integer, _remainder} = Integer.parse(binary)
+ integer
+ end
+end
+
+defmodule Util.Input do
+ @spec read_text(binary) :: binary
+ def read_text(filename) do
+ File.read!("data/#{filename}.txt")
+ end
+
+ @spec read_lines(binary) :: [binary]
+ def read_lines(filename) do
+ filename |> read_text() |> String.split()
+ end
+
+ @spec read_numbers(binary) :: [integer]
+ def read_numbers(filename) do
+ filename
+ |> read_lines()
+ |> Enum.map(&Util.Integer.parse!/1)
+ end
+end