tried to improve day 5, answer still incorrect
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
let compare_ranges fr sr = if fst fr > fst sr then 1 else -1
|
||||||
let split_empty_line lines =
|
let split_empty_line lines =
|
||||||
let rec split acc = function
|
let rec split acc = function
|
||||||
| [] -> (List.rev acc), []
|
| [] -> (List.rev acc), []
|
||||||
@ -33,8 +34,8 @@ let update_range (x, y) ranges =
|
|||||||
else if u1 > t2 then (u1, u2)
|
else if u1 > t2 then (u1, u2)
|
||||||
else if u2 < t1 then (u1, u2)
|
else if u2 < t1 then (u1, u2)
|
||||||
else if t1 <= u1 && t2 >= u2 then (0,0)
|
else if t1 <= u1 && t2 >= u2 then (0,0)
|
||||||
else if t1 >= u1 && u1 <= t2 then (u1, t1 - 1)
|
else if t1 >= u1 && u2 <= t2 then (u1, t1 - 1)
|
||||||
else if t1 <= u1 && t2 >= u1 then (t2 + 1, u2)
|
else if t1 <= u1 && u2 >= t2 then (t2 + 1, u2)
|
||||||
else (u1 ,u2)
|
else (u1 ,u2)
|
||||||
) (x, y) ranges
|
) (x, y) ranges
|
||||||
|
|
||||||
@ -43,8 +44,8 @@ let rec update_ranges to_process updated_ranges =
|
|||||||
| [] -> updated_ranges
|
| [] -> updated_ranges
|
||||||
| (x, y) :: xs ->
|
| (x, y) :: xs ->
|
||||||
let (u1, u2) = update_range (x, y) xs in
|
let (u1, u2) = update_range (x, y) xs in
|
||||||
Printf.printf "Updating range: (%i,%i) to (%i, %i)\n" x y u1 u2;
|
let removed = List.filter (fun (t1, t2) -> not (t1 <= u2 && t2 >= u1 && u2 <= t2)) xs in
|
||||||
update_ranges xs ((u1, u2) :: updated_ranges)
|
update_ranges removed ((u1, u2) :: updated_ranges)
|
||||||
|
|
||||||
let solve_part2 inputs =
|
let solve_part2 inputs =
|
||||||
let (first, _) = split_empty_line inputs in
|
let (first, _) = split_empty_line inputs in
|
||||||
|
|||||||
Reference in New Issue
Block a user