Golang : Print instead of building pyramids
Building a pyramid using ancient Egyptians way can be too difficult for more software developers. Just for fun, let's print some pyramids on the terminal instead of building them stones by stones.
Here you go!
package main
import (
"fmt"
)
func main() {
var rows = 5
fmt.Println("Half pyramid")
for i := 0; i < rows; i++ {
for j := 0; j <= i; j++ {
fmt.Print("∎")
}
fmt.Print("\n")
}
fmt.Println("Full pyramid")
for i := 0; i < rows; i++ {
for j := 0; j <= rows-i; j++ {
fmt.Print(" ")
}
for k := 0; k <= i; k++ {
fmt.Print("∎ ")
}
fmt.Print("\n")
}
fmt.Println("Inverted full pyramid")
for i := rows; i > -1; i-- {
for j := 0; j <= rows-i; j++ {
fmt.Print(" ")
}
for k := 0; k <= i; k++ {
fmt.Print("∎ ")
}
fmt.Print("\n")
}
}
Output:
Half pyramid
∎
∎∎
∎∎∎
∎∎∎∎
∎∎∎∎∎
Full pyramid
∎
∎ ∎
∎ ∎ ∎
∎ ∎ ∎ ∎
∎ ∎ ∎ ∎ ∎
Inverted full pyramid
∎ ∎ ∎ ∎ ∎ ∎
∎ ∎ ∎ ∎ ∎
∎ ∎ ∎ ∎
∎ ∎ ∎
∎ ∎
∎
Reference:
https://www.socketloop.com/tutorials/golang-progress-bar-with-bar-character
See also : Golang : Calculate percentage change of two values
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+5.4k Unix/Linux/MacOSx : Get local IP address
+11.9k Golang : Simple client-server HMAC authentication without SSL example
+31.7k Golang : Validate email address with regular expression
+15.3k Golang : Get checkbox or extract multipart form data value example
+6.3k Golang : Convert an executable file into []byte example
+29.4k Golang : Get and Set User-Agent examples
+10.1k Golang : Meaning of omitempty in struct's field tag
+12.3k Golang : Get absolute path to binary for os.Exec function with exec.LookPath
+7.5k Golang : Example of how to detect which type of script a word belongs to
+17.2k Golang : Clone with pointer and modify value
+20.4k PHP : Convert(cast) int to double/float
+20k Android Studio : AlertDialog and EditText to get user string input example