How to resolve the algorithm Set consolidation step by step in the Quackery programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Set consolidation step by step in the Quackery programming language
Table of Contents
Problem Statement
Given two sets of items then if any item is common to any set then the result of applying consolidation to those sets is a set of sets whose contents is: Given N sets of items where N>2 then the result is the same as repeatedly replacing all combinations of two sets by their consolidation until no further consolidation between set pairs is possible. If N<2 then consolidation has no strict meaning and the input can be returned.
See also
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Set consolidation step by step in the Quackery programming language
Source code in the quackery programming language
[ 0 swap witheach [ bit | ] ] is ->set ( $ --> { )
[ say "{" 0 swap
[ dup 0 != while
dup 1 & if [ over emit ]
1 >> dip 1+ again ]
2drop say "} " ] is echoset ( { --> )
[ [] swap dup size 1 - times
[ behead over witheach
[ 2dup & iff
[ | swap i^ poke
[] conclude ]
else drop ]
swap dip join ]
join ] is consolidate ( [ --> [ )
[ dup witheach echoset
say "--> "
consolidate witheach echoset
cr ] is task ( [ --> )
$ "AB" ->set
$ "CD" ->set join
task
$ "AB" ->set
$ "BD" ->set join
task
$ "AB" ->set
$ "CD" ->set join
$ "DB" ->set join
task
$ "HIK" ->set
$ "AB" ->set join
$ "CD" ->set join
$ "DB" ->set join
$ "FGH" ->set join
task
You may also check:How to resolve the algorithm Fractran step by step in the Julia programming language
You may also check:How to resolve the algorithm Sorting algorithms/Cocktail sort with shifting bounds step by step in the 360 Assembly programming language
You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the Java programming language
You may also check:How to resolve the algorithm Binary digits step by step in the Perl programming language
You may also check:How to resolve the algorithm Entropy/Narcissist step by step in the Factor programming language