diff --git a/src/day_07.gleam b/src/day_07.gleam index f07f9b9..54d2d93 100644 --- a/src/day_07.gleam +++ b/src/day_07.gleam @@ -1,3 +1,4 @@ +import file_streams/file_stream.{type FileStream} import gleam/bool import gleam/int import gleam/list @@ -111,3 +112,25 @@ pub fn filter_valid_calibration_v2( validate_calibration_v2(numbers_to_operate, target, 0, False) }) } + +fn rec_read_stream( + stream: FileStream, + acc: List(Calibration), +) -> List(Calibration) { + case file_stream.read_line(stream) { + Ok(line) -> { + let parsed_line = + line + |> string.trim_end + |> parse_line + + rec_read_stream(stream, [parsed_line, ..acc]) + } + Error(_) -> acc + } +} + +pub fn read_stream_file_into_string(input: FileStream) -> List(Calibration) { + input + |> rec_read_stream([]) +}