Last active
April 20, 2022 20:48
-
-
Save geotheory/99b1521e1e1ee0fcabe6da0927d7a135 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c1 = as.matrix(readr::read_csv("comp,x1,x2,y1,y2 | |
1,0,1,2,2 | |
2,0,1,1,1 | |
3,0,1,2,1 | |
4,0,1,1,2 | |
5,0,1,2,2 | |
5,0,1,1,2 | |
6,1,1,1,2 | |
7,1,1,1,2 | |
7,0,1,2,2 | |
8,1,1,1,2 | |
8,0,1,1,1 | |
9,1,1,1,2 | |
9,0,1,2,2 | |
9,0,1,1,1")) | |
c10 = do.call('rbind', lapply(1:14, function(x) c(1e1, -1, -1, 1, 1))) | |
c100 = do.call('rbind', lapply(1:14, function(x) c(1e2, 1, 1, -1, -1))) | |
c1000 = do.call('rbind', lapply(1:14, function(x) c(1e3, -1, -1, -1, -1))) | |
cn = do.call('rbind', lapply(list(1, c10, c100, c1000), function(x) x * c1)) | |
cn = rbind(t(c(0,0,0,-2,2)), cn) | |
cn_numeral = function(x){ | |
x0 = x | |
x[x > 9999 | x < 0] = NA | |
x_sep = lapply(strsplit(as.character(x), ''), function(cx) c(as.integer(cx),0) * tail(c(1000,100,10,1,0), length(cx)+1)) | |
cn_sets = lapply(x_sep, function(x) cn[cn[,1] %in% x,,drop=FALSE]) | |
cn_sets[is.na(x)] = list(t(c(number = NA, x1 = NA, x2 = NA, y1 = NA, y2 = NA))) | |
cn_sets = lapply(seq_along(cn_sets), function(i){ x = cn_sets[[i]]; cbind(x, id = i) }) | |
cn_df = as.data.frame(do.call('rbind', cn_sets)) | |
cn_df$number = x0[cn_df$id] | |
cn_df | |
} | |
#------------------------------------------------------ | |
require(primes) | |
require(ggplot2) | |
p = generate_primes(1, 9999) | |
d = cn_numeral(p) | |
d[,2:5] = d[,2:5] / 3 # down-scale numerals | |
n = 39 | |
d$x = 1 + ((d$id - 1) %% n) | |
d$y = -floor(((d$id - 1) / n) + 1) * 2 | |
ggplot(d, aes(x + x1, y + y1, xend = x + x2, yend = y + y2)) + | |
geom_segment(size=.4, lineend = 'round') + | |
theme_void() + | |
coord_fixed(ratio = 1) | |
ggsave('cisterian-primes.svg', w=6, h=12) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment