Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
45
Task/Left-factorials/Go/left-factorials.go
Normal file
45
Task/Left-factorials/Go/left-factorials.go
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Print("!0 through !10: 0")
|
||||
one := big.NewInt(1)
|
||||
n := big.NewInt(1)
|
||||
f := big.NewInt(1)
|
||||
l := big.NewInt(1)
|
||||
next := func() { f.Mul(f, n); l.Add(l, f); n.Add(n, one) }
|
||||
for ; ; next() {
|
||||
fmt.Print(" ", l)
|
||||
if n.Int64() == 10 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
for {
|
||||
for i := 0; i < 10; i++ {
|
||||
next()
|
||||
}
|
||||
fmt.Printf("!%d: %d\n", n, l)
|
||||
if n.Int64() == 110 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fmt.Println("Lengths of !1000 through !10000 by thousands:")
|
||||
for i := 110; i < 1000; i++ {
|
||||
next()
|
||||
}
|
||||
for {
|
||||
fmt.Print(" ", len(l.String()))
|
||||
if n.Int64() == 10000 {
|
||||
break
|
||||
}
|
||||
for i := 0; i < 1000; i++ {
|
||||
next()
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue