Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Van-Eck-sequence/Go/van-eck-sequence-1.go
Normal file
20
Task/Van-Eck-sequence/Go/van-eck-sequence-1.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
const max = 1000
|
||||
a := make([]int, max) // all zero by default
|
||||
for n := 0; n < max-1; n++ {
|
||||
for m := n - 1; m >= 0; m-- {
|
||||
if a[m] == a[n] {
|
||||
a[n+1] = n - m
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Println("The first ten terms of the Van Eck sequence are:")
|
||||
fmt.Println(a[:10])
|
||||
fmt.Println("\nTerms 991 to 1000 of the sequence are:")
|
||||
fmt.Println(a[990:])
|
||||
}
|
||||
19
Task/Van-Eck-sequence/Go/van-eck-sequence-2.go
Normal file
19
Task/Van-Eck-sequence/Go/van-eck-sequence-2.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
const max = 1000
|
||||
a := make([]int, max) // all zero by default
|
||||
seen := make(map[int]int)
|
||||
for n := 0; n < max-1; n++ {
|
||||
if m, ok := seen[a[n]]; ok {
|
||||
a[n+1] = n - m
|
||||
}
|
||||
seen[a[n]] = n
|
||||
}
|
||||
fmt.Println("The first ten terms of the Van Eck sequence are:")
|
||||
fmt.Println(a[:10])
|
||||
fmt.Println("\nTerms 991 to 1000 of the sequence are:")
|
||||
fmt.Println(a[990:])
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue