This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def decode(code) | |
"SOLUTION GOES HERE" | |
key = { | |
a: ".-", | |
b: "-...", | |
c: "-.-.", | |
d: "-..", | |
e: ".", | |
f: "..-.", | |
g: "--.", |
NewerOlder