streaming

This commit is contained in:
mehbark 2025-01-28 20:57:29 -05:00
parent 0706170d95
commit f03131610f

View file

@ -59,13 +59,17 @@ def main : List String → IO UInt32
| [width] =>
if let some width := width.toNat?
then do
let mut text := ""
let stdin ← IO.getStdin
let mut remainder : Array String := #[]
while true do
let line ← stdin.getLine
if line.isEmpty then break
text := text ++ line
IO.println $ solve width text
let lines := breakUp width (remainder ++ line.words)
if h : lines.size > 0 then
remainder := lines[lines.size-1]
for line in lines[0:lines.size-1] do
IO.println $ justify width line
IO.println $ String.intercalate " " remainder.toList
return 0
else fail
| _ => fail