Skip to content

Instantly share code, notes, and snippets.

@hchood
hchood / ruby_fund_1.rb
Last active December 28, 2015 08:19
Ruby Fundamentals I - CHALLENGE
# Ruby Fundamentals I - CHALLENGE
def check_and_format(amount)
formatted_amount = nil
if amount.match(/\A[0-9]*[.][\d]{2}\z/)
formatted_amount = amount.to_f
else
puts "WARNING: Invalid currency detected! Exiting..."
abort
@hchood
hchood / scm_check-in.txt
Created November 15, 2013 00:39
Source Control Management Fundamentals - Challenge
commit 8737fb36e370f669d616a8efe339a2dd8ab9ab9d
Author: Helen Hood <helen.c.hood@gmail.com>
Date: Thu Nov 14 19:33:24 2013 -0500
added README file to .gitignore
commit e3c01692adad0ea986bc92ddf3dcfafdcf78fbf5
Author: Helen Hood <helen.c.hood@gmail.com>
Date: Thu Nov 14 19:25:49 2013 -0500
@hchood
hchood / ruby_fund_2.rb
Last active December 28, 2015 11:19
Ruby Fundamentals II - Challenge
# Ruby Fundamentals II - CHALLENGE
# Cashier problem totals purchases, outputs subtotals, calculates changes, & prints receipt.
# METHOD DEFINITIONS
def gets_price
puts "What is the sale price?"
gets.chomp
end
@hchood
hchood / list_statistics.rb
Created November 16, 2013 16:54
Ruby Fundamentals I - Challenge
# Ruby Fundamentals III - Challenge
# Write a program, given a hardcoded list of test scores, that reports the average score, the lowest score, and the highest score.
SCORES = [75, 100, 85, 65, 84, 87, 95]
def average(numbers)
numbers = numbers.each {|num| num.to_f}
sum = numbers.inject(0) {|total, num| total += num}
number_of_numbers = numbers.length.to_f
@hchood
hchood / hangman.rb
Created November 18, 2013 03:44
Ruby Fundamentals - Non-core problem: hangman game
#!/usr/bin/env ruby
# DEFINITIONS
def replace_letters(word, letters)
string = "[^" + letters.join + "]"
regex = Regexp.new(string)
new_word = word.gsub(regex, '_')
end
@hchood
hchood / kata_mailing_list.rb
Created November 19, 2013 02:16
Ruby Fundamentals III - Kata (mailing list problem)
# Ruby Fundamentals III - Kata
# INPUT ARRAYS
salutations = [
['Mr.', 'Mrs.'],
'Mrs.',
['Mr.', 'Mrs.'],
['Dr.'],
'Ms.'
@hchood
hchood / ruby_fund_3.rb
Last active December 28, 2015 19:09
Ruby Fundamentals III - Challenge
# Ruby Fundamentals III - Challenge
# NOTE: I worked on this with Jonah and then refactored on my own.
# METHOD DEFINITIONS
def get_input(prompt)
puts prompt
input = gets.chomp.to_f
end
@hchood
hchood / game_data.rb
Created November 20, 2013 16:29
Ruby Fundamentals - Non-core challenge (leaderboard from game data)
# Ruby Fundamentals III - Non-core challenge
# Calculate the leaderboard in the following format (data is exaggerated, but the Patriots are on top!)
# The list should be sorted by number of wins.
# 1. Patriots 16 wins, 0 losses
# 2. Colts, 8 wins, 8 losses
# 3. Broncos, 4 wins, 12 losses
# 4. Steelers, 2 wins, 14 losses
@hchood
hchood / kata_next_train.rb
Created November 20, 2013 22:47
User Stories Kata: The Next Train
# User Stories Kata: The Next Train
# INPUT DATA
lyrics = "\n***DON'T STOP...BELIEVIN'!***
Just a small town girl
Living in a lonely world
She took the midnight train going anywhere
Just a city boy
@hchood
hchood / ruby_fund_4_movies.rb
Created November 21, 2013 14:10
# Ruby Fundamentals IV: Building Compound Data Structures Assignment
# Ruby Fundamentals IV: Building Compound Data Structures Assignment
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]}" }