Skip to content

Instantly share code, notes, and snippets.

@ambsvan
Forked from mayfer/examples.rb
Created June 4, 2014 15:51
Show Gist options
  • Save ambsvan/f4114f20233f2406767f to your computer and use it in GitHub Desktop.
Save ambsvan/f4114f20233f2406767f to your computer and use it in GitHub Desktop.
r = {
"shrimp" => [
"algae",
"other_shrimps",
"seaweed",
],
"toad" => [
"children",
"flies",
],
"lion" => [
"donut",
"tourists",
"children",
],
}
def largest_hash_key(hash)
hash.max_by{|k,v| v}[0]
end
def most_common_prey(animals_hash)
food_counts = {}
animals_hash.each do |animal, foods|
foods.each do |food|
if !food_counts.has_key? food
food_counts[food] = 0
end
food_counts[food] += 1
end
end
largest_hash_key(food_counts)
end
puts "Most common prey: #{most_common_prey(r)}"
def rhymes?(word1, word2, num_letters)
(1..num_letters).each do |letter_index|
if word1.chars[-letter_index] != word2.chars[-letter_index]
return false
end
end
return true
end
word1 = "murat"
word2 = "meercat"
puts "Do #{word1} and #{word2} rhyme? #{rhymes?(word1, word2, 100)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment