Skip to content

Instantly share code, notes, and snippets.

@Radcliffe
Radcliffe / merge_lists.py
Created August 6, 2017 02:26
Merge lists maintaining order
# Merge multiple lists of distinct elements into a single list, maintaining the order within each list.
# The result is a list of distinct elements, consisting of the union of the elements in the constituent lists.
# If A precedes B in one of the input lists, then A must precede B in the result.
# If this is not possible, then None is returned.
from collections import defaultdict
# Class to represent a graph - adapted from http://www.geeksforgeeks.org/topological-sorting-indegree-based-solution/
class Graph:
@Radcliffe
Radcliffe / scrape-7-eleven.py
Created December 1, 2017 02:05
Python web scraper to get a list of 7-Eleven locations in the US
# Download a list of all 7-Eleven stores in the United States.
# WARNING: The source data is inaccurate!
# Presented at PyMNtos, 2017-11-30
import requests
import csv
import time
import bs4
@Radcliffe
Radcliffe / fizzbuzz.bas
Created January 10, 2018 02:30
FizzBuzz in BASIC
10 PRINT "1"
20 PRINT "2"
30 PRINT "Fizz"
40 PRINT "4"
50 PRINT "Buzz"
60 PRINT "Fizz"
70 PRINT "7"
80 PRINT "8"
90 PRINT "Fizz"
100 PRINT "Buzz"
@Radcliffe
Radcliffe / a268305.py
Last active February 3, 2018 03:26
A268035: a(n) is the smallest integer m such that each of the numbers m, 2*m, 3*m, ..., n*m is the sum of two successive primes.
"""
Author: David Radcliffe (2018-02-02)
I am interested in numbers that are sums of two successive primes:
5, 8, 12, 18, 24, 30, 36, 42, 52, 60, 68, 78, 84, 90, 100, ...
Note that 2+3=5, 3+5=8, 5+7=12, 7+11=18, and so on.
This is sequence A001043 in the On-Line Encyclopedia of Integer Sequences.
@Radcliffe
Radcliffe / pop.sh
Last active May 16, 2018 14:54
Bash script to move downloaded files into current directory.
#!/bin/bash
# This script moves files from the Download directory to the current directory.
# Usage examples:
# pop - move the most recently downloaded file.
# pop 3 - move the three most recently downloaded files.
downloads=$HOME/Downloads
n=1
if [ "$1" != "" ]; then
n=$1
@Radcliffe
Radcliffe / pandas-plot-example.ipynb
Created June 1, 2018 06:25
Plotting a dataframe using Pandas
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Radcliffe
Radcliffe / multiply.erl
Last active August 23, 2018 01:42
Naive integer multiplication in Erlang
-module(multiply).
-export([mul/2]).
mul(_, 0) -> 0;
mul(A, B) -> mul(A, B-1) + A.
@Radcliffe
Radcliffe / multiply.erl
Created August 23, 2018 01:41
Naive multiplication with tail recursion
-module(multiply).
-export([mul/2]).
mul(A, B) -> mul(A, B, 0).
mul(_, 0, C) -> C;
mul(A, B, C) -> mul(A, B-1, A+C).
@Radcliffe
Radcliffe / multiply.erl
Created August 23, 2018 01:44
Peasant multiplication in Erlang
-module(multiply).
-export([mul/2]).
mul(A, B) -> mul(A, B, 0).
mul(_, 0, C) -> C;
mul(A, B, C) when B rem 2 == 1 -> mul(A, B-1, A+C);
mul(A, B, C) -> mul(A + A, B div 2, C).
@Radcliffe
Radcliffe / power.erl
Created August 23, 2018 01:55
Fast exponentiation in Erlang
-module(power).
-export([pow/2]).
pow(A, B) -> pow(A, B, 1).
pow(_, 0, C) -> C;
pow(A, B, C) when B rem 2 == 1 -> pow(A, B-1, A*C);
pow(A, B, C) -> pow(A*A, B div 2, C).