Skip to content

Instantly share code, notes, and snippets.

View joe-henke's full-sized avatar
🔹

Joe Henke joe-henke

🔹
  • Foundation
  • San Rafael
  • 01:16 (UTC -12:00)
View GitHub Profile
@joe-henke
joe-henke / fractional_knapsack.py
Created February 25, 2016 06:17
Greedy Fractional Knapsack
# Uses python3
import sys
# returns the ratio of value to weight
def getValueRatio(item):
return (item[0]/item[1])
def checkInput(n, min, max):
if n<min or n>max:
return True
@joe-henke
joe-henke / binary_search.py
Last active April 12, 2016 22:21
Binary Search for Algortihmic Toolbox
# Uses python3
import sys
import random
def binary_search(a, x):
left, right = 0, len(a)
def linear_search(a, x):
for i in range(len(a)):
if a[i] == x:
@joe-henke
joe-henke / knapsack.py
Created March 2, 2016 08:07
Knapsack problem dynamic programming no repetition of items
# Uses python3
import sys
def knapSackNoRep(capacity, bars):
amount = len(bars)
value=[[0 for row in range(0, amount+1)] for col in range(0, capacity+1)]
for i in range(1, amount+1):
wi = bars[i-1]
@joe-henke
joe-henke / check_brackets.py
Last active December 1, 2016 21:09
Checks For Brackets
# python3
import sys
class Bracket:
def __init__(self, bracket_type, position):
self.bracket_type = bracket_type
self.position = position
def Match(self, c):
@joe-henke
joe-henke / 0_reuse_code.js
Created April 13, 2016 18:55
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console