How to resolve the algorithm Order disjoint list items step by step in the Arturo programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Order disjoint list items step by step in the Arturo 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 Arturo programming language
Source code in the arturo programming language
orderDisjoint: function [m,n][
ms: split.words m
ns: split.words n
indexes: new []
loop ns 'item [
idx: index ms item
unless null? idx [
'indexes ++ idx
ms\[idx]: ""
]
]
sort 'indexes
loop.with:'i indexes 'idx ->
ms\[idx]: ns\[i]
return join.with:" " ms
]
process: function [a,b][
print [a "|" b "->" orderDisjoint a b]
]
process "the cat sat on the mat" "mat cat"
process "the cat sat on the mat" "cat mat"
process "A B C A B C A B C" "C A C A"
process "A B C A B D A B E" "E A D A"
process "A B" "B"
process "A B" "B A"
process "A B B A" "B A"
You may also check:How to resolve the algorithm Execute a system command step by step in the Racket programming language
You may also check:How to resolve the algorithm De Bruijn sequences step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Null object step by step in the Ruby programming language
You may also check:How to resolve the algorithm Ordered words step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm Mutual recursion step by step in the Scala programming language