Skip to content

Instantly share code, notes, and snippets.

View djrodgerspryor's full-sized avatar

Daniel Rodgers-Pryor djrodgerspryor

  • Stile Education
  • Melbourne, Australia
View GitHub Profile

Keybase proof

I hereby claim:

  • I am djrodgerspryor on github.
  • I am drodgers (https://keybase.io/drodgers) on keybase.
  • I have a public key ASBsRbmrdKv1yrMSp0y1K3HmQJapQ4J1Rfwn5lkYCO3K5wo

To claim this, I am signing this object:

@djrodgerspryor
djrodgerspryor / pascal.py
Created March 15, 2014 06:03
Quick, recursive generation of rows from Pascal's triangle.
def pascalRow(n):
" Returns the nth row of Pascal's triangle"
return [1] if n<=0 else reduce(lambda row, n: row[:-1] + [(row[-1] + n), n], pascalRow(n-1), [0])
if __name__ == '__main__': # Module Test/Demo
print pascalRow(12)
print
print '\n'.join([str(n) + ' : ' + str(pascalRow(n)) for n in xrange(10)])
@djrodgerspryor
djrodgerspryor / primes.py
Created March 15, 2014 05:58
A module for lazily generating prime numbers with python generators and the Sieve of Eratosthenes.
from itertools import takewhile, chain, count, islice
from collections import deque
knownPrimes = [2] # Numbers are tested by counting upwards from here. This also acts as a cache.
def storeAndReturn(p):
knownPrimes.append(p)
return p
def isNotDivisibleByKnownPrimes(n):