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
# James Tanton asked: A 756-567-657 triangle has three side lengths with digits | |
# permutations of each other. Is there a right triangle with this property? | |
# https://twitter.com/jamestanton/status/459633602159202304 | |
# | |
# This Python code generates all solutions with sides less than 10^9. | |
# The output is listed after the code. | |
from time import time | |
start_time = time() |
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
#!/usr/bin/python | |
# The birthday paradox predicts that in a group of 23 people, the probability | |
# is about 51% that two people share the same birthday. | |
# p = 1 - (1 - 1/365) * (1 - 2/365) * ... * (1 - 22/365) = 0.507297 | |
# This assumes that birthdays are distributed uniformly and independently | |
# among the 365 days of the year, excluding leap years. |
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
#!/usr/bin/env python | |
# Construct a graph whose nodes are labeled with the two-letter abbreviations | |
# for all 59 states and possessions of the United States. Two nodes are joined | |
# by an edge if and only if they differ by a single letter (i.e. they share | |
# the same first letter or the same second letter). For example, MN is | |
# adjacent to MI and TN, but not to NM. | |
# The output file can be read by GraphViz to produce a graphic file in a | |
# variety of formats. For example, the following command will produce a |
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
# A Harshad number (or Niven number) is a number that is divisible by its sum of digits. | |
def sum_of_digits(n): | |
s = 0 | |
while n > 0: | |
s += (n % 10) | |
n /= 10 | |
return s | |
# Alternative one-liner: | |
# sum_of_digits = lambda n: sum(map(int, str(n))) |
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
# Address Standardization with SmartyStreets | |
import urllib2 | |
import urllib | |
import json | |
# Note: Replace these lines with valid credentials | |
AUTH_ID = "########-####-####-####-############" | |
AUTH_TOKEN = "####################" |
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
# Download patent grants 1976 - 2014 | |
import os | |
import urllib | |
import urllib2 | |
import lxml.html | |
if not os.path.exists('data'): | |
os.mkdir('data') |
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
abatements abettors abrogative absconders acclimation | |
accounter accumulate acknowledge acolytes acquitted | |
acromegaly activates addressing adiabatically adulthood | |
advantaging adverting aerofoils aerometer affectation | |
afghanistan aggresses agrology airdrops alertest | |
alienation alkalinize allottable alpinist alternated | |
ambulating amiableness amortise amphiboles amputees | |
amusedly analysis anchoritic aneurism anginous | |
anglophobia animaters annually answerable anterior | |
anvilling aphrodisia apoplectic apostacy appeasers |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
<!doctype HTML> | |
<meta charset = 'utf-8'> | |
<html> | |
<head> | |
<link rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/nvd3/1.1.15-beta/nv.d3.min.css'> | |
<script src='//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js' type='text/javascript'></script> | |
<script src='//d3js.org/d3.v3.min.js' type='text/javascript'></script> | |
<script src='//cdnjs.cloudflare.com/ajax/libs/nvd3/1.1.15-beta/nv.d3.min.js' type='text/javascript'></script> | |
<script src='//nvd3.org/assets/lib/fisheye.js' type='text/javascript'></script> |
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
# Problem: Arrange the consecutive digits {x,x+1,..,y} to form two numbers A and B | |
# so that the product A*B is as large as possible. | |
# | |
# The generator `splitdigits` returns all candidate triples (P, A, B) where P = A * B. | |
def splitdigits(x=1, y=9, base=10): | |
if x == y: | |
yield (0, y, 0) | |
else: | |
for P, A, B in splitdigits(x+1, y, base): |