Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a64d6ee

Browse files
committed
Inital commit
0 parents commit a64d6ee

File tree

202 files changed

+13421
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+13421
-0
lines changed

‎2015/day01.livemd‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Day 01
2+
3+
```elixir
4+
Mix.install([
5+
{:kino, "~> 0.7.0"}
6+
])
7+
```
8+
9+
## Input
10+
11+
<!-- livebook:{"reevaluate_automatically":true} -->
12+
13+
```elixir
14+
input = Kino.Input.text("input")
15+
```
16+
17+
## Shared
18+
19+
```elixir
20+
movement = fn char ->
21+
case char do
22+
"(" -> 1
23+
")" -> -1
24+
end
25+
end
26+
```
27+
28+
## Part 1
29+
30+
```elixir
31+
input
32+
|> Kino.Input.read()
33+
|> String.graphemes()
34+
|> Enum.map(fn char ->
35+
movement.(char)
36+
end)
37+
|> Enum.sum()
38+
```
39+
40+
## Part 2
41+
42+
```elixir
43+
input
44+
|> Kino.Input.read()
45+
|> String.graphemes()
46+
|> Enum.reduce_while({0, 0}, fn char, {acc, index} ->
47+
acc = acc + movement.(char)
48+
49+
if acc >= 0 do
50+
{:cont, {acc, index + 1}}
51+
else
52+
{:halt, index + 1}
53+
end
54+
end)
55+
```

‎2015/day02.livemd‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Day 02
2+
3+
```elixir
4+
Mix.install([
5+
{:kino, "~> 0.7.0"}
6+
])
7+
```
8+
9+
## Input
10+
11+
<!-- livebook:{"reevaluate_automatically":true} -->
12+
13+
```elixir
14+
input = Kino.Input.textarea("input")
15+
```
16+
17+
## Part 1
18+
19+
```elixir
20+
input
21+
|> Kino.Input.read()
22+
|> String.split("\n")
23+
|> Enum.map(fn line ->
24+
[length, width, heigth] =
25+
line
26+
|> String.split("x")
27+
|> Enum.map(&String.to_integer/1)
28+
29+
sides = [length * width, width * heigth, length * heigth]
30+
Enum.sum(Enum.map(sides, &(&1 * 2))) + Enum.min(sides)
31+
end)
32+
|> Enum.sum()
33+
```
34+
35+
## Part 2
36+
37+
```elixir
38+
input
39+
|> Kino.Input.read()
40+
|> String.split("\n")
41+
|> Enum.map(fn line ->
42+
sides =
43+
line
44+
|> String.split("x")
45+
|> Enum.map(&String.to_integer/1)
46+
47+
[min_1, min_2, other] = Enum.sort(sides)
48+
min_1 + min_1 + min_2 + min_2 + min_1 * min_2 * other
49+
end)
50+
|> Enum.sum()
51+
```

‎2015/day03.livemd‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Day 03
2+
3+
```elixir
4+
Mix.install([
5+
{:kino, "~> 0.7.0"}
6+
])
7+
```
8+
9+
## Input
10+
11+
<!-- livebook:{"reevaluate_automatically":true} -->
12+
13+
```elixir
14+
input = Kino.Input.textarea("input")
15+
```
16+
17+
## Part 01
18+
19+
```elixir
20+
{map, _pos} =
21+
input
22+
|> Kino.Input.read()
23+
|> String.graphemes()
24+
|> Enum.reduce({%{{0, 0} => 1}, {0, 0}}, fn movement, {acc, {x, y}} ->
25+
pos =
26+
case movement do
27+
"^" -> {x - 1, y}
28+
"v" -> {x + 1, y}
29+
"<" -> {x, y - 1}
30+
">" -> {x, y + 1}
31+
end
32+
33+
{Map.update(acc, pos, 1, &(&1 + 1)), pos}
34+
end)
35+
36+
Enum.count(Map.keys(map))
37+
```
38+
39+
## Part 02
40+
41+
```elixir
42+
{map, _pos, _other_pos} =
43+
input
44+
|> Kino.Input.read()
45+
|> String.graphemes()
46+
|> Enum.reduce({%{{0, 0} => 2}, {0, 0}, {0, 0}}, fn movement, {acc, {x, y}, other_pos} ->
47+
pos =
48+
case movement do
49+
"^" -> {x - 1, y}
50+
"v" -> {x + 1, y}
51+
"<" -> {x, y - 1}
52+
">" -> {x, y + 1}
53+
end
54+
55+
{Map.update(acc, pos, 1, &(&1 + 1)), other_pos, pos}
56+
end)
57+
58+
Enum.count(Map.keys(map))
59+
```

‎2015/day04.livemd‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Day 04
2+
3+
```elixir
4+
Mix.install([
5+
{:kino, "~> 0.7.0"}
6+
])
7+
```
8+
9+
## Input
10+
11+
<!-- livebook:{"reevaluate_automatically":true} -->
12+
13+
```elixir
14+
input = Kino.Input.textarea("input")
15+
```
16+
17+
## Part 01
18+
19+
```elixir
20+
secret =
21+
input
22+
|> Kino.Input.read()
23+
24+
Stream.unfold(1, fn index ->
25+
<<leading::24, _::binary>> = :crypto.hash(:md5, secret <> Integer.to_string(index))
26+
27+
if leading < 16 do
28+
IO.inspect(index)
29+
nil
30+
else
31+
{index, index + 1}
32+
end
33+
end)
34+
|> Stream.run()
35+
```
36+
37+
## Part 02
38+
39+
```elixir
40+
secret =
41+
input
42+
|> Kino.Input.read()
43+
44+
Stream.unfold(1, fn index ->
45+
<<leading::24, _::binary>> = :crypto.hash(:md5, secret <> Integer.to_string(index))
46+
47+
if leading == 0 do
48+
IO.inspect(index)
49+
nil
50+
else
51+
{index, index + 1}
52+
end
53+
end)
54+
|> Stream.run()
55+
```

‎2015/day05.livemd‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Day 05
2+
3+
```elixir
4+
Mix.install([
5+
{:kino, "~> 0.7.0"}
6+
])
7+
```
8+
9+
## Input
10+
11+
<!-- livebook:{"reevaluate_automatically":true} -->
12+
13+
```elixir
14+
input = Kino.Input.textarea("input")
15+
```
16+
17+
## Part 01
18+
19+
```elixir
20+
input
21+
|> Kino.Input.read()
22+
|> String.split("\n")
23+
|> Enum.map(fn line ->
24+
line
25+
|> String.graphemes()
26+
|> Enum.chunk_every(2, 1)
27+
|> Enum.reduce_while({0, false}, fn [char1 | char2], {count, double} ->
28+
char2 = Enum.join(char2)
29+
count = if Enum.member?(["a", "e", "i", "o", "u"], char1), do: count + 1, else: count
30+
double = double || char1 == char2
31+
forbidden = Enum.member?(["ab", "cd", "pq", "xy"], char1 <> char2)
32+
33+
# IO.inspect({[char1, char2], count, double, forbidden})
34+
cond do
35+
forbidden -> {:halt, false}
36+
count >= 3 && double && char2 == "" -> {:halt, true}
37+
true -> {:cont, {count, double}}
38+
end
39+
end)
40+
end)
41+
|> Enum.count(&(&1 == true))
42+
```
43+
44+
## Part 02
45+
46+
```elixir
47+
input
48+
|> Kino.Input.read()
49+
|> String.split("\n")
50+
|> Enum.map(fn line ->
51+
graphemes = String.graphemes(line)
52+
53+
double =
54+
graphemes
55+
|> Enum.chunk_every(2, 1)
56+
|> Enum.reduce_while({%{}, ""}, fn chars, {acc, prev} ->
57+
chars = Enum.join(chars)
58+
59+
# IO.inspect({chars, prev, acc})
60+
cond do
61+
chars == prev -> {:cont, {acc, chars}}
62+
Map.get(acc, chars, 0) + 1 >= 2 -> {:halt, true}
63+
true -> {:cont, {Map.update(acc, chars, 1, &(&1 + 1)), chars}}
64+
end
65+
end)
66+
67+
sandwitch =
68+
graphemes
69+
|> Enum.chunk_every(3, 1, :discard)
70+
|> Enum.reduce_while(false, fn chars, _ ->
71+
case chars do
72+
[x, _, x] -> {:halt, true}
73+
_ -> {:cont, false}
74+
end
75+
end)
76+
77+
double == true && sandwitch
78+
end)
79+
|> Enum.count(& &1)
80+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /