Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View 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])
}

View 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])
}