fork download
  1. val height = 5
  2. val width = 72
  3.  
  4. val matrix = Array(height) {CharArray(width){ '*' }}
  5.  
  6. fun cantor(start: Int, len: Int, index: Int) {
  7.  
  8. val seg = len / 3
  9.  
  10. if( seg == 0 ) return
  11.  
  12. for(i in index until height) {
  13.  
  14. for (j in start + seg until start + seg * 2) matrix[i][j] = ' '
  15. }
  16.  
  17. cantor(start, seg, index + 1)
  18.  
  19. cantor(start + seg * 2, seg, index + 1)
  20. }
  21.  
  22. fun main(args: Array<String>) {
  23.  
  24. cantor(0, width, 1)
  25.  
  26. matrix.forEach { println(it) }
  27. }
Success #stdin #stdout 0.06s 33208KB
stdin
Standard input is empty
stdout
************************************************************************
************************                        ************************
********        ********                        ********        ********
**  ****        **  ****                        **  ****        **  ****
**  ****        **  ****                        **  ****        **  ****