Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- )
- var (
- ways = make([][][]rune, 0)
- count int
- )
- func rev(matrix [][]rune) [][]rune {
- new := defaultMatrix(len(matrix))
- for i := 0; i < len(matrix); i++ {
- for j := 0; j < len(matrix[i]); j++ {
- new[len(matrix)-i-1][j] = matrix[i][j]
- }
- }
- return new
- }
- func copy(matrix [][]rune) [][]rune {
- duplicate := make([][]rune, len(matrix))
- for i := 0; i < len(matrix); i++ {
- duplicate[i] = make([]rune, len(matrix[0]))
- for j := 0; j < len(matrix[0]); j++ {
- duplicate[i][j] = matrix[i][j]
- }
- }
- return duplicate
- }
- func rec(i, j int, current [][]rune) {
- if i < len(current) && j < len(current[0]) {
- current[i][j] = '#'
- }
- if i == len(current)-1 && j == len(current[0])-1 {
- new := copy(current)
- ways = append(ways, new)
- printMatrix(new)
- return
- }
- if j < len(current[0]) {
- new := copy(current)
- rec(i+1, j, new)
- }
- if j < len(current[0]) {
- new := copy(current)
- rec(i, j+1, new)
- }
- }
- func printMatrix(slice [][]rune) {
- slice = rev(slice)
- count++
- fmt.Printf("[%d]\n", count)
- for i := 0; i < len(slice); i++ {
- for j := 0; j < len(slice[i]); j++ {
- fmt.Print(string(slice[i][j]))
- }
- fmt.Println()
- }
- fmt.Println()
- }
- func defaultMatrix(n int) [][]rune {
- matrix := make([][]rune, n)
- for i := 0; i < n; i++ {
- matrix[i] = make([]rune, n)
- for j := 0; j < n; j++ {
- if j >= i {
- matrix[i][j] = '.'
- } else {
- matrix[i][j] = ' '
- }
- }
- }
- matrix[0][0] = ' '
- return matrix
- }
- func main() {
- var n int
- fmt.Scanf("%d", &n)
- initial := defaultMatrix(n)
- rec(0, 1, initial)
- fmt.Println(len(ways))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement