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,46 @@
package main
import (
"bytes"
"fmt"
"math/rand"
"time"
)
const (
nPts = 100
rMin = 10
rMax = 15
)
func main() {
rand.Seed(time.Now().Unix())
span := rMax + 1 + rMax
rows := make([][]byte, span)
for r := range rows {
rows[r] = bytes.Repeat([]byte{' '}, span*2)
}
u := 0 // count unique points
min2 := rMin * rMin
max2 := rMax * rMax
for n := 0; n < nPts; {
x := rand.Intn(span) - rMax
y := rand.Intn(span) - rMax
// x, y is the generated coordinate pair
rs := x*x + y*y
if rs < min2 || rs > max2 {
continue
}
n++ // count pair as meeting condition
r := y + rMax
c := (x + rMax) * 2
if rows[r][c] == ' ' {
rows[r][c] = '*'
u++
}
}
for _, row := range rows {
fmt.Println(string(row))
}
fmt.Println(u, "unique points")
}

View file

@ -0,0 +1,48 @@
package main
import (
"bytes"
"fmt"
"math/rand"
"time"
)
const (
nPts = 100
rMin = 10
rMax = 15
)
func main() {
rand.Seed(time.Now().Unix())
var poss []struct{ x, y int }
min2 := rMin * rMin
max2 := rMax * rMax
for y := -rMax; y <= rMax; y++ {
for x := -rMax; x <= rMax; x++ {
if r2 := x*x + y*y; r2 >= min2 && r2 <= max2 {
poss = append(poss, struct{ x, y int }{x, y})
}
}
}
fmt.Println(len(poss), "possible points")
span := rMax + 1 + rMax
rows := make([][]byte, span)
for r := range rows {
rows[r] = bytes.Repeat([]byte{' '}, span*2)
}
u := 0
for n := 0; n < nPts; n++ {
i := rand.Intn(len(poss))
r := poss[i].y + rMax
c := (poss[i].x + rMax) * 2
if rows[r][c] == ' ' {
rows[r][c] = '*'
u++
}
}
for _, row := range rows {
fmt.Println(string(row))
}
fmt.Println(u, "unique points")
}