Skip to content

Instantly share code, notes, and snippets.

@arbaieffendi
Created May 27, 2019 06:24
Show Gist options
  • Save arbaieffendi/3f4cc1c0b089ab7436c4f7082280da0f to your computer and use it in GitHub Desktop.
Save arbaieffendi/3f4cc1c0b089ab7436c4f7082280da0f to your computer and use it in GitHub Desktop.
Maze SxS. S = 4n-1, n = bilangan bulat ganjil positif
package main
import (
"fmt"
)
func main() {
maze(3)
}
// Labirin SxS. S = 4n-1, n = bilangan bulat ganjil positif
// row ganjil maka harus punya pintu
// row genap hanya ujungnya saja yang terisi
func maze(n int) {
s := 4*n - 1
var door int = 0 // 0 left 1 right
for r := 1; r <= s; r++ {
if isOdd(r) {
//# ## or ## #
for c := 0; c < s; c++ {
if c == 1 && door == 0 {
fmt.Print(" ")
} else if c == s-2 && door == 1 {
fmt.Print(" ")
} else {
fmt.Print("#")
}
}
if door == 0 {
door = 1
} else {
door = 0
}
} else {
//# #
for c := 0; c < s; c++ {
if c == 0 || c == s-1 {
fmt.Print("#")
} else {
fmt.Printf(" ")
}
}
}
fmt.Println("")
}
}
func isOdd(value int) bool {
if value%2 == 1 {
return true
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment