Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
# Answer to the Fiddler On the Proof newsletter for Jan 12, 2024
from fractions import Fraction
from itertools import combinations
dice_values = [4, 6, 8, 10, 12, 20]
# Part 1
probs = []
#!/usr/bin/env python3
#
# Author: Lowell Vaughn
# Answer to The "Fiddler on the Proof" for November 17, 2023
# https://open.substack.com/pub/thefiddler/p/can-you-flip-the-coins-exactly-as
from collections import Counter
from fractions import Fraction
from typing import Tuple
#!/usr/bin/env python3
#
# Answer to the 538 Riddler for Sept 9, 2022
#
# https://fivethirtyeight.com/features/can-you-cover-the-baking-sheet-with-cookies/
import sys
def find_combos(n_soldiers, n_castles):
#!/usr/bin/env python3
#
# Answer to the 538 Riddler Express for Nov 12, 2021
# Author: Lowell Vaughn
def generate_roles(dice):
""" Generates a list of lists enumerating all of outcomes of rolling a set of dice of
various numbers of sides. For instance, generate_roles([4, 6, 8]) will return a list
of all outcomes from rolling 4-sided, 6-sized, and 8-sided die (in that order)
"""
@lvaughn
lvaughn / clever.py
Created August 14, 2021 20:16
My answer to 538's Riddler Express for 8/13/2021
#!/usr/bin/env python3
#
# A script that answers the Riddler Express for 8/13/21 three different ways
# https://fivethirtyeight.com/features/are-you-clever-enough/
#
# 1) Using a Monte Carlo simulation with the possibility of resample
# 2) Slow Monte Carlo that doesn't have resample
# 3) Calculating the odds using a Binomial Distribution and averaging it across the
# all the percentiles form 90th to 99.999th
#
#!/usr/bin/env python3
# Answer for the 538 Ridder Express for 5/28/21
#
# https://fivethirtyeight.com/features/can-you-crack-the-case-of-the-crystal-key/
N_TEAMS = 30
N_GAMES = 162
EPSILON = 10e-16
@lvaughn
lvaughn / jenga.py
Created February 21, 2021 15:25
Answer to the fivethirtyeight.com riddler for Feb 19, 2021
#!/usr/bin/env python3
#
# Answer for the 538 Riddler for Feb 18, 2021 (https://fivethirtyeight.com/features/can-you-win-riddler-jenga/)
#
# Author: Lowell Vaughn
#
# This performs a Monte Carlo simulation of stacking the Jenga blocks and
# finds out at which point they would fall over.
#
# For this simulation all blocks are of width 1, and the first block is always placed at location 0.
#!/usr/bin/env python3
#
# The solution to 538's Riddler for 1/15/2021
#
# https://fivethirtyeight.com/features/can-you-hunt-for-the-mysterious-numbers/
from itertools import permutations
def find_breakdowns(n, digits, highest):
#!/usr/bin/env python3
# Code to help answer the Riddler Express from 11/13/2020:
# https://fivethirtyeight.com/features/can-you-snatch-defeat-from-the-jaws-of-victory/
from fractions import Fraction
import random
TOTAL_ON_BOARD = (2 + 4 + 6 + 8 + 10) * 100 * 6 # Total amount a Jeopardy! board is worth
#!/usr/bin/env python3
#
# Solution to the 538 Riddler Express for 2020-10-02
# https://fivethirtyeight.com/features/can-you-eat-all-the-chocolates/
from math import sqrt
# The number we're checking for "hippness"
target = 1400