diff --git a/src/q6/oz-INGI1131/exercises/APE2/q10.oz b/src/q6/oz-INGI1131/exercises/APE2/q10.oz index 0cf8ce6403b8616b3409fef157f6b6e4040c9d2f..38a3826f5ccf6866001f63c3054a16d026ec57d6 100644 --- a/src/q6/oz-INGI1131/exercises/APE2/q10.oz +++ b/src/q6/oz-INGI1131/exercises/APE2/q10.oz @@ -1,10 +1,25 @@ declare -fun {Flatten List} - case List - of nil then nil - [] H|T then {Append {Flatten H} {Flatten T}} - else [List] - end +fun {Flatten X} + fun {DoFlatten Xs Start End} + case Xs + of X|Xr then S S1 in + if {DoFlatten X S S1} then + S = Start + {DoFlatten Xr S1 End} + else S2 in + Start = X|S2 + {DoFlatten Xr S2 End} + end + [] nil then + Start = End + true + else false + end + end + Start +in + if {DoFlatten X Start nil} then Start + else X + end end - {Browse {Flatten [a [b [c d]] e [[[f]]]]}} % -> [a b c d e f] \ No newline at end of file