Skip to content

Instantly share code, notes, and snippets.

@dstahlke
Created August 1, 2021 07:48
Show Gist options
  • Save dstahlke/93fe8587bd95d3f2b064b43f2b4403cd to your computer and use it in GitHub Desktop.
Save dstahlke/93fe8587bd95d3f2b064b43f2b4403cd to your computer and use it in GitHub Desktop.
Walk as we count integers, turning right when it's prime.
using Primes
using StatsBase
using InteractiveViz
using GLMakie
function run(L, turns, zoom)
function xy_to_grid(x, y)
return round(Integer, L/2 + x*zoom), round(Integer, L/2 + y*zoom)
end
img = zeros(Int32, L, L)
x = 0
y = 0
dx = 1
dy = 0
n = 1
for p in turns
while n < p
x += dx
y += dy
i, j = xy_to_grid(x, y)
if i >= 1 && j >= 1 && i <= L && j <= L
img[i, j] += 1
end
n += 1
end
dx, dy = dy, -dx
end
return img
end
N = 1_000_000_000
T = primes(N)
#T = filter(x -> rand() < 1/log(x), 1:N)
@time img = run(2_000, T, 1//150)
@show entropy(img / sum(img)) / log(2)
iheatmap(log.(1 .+ img))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment