Skip to content

Instantly share code, notes, and snippets.

View IanWitham's full-sized avatar

amuletofyendor IanWitham

View GitHub Profile
@IanWitham
IanWitham / frequency_count.py
Created March 5, 2015 06:54
Frequency count algorithm for creating an anagram key.
import string
# initialise a "zeroed" frequency count dict for the upper case chars
empty_freq_counts = dict.fromkeys(string.ascii_uppercase, 0)
def freq_count(word):
# precondition: word is upper and lowercase ascii characters only
# Setup loop invariant. Making a copy of an existing dict
# is faster than creating a new dict.
@IanWitham
IanWitham / AnagramKey.py
Last active August 29, 2015 14:16
Alternative method for creating anagram keys. In practice seems to be faster to use something like ''.join(sorted(word.upper()))
from operator import mul
# indices 0 - 64 are non-word characters
# followed by indices corrolating to capital letters
# followed by 6 non-word characters
# followed by indices corrolating to lower-case letters
primes = [1] * 65 \
+ [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101] \
+ [1] * 6 \
+ [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]
@IanWitham
IanWitham / Fireworks.pde
Created February 13, 2015 03:29
Processing code used to produce fireworks animations at: https://www.youtube.com/watch?v=wOhY-O0UqbI
// https://www.youtube.com/watch?v=wOhY-O0UqbI
ArrayList<Particle> particles;
PImage[] bullets;
PImage red_bullet;
PImage green_bullet;
PImage blue_bullet;
final float GRAVITY = 200;
[person for person in world_population
if is_nice(person) and is_nice(person)]
@IanWitham
IanWitham / spiro.rkt
Last active December 18, 2015 12:59
Spiro-graph like image generation definitions.
(require 2htdp/image)
(define-struct spiro (minor-radius
major-radius
minor-turn-rate
major-turn-rate))
(define (major-turns
minor-turns
this-spiro)
@IanWitham
IanWitham / BSL_CAT.rkt
Last active December 18, 2015 10:59
Cat drawn in BSL language for Coursera: Introduction to Systematic Program Design - Part 1
(require 2htdp/image)
(define FUR_COLOR (make-color 130 130 130))
(define FUR_COLOR_DARK (make-color 80 85 90))
(define FUR_COLOR_LIGHT (make-color 160 160 155))
(define FUR_COLOR_LIGHTEST (make-color 190 190 180))
(define EYE_COLOR_DARK (make-color 20 160 20))
(define EYE_COLOR_LIGHT (make-color 50 200 50))