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
fairness_ratio <- function(coins, flips, trials = 10^6) { | |
all_heads <- rbinom(trials, flips, 1/2) == flips | |
is_unfair <- rbinom(trials, 1, 1 / coins) | |
ratio <- sum(all_heads & !is_unfair) / sum(is_unfair) | |
return(ratio) | |
} | |
# the problem as Daniel stated it | |
fairness_ratio(coins = 10000, flips = 10) |
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
WITH generate_date AS ( | |
SELECT CAST(RANGE AS DATE) AS date_key | |
FROM RANGE(DATE '2009-01-01', DATE '2013-12-31', INTERVAL 1 DAY) | |
) | |
SELECT date_key AS date_key, | |
DAYOFYEAR(date_key) AS day_of_year, | |
YEARWEEK(date_key) AS week_key, | |
WEEKOFYEAR(date_key) AS week_of_year, | |
DAYOFWEEK(date_key) AS day_of_week, | |
ISODOW(date_key) AS iso_day_of_week, |