Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
19
Task/Man-or-boy-test/Go/man-or-boy-test-1.go
Normal file
19
Task/Man-or-boy-test/Go/man-or-boy-test-1.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package main
|
||||
import "fmt"
|
||||
|
||||
func a(k int, x1, x2, x3, x4, x5 func() int) int {
|
||||
var b func() int
|
||||
b = func() int {
|
||||
k--
|
||||
return a(k, b, x1, x2, x3, x4)
|
||||
}
|
||||
if k <= 0 {
|
||||
return x4() + x5()
|
||||
}
|
||||
return b()
|
||||
}
|
||||
|
||||
func main() {
|
||||
x := func(i int) func() int { return func() int { return i } }
|
||||
fmt.Println(a(10, x(1), x(-1), x(-1), x(1), x(0)))
|
||||
}
|
||||
24
Task/Man-or-boy-test/Go/man-or-boy-test-2.go
Normal file
24
Task/Man-or-boy-test/Go/man-or-boy-test-2.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func A(k int, x1, x2, x3, x4, x5 func() int) (a int) {
|
||||
var B func() int
|
||||
B = func() (b int) {
|
||||
k--
|
||||
a = A(k, B, x1, x2, x3, x4)
|
||||
b = a
|
||||
return
|
||||
}
|
||||
if k <= 0 {
|
||||
a = x4() + x5()
|
||||
} else {
|
||||
_ = B()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
K := func(x int) func() int { return func() int { return x } }
|
||||
fmt.Println(A(10, K(1), K(-1), K(-1), K(1), K(0)))
|
||||
}
|
||||
34
Task/Man-or-boy-test/Go/man-or-boy-test-3.go
Normal file
34
Task/Man-or-boy-test/Go/man-or-boy-test-3.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func eval(v interface{}) int {
|
||||
switch v := v.(type) {
|
||||
case int:
|
||||
return v
|
||||
case func() int:
|
||||
return v()
|
||||
}
|
||||
panic("bad type")
|
||||
return 0
|
||||
}
|
||||
|
||||
func A(k int, x1, x2, x3, x4, x5 interface{}) (a int) {
|
||||
var B func() int
|
||||
B = func() (b int) {
|
||||
k--
|
||||
a = A(k, B, x1, x2, x3, x4)
|
||||
b = a
|
||||
return
|
||||
}
|
||||
if k <= 0 {
|
||||
a = eval(x4) + eval(x5)
|
||||
} else {
|
||||
_ = B()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println(A(10, 1, -1, -1, 1, 0))
|
||||
}
|
||||
49
Task/Man-or-boy-test/Go/man-or-boy-test-4.go
Normal file
49
Task/Man-or-boy-test/Go/man-or-boy-test-4.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
func A(k int) *big.Int {
|
||||
if k < 6 {
|
||||
var x1, x2, x3, x4 int64 = 1, -1, -1, 1
|
||||
c1 := []int64{0, 0, 0, 1, 2, 3}[k]
|
||||
c2 := []int64{0, 0, 1, 1, 1, 2}[k]
|
||||
c3 := []int64{0, 1, 1, 0, 0, 1}[k]
|
||||
c4 := []int64{1, 1, 0, 0, 0, 0}[k]
|
||||
t := c1*x1 + c2*x2 + c3*x3 + c4*x4
|
||||
return big.NewInt(t)
|
||||
}
|
||||
one := big.NewInt(1)
|
||||
c0 := big.NewInt(3)
|
||||
c1 := big.NewInt(2)
|
||||
c2 := big.NewInt(1)
|
||||
c3 := big.NewInt(0)
|
||||
for j := 5; j < k; j++ {
|
||||
c3.Sub(c3.Add(c3, c0), one)
|
||||
c0.Add(c0, c1)
|
||||
c1.Add(c1, c2)
|
||||
c2.Add(c2, c3)
|
||||
}
|
||||
return c0.Add(c0.Sub(c0.Sub(c0, c1), c2), c3)
|
||||
}
|
||||
|
||||
func p(k int) {
|
||||
fmt.Printf("A(%d) = ", k)
|
||||
if s := A(k).String(); len(s) < 60 {
|
||||
fmt.Println(s)
|
||||
} else {
|
||||
fmt.Printf("%s...%s (%d digits)\n",
|
||||
s[:6], s[len(s)-5:], len(s)-1)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
for i := 0; i < 40; i++ {
|
||||
p(i)
|
||||
}
|
||||
p(500)
|
||||
p(10000)
|
||||
p(1e6)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue