Skip to content

Instantly share code, notes, and snippets.

@Radcliffe
Radcliffe / rearrange_power_of_three.py
Last active December 16, 2015 03:27
Powers of 3 having the same digits
"""
James Tanton @jamestanton asked:
Is there a power of three whose digits can be rearranged to form
another power of three?
(https://twitter.com/jamestanton/status/676773021223272448)
The following Python script searches for examples. There is no power
of three, less than 3^200000, whose digits can be rearranged to form
another power of three.
"""
"""
Problem:
Arrange the numbers from 1 to m*n in an m-by-n grid so that
no two consecutive numbers are placed in adjacent cells.
In how many ways can this be done? Two squares are considered
touching if they share a corner.
Example:
@Radcliffe
Radcliffe / invfactorial.py
Last active August 29, 2015 14:26
Inverse factorial
from math import log, sqrt, pi, e
from scipy.special import lambertw
fomm numpy import real
# http://mathforum.org/kb/message.jspa?messageID=342551&tstart=0
def invfactorial(n):
""" Approximate inverse factorial"""
L = log((x + .036534) / sqrt(2*pi))
return real(L/W(L/e) - .5)
@Radcliffe
Radcliffe / zips-tc-metro.txt
Created July 3, 2015 19:31
ZIP codes in the seven county twin cities metropolitan area
ZIP Code,County
55001,Washington County
55003,Washington County
55005,Anoka County
55010,Dakota County
55011,Anoka County
55014,Anoka County
55016,Washington County
55020,Scott County
55024,Dakota County
@Radcliffe
Radcliffe / scrape_youtube_playlist.py
Last active August 29, 2015 14:23
Find the titles and running times of videos in a YouTube playlist by scraping the web page
# Python script to list the titles and running times of the videos
# in a YouTube playlist.
# Note: Only works for up to 100 videos. TODO: Fix this bug.
# The playlist id can be found in the playlist's URL.
playlist_id = "PLt5AfwLFPxWLNZRKWlcRmTABh_SExiiCj"
from lxml import html
import requests
@Radcliffe
Radcliffe / squareplus2graph.py
Created February 16, 2015 00:47
A "square-plus-two" digraph
# This Python script generates a directed graph with
# vertex set V = {0, 1, 2, ..., m-1} and edge set
# E = {(n, f(n)) : n in V} where f(n) = n*n + c (mod m).
#
# Requires the python-igraph package (http://igraph.org/python/)
#
# Author: David Radcliffe (14 February 2014)
# Based on an idea of James Tanton
# https://twitter.com/jamestanton/status/549558473868849152
#
@Radcliffe
Radcliffe / splitdigits.py
Last active August 29, 2015 14:14
Arrange consecutive digits to form two numbers whose product is as large as possible.
# 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):
@Radcliffe
Radcliffe / index.html
Created January 11, 2015 22:58
myPlot
<!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>
@Radcliffe
Radcliffe / mplswards.json
Created January 8, 2015 21:05
Minneapolis Wards - GeoJSON
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Radcliffe
Radcliffe / 100pointwords.txt
Created January 6, 2015 23:33
English words with letter sum of 100, where A=1, B=2, C=3, etc.
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