Sierpinski Carpet in Go Programming Language
Example
package main
import (
"fmt"
"strings"
"unicode/utf8"
)
func main() {
var order = 3
var hash = "#"
carpet := []string{hash}
for ; order > 0; order-- {
hole := strings.Repeat(" ", utf8.RuneCountInString(carpet[0]))
middle := make([]string, len(carpet))
for i, s := range carpet {
middle[i] = s + hole + s
carpet[i] = strings.Repeat(s, 3)
}
carpet = append(append(carpet, middle...), carpet...)
}
for _, r := range carpet {
fmt.Println(r)
}
}
Output
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ###### ###
###########################
# ## ## ## ## ## ## ## ## #
###########################
######### #########
# ## ## # # ## ## #
######### #########
### ### ### ###
# # # # # # # #
### ### ### ###
######### #########
# ## ## # # ## ## #
######### #########
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ###### ###
###########################
# ## ## ## ## ## ## ## ## #
###########################
Most Helpful This Week
Convert Float32 to Float64 and Float64 to Float32
Example to compare Println vs Printf
Golang program for implementation of Huffman Coding Algorithm
How to create Slice using new keyword in Golang?
Golang program for implementation of Radix Sort
How do you send an HTTP GET request with an HTTP client in Go?