Skip to content

Instantly share code, notes, and snippets.

@ewhitebloom
ewhitebloom / Sorting and Averaging Algorithms
Last active August 29, 2015 13:56
Sorting and Averaging Algorithms
nums = [75, 100, 85, 65, 84, 87, 95]
def average(nums)
sum = 0
nums.each do |number|
sum += number
end
sum/nums.length
end
@ewhitebloom
ewhitebloom / gist:9126682
Created February 21, 2014 00:49
Grocery Git Practice
commit 1b60a793e9a74abba5eda41a265c58f011c661b5
Author: ewhitebloom <ewhitebloom@gmail.com>
Date: Thu Feb 20 19:48:55 2014 -0500
Even more items added
commit 191736b523c0cc14a191a5acc5fae586952d4a74
Author: ewhitebloom <ewhitebloom@gmail.com>
Date: Thu Feb 20 19:47:32 2014 -0500
@ewhitebloom
ewhitebloom / Favorite Movies
Created February 21, 2014 00:30
Favorite Movies
favorite_movies = [
{ title: 'The Big Lebowski', year_released: 1998, director: 'Joel Coen', imdb_rating: 8.2 },
{ title: 'The Shining', year_released: 1980, director: 'Stanley Kubrick', imdb_rating: 8.5 },
{ title: 'Troll 2', year_released: 1990, directory: 'Claudio Fragasso', imdb_rating: 2.5 }
]
favorite_movies.each do |movie|
puts "#{movie[:year_released]}: #{movie[:title]}"
end
@ewhitebloom
ewhitebloom / Game of Thrones Hash Practice
Created February 20, 2014 22:49
Game of Thrones Hash Practice
characters = {
"Tyrion Lannister" => "House Lannister",
"Jon Snow" => "Night's Watch",
"Hodor" => "House Stark",
"Stannis Baratheon" => "House Baratheon",
"Theon Greyjoy" => "House Greyjoy"
}
characters.each do |key,value|
puts key + " represents the " + value
@ewhitebloom
ewhitebloom / Second Cash Register Challenge
Last active August 29, 2015 13:56
Second Register Challenge
def sales_price_loop
input = nil
totals = []
subtotal = 0
until input == "done"
puts "What is the sale price?"
unless input == "done"
input = gets.chomp
subtotal = tally(input, totals, subtotal)
end
@ewhitebloom
ewhitebloom / gist:9085487
Last active August 29, 2015 13:56
Guessing Game
NUMBER = 673
message = print "Guess a number between 0 and 1000:"
guess = gets.chomp.to_i
until guess == NUMBER
message = "Guess a number between 0 and 1000:"
difference = NUMBER - guess
if difference >= 0
puts "Too low, try again..."
light = 5
medium = 7.50
bold = 9.75
puts "How much money does the customer owe?"
owed = gets.chomp.to_f
puts "How much money did the customer give you?"