Then I have this homework because Mimora will have to filter every nth element in the list and return it as a list For example:
? - Each (3, [A, B, C, D, E, F], RS) = [C, F].
My idea was originally:
Harnath (n, [x | xs], l): - harnath (n, [x | x], n, L) Harnath (N, [], C, L) Every Anth (N, [X | X], 0, [X]): - Hernath (N, XS, N, [X]). Every Anth (n, [x | xs], c, l): - c1c-1, every anninth (n, xs, c1, l). But it does not work in this way, because in the third line it matches X and returns X and count 0 goes to the second time it goes there.
You are almost there to check these modifications:
Hernan (N, L, NL): - Each Anth (N, L, N, NL). Everywhere (_, [], _, []) every anith (n, [x | xs], 1, [x | nx]): - hernath (n, xs, n, nx). Every Anth (N, [_ | X], C, NX): - C1 C-1, C1 & gt; 0, is every ann (n, xs, c1, nx). The first section of everynth / 4 is the end of the recursion. If there is no other item in the list, then an empty list should be given. The second section of everynth / 4 is related to the nth item, it must input the item in the output list and continue processing while remaining items restart your item counter. . The third section of and everynth / 4 , which are not item nth elements, must leave the item, reduce the counter and continue with the remaining items.
Comments
Post a Comment