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
+7.3k Golang : Word limiter example
+14.4k Golang : Overwrite previous output with count down timer
+11.4k Golang : Generate DSA private, public key and PEM files example
+5.7k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+7.4k Golang : Shuffle strings array
+4.8k Unix/Linux : secure copying between servers with SCP command examples
+5.3k Golang : Reclaim memory occupied by make() example
+11.6k Golang : Secure file deletion with wipe example
+25.8k Golang : Convert IP address string to long ( unsigned 32-bit integer )
+7.3k Golang : Gorrila set route name and get the current route name
+11.3k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+8.7k Golang : Take screen shot of browser with JQuery example