How to resolve the algorithm Symmetric difference step by step in the Pike programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Symmetric difference step by step in the Pike programming language
Table of Contents
Problem Statement
Given two sets A and B, compute
( A ∖ B ) ∪ ( B ∖ A ) .
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words:
( A ∪ B ) ∖ ( A ∩ B )
{\displaystyle (A\cup B)\setminus (A\cap B)}
(the set of items that are in at least one of A or B minus the set of items that are in both A and B). Optionally, give the individual differences (
A ∖ B
{\displaystyle A\setminus B}
and
B ∖ A
{\displaystyle B\setminus A}
) as well.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Symmetric difference step by step in the Pike programming language
Source code in the pike programming language
> multiset(string) A = (< "John", "Serena", "Bob", "Mary", "Bob", "Serena" >);
> multiset(string) B = (< "Jim", "Mary", "Mary", "John", "Bob", "Jim" >);
> A^B;
Result: (< "Bob", "Serena", "Serena", "Mary", "Jim", "Jim" >)
> array(string) A = ({ "John", "Serena", "Bob", "Mary", "Serena", "Bob" });
> array(string) B = ({ "Jim", "Mary", "John", "Jim", "Bob", "Mary" });
> A^B;
Result: ({ "Serena", "Serena", "Bob", "Jim", "Jim", "Mary"})
> Array.uniq((A-B)+(B-A));
Result: ({ "Serena", "Jim" })
> mapping(string:int) A = ([ "John":1, "Serena":1, "Bob":1, "Mary":1 ]);
> mapping(string:int) B = ([ "Jim":1, "Mary":1, "John":1, "Bob":1 ]);
> A^B;
Result: ([ "Jim": 1, "Serena": 1 ])
> ADT.Set A = ADT.Set((< "John", "Serena", "Bob", "Mary", "Serena", "Bob" >));
> ADT.Set B = ADT.Set((< "Jim", "Mary", "John", "Jim", "Bob", "Mary" >));
> (A-B)+(B-A);
Result: ADT.Set({ "Serena", "Jim" })
You may also check:How to resolve the algorithm Find the last Sunday of each month step by step in the Befunge programming language
You may also check:How to resolve the algorithm Least common multiple step by step in the Wortel programming language
You may also check:How to resolve the algorithm Verify distribution uniformity/Naive step by step in the RPL programming language
You may also check:How to resolve the algorithm ISBN13 check digit step by step in the BCPL programming language
You may also check:How to resolve the algorithm Sum digits of an integer step by step in the EDSAC order code programming language