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
+4.4k Linux : sudo yum updates not working
+18.4k Golang : Generate thumbnails from images
+17.4k Golang : Parse date string and convert to dd-mm-yyyy format
+6k Golang : Scan forex opportunities by Bollinger bands
+9.4k Golang : How to generate Code 39 barcode?
+6.3k Grep : How to grep for strings inside binary data
+12.1k Golang : Display list of countries and ISO codes
+10.8k How to test Facebook App on localhost ?
+11.1k Golang : How to use if, eq and print properly in html template
+16.7k Golang : Capture stdout of a child process and act according to the result
+9k Golang : Write multiple lines or divide string into multiple lines
+20.6k Golang : Convert PNG transparent background image to JPG or JPEG image