How to resolve the algorithm Symmetric difference step by step in the J programming language

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm Symmetric difference step by step in the J 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 J programming language

Source code in the j programming language

   A=: ~.;:'John Serena Bob Mary Serena'
   B=: ~. ;:'Jim Mary John Jim Bob'

   (A-.B) , (B-.A)   NB. Symmetric Difference
┌──────┬───┐
│Serena│Jim│
└──────┴───┘
   A (-. , -.~) B    NB. Tacit equivalent
┌──────┬───┐
│Serena│Jim│
└──────┴───┘


   A -. B            NB. items in A but not in B
┌──────┐
│Serena│
└──────┘
   A -.~ B           NB. items in B but not in A
┌───┐
│Jim│
└───┘
   A                 NB. A is a sequence without duplicates
┌────┬──────┬───┬────┐
│John│Serena│Bob│Mary│
└────┴──────┴───┴────┘


   A (, -. [ -. -.) B
┌──────┬───┐
│Serena│Jim│
└──────┴───┘


  

You may also check:How to resolve the algorithm Josephus problem step by step in the Racket programming language
You may also check:How to resolve the algorithm Averages/Root mean square step by step in the Prolog programming language
You may also check:How to resolve the algorithm Roman numerals/Encode step by step in the Excel programming language
You may also check:How to resolve the algorithm Draw a rotating cube step by step in the Processing programming language
You may also check:How to resolve the algorithm URL decoding step by step in the Sidef programming language