Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %List2
- %2
- declare fun {Fib1 N}
- if N==0 then 0 elseif N==1 then 1 else {Fib1 N-1}+{Fib1 N-2} end end
- {Show {Fib1 37}}
- %approx 10 secs
- declare fun {Fib2 N}
- local fun {TailFib N Acc Next}
- if N == 0 then Acc else {TailFib N-1 Next Acc+Next}
- end
- end
- in {TailFib N 0 1}
- end
- end
- {Show {Fib2 37}}
- %Less than 1 sec
- %4.
- declare X = 0
- %a)
- declare _|_|X|_|_|nil = ~2|~1|0|1|2|nil
- %b)
- declare _#_|X#_|nil = 1#2|0#1|nil
- %5.
- declare fun {Initsegment L1#L2}
- case L1 of
- nil then true
- [] H|T then if L2 == nil then false
- elseif H == L2.1 then {Initsegment T#L2.2} else false
- end
- end
- end
- %6.
- declare fun {Replace_nth L#N#V}
- if L == nil orelse {Length L}< N then raise 'Incorrect Arguments' end
- elseif N == 0 then V|L.2 else L.1|{Replace_nth L.2#N-1#V}
- end
- end
- {Show {Replace_nth (nil)#0#0}}
Add Comment
Please, Sign In to add comment