scribble

Adrian Statescu

About GitHub LinkedIn Xing Contact

30 Jan 2020
Cantor set

Cantorset

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
val height = 5
val width = 81

val matrix = Array(height) {CharArray(width){ '*' }}

fun cantor(start: Int, len: Int, index: Int) {
	 
	 val seg = len / 3

     if( seg == 0 ) return

     for(i in index until height) {

         for (j in start + seg until start + seg * 2) matrix[i][j] = ' '       
     }

     cantor(start, seg, index + 1)

     cantor(start + seg * 2, seg, index + 1)
}

fun main(args: Array<String>) {
	
	cantor(0, width, 1)

	matrix.forEach { println(it) } 
}

Demo:

https://ideone.com/mVNpaS

About GitHub LinkedIn Xing Contact