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.
73 lines
988 B
73 lines
988 B
5 years ago
|
package main
|
||
|
|
||
5 years ago
|
import "./student"
|
||
|
|
||
|
func game23(a, b int) int {
|
||
|
if a > b {
|
||
|
return -1
|
||
|
}
|
||
|
if a == b {
|
||
|
return 0
|
||
|
}
|
||
|
if Game23(a*2, b) != -1 {
|
||
|
return 1 + Game23(a*2, b)
|
||
|
}
|
||
|
if Game23(a*3, b) != -1 {
|
||
|
return 1 + Game23(a*3, b)
|
||
|
}
|
||
|
return -1
|
||
|
}
|
||
5 years ago
|
|
||
|
func nd(a, b int) int {
|
||
|
if a > b {
|
||
|
return -1
|
||
|
}
|
||
|
if a == b {
|
||
|
return 0
|
||
|
}
|
||
|
if nd(a*2, b) != -1 {
|
||
|
return 1 + nd(a*2, b)
|
||
|
}
|
||
|
if nd(a*3, b) != -1 {
|
||
|
return 1 + nd(a*3, b)
|
||
|
}
|
||
|
return -1
|
||
|
}
|
||
|
|
||
5 years ago
|
func main() {
|
||
5 years ago
|
type node struct {
|
||
|
init int
|
||
|
fin int
|
||
|
}
|
||
5 years ago
|
table := []node{
|
||
|
{50, 43},
|
||
|
{13, 13},
|
||
|
{10, 9},
|
||
|
{5, 9},
|
||
|
}
|
||
5 years ago
|
|
||
|
for i := 0; i < 20; i++ {
|
||
5 years ago
|
table = append(table, node{
|
||
5 years ago
|
init: lib.RandIntBetween(1, 1000),
|
||
|
fin: lib.RandIntBetween(1, 1000),
|
||
5 years ago
|
})
|
||
5 years ago
|
}
|
||
|
|
||
|
for i := 1; i < 100; i++ {
|
||
|
value := node{
|
||
|
init: 1,
|
||
|
fin: 1,
|
||
|
}
|
||
|
if nd(1, i) > 0 {
|
||
|
value = node{
|
||
|
init: 1,
|
||
|
fin: i,
|
||
|
}
|
||
|
}
|
||
|
table = append(table, value)
|
||
|
}
|
||
|
for _, arg := range table {
|
||
5 years ago
|
lib.Challenge("Game23", student.Game23, game23, arg.init, arg.fin)
|
||
5 years ago
|
}
|
||
|
}
|