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
| stopifnot(requireNamespace("rlang")) | |
| rlang::check_installed("pak") | |
| pkgs <- rlang::chr( | |
| "rlang" = "rlang", | |
| "plumber2" = "posit-dev/plumber2", | |
| "S7", | |
| "jsonlite", | |
| "httr2", | |
| "mirai", |
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
| 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 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
| 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, |