Skip to content

Instantly share code, notes, and snippets.

View danielbonnell's full-sized avatar

Daniel Bonnell danielbonnell

  • Mondu
  • Hannover, Germany
View GitHub Profile
@danielbonnell
danielbonnell / 99bottles.rb
Last active August 29, 2015 14:06
99 Bottles Challenge
beers = 99
while beers > 0
puts beers.to_s + ' bottles of beer on the wall, ' + beers.to_s + ' bottles of beer!'
beers -= 1
if beers < 1
puts "Ya take one down, pass it around, no more bottles of beer on the wall!"
else
puts 'Ya take one down, pass it around, ' + beers.to_s + ' bottles of beer on the wall!'
end
@danielbonnell
danielbonnell / numSheep.js
Created September 25, 2014 17:53
Codeschool: Javascript Roadtrip II Challenge
var numSheep = 4;
var monthsToPrint = 12;
for(var monthNumber = 1; monthNumber <= monthsToPrint; monthNumber++) {
if (monthNumber % 4 = 0) {
numSheep *= .75;
var removed = numSheep;
console.log("Removing " + removed + " sheep from the population. Phew!");
} else if (numSheep > 10000) {
numSheep /= 2;
@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: "--.",
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 / 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
@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 / 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 / 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 / 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 / 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