Set consolidation: Difference between revisions
Content added Content deleted
(Updated both D entries) |
m ({{out}}) |
||
Line 12: | Line 12: | ||
:Given the two sets <tt>{A,B}</tt> and <tt>{B,D}</tt> then there is a common element <tt>B</tt> between the sets and the result is the single set <tt>{B,D,A}</tt>. (Note that order of items in a set is immaterial: <tt>{A,B,D}</tt> is the same as <tt>{B,D,A}</tt> and <tt>{D,A,B}</tt>, etc). |
:Given the two sets <tt>{A,B}</tt> and <tt>{B,D}</tt> then there is a common element <tt>B</tt> between the sets and the result is the single set <tt>{B,D,A}</tt>. (Note that order of items in a set is immaterial: <tt>{A,B,D}</tt> is the same as <tt>{B,D,A}</tt> and <tt>{D,A,B}</tt>, etc). |
||
;'''Example 3:''' |
;'''Example 3:''' |
||
:Given the three sets <tt>{A,B}</tt> and <tt>{C,D}</tt> and <tt>{D,B}</tt> then there is no common element between the sets <tt>{A,B}</tt> and <tt>{C,D}</tt> but the sets <tt>{A,B}</tt> and <tt>{D,B}</tt> do share a common element that consolidates to produce the result <tt>{B,D,A}</tt>. |
:Given the three sets <tt>{A,B}</tt> and <tt>{C,D}</tt> and <tt>{D,B}</tt> then there is no common element between the sets <tt>{A,B}</tt> and <tt>{C,D}</tt> but the sets <tt>{A,B}</tt> and <tt>{D,B}</tt> do share a common element that consolidates to produce the result <tt>{B,D,A}</tt>. |
||
On examining this result with the remaining set, <tt>{C,D}</tt>, they share a common element and so consolidate to the final output of the single set <tt>{A,B,C,D}</tt> |
|||
;'''Example 4:''' |
;'''Example 4:''' |
||
:The consolidation of the five sets: |
:The consolidation of the five sets: |
||
Line 177: | Line 178: | ||
end Set_Consolidation;</lang> |
end Set_Consolidation;</lang> |
||
{{out}} |
|||
This generates the following output: |
|||
<pre>{A,B}{C,D} |
<pre>{A,B}{C,D} |
||
{A,B,D} |
{A,B,D} |
||
Line 350: | Line 350: | ||
& test$(H+I+K A+B C+D D+B F+G+H) |
& test$(H+I+K A+B C+D D+B F+G+H) |
||
);</lang> |
);</lang> |
||
{{out}} |
|||
Output: |
|||
<pre>A+B C+D ==> A+B C+D |
<pre>A+B C+D ==> A+B C+D |
||
A+B B+D ==> A+B+D |
A+B B+D ==> A+B+D |
||
Line 616: | Line 616: | ||
(test (consolidate {{'H' 'I' 'K'} {'A' 'B'} {'C' 'D'} {'D' 'B'} {'F' 'G' 'H'}})) |
(test (consolidate {{'H' 'I' 'K'} {'A' 'B'} {'C' 'D'} {'D' 'B'} {'F' 'G' 'H'}})) |
||
</lang> |
</lang> |
||
{{out}} |
|||
'''Output:''' |
|||
<lang egison> |
<lang egison> |
||
{"DBAC" "HIKFG"} |
{"DBAC" "HIKFG"} |
||
Line 670: | Line 670: | ||
] |
] |
||
0</lang> |
0</lang> |
||
{{out}} |
|||
Output |
|||
<pre>seq [set ["C"; "D"]; set ["A"; "B"]] |
<pre>seq [set ["C"; "D"]; set ["A"; "B"]] |
||
seq [set ["A"; "B"; "C"]] |
seq [set ["A"; "B"; "C"]] |
||
Line 989: | Line 989: | ||
;;</lang> |
;;</lang> |
||
{{out}} |
|||
Output: |
|||
<pre>{ {A B} {C D} } |
<pre>{ {A B} {C D} } |
||
{ {A B C} } |
{ {A B C} } |
||
Line 1,113: | Line 1,112: | ||
End |
End |
||
Return strip(ol)</lang> |
Return strip(ol)</lang> |
||
{{out}} |
|||
Output: |
|||
<pre> |
<pre> |
||
Input 1 (B,A) (C,D) |
Input 1 (B,A) (C,D) |
||
Line 1,364: | Line 1,363: | ||
(consolidate (list (set 'h 'i 'k) (set 'a 'b) (set 'c 'd) (set 'd 'b) (set 'f 'g 'h))) |
(consolidate (list (set 'h 'i 'k) (set 'a 'b) (set 'c 'd) (set 'd 'b) (set 'f 'g 'h))) |
||
</lang> |
</lang> |
||
{{out}} |
|||
Output: |
|||
<lang racket> |
<lang racket> |
||
(list (set 'b 'a) (set 'd 'c)) |
(list (set 'b 'a) (set 'd 'c)) |
||
Line 1,427: | Line 1,426: | ||
/*──────────────────────────────────iSIN subroutine─────────────────────*/ |
/*──────────────────────────────────iSIN subroutine─────────────────────*/ |
||
isIn: return wordpos(arg(1), arg(2))\==0 /*is (word) arg1 in set arg2? */</lang> |
isIn: return wordpos(arg(1), arg(2))\==0 /*is (word) arg1 in set arg2? */</lang> |
||
{{out}} when using the default supplied sample sets: |
|||
<pre> |
<pre> |
||
the old sets= {A,B} {C,D} |
the old sets= {A,B} {C,D} |
||
Line 1,566: | Line 1,565: | ||
(format t "~s -> ~s\n" test (consoli test))))</lang> |
(format t "~s -> ~s\n" test (consoli test))))</lang> |
||
{{out}} |
|||
Output: |
|||
<pre>((a b) (c d)) -> ((d c) (b a)) |
<pre>((a b) (c d)) -> ((d c) (b a)) |
||
((a b) (b d)) -> ((d b a)) |
((a b) (b d)) -> ((d b a)) |
||
Line 1,597: | Line 1,595: | ||
[mapcar hash-keys (consoli [mapcar mkset test])])))</lang> |
[mapcar hash-keys (consoli [mapcar mkset test])])))</lang> |
||
{{out}} |
|||
Output: |
|||
<pre>((a b) (c d)) -> ((b a) (d c)) |
<pre>((a b) (c d)) -> ((b a) (d c)) |
||
((a b) (b d)) -> ((b a d)) |
((a b) (b d)) -> ((b a d)) |