Skip to content

Instantly share code, notes, and snippets.

# Put your answers here!
@sandbochs
sandbochs / words_in_numbers.rb
Created October 10, 2012 23:42 — forked from webdevlasse/words_in_numbers.rb
solution for words_in_numbers
@ones = {1 => "one", 2 => "two", 3 => "three", 4 => "four", 5 => "five",
6 => "six", 7 => "seven", 8 => "eight", 9 => "nine", 10 => "ten",
11 => "eleven", 12 => "twelve", 13 => "thirteen", 14 => "fourteen",
15 => "fifteen", 16 => "sixteen", 17 => "seventeen", 18 => "eighteen", 19 => "nineteen"}
@tens = {10 => "ten", 20 => "twenty", 30 => "thirty",40 => "forty", 50 => "fifty",
60 => "sixty", 70 => "seventy", 80 => "eighty", 90 => "ninety"}
# Put your answers here!
@sandbochs
sandbochs / random_motd.rb
Created October 11, 2012 05:39
Random MOTD
def random_motd
file_reader = File.new("motd_list.txt", "r")
count = 0
file_reader.each do |line|
count += 1
if Random.rand(count) == 0
motd = file_reader.readline
end
end
@sandbochs
sandbochs / gist:3887536
Created October 14, 2012 05:55
FLEETS AND CARS
class Fleet
def initialize
@a_fleet = []
end
def add_car(car)
if car.class.to_s != "Car"
puts "Not a car..."
end
@a_fleet << car
@sandbochs
sandbochs / GateState.py
Created October 18, 2012 20:00
minimax
class __GameState:
ALL_STATES = {}
def __init__(self, value, prettyStr):
self.value = value
self.prettyStr = prettyStr
GameState.ALL_STATES[self.value] = self
def invert(self):
return GameState.ALL_STATES[ 2 - self.value ]
def __cmp__(self, other):
return self.value - other.value
@sandbochs
sandbochs / ruby_hash_example.rb
Created November 9, 2012 07:48
Ruby Hash Example
http://blog.sandbochs.com
# The hash method produces a different value
# every time you load up ruby
# because it is based off of the object_id
1.hash => 3843363811812838534
num = 1
num.hash => 3843363811812838534
# Strings override Object's hash method
# The hash function is based on the characters in the string
@sandbochs
sandbochs / linked list J
Created December 7, 2012 05:34
linked list w Amy
def filter(ll, val)
fake_ll = Pair.new(424242, ll)
previous = fake_ll
while ll != nil
if ll.a == val
previous.b = ll.b
else
previous = ll
end
@sandbochs
sandbochs / b33r_song.rb
Created January 2, 2013 21:14
The B33r Song!
# Beer song with a little RUBY style refactoring.
# A space should be put after the # character to denote a written comment,
# so people don't get confused with commented out code (no space).
def beer_song(num)
num.downto(1) do |count|
puts "#{count} #{pluralize_bottle(count)} of beer on the wall, #{count} #{pluralize_bottle(count)} of beer."
puts "Take one down and pass it around, #{count - 1} #{pluralize_bottle(count - 1)} of beer on the wall."
end
@sandbochs
sandbochs / board.rb
Last active December 12, 2015 01:49
Battleship, ship class
class Board
def initialize
@ships = self.reset_board # perhaps this needs a better name
end
def self.reset_board
#returns an array of new ships
end