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

Published on 12 May 2024 09:40 PM

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

Source code in the m2000 programming language

Function Checkit$ {
	Document Ret$
	Flush
	Data "the cat sat on the mat", "mat cat"
	Data "the cat sat on the mat","cat mat"'
	Data "A B C A B C A B C", "C A C A"
	Data "A B C A B D A B E", "E A D A"
	Data "A B", "B"
	Data "A B", "B A"
	Data "A B B A","B A"
	Dim A$()
	while not empty
		read m$, n$
		A$()=piece$(m$, " ")
		Let w=piece$(n$, " ")
		Let z=A$() 
		x=each(w)
		while x
			y=z#pos(array$(x))
			if y>-1 then a$(y)=""
		end while
		p=0
		x=each(w)
		while x
			while a$(p)<>"" : p++: end while
			a$(p)=array$(x)
		end while
		ret$=m$+" | "+n$+" -> "+z#str$()+{
		}
	end while
	=ret$
}
Report Checkit$()
Clipboard  Checkit$()

Function Checkit2$ {
	Document Ret$
	Flush
	Data "the cat sat on the mat", "mat cat"
	Data "the cat sat on the mat","cat mat"'
	Data "A B C A B C A B C", "C A C A"
	Data "A B C A B D A B E", "E A D A"
	Data "A B", "B"
	Data "A B", "B A"
	Data "A B B A","B A"
	Dim A$()
	while not empty
		read m$, n$
		A$()=piece$(m$, " ")
		Let w=piece$(n$, " ")
		Let z=A$()
		dim p(len(w))
		x=each(w)
		p=0
		while x
			y=z#pos(array$(x))
			if y>-1 then a$(y)="": p(p)=y : p++
		end while
		u=p()#Sort()
		x=each(u)
		while x
			a$(array(x))=w#val$(x^)
		end while
		ret$=m$+" | "+n$+" -> "+z#str$()+{
		}
	end while
	=ret$
}
Report Checkit2$()
Clipboard  Checkit2$()

  

You may also check:How to resolve the algorithm Menu step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Loops/Continue step by step in the Ol programming language
You may also check:How to resolve the algorithm Integer sequence step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Read a configuration file step by step in the jq programming language
You may also check:How to resolve the algorithm Sort disjoint sublist step by step in the Tcl programming language