How to print text diagonally from left to right recursively in Go

1 Answer

0 votes
package main

import (
    "fmt"
)

func printTextDiagonallyRecursivelyLTR(spaces string, text string) {
    if len(text) > 0 {
        fmt.Println(spaces + string(text[0]))
        printTextDiagonallyRecursivelyLTR(spaces+" ", text[1:])
    }
}

func main() {
    printTextDiagonallyRecursivelyLTR("", "HELLO WORLD")
}



/*
run:

H
 E
  L
   L
    O
      
      W
       O
        R
         L
          D

*/

 



answered Apr 8 by avibootz

Related questions

...