{}
is the empty set. You may use ()
or []
if you choose.
We aren't going to rigorously define "set", but sets all satisfy the following properties:
Sets follow the usual mathematical structure. Here are some important points:
- Sets are not ordered.
- No set contains itself.
- Elements are either in a set or not, this is boolean. Therefore set elements cannot have multiplicities (i.e. an element cannot be in a set multiple times.)
- Elements of a set are also sets and
{}
is the only primitive element.
Task
Write a program/function that determines whether two sets are equal.
Input
Two valid sets via stdin or function argument. The input format is loose within reason.
Some valid inputs are:
{} {{}}
{{},{{}}} {{{{{},{{}}}}}}
{{},{{},{{}}}} {{{},{{}}},{{{{{},{{}}}}}}}
Invalid inputs:
{{} {} Brackets will always be balanced.
{{},{}} {} Set contains the same element twice
Output
A truthy value if the inputs are equal, falsy otherwise.
Test cases
Your submission should answer correctly for all valid inputs, not just for the test cases. These may be updated at any point.
Truthy:
{} {}
{{},{{}}} {{{}},{}}
{{},{{},{{{}},{}}}} {{{{},{{}}},{}},{}}
Falsy:
{} {{}}
{{},{{},{{{}},{}}}} {{{{}}},{},{{}}}
{{},{{}},{{{}}},{{},{{}}}} {}
Scoring
Additional Rules
An additional rule has been added banning unordered iterable types altogether. They are too common and trivialize this challenge far too much. Feel free to leave answers that violate this in place, please just make an indication that they were made before the rule change.
==
in Julia, 2 bytes;frozenset.__eq__
in Python, 16 bytes; etc.). \$\endgroup\$See the comments for an explanation.
Please don't do this. Comments are volatile and go away very easily, so important sutff goes in the post body \$\endgroup\$