Skip to content

Instantly share code, notes, and snippets.

View goakley's full-sized avatar

Glen Oakley goakley

View GitHub Profile
@goakley
goakley / qmc.py
Created September 30, 2012 17:43
Q-MC Algorithm
#!/usr/bin/env python
import sys
import math
import re
""" Find the index of the single difference between two strings """
def find_char_difference(str1, str2) :
if len(str1) != len(str2) :
return None;
@goakley
goakley / find.c
Created October 11, 2012 02:36
FIND UNION
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef ENOMEM
#define ENOMEM 12
#endif
@goakley
goakley / linus.c
Last active December 10, 2020 00:34
In response to: http://meta.slashdot.org/story/12/10/11/0030249/linus-torvalds-answers-your-questions An explanation of the two different types of singly-linked list removal explained by Linus Torvalds, using the variable names introduced here: http://stackoverflow.com/questions/12914917/
#include <stdio.h>
typedef struct ll {
int value;
struct ll *next;
} ll;
void print_list(ll *list_head)
{
@goakley
goakley / resume.c
Created January 30, 2013 01:50 — forked from klange/_.md
#include <stdio.h>
#include <time.h>
/* TODO: resume.h */
typedef struct {
char * company;
char * location;
char * title;
@goakley
goakley / coingame.hs
Last active December 14, 2015 12:38
Plays a "Coin Game". The game starts with a stack of coins. Each turn, a player splits a stack into two stacks that must be of two different heights. The game ends when no more stacks can be split, and the person whose turn it is is marked the loser.
import Data.List (elemIndex)
import Data.Maybe (fromJust)
-- A pile of coins is just an Int describing how many coins are in the pile
type CoinPile = Int
-- A state in the coin game is just a number of piles
type CoinState = [CoinPile]
-- A player is either Me or You
data Player = Me | You deriving (Eq)
@goakley
goakley / captainm.c
Created April 1, 2013 00:54
Captain's Mistress game written in C, with an AI that utilizes Alpha-Beta depth-limited pruning.
#include <limits.h>
#include <stdio.h>
#define DEPTH (7)
long int max(long int a,long int b){return(a>b?a:b);}
long int min(long int a,long int b){return(a<b?a:b);}
short player();
short ai();
@goakley
goakley / NCR.java
Created April 27, 2013 20:50
Java-based nCr on an array for @AlexaCain and @lhsu92 - Gets all `r` combinations on an array of ints
class NCR {
// Take the factorial of an integer
public static int factorial(int num)
{
int fact = 1;
for (int i = 1; i <= num; i++)
fact = fact*i;
return fact;
}
#!/bin/bash
# subtree merge with branches
rm -rf commcare-hq core-hq
git clone git://github.com/dimagi/commcare-hq.git
git clone git://github.com/dimagi/core-hq.git
cd core-hq
@goakley
goakley / trigram.py
Created November 11, 2013 01:17
Trigram tool that takes text input and creates a random output based on the N-grams of the input.
#!/usr/bin/env python
"""
Trigram tool that takes text input and creates a random output based
on the N-grams of the input.
"""
import argparse
from sys import stdin
from random import choice
@goakley
goakley / collage.py
Created February 15, 2014 18:12
Generates a collage given a directory containing only images
#!/usr/bin/env python3
import glob
from PIL import Image
from random import shuffle
from sys import argv
# The maximum size an individual image can be
MAXSIZE = (640,480)