Forward difference: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|C sharp}}: Regularize header markup to recommended on category page) |
|||
Line 2,255: | Line 2,255: | ||
}</lang> |
}</lang> |
||
=={{header|Picat}}== |
|||
<lang Picat>go => |
|||
L = [90, 47, 58, 29, 22, 32, 55, 5, 55, 73], |
|||
foreach(I in 1..L.length-1) |
|||
println([d=I,diffi(L,I)]) |
|||
end, |
|||
nl, |
|||
% All differences (a sublist to save space) |
|||
println(alldiffs(L[1..6])), |
|||
nl. |
|||
% Difference of the list |
|||
diff(L) = Diff => |
|||
Diff = [L[I]-L[I-1] : I in 2..L.length]. |
|||
% The i'th list difference |
|||
diffi(L,D) = Diff => |
|||
Diff1 = L, |
|||
foreach(_I in 1..D) |
|||
Diff1 := diff(Diff1) |
|||
end, |
|||
Diff = Diff1. |
|||
% all differences |
|||
alldiffs(L) = Diffs => |
|||
Diffs1 = [], |
|||
Diff = L, |
|||
foreach(_I in 1..L.length-1) |
|||
Diff := diff(Diff), |
|||
Diffs1 := Diffs1 ++ [Diff] |
|||
end, |
|||
Diffs = Diffs1.</lang> |
|||
Output: |
|||
<pre>[d = 1,[-43,11,-29,-7,10,23,-50,50,18]] |
|||
[d = 2,[54,-40,22,17,13,-73,100,-32]] |
|||
[d = 3,[-94,62,-5,-4,-86,173,-132]] |
|||
[d = 4,[156,-67,1,-82,259,-305]] |
|||
[d = 5,[-223,68,-83,341,-564]] |
|||
[d = 6,[291,-151,424,-905]] |
|||
[d = 7,[-442,575,-1329]] |
|||
[d = 8,[1017,-1904]] |
|||
[d = 9,[-2921]] |
|||
[[-43,11,-29,-7,10],[54,-40,22,17],[-94,62,-5],[156,-67],[-223]]</pre> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |