diff --git a/src/q6/oz-INGI1131/exercises/APE2/q10.oz b/src/q6/oz-INGI1131/exercises/APE2/q10.oz index 38a3826f5ccf6866001f63c3054a16d026ec57d6..c729e3f621603fd8a81be488a74771d28fa3c8ad 100644 --- a/src/q6/oz-INGI1131/exercises/APE2/q10.oz +++ b/src/q6/oz-INGI1131/exercises/APE2/q10.oz @@ -1,25 +1,40 @@ -declare -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} +local + 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 - [] nil then - Start = End - true - else false + end + Start + in + if {DoFlatten X Start nil} then Start + else X end end - Start in - if {DoFlatten X Start nil} then Start - else X - end + {Browse {Flatten [a [b [c d]] e [[[f]]]]}} % -> [a b c d e f] end -{Browse {Flatten [a [b [c d]] e [[[f]]]]}} % -> [a b c d e f] \ No newline at end of file + +%%% Plus simple mais moins optimisée %%% +local + fun {Flatten X} + case X + of H|T then {Append {Flatten H} {Flatten T}} + [] nil then nil + else [X] + end + end +in + {Browse {Flatten [a [b [c d]] e [[[f]]]]}} % -> [a b c d e f] +end \ No newline at end of file