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
+36.1k Golang : Convert date or time stamp from string to time.Time type
+36.1k Golang : Validate IP address
+9.5k PHP : Get coordinates latitude/longitude from string
+14.2k Golang : Find network of an IP address
+6.7k Golang : Gargish-English language translator
+18.5k Golang : convert int to string
+4.5k Facebook : How to place save to Facebook button on your website
+10.7k Golang : Sieve of Eratosthenes algorithm
+5.4k Unix/Linux : How to find out the hard disk size?
+10.8k How to test Facebook App on localhost ?
+12.7k Python : Convert IPv6 address to decimal and back to IPv6
+45.7k Golang : Read tab delimited file with encoding/csv package