[ Launch: Tributary inlet ] 9024863 by Radcliffe
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
# 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
# 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
#!/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
#!/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
# 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/env python | |
# | |
# List the numbers n such that the digits of the square of n | |
# can be rearranged to form exactly two other squares. | |
# For example, 13 belongs to list because 13*13 = 169, and | |
# the digits of 169 can be rearranged to form the squares 196 | |
# (= 14*14) and 961 (= 31*31); but no other squares can be formed | |
# by rearranging the digits of 169. | |
# | |
# Inspired by a question of James Tanton (@jamestanton on Twitter). |
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 | |
# | |
# This Python 2.7 script solves the following probability problem: | |
# If 20 distinct positive integers are chosen from the range 1 - 80 | |
# (without replacement) what is the probability that their sum is 810? | |
# Source: Kim Zafra, http://lnkd.in/bmg4AR5 | |
# Remarks: |
[ Launch: Covering a grid with circles ] 8071295 by Radcliffe