Skip to content

Instantly share code, notes, and snippets.

@Radcliffe
Radcliffe / domino-tilings-by-height.csv
Created June 22, 2016 15:15
Number of domino tilings of an 8x8 chessboard, by height.
height n
0 1
1 1
2 2
3 5
4 10
5 18
6 32
7 59
8 102
@Radcliffe
Radcliffe / four-fours.py
Last active July 3, 2022 06:45
Python solver for puzzles like the "Four Fours" puzzle.
# This Python 3 script solves the "Four Fours" problem and similar problems.
# The example at the end of the script generates all combinations of [2,3,5,7]
# that equal 10, using the operations of addition, subtraction, multiplication,
# and division.
# Exact arithmetic is used. Only integer exponents between -99 and 99 are allowed.
from fractions import Fraction
@Radcliffe
Radcliffe / 538.py
Last active October 17, 2016 23:29
Get most recent US presidential election predictions from FiveThirtyEight.com
import requests
from bs4 import BeautifulSoup
def main():
url = 'http://projects.fivethirtyeight.com/2016-election-forecast/mobile-bar.html'
r = requests.get(url)
soup = BeautifulSoup(r.text, 'lxml')
return [(p.contents[0], p.contents[1].text)
for p in soup.find_all('p', class_ = 'value-wrap')]
def isprime(n):
"""Check if a number is prime, using trial division"""
return n>1 and all(n % d for d in range(2, int(n**.5) + 1))
@Radcliffe
Radcliffe / cryptarithm-solver.py
Created January 13, 2017 00:02
Python script to solve additive cryptarithms
#!/usr/bin/env python
# This programs solves additive cryptarithms using brute force.
# Example: solve_cryptarithm(['SEND', 'MORE', 'MONEY']) returns a list of
# all solutions to the equation SEND + MORE = MONEY, where each letter
# stands for a different digit in base 10. Leading zeros are not allowed.
from itertools import permutations
@Radcliffe
Radcliffe / qwerty-to-dvorak.py
Last active February 28, 2019 14:38
Qwerty to Dvorak translator: Explaining XKCD 1787.
#!/usr/bin/env python
# This little Python script was written to explain XKCD comic #1787 (Voice Commands).
# In the comic, Cue Ball has reprogrammed his phone to use the Dvorak keyboard layout
# for voice recognition. (See http://xkcd.com/1787/)
# For those who don't know, the standard keyboard layout in the United States is called
# QWERTY, after the first six letters in the first row of letters. But there are a few
# enthusiasts who advocate an alternative layout, called Dvorak. These layouts have the
# same characters, but in different positions, as shown below.
@Radcliffe
Radcliffe / inaugural-emotions.csv
Last active January 20, 2017 22:34
Emotion analysis of inaugural adresses 1789-2017 using IBM Watson's AlchemyLanguage API
year name fear sadness joy anger disgust
1789 Washington 0.431542 0.212422 0.297166 0.155104 0.456401
1793 Washington 0.170726 0.110822 0.080267 0.238734 0.51617
1797 Adams 0.482235 0.498792 0.538104 0.094651 0.475888
1801 Jefferson 0.592254 0.539775 0.523261 0.139209 0.172762
1805 Jefferson 0.658992 0.230946 0.508855 0.136953 0.441134
1809 Madison 0.407716 0.46959 0.503345 0.398835 0.168831
1813 Madison 0.410416 0.496523 0.167754 0.422014 0.508343
1817 Monroe 0.184481 0.188871 0.550531 0.132109 0.445847
1821 Monroe 0.135458 0.258702 0.540292 0.135676 0.441433
@Radcliffe
Radcliffe / us_states.txt
Last active May 26, 2017 04:47
List of US States
StateCode|StateName|StateDate
AK|Alaska|1959-01-03
AL|Alabama|1819-12-14
AR|Arkansas|1836-06-15
AZ|Arizona|1912-02-14
CA|California|1850-09-09
CO|Colorado|1876-08-01
CT|Connecticut|1788-01-09
DE|Delaware|1787-12-07
FL|Florida|1845-03-03
# Filename: pick_state.py
# To run this file, type
# python pick_state.py
# in a terminal window.
# This script requires the file us_states.txt which is available at
# https://gist.github.com/Radcliffe/7a3e0fe2efc0a9aeb523abfac67865db
import csv
@Radcliffe
Radcliffe / keybase.md
Created July 16, 2017 21:13
keybase.io proof of identity

Keybase proof

I hereby claim:

To claim this, I am signing this object: