solve 2015 day 10
This commit is contained in:
parent
1a447d7323
commit
3e21b24509
3 changed files with 43 additions and 1 deletions
|
@ -15,7 +15,7 @@
|
||||||
| S | M | T | W | T | F | S |
|
| S | M | T | W | T | F | S |
|
||||||
| :-: | :-: | :-: | :-: | :-: | :-: | :-: |
|
| :-: | :-: | :-: | :-: | :-: | :-: | :-: |
|
||||||
| | | [1] | [2] | [3] | [4] | [5] |
|
| | | [1] | [2] | [3] | [4] | [5] |
|
||||||
| [6] | [7] | 8 | 9 | 10 | 11 | 12 |
|
| [6] | [7] | [8] | [9] | [10]| 11 | 12 |
|
||||||
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
|
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
|
||||||
| 20 | 21 | 22 | 23 | 24 | 25 | |
|
| 20 | 21 | 22 | 23 | 24 | 25 | |
|
||||||
|
|
||||||
|
@ -26,3 +26,6 @@
|
||||||
[5]: ./lib/2015/5.ex
|
[5]: ./lib/2015/5.ex
|
||||||
[6]: ./lib/2015/6.ex
|
[6]: ./lib/2015/6.ex
|
||||||
[7]: ./lib/2015/7.ex
|
[7]: ./lib/2015/7.ex
|
||||||
|
[8]: ./lib/2015/8.ex
|
||||||
|
[9]: ./lib/2015/9.ex
|
||||||
|
[10]: ./lib/2015/10.ex
|
||||||
|
|
33
2015/lib/2015/10.ex
Normal file
33
2015/lib/2015/10.ex
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import AOC
|
||||||
|
|
||||||
|
aoc 2015, 10 do
|
||||||
|
def look_and_say(s) when is_binary(s),
|
||||||
|
do:
|
||||||
|
String.to_integer(s)
|
||||||
|
|> Integer.digits()
|
||||||
|
|> look_and_say()
|
||||||
|
|> IO.iodata_to_binary()
|
||||||
|
|
||||||
|
def look_and_say([x | xs]), do: look_and_say(xs, {x, 1})
|
||||||
|
def look_and_say([x | xs], {x, c}), do: look_and_say(xs, {x, c + 1})
|
||||||
|
def look_and_say([x | xs], state), do: [look_and_say([], state), look_and_say(xs, {x, 1})]
|
||||||
|
def look_and_say([], {x, c}), do: [Integer.to_string(c), Integer.to_string(x)]
|
||||||
|
|
||||||
|
def p1 do
|
||||||
|
Enum.reduce(1..40, String.trim(input_string()), fn iteration, acc ->
|
||||||
|
IO.puts("#{iteration / 40 * 100}%")
|
||||||
|
|
||||||
|
look_and_say(acc)
|
||||||
|
end)
|
||||||
|
|> String.length()
|
||||||
|
end
|
||||||
|
|
||||||
|
def p2 do
|
||||||
|
Enum.reduce(1..50, String.trim(input_string()), fn iteration, acc ->
|
||||||
|
IO.puts("#{iteration / 50 * 100}%")
|
||||||
|
|
||||||
|
look_and_say(acc)
|
||||||
|
end)
|
||||||
|
|> String.length()
|
||||||
|
end
|
||||||
|
end
|
|
@ -6,8 +6,14 @@
|
||||||
|
|
||||||
## Years
|
## Years
|
||||||
|
|
||||||
|
1. [2015]
|
||||||
|
1. 2016
|
||||||
|
1. 2017
|
||||||
|
1. 2018
|
||||||
|
1. 2019
|
||||||
1. [2020]
|
1. [2020]
|
||||||
1. [2021]
|
1. [2021]
|
||||||
|
|
||||||
|
[2015]: ./2015
|
||||||
[2020]: ./2020
|
[2020]: ./2020
|
||||||
[2021]: ./2021
|
[2021]: ./2021
|
||||||
|
|
Loading…
Reference in a new issue