7 kyu

Natural Emptiness

176 of 278saudiGuy

Description:

Task

In abstract set theory, a construction due to von Neumann represents the natural numbers by sets, as follows:

  • 0 = [ ] is the empty set
  • 1 = 0 ∪ [ 0 ] = [ 0 ] = [ [ ] ]
  • 2 = 1 ∪ [ 1 ] = [ 0, 1 ] = [ [ ], [ [ ] ] ]
  • n = n−1 ∪ [ n−1 ] = ...

Write a function that receives an integer n and produces the representing set.

Examples

rep_set(0) ➞ []

rep_set(1) ➞ [[]]

rep_set(2) ➞ [[], [[]]]

rep_set(3) ➞ [[], [[]], [[], [[ ]]]]

Input Constraints

  • 0 <= n <= 15
  • Code limit is <= 200 characters for Python and <= 300 characters for TypeScript and JavaScript.
Algorithms
Set Theory
Recursion

More By Author:

Check out these other kata created by saudiGuy

Stats:

CreatedJul 20, 2023
PublishedJul 20, 2023
Warriors Trained693
Total Skips14
Total Code Submissions804
Total Times Completed278
Python Completions176
JavaScript Completions99
TypeScript Completions26
Total Stars7
% of votes with a positive feedback rating90% of 55
Total "Very Satisfied" Votes45
Total "Somewhat Satisfied" Votes9
Total "Not Satisfied" Votes1
Total Rank Assessments20
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • saudiGuy Avatar
  • SagePtr Avatar
  • goldenratio161 Avatar
Ad