Skip to content

Instantly share code, notes, and snippets.

View Deathnerd's full-sized avatar

Wes Gilleland Deathnerd

  • eLink Design
  • Lexington, KY
View GitHub Profile
@Deathnerd
Deathnerd / make_change.py
Created February 20, 2016 01:09
A dynamic programming attempt to make change
def make_change(change, denominations=None):
"""
Given an integer amount of change and a list of denominations of coins
you can use to make it, return the least amount of coins to make change
:param change:
:param denominations:
:return:
"""
if denominations is None:
# start with some sensible (American) defaults
@Deathnerd
Deathnerd / string_benchmarks.php
Last active February 3, 2016 18:47
A nice, concise micro benchmark for PHP string functions. Credits to Thiemo Mättig (http://maettig.com/)
<?php
error_reporting(E_NONE);
$repetitions = 10000;
function getmicrotime()
{
$t = gettimeofday();
return $t['sec'] * 1000 + $t['usec'] / 1000;
@Deathnerd
Deathnerd / BinarySearchTree.java
Created November 15, 2015 06:26
A Queue approach to Breadth-First searching of a binary tree
/**
* Searches through the current tree for a given key. Will return a match if
* a node exists that has a value that starts with key or is equal to key.
* All comparisons are in lowercase.
*
* @param key The key containing the value to search for
* @return The node if it finds it
* @throws EmptyTreeException If the current tree is empty
* @throws NodeNotFoundException If the node isn't found
*/
<?
// Old Code
function CheckCC($field, $msg)
{
$Name = 'n/a';
$Num = $this->_getValue($field);
// Innocent until proven guilty
$GoodCard = true;
@Override
public void deleteNode(int key) {
Term current = this.first;
while(current != null){
if(((Term)current.next).getCoefficient() == key){
Term t = (Term) current.next.next;
current.next.next = null;
current.next = t;
} else {
current = (Term) current.next;
package com.gilleland.george.homework;
import com.gilleland.george.utils.ImproperInsertionOrderException;
import com.gilleland.george.utils.InvalidPolynomialExpressionException;
import com.gilleland.george.utils.Link;
import com.gilleland.george.utils.LinkListInterface;
import com.sun.org.apache.xerces.internal.impl.xpath.regex.RegularExpression;
import java.util.ArrayList;
import java.util.List;
@Override
public void run() {
while (true) {
ArrayList<String> menu_choices = new ArrayList<String>() {{
add("Read");
add("Generate");
add("Print");
add("Sort");
add("Search");
}};
def primes():
"""
Generate an infinite series of primes based on the
Sieve of Eratosthenes
"""
D = {}
q = 2
while True:
if q not in D:
yield q
@Deathnerd
Deathnerd / Main.java
Created September 28, 2015 19:45
An example of inline ArrayList declarations
package com.gilleland.george;
import com.gilleland.george.utils.Utils;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
// write your code here
@Deathnerd
Deathnerd / stats.py
Last active September 16, 2015 01:32
A Python class I wrote to do the boring parts of my Stats homework
from math import sqrt
class Stats(object):
def __init__(self, dataset):
"""
A basic statistics class. Takes in a dataset of a list of numbers
"""
self.dataset = dataset