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,68 @@
package main
import (
"fmt"
"time"
)
func sumDigits(n int) int {
sum := 0
for n > 0 {
sum += n % 10
n /= 10
}
return sum
}
func max(x, y int) int {
if x > y {
return x
}
return y
}
func main() {
st := time.Now()
count := 0
var selfs []int
i := 1
pow := 10
digits := 1
offset := 9
lastSelf := 0
for count < 1e8 {
isSelf := true
start := max(i-offset, 0)
sum := sumDigits(start)
for j := start; j < i; j++ {
if j+sum == i {
isSelf = false
break
}
if (j+1)%10 != 0 {
sum++
} else {
sum = sumDigits(j + 1)
}
}
if isSelf {
count++
lastSelf = i
if count <= 50 {
selfs = append(selfs, i)
if count == 50 {
fmt.Println("The first 50 self numbers are:")
fmt.Println(selfs)
}
}
}
i++
if i%pow == 0 {
pow *= 10
digits++
offset = digits * 9
}
}
fmt.Println("\nThe 100 millionth self number is", lastSelf)
fmt.Println("Took", time.Since(st))
}

View file

@ -0,0 +1,63 @@
package main
import (
"fmt"
"time"
)
func sieve() []bool {
sv := make([]bool, 2*1e9+9*9 + 1)
n := 0
var s [8]int
for a := 0; a < 2; a++ {
for b := 0; b < 10; b++ {
s[0] = a + b
for c := 0; c < 10; c++ {
s[1] = s[0] + c
for d := 0; d < 10; d++ {
s[2] = s[1] + d
for e := 0; e < 10; e++ {
s[3] = s[2] + e
for f := 0; f < 10; f++ {
s[4] = s[3] + f
for g := 0; g < 10; g++ {
s[5] = s[4] + g
for h := 0; h < 10; h++ {
s[6] = s[5] + h
for i := 0; i < 10; i++ {
s[7] = s[6] + i
for j := 0; j < 10; j++ {
sv[s[7]+j+n] = true
n++
}
}
}
}
}
}
}
}
}
}
return sv
}
func main() {
st := time.Now()
sv := sieve()
count := 0
fmt.Println("The first 50 self numbers are:")
for i := 0; i < len(sv); i++ {
if !sv[i] {
count++
if count <= 50 {
fmt.Printf("%d ", i)
}
if count == 1e8 {
fmt.Println("\n\nThe 100 millionth self number is", i)
break
}
}
}
fmt.Println("Took", time.Since(st))
}

View file

@ -0,0 +1,76 @@
package main
import (
"fmt"
"time"
)
const MAX_COUNT = 103*1e4*1e4 + 11*9 + 1
var sv = make([]bool, MAX_COUNT+1)
var digitSum = make([]int, 1e4)
func init() {
i := 9999
var s, t int
for a := 9; a >= 0; a-- {
for b := 9; b >= 0; b-- {
s = a + b
for c := 9; c >= 0; c-- {
t = s + c
for d := 9; d >= 0; d-- {
digitSum[i] = t + d
i--
}
}
}
}
}
func sieve() {
n := 0
for a := 0; a < 103; a++ {
for b := 0; b < 1e4; b++ {
s := digitSum[a] + digitSum[b] + n
for c := 0; c < 1e4; c++ {
sv[digitSum[c]+s] = true
s++
}
n += 1e4
}
}
}
func main() {
st := time.Now()
sieve()
fmt.Println("Sieving took", time.Since(st))
count := 0
fmt.Println("\nThe first 50 self numbers are:")
for i := 0; i < len(sv); i++ {
if !sv[i] {
count++
if count <= 50 {
fmt.Printf("%d ", i)
} else {
fmt.Println("\n\n Index Self number")
break
}
}
}
count = 0
limit := 1
for i := 0; i < len(sv); i++ {
if !sv[i] {
count++
if count == limit {
fmt.Printf("%10d %11d\n", count, i)
limit *= 10
if limit == 1e10 {
break
}
}
}
}
fmt.Println("\nOverall took", time.Since(st))
}