mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
524 B
36 lines
524 B
5 years ago
|
package main
|
||
|
|
||
5 years ago
|
func recursion(b board, a []tetrimino, idx int) bool {
|
||
|
if idx == len(a) {
|
||
5 years ago
|
return true
|
||
|
}
|
||
|
for i := range b {
|
||
|
for j := range b[i] {
|
||
5 years ago
|
if !b.check(i, j, a[idx]) {
|
||
5 years ago
|
continue
|
||
|
}
|
||
5 years ago
|
b.put(i, j, idx, a[idx])
|
||
|
if recursion(b, a, idx+1) {
|
||
5 years ago
|
return true
|
||
|
}
|
||
5 years ago
|
b.remove(i, j, a[idx])
|
||
5 years ago
|
}
|
||
|
}
|
||
|
return false
|
||
|
}
|
||
|
|
||
5 years ago
|
func solve(a []tetrimino) board {
|
||
5 years ago
|
square := 2
|
||
5 years ago
|
for square*square < len(a)*4 {
|
||
5 years ago
|
square++
|
||
|
}
|
||
|
for {
|
||
|
b := makeBoard(square)
|
||
|
square++
|
||
5 years ago
|
if !recursion(b, a, 0) {
|
||
5 years ago
|
continue
|
||
|
}
|
||
|
return b
|
||
|
}
|
||
|
}
|