How to resolve the algorithm Order disjoint list items step by step in the EchoLisp programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Order disjoint list items step by step in the EchoLisp 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 EchoLisp programming language

Source code in the echolisp programming language

(lib 'list) ;; for list-delete

(define dataM
'((the cat sat on the mat)
(the cat sat on the mat)
(A B C A B C A B C)
(A B C A B D A B E)      
(A B)                    
(A B)                    
(A B B A)))               
		
(define orderM
'((mat cat)
(cat mat)
(C A C A)
(E A D A)
(B)      
(B A)    
(B A)))

(define (order-disjoint M N)
(define R (append N null)) ;; tmp copy of N : delete w when used
	(for/list [(w M)]
	(if
		(not (member w R)) w ;; output as is
		(begin0
		(first N) ;; replacer
		(set! N (rest N))
		(set! R (list-delete R w))))))


  

You may also check:How to resolve the algorithm Sorting algorithms/Bubble sort step by step in the Symsyn programming language
You may also check:How to resolve the algorithm Atomic updates step by step in the Ada programming language
You may also check:How to resolve the algorithm Extend your language step by step in the Ada programming language
You may also check:How to resolve the algorithm Greedy algorithm for Egyptian fractions step by step in the Factor programming language
You may also check:How to resolve the algorithm Arbitrary-precision integers (included) step by step in the Lasso programming language