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 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. |
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 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 |
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
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)) |
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
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')] |
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
# 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 |
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
height | n | |
---|---|---|
0 | 1 | |
1 | 1 | |
2 | 2 | |
3 | 5 | |
4 | 10 | |
5 | 18 | |
6 | 32 | |
7 | 59 | |
8 | 102 |
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
function partition(arr, lo, hi) { | |
var swap = function (i, j) { | |
var tmp = arr[i]; | |
arr[i] = arr[j]; | |
arr[j] = tmp; | |
} | |
var pivot = arr[hi]; | |
var pivotLoc = lo; | |
var i; |
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
YearAwarded | Name | Gender | Citizenship | SecondCitizenship | BirthYear | Remarks | Affiliation | AgeAtAward | |
---|---|---|---|---|---|---|---|---|---|
2014 | Artur Avila Cordeiro de Melo | Male | Brazil | France | 1979 | CNRS - Institut de Mathématiques de Jussieu-Paris Rive Gauche | 35 | ||
2014 | Manjul Bhargava | Male | Canada | United States | 1974 | Princeton University, | 40 | ||
2014 | Martin Hairer | Male | Austria | 1975 | University of Warwick | 39 | |||
2014 | Maryam Mirzakhani | Female | Iran | 1977 | Stanford University | 37 | |||
2010 | Ngô Bao Châu | Male | Vietnam | France | 1972 | Université Paris-Sud 11 and Institute for Advanced Study | 38 | ||
2010 | Elon Lindenstrauss | Male | Israel | 1970 | Hebrew University of Jerusalem | 40 | |||
2010 | Stanislav K. Smirnov | Male | Russia | 1970 | University of Geneva | 40 | |||
2010 | Cédric Villani | Male | France | 1973 | École Normale Supérieure de Lyon and Institut Henri Poincaré | 37 | |||
2006 | Andrei Okounkov | Male | Russia | 1969 | Princeton University | 37 |
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
Location | DateClosed | StoreNumber | StoreTypes | lon | lat | |
---|---|---|---|---|---|---|
14331 Count Rd. 99, Headland, AL | 2016-01-28 | 2173 | Walmart Express | -85.3259952 | 31.3607946 | |
18 Apple Way, Ashford, AL | 2016-01-28 | 2011 | Walmart Express | -85.237821 | 31.1765287 | |
952 E. Lawrence Harris Hwy, Slocomb, AL | 2016-01-28 | 2165 | Walmart Express | -85.5907905 | 31.1076635 | |
407 West Washington St., Abbeville, AL | 2016-01-28 | 2186 | Walmart Express | -85.2594391 | 31.5737215 | |
6361 Hwy 72 East Gurley, AL | 2016-01-28 | 2235 | Walmart Express | -86.3700933 | 34.6947341 | |
87395 US Hwy 278, Snead, AL | 2016-01-28 | 2260 | Walmart Express | -86.8494742 | 34.17204 | |
3530 Cathedral Caverns Hwy, Grant, AL | 2016-01-28 | 3769 | Walmart Express | -86.2611173 | 34.5014024 | |
10188 Hwy 431 South, New Hope, AL | 2016-01-28 | 3779 | Walmart Express | -86.3911528 | 34.5277698 | |
720 N Hwy 71, Mansfield, AR | 2016-01-28 | 2498 | Walmart Express | -94.2619279 | 35.077937 |
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
import itertools | |
for a,e,f,h,i,l,t,n,o,w in itertools.permutations(range(10)): | |
if h > 0 and t > 0 and f > 0 and w > 0: | |
half = 1000*h + 100*a + 10*l + f | |
fifth = 10100*f + i*1000 + t*10 + h | |
tenth = 10010*t + 1000*e + n*100 + h | |
whole = w*10000 + h*1000 + o*100 + l*10 + e | |
if half + fifth + 3*tenth == whole: | |
print "%s + %s + %s + %s + %s = %s" % ( | |
half, fifth, tenth, tenth, tenth, whole) |