Skip to content

Instantly share code, notes, and snippets.


Dan Murphy Murphydbuffalo

View GitHub Profile
Murphydbuffalo / cashier3.rb
Last active Aug 29, 2015
Initial solution to the 3rd cashier problem
View cashier3.rb
require "CSV"
items = []
subtotal = 0
input = nil
def read_csv(items)
i = 1
CSV.foreach("products.csv", headers: true) do |entry|
items << {item_number: i, name: entry[1], price: entry[3], sku: entry[0]}
i += 1
Murphydbuffalo / compound.rb
Created May 14, 2014
1st question in compound data structures reading
View compound.rb
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 {|movie| puts "#{movie[:year_released]}: #{movie[:title]}"}
Murphydbuffalo / hangman.rb
Last active Aug 29, 2015
Solution to the hangman problem
View hangman.rb
#!/usr/bin/env ruby
wordbank = ["tumble", "elixir", "falter", "erroneous", "sensible", "arrogant"] #Create wordbank with some words
word = wordbank.sample.upcase #Choose sample word from bank
unaltered_word = word.upcase #Word will be altered later, this is used for congrats message
previous_guesses = [] #Stores user's guesses to alert when re-use is attempted
target = "_"*word.length #Displays user's progress in guessing the word
counter = 8 #Create and display a counter for guesses
def add_guess(array, guess) #DRY's out adding old guesses to their array
Murphydbuffalo / cashier2.rb
Last active Aug 29, 2015
The solution to the second cashier problem
View cashier2.rb
puts "Please enter item prices: " #prompts for item prices
input = gets.chomp
charges = []
def total(array)
array.inject(0) {|total, each| total + each}
until input.downcase == "done"
charges << input.to_f
Murphydbuffalo / cashier.rb
Last active Aug 29, 2015
Solution to the cashier problem
View cashier.rb
#prompted for amount due
puts "How much does the customer owe?"
bill = gets.chomp.to_f.round(2)
#prompted for amount received
puts "How much did the customer pay?"
payment = gets.chomp.to_f.round(2)
#gives change and time of transaction or provides message and exits if not enough is provided
change = (payment-bill).abs
#if payment > bill return the difference of the two and the time
if payment > bill