Then, I created two huge sets Abig and Bbig with 100,000 elements with repeated elements. Next, I created two equal sets Aequal and Bequal again with 5 elements each: I also created a set Asub which is a subset of set A and Anotsub which is not a subset of A (to test the Subset Test operation): It's easy to see that only elements 1, 2 and 3 are in common: The elements are positive numbers.įirst, I created two sets A and B with 5 elements each so that I could easily check if the operations really worked. Each set is represented as a file with one element per line. To illustrate these operations, I created a couple of random sets to work with. Update: I wrote another post about these operations and created a cheat sheet.ĭownload cheat sheet: set operations in unix shell (.txt) Given two sets A and B, find all elements in A that are not in B. Test if a given set is a subset of another set. Return the number of elements in the set. Test if two sets contain the same elements. I'll cover the following set operations in this article. This lead me to an idea to write a post about how to do various set operations from the shell by using common utilities such as sort, uniq, diff, grep, head, tail, comm, and others. The solution involved finding the intersection between a bunch of files containing numbers. I took an unusual approach and solved this problem entirely from the Unix shell. A while ago I wrote about how I solved the Google Treasure Hunt Puzzle #4 about prime numbers.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |