Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
62
Task/Fractran/Go/fractran-1.go
Normal file
62
Task/Fractran/Go/fractran-1.go
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math/big"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func compile(src string) ([]big.Rat, bool) {
|
||||
s := strings.Fields(src)
|
||||
r := make([]big.Rat, len(s))
|
||||
for i, s1 := range s {
|
||||
if _, ok := r[i].SetString(s1); !ok {
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
return r, true
|
||||
}
|
||||
|
||||
func exec(p []big.Rat, n *big.Int, limit int) {
|
||||
var q, r big.Int
|
||||
rule:
|
||||
for i := 0; i < limit; i++ {
|
||||
fmt.Printf("%d ", n)
|
||||
for j := range p {
|
||||
q.QuoRem(n, p[j].Denom(), &r)
|
||||
if r.BitLen() == 0 {
|
||||
n.Mul(&q, p[j].Num())
|
||||
continue rule
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
func usage() {
|
||||
log.Fatal("usage: ft <limit> <n> <prog>")
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 4 {
|
||||
usage()
|
||||
}
|
||||
limit, err := strconv.Atoi(os.Args[1])
|
||||
if err != nil {
|
||||
usage()
|
||||
}
|
||||
var n big.Int
|
||||
_, ok := n.SetString(os.Args[2], 10)
|
||||
if !ok {
|
||||
usage()
|
||||
}
|
||||
p, ok := compile(os.Args[3])
|
||||
if !ok {
|
||||
usage()
|
||||
}
|
||||
exec(p, &n, limit)
|
||||
}
|
||||
35
Task/Fractran/Go/fractran-2.go
Normal file
35
Task/Fractran/Go/fractran-2.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math/big"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c := exec.Command("ft", "1000000", "2", `17/91 78/85 19/51 23/38
|
||||
29/33 77/29 95/23 77/19 1/17 11/13 13/11 15/14 15/2 55/1`)
|
||||
c.Stderr = os.Stderr
|
||||
r, err := c.StdoutPipe()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err = c.Start(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
var n big.Int
|
||||
for primes := 0; primes < 20; {
|
||||
if _, err = fmt.Fscan(r, &n); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
l := n.BitLen() - 1
|
||||
n.SetBit(&n, l, 0)
|
||||
if n.BitLen() == 0 && l > 1 {
|
||||
fmt.Printf("%d ", l)
|
||||
primes++
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue