This file contains 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
library(tidyverse) | |
answers <- | |
read_csv("https://git.io/fjoZ2") %>% | |
mutate(rounded = round(pick_a_random_number_from_1_10)) %>% | |
filter(!is.na(rounded)) | |
modulo_rng <- function(n, data) { | |
data %>% |
This file contains 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
''' | |
How many turns does it take to complete a game of Concentration? | |
https://en.wikipedia.org/wiki/Concentration_(game) | |
With perfect memory and strategy, for a game of n pairs, this converges to | |
(approximately) 1.61n moves. | |
https://www.jstor.org/stable/10.4169/amer.math.monthly.120.09.787 | |
What about with imperfect memory? | |
''' |
This file contains 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
library(tidyverse) | |
year <- 2019 | |
start_date <- lubridate::date(str_glue("{year}-01-01")) # there must be a better way?? | |
month_colours <- c( | |
"January" = "#a5cdff", | |
"February" = "#c9e1ff", | |
"March" = "#b2edb6", |
This file contains 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
import os | |
import urllib.request | |
import bs4 | |
import progressbar | |
import requests | |
URL = 'http://esperantofre.com/zagreb/zagreba.htm' | |
IMG_DIR = os.path.join(os.path.dirname(__file__), 'zagreba-metodo') |
This file contains 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
library(tidyverse) | |
# https://math.stackexchange.com/questions/35791/birthday-problem-expected-number-of-collisions | |
exp_collisions <- function(n, d) { | |
n * (1 - (1 - (1 / d)) ^ (n - 1)) | |
} | |
tibble(n = 1:80) %>% | |
mutate(collisions = exp_collisions(n, 365)) %>% | |
ggplot(aes(x = n, y = collisions)) + |
This file contains 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
library(tidyverse) | |
library(rvest) | |
url <- "https://en.wikipedia.org/wiki/List_of_minimum_annual_leave_by_country" | |
clean_colnames <- | |
. %>% | |
str_to_lower() %>% | |
str_remove_all("\\[.*\\]") %>% | |
str_remove_all("\\(.*\\)") %>% |
This file contains 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
suppressPackageStartupMessages({ | |
library(tidyverse) | |
library(sf) | |
}) | |
# c.f. http://web.mit.edu/tee/www/bertrand/problem.html | |
chord_length <- function(theta) { | |
2 * sin(theta / 2) | |
} |
This file contains 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
lower_bound <- function(d) { | |
(1 - sqrt(1 - 2*d)) / 2 | |
} | |
upper_bound <- function(d) { | |
(1 + sqrt(1 - 2*d)) / 2 | |
} | |
tibble(d = seq(0, 0.5, 0.001), | |
lower = lower_bound(d), |
This file contains 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
to_clipboard <- function(data) { | |
clip <- pipe("pbcopy", "w") | |
write.table(data, file = clip, row.names = FALSE) | |
close(clip) | |
} |
This file contains 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
benchmark <- | |
games %>% | |
mutate( | |
outcome = case_when( | |
hgoals > agoals ~ "home_win", | |
agoals > hgoals ~ "away_win", | |
hgoals == agoals ~ "draw" | |
) | |
) %>% | |
count(outcome) %>% |