mirror of
https://github.com/wezm/advent-of-code.git
synced 2024-12-18 18:29:55 +00:00
Day 6 part 2
This commit is contained in:
parent
1e8e3308fc
commit
d2f60b0427
1 changed files with 14 additions and 8 deletions
|
@ -4,25 +4,31 @@ import gleam/string
|
||||||
import gleam/list
|
import gleam/list
|
||||||
|
|
||||||
pub fn pt_1(input: String) -> Int {
|
pub fn pt_1(input: String) -> Int {
|
||||||
|
input
|
||||||
|
|> tune(4)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pt_2(input: String) -> Int {
|
||||||
|
input
|
||||||
|
|> tune(14)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tune(input: String, window: Int) -> Int {
|
||||||
assert Ok(header) =
|
assert Ok(header) =
|
||||||
input
|
input
|
||||||
|> string.trim_right
|
|> string.trim_right
|
||||||
|> string.to_graphemes
|
|> string.to_graphemes
|
||||||
|> list.index_map(fn(i, el) { #(i + 1, el) })
|
|> list.index_map(fn(i, el) { #(i + 1, el) })
|
||||||
|> list.window(4)
|
|> list.window(window)
|
||||||
|> list.find(is_unique)
|
|> list.find(is_unique(_, window))
|
||||||
|
|
||||||
assert Ok(index) = list.last(header)
|
assert Ok(index) = list.last(header)
|
||||||
index.0
|
index.0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pt_2(input: String) -> Int {
|
fn is_unique(chars: List(#(Int, String)), window: Int) -> Bool {
|
||||||
todo
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_unique(chars: List(#(Int, String))) -> Bool {
|
|
||||||
chars
|
chars
|
||||||
|> list.map(fn(pair) { pair.1 })
|
|> list.map(fn(pair) { pair.1 })
|
||||||
|> list.unique
|
|> list.unique
|
||||||
|> list.length == 4
|
|> list.length == window
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue