Skip to content

Instantly share code, notes, and snippets.

@acoshift
Created January 31, 2019 18:51
Show Gist options
  • Save acoshift/7baf2c78b7d016dd20239839694fd254 to your computer and use it in GitHub Desktop.
Save acoshift/7baf2c78b7d016dd20239839694fd254 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func p(s, n, i, j int) int {
if i == 0 || j == 0 || i == n-1 || j == n-1 {
if i-j <= 0 {
return s + j + i + 1
}
return s + 4*(n-1) - j - i + 1
}
return p(s+4*(n-1), n-2, i-1, j-1)
}
func f(n int) {
for i := 0; i < n; i++ {
for j := 0; j < n; j++ {
fmt.Printf("%3d", p(0, n, i, j))
}
fmt.Printf("\n")
}
}
func main() {
for i := 0; i < 10; i++ {
fmt.Printf("n = %d\n", i)
f(i)
fmt.Println("-----------------")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment