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
#!/usr/bin/env python3 | |
# | |
# Code to solve this week's 538 Riddler: | |
# | |
# https://fivethirtyeight.com/features/can-you-break-a-very-expensive-centrifuge/ | |
import itertools | |
import math | |
# Slots and their locations (with an x/y plane) |
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
#!/usr/bin/env python3 | |
# | |
# My answer for the riddler express for July 24, 2020 | |
# lowell@lowellvaughn.com | |
# | |
# https://fivethirtyeight.com/features/are-you-a-pinball-wizard/ | |
from itertools import chain, combinations | |
def all_subsets(ls): |
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
#!/usr/bin/env python3 | |
# Solution for the Riddler Express for Mar 27, 2020 | |
# | |
# https://fivethirtyeight.com/features/can-you-get-the-gloves-out-of-the-box/ | |
# Author: lowell@lowellvaughn.com | |
cache = {0: 1, | |
1: None, | |
2: 1, | |
3: 1} |
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
#!/usr/bin/env python3 | |
# | |
# My solution to the 538 Riddler for Feb 7, 2020 | |
# | |
# https://fivethirtyeight.com/features/how-many-more-palindrome-dates-will-you-see/ | |
# | |
# The basic approach is to recursively work out all of the possible ways you can parse the | |
# string and have the |'s balance out | |
# | |
# E.g., |-1|-2|-3| can evaluate to two different values |
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
#!/usr/bin/env python3 | |
# | |
# My solution to https://fivethirtyeight.com/features/can-you-find-a-number-worth-its-weight-in-letters/ | |
from fractions import Fraction | |
import sys | |
# Since 1/2020 == 2/4040 and 1/2019==2/4038, 2/4039 is between them, so | |
# 4039 is an upper bound |
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
#!/usr/bin/env python3 | |
# | |
# Solution to this week's "Riddler classic" | |
# | |
# https://fivethirtyeight.com/features/can-you-solve-the-vexing-vexillology/ | |
# | |
# The general approach is to create a mapping from all of the words in the list | |
# and index them by their set of unique letters. Then for every possible lattice | |
# find all the subsets and find the sum of all the scores for each subset. Then | |
# just find the highest score. |
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
#!/usr/bin/env python | |
# | |
# This solves the "Riddler Classic" problem from | |
# https://fivethirtyeight.com/features/how-long-is-the-snails-slimy-trail/ | |
# | |
# It's brute force, but runs in 33 seconds on a 5 year old MacBook Pro, | |
# so I'm calling it good enough | |
import itertools |
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
#!/usr/bin/env python | |
# | |
# Solution for https://fivethirtyeight.com/features/can-you-help-dakota-jones-raid-the-lost-arc/ | |
# | |
# This is a "cheap and cheerful" solution. You could probably do something faster | |
# using dynamic programing, but this works in a reasonable amount of time. | |
from collections import defaultdict | |
# Abbreviation list from the USPS https://pe.usps.com/text/pub28/28apb.htm |
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
#!/usr/bin/env python | |
# A solution for FiveThirtyEight's Riddler for 2019.05.10 | |
# https://fivethirtyeight.com/features/can-the-riddler-bros-beat-joe-dimaggios-hitting-streak/ | |
# | |
# Adapted from solution at https://www.askamathematician.com/2010/07/q-whats-the-chance-of-getting-a-run-of-k-successes-in-n-bernoulli-trials-why-use-approximations-when-the-exact-answer-is-known/ | |
# | |
# Usage: hit_streak.py batting_average number_of_seasons | |
import sys |
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
#!/usr/bin/env python | |
from collections import defaultdict | |
GAMES_FILE = 'womens.txt' | |
WINNER = 'Baylor' | |
# Maps team name to a set of teams they lost to | |
beat_by = defaultdict(set) |