Skip to content

Instantly share code, notes, and snippets.

@arn-e
arn-e / fibonacci_sequence.rb
Created October 29, 2012 00:42
fibonacci_sequence
def fb?(i,a=0,b=1)
b>i ?false:(b==i ?true:fb?(i,b,a+b))
end
@arn-e
arn-e / prime_factorization_abridged.rb
Created October 29, 2012 00:42
prime_factorization_abridged
def pf(n,a=[],f=2)
n==f ?a<<f:n%f==0?pf(n/f,a<<f):pf(n,a,f+1)
end
@arn-e
arn-e / binary_search_abridged.rb
Created October 29, 2012 00:41
binary_search_abridged
def bs(i,a,m=0,x=a.size,h=(m+x)/2,l=a.size)
i==a[m]?m:(i<a[0]||i>a[l-1])||m==x-1?-1:i<a[h]?bs(i,a,m,h):bs(i,a,h,l)
end
@arn-e
arn-e / todo.rb
Created October 18, 2012 23:33
todo
#!/usr/bin/env ruby
require 'term/ansicolor'
require "docopt"
doc = <<DOCOPT
Usage:
#{__FILE__} add <task>...
#{__FILE__} prepend <task>
#{__FILE__} list <optional : --tag --priority>
@arn-e
arn-e / rspec_binary_search.rb
Created October 18, 2012 17:59 — forked from dbc-challenges/rspec_binary_search.rb
Rspec Binary Search
require './binary_search'
# your rspec code here!
@arn-e
arn-e / rspec_binary_search.rb
Created October 18, 2012 17:59 — forked from dbc-challenges/rspec_binary_search.rb
Rspec Binary Search
require './binary_search'
# your rspec code here!
@arn-e
arn-e / administrator.rb
Created October 17, 2012 03:36
hospital
require './user'
require './employee'
class Administrator < Employee
def initialize(name)
super
@record_access = :admin
@title = "Administrator"
@password = default_password
end
require 'securerandom'
class Hospital
attr_accessor :name,:location
def initialize
@name = "Dev Bootcamp Asylum?"
@location = "717 California St"
@employee_count = 7
@arn-e
arn-e / todo1.rb
Created October 16, 2012 05:11
todo list revision 1
#questions :
#1. how to check if file exists? Better way than opening with 'append' (+)?
#2. how to write to middle of file? does the entire file need to be re-written from the contents in memory?
class TodoList
def initialize()
@file_name = "todo_file.txt"
@file = File.new(@file_name,'r+')
@todo_list = {}
@arn-e
arn-e / hospital.rb
Created October 15, 2012 19:55
hospital_framework
class Hospital
#name, location, number of employees
#number of patients
#login, show interface
#wait for user input
#present login menu
#accept credentials
#credentials are associated on a employee level
end