Skip to content

Instantly share code, notes, and snippets.

@lordhumunguz
lordhumunguz / gist_1
Created March 7, 2013 20:00
This gist has been created from CodeCred.me
def leap_year? (year)
if year%100 == 0 && year%400 == 0
puts "Leap Year!"
elsif year%4 == 0 && year%100 != 0
puts "Leap Year!"
else
puts "Not Leap Year!"
end
end
@lordhumunguz
lordhumunguz / leap_year.rb
Created March 7, 2013 20:07
Leap year method
#Leap years are divisible by 4 (like 1992 and 1996).
#There is an exception, though, and an exception to the exception:
#if a year is divisible by 100, it's not a leap year (like 1900),
#unless it is also divisible by 400 (like the year 2000).
def leap_year? (year)
if year%100 == 0 && year%400 == 0
puts "Leap Year!"
elsif year%4 == 0 && year%100 != 0
puts "Leap Year!"
@lordhumunguz
lordhumunguz / pig_latin.rb
Created March 8, 2013 09:26
This gist has been created from CodeCred.me
def pig_latin(string1)
string1.to_s.downcase!
if #If a word begins with a vowel (aeiou), add 'ay' to the end.
string1[0] == 'a' || string1[0] == 'e' || string1[0] == 'i' || string1[0] == 'o' || string1[0] == "u"
string1 += 'ay'
elsif #If a word begins with 'qu', move the 'qu' to the end of the word and add 'ay' after it.
string1[0,2] == 'qu'
string1 = string1.insert(-1, 'qu') + 'ay'
string1 = string1[2..-1]
else #If a word begins with a consonant, move it to the end of the word and add 'ay' after it.
@lordhumunguz
lordhumunguz / gist_1
Created March 12, 2013 04:28
This gist has been created from CodeCred.me
#Turns Integer into a Roman Numeral
# Old Roman Numeral
puts "What number would you like to convert to Roman Numeral?"
def to_roman(number)
number = number.to_i
str = ""
until number < 3000 && number > 0
puts "Please put in a number between 1 and 3000"
number = gets.chomp.to_i
end
@lordhumunguz
lordhumunguz / gist_1
Created March 12, 2013 05:44
This gist has been created from CodeCred.me
def bottle_song_recursive(n)
if n==1
puts "1 bottle of beer on the wall, 1 bottle of beer. Take one down, pass it around, no more bottles of beer on the wall!"
else
puts "#{n} bottles of beer on the wall, #{n} bottles of beer. Take one down, pass it around, #{n-1} bottles of beer on the wall!"
n -= 1
bottle_song_recursive(n) unless n == 0
end
end
@lordhumunguz
lordhumunguz / gist_1
Created March 15, 2013 08:00
This gist has been created from CodeCred.me
require_relative './racer_utils'
#assume 'racer_utils' works
class RubyRacer
attr_reader :players, :length
def initialize(players, length = 30)
@players = players
@length = length
@die = Die.new
@lordhumunguz
lordhumunguz / gist_1
Created March 15, 2013 08:01
This gist has been created from CodeCred.me
class BoggleBoard
DICE = [['A','A','E','E','G','N'],
['E','L','R','T','T','Y'],
['A','O','O','T','T','W'],
['A','B','B','J','O','O'],
['E','H','R','T','V','W'],
['C','I','M','O','T','U'],
['D','I','S','T','T','Y'],
['E','I','O','S','S','T'],
['D','E','L','R','V','Y'],
@lordhumunguz
lordhumunguz / datastructure.rb
Created May 22, 2013 05:09
Data Structure exercise
class Array_List
attr_accessor :initial_size, :list_size, :array_length, :content
def initialize
@initial_size = 10
@list_size = 0
@array_length = @initial_size
@content = Array.new(@initial_size)
end
def append(element)
var binarySearch = function(list1, item){
var list = list1.sort();
var startIndex = 0;
var endIndex = list.length-1;
var midIndex = Math.ceil(list.length/2);
while(startIndex !== endIndex){
midIndex = Math.ceil((endIndex+1)/2);
var midVal = list[midIndex];
class Car
attr_reader :ignited, :direction
def initialize(brand, model, args={})
@brand = brand
@model = model
@color = args[:color]
@mpg = args[:mpg]
@ignited = false
@direction = nil
end