Skip to content

Instantly share code, notes, and snippets.

View danielbonnell's full-sized avatar

Daniel Bonnell danielbonnell

  • HDI AG
  • Hannover, Deutschland
View GitHub Profile
@danielbonnell
danielbonnell / cats.rb
Created November 13, 2014 13:36
Apollo: building-compound-data-structures
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
@danielbonnell
danielbonnell / round_robin.rb
Last active August 29, 2015 14:08
Round Robin Challenge
def schedule_tournament(names)
matches = names.product(names)
rounds = []
matches.sort!.each do |sub|
sub.sort!
matches.delete(sub) if sub[0] == sub[1]
end
matches.uniq!
@danielbonnell
danielbonnell / shakespeare.rb
Last active August 29, 2015 14:08
Shakespeare Challenge
def word_frequency(sample_file)
count = Hash.new(0)
IO.readlines(sample_file).each do |line|
line.split(/[\W\s]/).each do |word|
count[word.downcase] += 1
end
end
count
@danielbonnell
danielbonnell / drills.rb
Created October 22, 2014 18:53
Regex Drills Challenge
def valid_email?(input)
regex = /(\w*|\w*[.]\w*|\w*[-]\w*)[@](\w*|\w*[.]\w*|\w*[-]\w*)[.]((\w{2,4})|(\w{2}[.]\w{2,3}))/
regex.match(input) != nil ? true : false
end
def valid_phone_number?(input)
regex = /\d{10}|[(]\d{3}[)]\s\d{3}[-]\d{4}|[(]\d{3}[)][-]\d{3}[-]\d{4}|\d{3}[-]\d{3}[-]\d{4}/
regex.match(input) != nil ? true : false
end
@danielbonnell
danielbonnell / mini_golf.rb
Created October 21, 2014 21:04
Mini Golf Challenge
def display_scores(file)
num = 1
rankings = Hash.new
File.open(file).each_line do |line|
total = 0
line = line.split(',')
name = line.shift
line.each do |strokes|
@danielbonnell
danielbonnell / hex_to_decimal.rb
Last active August 29, 2015 14:07
Hexadecimal Converter Challenge
def hex_to_decimal(input)
input = input.split('')
array = []
input.each do |x|
x == "A" ? x.replace("10").to_i : x
x == "B" ? x.replace("11").to_i : x
x == "C" ? x.replace("12").to_i : x
x == "D" ? x.replace("13").to_i : x
x == "E" ? x.replace("14").to_i : x
@danielbonnell
danielbonnell / common_words.rb
Last active August 29, 2015 14:07
Common Words Challenge
def most_common(string)
counts = {}
words = string.downcase.tr(",.?!",'').split(' ')
words.uniq.each do |word|
counts[word] = 0
end
words.each do |word|
counts[word] = string.scan(word).count
@danielbonnell
danielbonnell / tic_tac_to.rb
Last active August 29, 2015 14:07
tic-tac-to challenge
def winner?(board)
@match = false
def check(type)
@match = true if type.uniq.length == 1 && !type.include?(" ")
end
board.each do |row|
check(row)
end
class Person
def initialize(first_name,last_name)
@first_name = first_name
@last_name = last_name
@full_name = @first_name + " " + @last_name
end
def print
puts "My name is #{@full_name}."
puts "My name is #{@first_name} #{@last_name}."
end
@danielbonnell
danielbonnell / morse_code.rb
Last active August 29, 2015 14:07
morse_code
def decode(code)
"SOLUTION GOES HERE"
key = {
a: ".-",
b: "-...",
c: "-.-.",
d: "-..",
e: ".",
f: "..-.",
g: "--.",