(* The lines of a text, counted all at once with Bytes.count, and walked one by one with Bytes.index: lines.pas does the same with FPC's IndexByte, which is assembly, and a counting loop. *) module Lines; import Out, Bytes; import SYSTEM; check off; const N = 16777216; Rounds = 32; Letters = "etaoinshrdlucmfw"; var text: [N]U8; proc main*; var i, r, x, v, k, total, walked: INT; begin x := 1; for i := 0 to N - 1 do x := (x * 1103515245 + 12345) & 7FFFFFFFH; v := (x shr 16) & 63; if v = 0 then text[i] := 10; elsif v < 10 then text[i] := U8(' '); else text[i] := Letters[v & 15]; end; end; total := 0; walked := 0; for r := 1 to Rounds do total := total + Bytes.count(text, 10); i := 0; k := Bytes.index(text, 10); while k >= 0 do INC(walked); i := i + k + 1; k := Bytes.index(text[i..N], 10); end; end; Out.int(total); Out.str(" "); Out.int(walked); Out.ln; end; end Lines.