Posted in Mathematics, Programming

Generating the Cantor’s set with recursion

In my old article I have implementation for Cantor’s set without recursion. Now I implemented the Cantor’s set with recursion in JavaScript. This is better solution.

The definition of the Cantor’s set in the language of set theory is the following:

If this doesn’t mean anything to you, you might want to check the old post. 🙂

Below is a picture from the output of the program of this post:


Below is the JavaScript listing from Notepad++ in full as png-file:


cantor listing

You could also divide the segement length in the recursive call. This way you would get the first straight line directly…