Skip to content

Instantly share code, notes, and snippets.

View rvbsanjose's full-sized avatar

Richard Van Breemen rvbsanjose

View GitHub Profile
@rvbsanjose
rvbsanjose / hashed_table.rb
Created October 7, 2012 10:23
Hashed table
def hashed_table
hashed_data_table = Array.new(4)
hashed_data_table[0] = ["Number", "Name", "Position", "Points per Game"]
hashed_data_table[1] = ["12", "Joe Schmo", "Center", "[14, 32, 7, 0, 23]"]
hashed_data_table[2] = ["9", "Ms. Buckets", "Point Guard", "[19, 0, 11, 22, 0]"]
hashed_data_table[3] = ["31", "Harvey Kay", "Shooting Guard", "[0, 30, 16, 0, 25]"]
hashed_data_table[4] = ["18", "Sally Talls", "Power Forward", "[18, 29, 26, 31, 19]"]
hashed_data_table[5] = ["22", "MK DiBoux", "Small Forward", "[11, 0, 23, 17, 0]"]
index = 1
player_info = []
@rvbsanjose
rvbsanjose / birthday_timestamp.rb
Created October 7, 2012 10:15
Birthday timestamp
def birthday_timestamp(date)
date = date.split('/')
month, day, year = date.pop(3)
birthday = Time.mktime(year, month, day)
time_now = Time.now
years = time_now.year - birthday.year
months = time_now.month - birthday.month
days = time_now.day - birthday.day
puts "#{years} years #{-months} months #{-days} day old" if days < 2
puts "#{years} years #{months} months #{days} days old" if days > 2
@rvbsanjose
rvbsanjose / read_the_error_2.rb
Created October 7, 2012 10:10
Deaf Grandma 2
def print_and_sort(array)
output_string = ""
array.map!(&:to_s).each do |element|
output_string = output_string + " " + element
end
puts output_string
array.sort
end
@rvbsanjose
rvbsanjose / read_the_error.rb
Created October 7, 2012 10:09
Read the Error
def print_and_sort(array)
output_string = ""
array = array.map! {|str| str.to_s }
array.each do |element|
output_string = output_string + " " + element
end
puts output_string
array.sort
end
@rvbsanjose
rvbsanjose / deaf_grandma.rb
Created October 7, 2012 10:03
Deaf Grandma
def deaf_grandma
returns = 0
until returns == 2
print "Say something to grandma: "
response = gets.chomp
if response.empty?
returns += 1
elsif response.match(/[A-Z]/)
puts "NO, NOT SINCE 1938!"
else
# Put your answers here!
@rvbsanjose
rvbsanjose / prime_factors.rb
Created October 4, 2012 06:30
Prime factors
def primes(input)
primes = []
number = 2
(number..input).each do
if input % number == 0
primes << number
input /= number
else
number += 1
end
@rvbsanjose
rvbsanjose / pseudocode.rb
Created October 2, 2012 21:51 — forked from scottchiang/pseudocode
pseudocode
Script: CONVERT EVERY OTHER LETTER OF A SENTENCE TO CAPITAL LETTERS
GET a sentence from user input
IF the word starts with a capital letter, don't change it
ELSE convert every other letter to capital letters
ENDIF
PRINT the formatted sentence
def new_pseudo
sentence = gets.chomp
@rvbsanjose
rvbsanjose / my_pseudo.txt
Created October 2, 2012 21:44
Pseudocode and share
Script: Covert sentences
Get a sentence from user input.
If the sentence length is greater than 20, randomize the sentence
Else take the 2nd letter of each word and change it to the letter P
ENDIF
PRINT the new sentence
$name = function($name) {
echo "Hello $name";
}
$name("A name");