Skip to content

Commit a792723

Browse files
committed
🚧 WIP
1 parent e0d2c43 commit a792723

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

Diff for: ‎elixir/day_01/lib/day01.ex

+43-9
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@ defmodule Day01 do
33
Documentation for `Day01`.
44
"""
55

6-
@doc """
7-
Hello world.
8-
9-
## Examples
10-
11-
iex> Day01.hello()
12-
:world
13-
14-
"""
156
def partOne() do
167
input = File.read!("./lib/input.txt")
178

@@ -24,4 +15,47 @@ defmodule Day01 do
2415
|> Enum.map(&String.to_integer/1)
2516
|> Enum.sum()
2617
end
18+
19+
def partTwo() do
20+
# input = File.read!("./lib/input.txt")
21+
input = """
22+
two1nine
23+
eightwothree
24+
abcone2threexyz
25+
xtwone3four
26+
4nineeightseven2
27+
zoneight234
28+
7pqrstsixteen
29+
"""
30+
31+
numbers_as_text = [
32+
"one 1",
33+
"two 2",
34+
"three 3",
35+
"four 4",
36+
"five 5",
37+
"six 6",
38+
"seven 7",
39+
"eight 8",
40+
"nine 9"
41+
]
42+
43+
sanitized_input =
44+
input
45+
|> String.split("\n", trim: true)
46+
|> Enum.map(fn x ->
47+
numbers_as_text
48+
|> Enum.reduce(x, fn {k, v}, acc -> String.replace(acc, k, v) end)
49+
end)
50+
|> Enum.map(fn x -> String.replace(x, ~r/[^\d]/, "") end)
51+
52+
IO.inspect(sanitized_input)
53+
54+
sanitized_input
55+
|> Enum.map(fn x ->
56+
(x |> String.first()) <> (x |> String.last())
57+
end)
58+
|> Enum.map(&String.to_integer/1)
59+
|> Enum.sum()
60+
end
2761
end

0 commit comments

Comments
 (0)