Skip to content

Instantly share code, notes, and snippets.

View mattdodge's full-sized avatar
😺
Oh look! A status that I'll never change again!

Matt Dodge mattdodge

😺
Oh look! A status that I'll never change again!
View GitHub Profile
@mattdodge
mattdodge / solve24.py
Last active December 20, 2015 00:39
Trimmed down 24 solver
def solve(n, nums, solveStr='x'):
''' Play 24 with nums 1,3,4,6 like so:
>>> solve(24, [1,3,4,6])
(6/(1-(3/4))) '''
n = float(n)
solved = False
if len(nums) == 1:
return (solveStr.replace('x', str(int(n))) if n == float(nums[0]) else False)
@mattdodge
mattdodge / solve24.py
Created July 19, 2013 23:18
Solve the game 24 for any solution target and any numbers n = The target number (e.g. 24) nums = Array of numbers (floating point ok) to use solveStr = A helper string for this recursive method that returns a formula This method will return the first (not exhaustive!) possible solution to the game, or False if none exists Example: For the 24 gam…
def solve(n, nums, solveStr='x'):
''' Solve the game 24 for any solution target and any numbers
n = The target number (e.g. 24)
nums = Array of numbers (floating point ok) to use
solveStr = A helper string for this recursive method that returns a formula
This method will return the first (not exhaustive!) possible solution to the game, or False if none exists
Example: For the 24 game 1,3,4,6 call it the following way:
solve(24, [1,3,4,6])
@mattdodge
mattdodge / ncaaMatchupProbability.py
Created March 19, 2013 17:52
A utility that hits TeamRankings and gets the matchup probabilities for each team in the NCAA tournament. You will need to hard-code (blech) all of the team IDs for now, I'm lazy
'''
Created on Mar 18, 2013
@author: Matt Dodge
'''
from bs4 import BeautifulSoup as BS
from httplib2 import Http
from urllib import urlencode
import json
@mattdodge
mattdodge / bracketBayes.py
Created March 19, 2013 16:50
Run a Bayesian analysis on matchup probabilities for an NCAA bracket. This will spit out the probability that each seed makes it to a given round
'''
Created on Mar 18, 2013
@author: Matt Dodge
'''
'''
You can put your own probabilities here. It is a dict where the key is the lower seed
(lower by number, not by rank) followed by the higher seed, separated by comma, no space.
@mattdodge
mattdodge / php_file_editor.php
Created June 20, 2012 19:19
Simple PHP File Editor
<?php
$the_file = "file.txt";
if (isset($_POST['content'])) {
$content = stripslashes($_POST['content']);
$fp = fopen($the_file,"w") or die ("Error opening file in write mode!");
fputs($fp,$content);
fclose($fp) or die ("Error closing file!");
}
@mattdodge
mattdodge / gist:90704ecbbfecc78be50f
Created March 2, 2015 19:57
Human Readable Time Difference
function timeAgo(num_seconds) {
function numberEnding (number) {
return (number > 1) ? 's ago' : ' ago';
}
if (num_seconds <= 0) {
return 'just now!';
}
var years = Math.floor(num_seconds / 31536000);
if (years) {
return years + ' yr' + numberEnding(years);