Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
44
Task/Mian-Chowla-sequence/Go/mian-chowla-sequence-1.go
Normal file
44
Task/Mian-Chowla-sequence/Go/mian-chowla-sequence-1.go
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func contains(is []int, s int) bool {
|
||||
for _, i := range is {
|
||||
if s == i {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func mianChowla(n int) []int {
|
||||
mc := make([]int, n)
|
||||
mc[0] = 1
|
||||
is := []int{2}
|
||||
var sum int
|
||||
for i := 1; i < n; i++ {
|
||||
le := len(is)
|
||||
jloop:
|
||||
for j := mc[i-1] + 1; ; j++ {
|
||||
mc[i] = j
|
||||
for k := 0; k <= i; k++ {
|
||||
sum = mc[k] + j
|
||||
if contains(is, sum) {
|
||||
is = is[0:le]
|
||||
continue jloop
|
||||
}
|
||||
is = append(is, sum)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return mc
|
||||
}
|
||||
|
||||
func main() {
|
||||
mc := mianChowla(100)
|
||||
fmt.Println("The first 30 terms of the Mian-Chowla sequence are:")
|
||||
fmt.Println(mc[0:30])
|
||||
fmt.Println("\nTerms 91 to 100 of the Mian-Chowla sequence are:")
|
||||
fmt.Println(mc[90:100])
|
||||
}
|
||||
42
Task/Mian-Chowla-sequence/Go/mian-chowla-sequence-2.go
Normal file
42
Task/Mian-Chowla-sequence/Go/mian-chowla-sequence-2.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type set map[int]bool
|
||||
|
||||
func mianChowla(n int) []int {
|
||||
mc := make([]int, n)
|
||||
mc[0] = 1
|
||||
is := make(set, n*(n+1)/2)
|
||||
is[2] = true
|
||||
var sum int
|
||||
isx := make([]int, 0, n)
|
||||
for i := 1; i < n; i++ {
|
||||
isx = isx[:0]
|
||||
jloop:
|
||||
for j := mc[i-1] + 1; ; j++ {
|
||||
mc[i] = j
|
||||
for k := 0; k <= i; k++ {
|
||||
sum = mc[k] + j
|
||||
if is[sum] {
|
||||
isx = isx[:0]
|
||||
continue jloop
|
||||
}
|
||||
isx = append(isx, sum)
|
||||
}
|
||||
for _, x := range isx {
|
||||
is[x] = true
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return mc
|
||||
}
|
||||
|
||||
func main() {
|
||||
mc := mianChowla(100)
|
||||
fmt.Println("The first 30 terms of the Mian-Chowla sequence are:")
|
||||
fmt.Println(mc[0:30])
|
||||
fmt.Println("\nTerms 91 to 100 of the Mian-Chowla sequence are:")
|
||||
fmt.Println(mc[90:100])
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue