How to resolve the algorithm Order disjoint list items step by step in the PicoLisp programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Order disjoint list items step by step in the PicoLisp programming language
Table of Contents
Problem Statement
Given M as a list of items and another list N of items chosen from M, create M' as a list with the first occurrences of items from N sorted to be in one of the set of indices of their original occurrence in M but in the order given by their order in N. That is, items in N are taken from M without replacement, then the corresponding positions in M' are filled by successive items from N.
The words not in N are left in their original positions.
If there are duplications then only the first instances in M up to as many as are mentioned in N are potentially re-ordered.
Is ordered as:
Show the output, here, for at least the following inputs:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Order disjoint list items step by step in the PicoLisp programming language
Source code in the picolisp programming language
(de orderDisjoint (M N)
(for S N
(and (memq S M) (set @ NIL)) )
(mapcar
'((S) (or S (pop 'N)))
M ) )
: (orderDisjoint '(the cat sat on the mat) '(mat cat))
-> (the mat sat on the cat)
: (orderDisjoint '(the cat sat on the mat) '(cat mat))
-> (the cat sat on the mat)
: (orderDisjoint '(A B C A B C A B C) '(C A C A))
-> (C B A C B A A B C)
: (orderDisjoint '(A B C A B D A B E) '(E A D A))
-> (E B C A B D A B A)
: (orderDisjoint '(A B) '(B))
-> (A B)
: (orderDisjoint '(A B) '(B A))
-> (B A)
: (orderDisjoint '(A B B A) '(B A))
-> (B A B A)
You may also check:How to resolve the algorithm Mutual recursion step by step in the VBA programming language
You may also check:How to resolve the algorithm Farey sequence step by step in the Scheme programming language
You may also check:How to resolve the algorithm Function composition step by step in the REXX programming language
You may also check:How to resolve the algorithm Sum and product of an array step by step in the Fantom programming language
You may also check:How to resolve the algorithm ABC problem step by step in the CLU programming language