{{ message }}

Instantly share code, notes, and snippets.

# Christian Oudard christian-oudard

• San Francisco
Created Oct 21, 2020
How many ways are there to additively partition a natural number?
View partitions.py
 # How many unique ways are there to add positive integers to get the number N? # https://oeis.org/A000041 from itertools import count, chain, islice def partitions(): """ >>> list(islice(partitions(), 20)) [1, 1, 2, 3, 5, 7, 11, 15, 22, 30, 42, 56, 77, 101, 135, 176, 231, 297, 385, 490]
Created Sep 4, 2020
Brute force solution to level 47 in Black, by Bart Bonte.
View black47.py
 numbers = [4, 6, 1, 3, 4, 4, 5, 3, 2, 3, 5, 2, 2, 4, 2, 6] size = len(numbers) path = [] def explore(pos): num = numbers[pos] print('explore', pos, num)
Created Jun 25, 2020
Use unicode braille characters to draw a picture in the terminal
View braille.py
 import math import shutil # Braille bit order: # 0 3 # 1 4 # 2 5 # 6 7 # bit: (x, y)
Created Jul 13, 2016
View keybase.md

Please publicly post the following Gist, and name it keybase.md

### Keybase proof

I hereby claim:

• I am christian-oudard on github.
• I am christianoudard (https://keybase.io/christianoudard) on keybase.
• I have a public key ASDUW30p7kTHKwf_VGcYiMCC_iPMzpJVFihxm4EGJG3_Gwo
Created Apr 28, 2015
View gist:16eaeeffa2a1b1004f75
 import Data.List.Zipper as Z main = do let string = "yabbadabbadoo" print \$ maximum \$ palindromeSizes string -- Find the size of the largest palindrome centered at each location in -- a string. There will be 2*n-1 locations, because we count even and odd -- centers. Go along the zipper, checking the sizes of palindromes to the left -- and right as we go.
Created Feb 8, 2012
Luhn validation algorithm for credit cards.
View luhn.py
 """ Python implementation of the Luhn algorithm. Refer to: http://en.wikipedia.org/wiki/Luhn_algorithm >>> is_luhn_valid(79927398713) True >>> is_luhn_valid(79927398714) False >>> is_luhn_valid(4532990475689429)
Created Mar 15, 2011
Palindrome number investigations
View palindromes
 def digits_of(n, base=10): """ Split the number into its digits. >>> digits_of(0) [0] >>> digits_of(123) [1, 2, 3] >>> digits_of(0xabc, base=16) [10, 11, 12]
Created Jun 29, 2010
Github Flavored Markdown in Python
View gfm.py
 import re from hashlib import md5 def gfm(text): # Extract pre blocks. extractions = {} def pre_extraction_callback(matchobj): digest = md5(matchobj.group(0)).hexdigest() extractions[digest] = matchobj.group(0) return "{gfm-extraction-%s}" % digest
Created Jun 18, 2010
Python flatten
View python flatten
 """ Flatten a nested list structure. * Works for nested structures of lists, tuples, generators, or any other iterable. * Special-cases string types and treats them as non-iterable. * Is not limited to the system recursion limit. * Yields items from the structure instead of constructing a new list, and can work on non-terminating generators. This is basically a non-recursive version of the following:
Created Feb 24, 2010 — forked from winhamwr/hudson fabric deploy bash script
View hudson fabric deploy bash script
 #!/bin/bash SSHAGENT=/usr/bin/ssh-agent SSHAGENTARGS="-s" PARENT_JOB=pstat_master_unittest KEY_PATH=\$HOME/policystat/fabric/pstat_dev.key PROJECT_ROOT=/var/www/pstattest.com/ if [ ! -z "\$WORKSPACE" ]; then WORKSPACE=/vol/fs/var/lib/hudson/home/jobs/pstat_master_deploy/workspace