From ecf522ef6a8dd8f366c314dcaa2fa366779d3a79 Mon Sep 17 00:00:00 2001 From: Dj0ulo <julien.launois@student.uclouvain.be> Date: Sun, 26 Apr 2020 19:05:55 +0200 Subject: [PATCH] INGI1131 - APE2 - q10 update --- src/q6/oz-INGI1131/exercises/APE2/q10.oz | 55 +++++++++++++++--------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/src/q6/oz-INGI1131/exercises/APE2/q10.oz b/src/q6/oz-INGI1131/exercises/APE2/q10.oz index 38a3826f5..c729e3f62 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 -- GitLab