solve 2015 19.1
This commit is contained in:
parent
e73bc3ecb8
commit
407453790f
5 changed files with 24 additions and 21 deletions
|
@ -1 +1 @@
|
|||
export ADVENT_OF_CODE_SESSION=53616c7465645f5f92dfbc249005a7e94ec3c6e62cd4e5e9ddf8e368a48c0c80440b6c5e37d836cc0b294e19a9e8a7f1
|
||||
export ADVENT_OF_CODE_SESSION=53616c7465645f5f18112545c7b5290961cf3f2c965e90c1b68415326ef1f99790e4dde4ef0cebc7abd120ea1b537aada76420516a0ceb883a722a84b81e7a02
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
erlang 24.1.4
|
||||
elixir 1.12.3-otp-24
|
||||
erlang 26.1.2
|
||||
elixir 1.15.7-otp-26
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
| :--: | :--: | :-: | :-: | :-: | :-: | :-: |
|
||||
| | | [1] | [2] | [3] | [4] | [5] |
|
||||
| [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 | |
|
||||
|
||||
[1]: ./lib/2015/1.ex
|
||||
|
@ -37,3 +37,4 @@
|
|||
[16]: ./lib/2015/16.ex
|
||||
[17]: ./lib/2015/17.ex
|
||||
[18]: ./lib/2015/18.ex
|
||||
[19]: ./lib/2015/19.ex
|
||||
|
|
|
@ -18,25 +18,27 @@ aoc 2015, 19 do
|
|||
{replacement_mappings, starting_molecule}
|
||||
end
|
||||
|
||||
def splits(xs) do
|
||||
for i <- 1..(length(xs) - 1) do
|
||||
Enum.split(xs, i)
|
||||
end
|
||||
def possible_substitutions("", _, _), do: []
|
||||
|
||||
def possible_substitutions(str, source, replacement) do
|
||||
<<curr::binary-size(1), next::binary>> = str
|
||||
|
||||
this =
|
||||
if String.starts_with?(str, source),
|
||||
do: [String.replace(str, source, replacement, global: false)],
|
||||
else: []
|
||||
|
||||
this ++ for r <- possible_substitutions(next, source, replacement), do: curr <> r
|
||||
end
|
||||
|
||||
def possible_replacements(mappings, str) do
|
||||
for {source, replacements} <- mappings,
|
||||
replacement <- replacements,
|
||||
{l, r} <- splits(String.split(str, source)),
|
||||
uniq: true do
|
||||
Enum.join(
|
||||
[
|
||||
Enum.join(l, source),
|
||||
Enum.join(r, source)
|
||||
],
|
||||
replacement
|
||||
)
|
||||
def possible_replacements(mappings, molecule) do
|
||||
for {source, replacements} <- mappings, replacement <- replacements do
|
||||
{source, replacement}
|
||||
end
|
||||
|> Enum.flat_map(fn {source, replacement} ->
|
||||
possible_substitutions(molecule, source, replacement)
|
||||
end)
|
||||
|> Enum.uniq()
|
||||
end
|
||||
|
||||
def p1 do
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
## Years
|
||||
|
||||
1. [2015] **36/50** 🌟
|
||||
1. [2015] **37/50** 🌟
|
||||
1. 2016
|
||||
1. [2017] **18/50** 🌟
|
||||
1. 2018
|
||||
|
|
Loading…
Reference in a new issue