Skip to content

Instantly share code, notes, and snippets.

View andrewberls's full-sized avatar

Andrew Berls andrewberls

View GitHub Profile
# Test cases used
#
# DOWN LEFT
# 3
# ---
# -m-
# p--
# UP RIGHT
# 3
@andrewberls
andrewberls / FizzBuzz_golf.rb
Created February 3, 2013 01:52
The classic FizzBuzz challenge, with an infusion of code golf
# Print the numbers from 1 to 100, except for multiples of 3 print "Fizz", for multiples of 5 print "Buzz",
# and for multiples of 3 and 5 print "FizzBuzz".
# Ex:
# 1
# 2
# Fizz
# 4
# Buzz
# Fizz
# 7
// hashtable.hpp
class HashTable {
public:
struct HashTable::HashEntry* insert(int);
struct HashEntry {
// Some stuff
};
};
@andrewberls
andrewberls / pizza.rb
Created October 13, 2012 00:33
ACM Micro-Challenge 1
require "test/unit"
# Write a function called numPizzas, that takes the number of people present,
# the number of slices in a pizza, and the time of day, and returns the
# number of pizzas to buy (as a whole integer).
#
# Spec:
# Signature: int numPizzas(int numPeople, int slicesPerPizza, int time)
# Time is an int on 24-hour clock (0-23), e.g. 8 = 8am, 14 = 2pm
# Between 11am - 11pm: 2 slices per person, else 1
def sumDouble(ary); ary.map{|i| i*2}.inject(&:+); end
@andrewberls
andrewberls / list_remove.c
Created August 13, 2012 03:47
Remove linked list node
static int
list_remove(node* root, node* n) {
node* temp = (node*) malloc(sizeof(node));
temp = root;
node* garbage = (node*) malloc(sizeof(node));
int found = -1;
while (temp) {
if (temp->next->val == n->val) {
garbage = temp->next;
@andrewberls
andrewberls / ex.coffee
Created July 30, 2012 20:16
Nested functions
@fadeWith = (sound, duration) ->
return @ if !supported
@fadeOut duration, ->
@stop()
sound.play().fadeIn(duration)
return @
@andrewberls
andrewberls / Gemfile
Created July 15, 2012 21:56
Rakefile for building and minifying a CoffeeScript project
source 'http://rubygems.org'
gem "rake", "~> 0.9.2.2"
gem "uglifier", "~> 1.2.6"
gem "listen", "~> 0.4.7"
@andrewberls
andrewberls / scrollTo
Created February 5, 2012 19:15
jQuery Scrolling Function
function scrollTo(id) {
$('html,body').animate({scrollTop: $("#" + id).offset().top}, 'slow');
}