2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,98 @@
package main
import (
"fmt"
"math/rand"
"time"
)
var (
n_range = []int{4, 64, 256, 1024, 4096}
M = 15
N = 15
)
const (
p = .5
t = 5
NOT_CLUSTERED = 1
cell2char = " #abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
)
func newgrid(n int, p float64) [][]int {
g := make([][]int, n)
for y := range g {
gy := make([]int, n)
for x := range gy {
if rand.Float64() < p {
gy[x] = 1
}
}
g[y] = gy
}
return g
}
func pgrid(cell [][]int) {
for n := 0; n < N; n++ {
fmt.Print(n%10, ") ")
for m := 0; m < M; m++ {
fmt.Printf(" %c", cell2char[cell[n][m]])
}
fmt.Println()
}
}
func cluster_density(n int, p float64) float64 {
cc := clustercount(newgrid(n, p))
return float64(cc) / float64(n) / float64(n)
}
func clustercount(cell [][]int) int {
walk_index := 1
for n := 0; n < N; n++ {
for m := 0; m < M; m++ {
if cell[n][m] == NOT_CLUSTERED {
walk_index++
walk_maze(m, n, cell, walk_index)
}
}
}
return walk_index - 1
}
func walk_maze(m, n int, cell [][]int, indx int) {
cell[n][m] = indx
if n < N-1 && cell[n+1][m] == NOT_CLUSTERED {
walk_maze(m, n+1, cell, indx)
}
if m < M-1 && cell[n][m+1] == NOT_CLUSTERED {
walk_maze(m+1, n, cell, indx)
}
if m > 0 && cell[n][m-1] == NOT_CLUSTERED {
walk_maze(m-1, n, cell, indx)
}
if n > 0 && cell[n-1][m] == NOT_CLUSTERED {
walk_maze(m, n-1, cell, indx)
}
}
func main() {
rand.Seed(time.Now().Unix())
cell := newgrid(N, .5)
fmt.Printf("Found %d clusters in this %d by %d grid\n\n",
clustercount(cell), N, N)
pgrid(cell)
fmt.Println()
for _, n := range n_range {
M = n
N = n
sum := 0.
for i := 0; i < t; i++ {
sum += cluster_density(n, p)
}
sim := sum / float64(t)
fmt.Printf("t=%3d p=%4.2f n=%5d sim=%7.5f\n", t, p, n, sim)
}
}

View file

@ -0,0 +1,49 @@
M=: (* 1+i.@$)?15 15$2
M
0 2 3 4 0 6 0 8 0 10 11 12 0 0 15
0 0 18 19 20 0 22 0 0 0 0 0 28 29 0
31 32 0 34 35 36 37 38 0 0 0 42 0 0 45
0 0 48 49 0 51 0 0 54 55 0 57 58 0 0
61 62 63 64 0 0 67 0 69 0 71 72 0 74 0
0 0 78 79 0 0 82 0 84 85 86 87 88 0 0
0 92 0 94 0 0 0 0 99 100 101 0 103 0 105
106 107 108 0 0 111 0 0 114 115 116 0 0 0 0
0 0 0 124 125 126 127 0 0 0 0 0 133 134 135
0 0 138 0 0 141 0 143 144 145 0 0 0 0 150
0 152 153 154 0 0 0 158 0 160 0 162 163 164 165
0 167 168 169 170 0 172 173 0 175 176 177 0 0 180
181 182 183 0 0 186 0 188 189 190 191 192 0 194 195
196 197 198 0 200 201 202 0 0 205 0 207 0 0 0
211 212 213 0 0 0 217 218 0 220 221 0 0 224 0
congeal M
0 94 94 94 0 6 0 8 0 12 12 12 0 0 15
0 0 94 94 94 0 94 0 0 0 0 0 29 29 0
32 32 0 94 94 94 94 94 0 0 0 116 0 0 45
0 0 94 94 0 94 0 0 116 116 0 116 116 0 0
94 94 94 94 0 0 82 0 116 0 116 116 0 74 0
0 0 94 94 0 0 82 0 116 116 116 116 116 0 0
0 108 0 94 0 0 0 0 116 116 116 0 116 0 105
108 108 108 0 0 141 0 0 116 116 116 0 0 0 0
0 0 0 141 141 141 141 0 0 0 0 0 221 221 221
0 0 213 0 0 141 0 221 221 221 0 0 0 0 221
0 213 213 213 0 0 0 221 0 221 0 221 221 221 221
0 213 213 213 213 0 221 221 0 221 221 221 0 0 221
213 213 213 0 0 218 0 221 221 221 221 221 0 221 221
213 213 213 0 218 218 218 0 0 221 0 221 0 0 0
213 213 213 0 0 0 218 218 0 221 221 0 0 224 0
(~.@, i. ])congeal M
0 1 1 1 0 2 0 3 0 4 4 4 0 0 5
0 0 1 1 1 0 1 0 0 0 0 0 6 6 0
7 7 0 1 1 1 1 1 0 0 0 8 0 0 9
0 0 1 1 0 1 0 0 8 8 0 8 8 0 0
1 1 1 1 0 0 10 0 8 0 8 8 0 11 0
0 0 1 1 0 0 10 0 8 8 8 8 8 0 0
0 12 0 1 0 0 0 0 8 8 8 0 8 0 13
12 12 12 0 0 14 0 0 8 8 8 0 0 0 0
0 0 0 14 14 14 14 0 0 0 0 0 15 15 15
0 0 16 0 0 14 0 15 15 15 0 0 0 0 15
0 16 16 16 0 0 0 15 0 15 0 15 15 15 15
0 16 16 16 16 0 15 15 0 15 15 15 0 0 15
16 16 16 0 0 17 0 15 15 15 15 15 0 15 15
16 16 16 0 17 17 17 0 0 15 0 15 0 0 0
16 16 16 0 0 0 17 17 0 15 15 0 0 18 0