This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import defaultdict | |
| class Lint(defaultdict): | |
| def __init__(self, item): | |
| super(Lint, self).__init__(int) | |
| if isinstance(item, int) or isinstance(item, long): | |
| st = str(item)[::-1] | |
| d = {i: int(st[i]) for i in xrange(len(st))} | |
| elif isinstance(item, dict): | |
| d = item | |
| else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| marriage is a long-term contract | |
| and if u put it in nominal terms | |
| by eating recklessly, | |
| he is shortening the benefits of this contract |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Source: http://stackoverflow.com/questions/11671731/in-r-how-can-i-make-a-running-count-of-runs | |
| x <- data.frame(end.group=c(0,0,1,0,0,1,1,0,0,0,1,1,1,0,1)) | |
| # create groups | |
| x$group <- rev(cumsum(rev(x$end.group))) | |
| # re-number groups from smallest to largest | |
| x$group <- abs(x$group-max(x$group)-1) | |
| x$group.count <- ave(x$end.group, x$group, FUN=seq_along) | |
| # Even Better: http://stackoverflow.com/questions/9961700/how-to-partition-when-ranking-on-a-particular-column |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from numpy import * | |
| # The Matrix! | |
| x = matrix([ | |
| [1,6,0,0,0,0], | |
| [1,1,5,0,0,0], | |
| [1,1,1,4,0,0], | |
| [1,1,1,1,3,0], | |
| [1,1,1,1,1,2], | |
| [1,1,1,1,1,1], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import itertools | |
| # using reverse polish notation | |
| def calculate(expr): | |
| stack = list() | |
| for e in expr: | |
| if type(e) == int: | |
| stack.append(e) | |
| else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| N <- 100000000 | |
| isprime <- rep(1,N) | |
| for (i in 2:(floor(sqrt(N)))) { | |
| if (isprime[i]==1) { | |
| for (k in i:(floor(N/i))) { | |
| isprime[i*k] <- 0 | |
| } | |
| } | |
| print(i) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # The primes 3, 7, 109, and 673, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For example, taking 7 and 109, both 7109 and 1097 are prime. The sum of these four primes, 792, represents the lowest sum for a set of four primes with this property. | |
| # Find the lowest sum for a set of five primes for which any two primes concatenate to produce another prime. | |
| def primes(n): | |
| ret = list() | |
| multiples = set() | |
| for i in xrange(2, n+1): | |
| if i not in multiples: | |
| ret.append(i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| sys.setrecursionlimit(100000) | |
| # dynamic programming | |
| def fun(A, motes): | |
| # print A, motes | |
| if A == 1: | |
| return len(motes) | |
| if len(motes) == 0: | |
| return 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| FILE=$(date +%Y%m%d-%H%M%S) | |
| cd ~/Dropbox/Public/Screenshots | |
| screencapture -i $FILE.png | |
| echo "https://dl.dropboxusercontent.com/u/*/Screenshots/$FILE.png" | pbcopy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # randomize 1:nSongs across each iteration (?) | |
| # be aware of the songs in the basedir, so that we don't resing songs | |
| beMarkov <- TRUE # flag: don't do previous songs | |
| Sys.setlocale("LC_ALL", "chs") | |
| basedir <- "D:/Karaoke/To Sing/" #"C:/Users/Susan/Dropbox" | |
| outdir <- "D:/Karaoke/To Sing/" | |
| addLeadZero <- function(x, n=2) { | |
| x <- as.character(x) |