mirror of
https://github.com/wezm/advent-of-code.git
synced 2024-12-18 10:19:55 +00:00
Day 4 part 2
This commit is contained in:
parent
a0e0065c40
commit
49f1283cf6
1 changed files with 14 additions and 1 deletions
|
@ -16,7 +16,11 @@ pub fn pt_1(input: String) -> Int {
|
|||
}
|
||||
|
||||
pub fn pt_2(input: String) -> Int {
|
||||
todo
|
||||
string.split(input, on: "\n")
|
||||
|> iterator.from_list
|
||||
|> iterator.map(parse_line)
|
||||
|> iterator.filter(overlaps)
|
||||
|> iterator.fold(0, fn(sum, _) { sum + 1 })
|
||||
}
|
||||
|
||||
fn parse_line(line: String) -> #(Range, Range) {
|
||||
|
@ -43,3 +47,12 @@ fn fully_contains(pair: #(Range, Range)) -> Bool {
|
|||
let b = pair.1
|
||||
b.start >= a.start && b.end <= a.end || a.start >= b.start && a.end <= b.end
|
||||
}
|
||||
|
||||
fn overlaps(pair: #(Range, Range)) -> Bool {
|
||||
let a = pair.0
|
||||
let b = pair.1
|
||||
case a.start < b.start {
|
||||
True -> b.start <= a.end
|
||||
False -> a.start <= b.end
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue