Skip to content

Instantly share code, notes, and snippets.

View alanjcfs's full-sized avatar
🧏‍♂️

Alan Fung-Schwarz alanjcfs

🧏‍♂️
View GitHub Profile
# Rock Paper Scissors is a usual game
class Opponent
def initialize
@rps = ['rock', 'paper', 'scissors']
end
def play
@rps[rand 3]
end
@alanjcfs
alanjcfs / dayth of the year
Created September 5, 2011 04:48
Will return the day of the year in a sentence form
t = Time.now
dayth = t.yday
last_digit = dayth.to_s.slice(-1, 1).to_i
def ordinal(last_digit)
case last_digit
when 1
"st"
when 2
"nd"
@alanjcfs
alanjcfs / heap_in_ruby
Created August 27, 2011 00:02
An attempt at implementing Priority Queue through solely Ruby
class Binary_heap
def initialize(num = 10)
@ary = Array.new
num.times do @ary << rand(100) end
end
attr_reader :items, :ary
def binary_heap()
@ary.unshift(nil)