Skip to content

Instantly share code, notes, and snippets.

@bbolker
Created December 20, 2022 20:54
Show Gist options
  • Save bbolker/7dd20df15650709288193402894ee484 to your computer and use it in GitHub Desktop.
Save bbolker/7dd20df15650709288193402894ee484 to your computer and use it in GitHub Desktop.
visualizing dreidel payoffs
## https://forward.com/fast-forward/389673/finally-mathematical-proof-that-dreidel-is-a-terrible-game/
## Feinerman, Robert. “An Ancient Unfair Game.” American Mathematical Monthly 83, no. 8 (1976). https://www.jstor.org/stable/2319887.
library(emdbook)
library(ggplot2)
library(rayshader)
library(colorspace)
pvec <- 2:5
nvec <- 2:20
dd <- expand.grid(p = pvec, n = nvec)
dd$payoff <- with(dd,
p/4 + (5/8)^(n-1)*(p-2)/8)
dd$payoff_sc <- with(dd,
(p/4 + (5/8)^(n-1)*(p-2)/8)/p)
gg0 <- ggplot(dd, aes(p, n)) + geom_raster(aes(fill=payoff_sc)) +
labs(x = "number of players", y = "spin") +
scale_x_continuous(position = "top", expand = c(0,0), breaks = pvec) +
scale_y_continuous(expand = c(0,0)) +
print(gg0)
## flip labels so they look good when plot is rotated
flip <- element_text(angle = 180)
gg1 <- gg0 + theme(legend.position = "none",
axis.title.x = flip,
axis.title.y = flip,
axis.text.x = flip,
axis.text.y = flip)
gg1R <- plot_gg(gg1, scale = 500)
rgl.snapshot("dreidel1.png")
theme_set(theme_bw(base_size=16))
gg2 <- ggplot(dd, aes(n, payoff_sc)) +
geom_line(aes(colour = factor(p), group = p), linewidth = 3) +
labs(x = "spin", y = "payoff\n(scaled by number of players)") +
scale_colour_discrete_sequential(palette = "Blues",
name="number of\nplayers")
print(gg2)
ggsave("dreidel2.R")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment