[erlang-questions] Erlang again!
Corrado Santoro
csanto@REDACTED
Thu Jul 22 17:52:54 CEST 2010
> Hi All,
> after a long time, here I am programming in Erlang again...
> I have 2 lists:
> L1=[1,2,3,4,5], L2=[1.1,2.2,3.3,4.4,5.5]
> and I want to have a third list which is the difference of them:
> L3=[
> L2[1] - L1[1],
> L2[2] - L1[2],
> L2[3] - L1[3],
> L2[4] - L1[4],
> L2[5] - L1[5]
> ]
> The result should be
> L3=[0.1,0.2,0.3,0.4,0.5]
Try this:
sub ([],[]) -> [];
sub (_, []) -> [];
sub ([], _) -> [];
sub ([H1 | T1], [H2 | T2]) -> [ H2 - H1 | sub (T1, T2)].
not tail-recursive... however :-)
--Corrado
More information about the erlang-questions
mailing list