Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions candy_count_flex.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#The following is an array of each color of skittles in a single bag. It is your job to enter a color, and for it to return to you the number count of that color. It should be in a sentence.

#Example "There are 4 orange"

candy_array = ["PUrple", "reD", "Red", "PUrple", "red", "GreEn", "Red", "PUrple", "Red", "Orange", "PUrple", "Green", "Red", "PUrple", "Red", "Green", "PUrple", "PUrple", "Red", "PUrple", "Red", "Red", "Red", "Yellow", "PUrple", "PUrple", "OrAnge", "PUrple", "Red", "Red", "PUrPle", "Green", "Green", "Red", "Red", "Orange", "OraNge", "PUrple", "PUrple", "Green", "Yellow", "Purple", "purple", "Red", "Orange", "Purple", "Green", "Red", "Red", "Green", "Yellow", "Red", "Red", "Green", "Red", "Green", "Yellow", "Orange", "Red", "Green", "Yellow", "Yellow", "Green", "OraNge", "Red", "Purple", "Green", "Red", "Red", "Purple", "Purple", "red", "Purple", "YelLow", "Green", "Purple", "YEllow", "orange", "Orange", "Green", "red", "red", "Green", "OrAnge", "Purple", "red", "red", "Red", "Yellow", "REd", "Purple", "Red", "Yellow", "Green", "Red", "Purple", "Yellow", "Red", "Purple", "green", "Purple", "Purple", "green", "Red"]

input = gets.chomp.downcase

candy_count = 0

candy_array.each do |color|
color = color.downcase
if color == input
candy_count = candy_count + 1
end
end

puts "There are #{candy_count} #{input}"
39 changes: 39 additions & 0 deletions candy_count_sort.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#The following is an array of each color of skittles in a single bag. It is your job to return in a sentace the number of each of color. The order of the colors matter in the output.

#Example "12 yellow, 33 red, 22 purple, 5 green and 1 orange."

candy_array = ["PUrple", "reD", "Red", "PUrple", "red", "GreEn", "Red", "PUrple", "Red", "Orange", "PUrple", "Green", "Red", "PUrple", "Red", "Green", "PUrple", "PUrple", "Red", "PUrple", "Red", "Red", "Red", "Yellow", "PUrple", "PUrple", "OrAnge", "PUrple", "Red", "Red", "PUrPle", "Green", "Green", "Red", "Red", "Orange", "OraNge", "PUrple", "PUrple", "Green", "Yellow", "Purple", "purple", "Red", "Orange", "Purple", "Green", "Red", "Red", "Green", "Yellow", "Red", "Red", "Green", "Red", "Green", "Yellow", "Orange", "Red", "Green", "Yellow", "Yellow", "Green", "OraNge", "Red", "Purple", "Green", "Red", "Red", "Purple", "Purple", "red", "Purple", "YelLow", "Green", "Purple", "YEllow", "orange", "Orange", "Green", "red", "red", "Green", "OrAnge", "Purple", "red", "red", "Red", "Yellow", "REd", "Purple", "Red", "Yellow", "Green", "Red", "Purple", "Yellow", "Red", "Purple", "green", "Purple", "Purple", "green", "Red"]

candy_hash = {:red => 0, :yellow => 0, :purple => 0, :green => 0, :orange => 0}

candy_array.each do |color|

color = color.downcase

if color == "red"

count = candy_hash.fetch(:red) + 1
candy_hash.store(:red, count)

elsif color == "green"
count = candy_hash.fetch(:green) + 1
candy_hash.store(:green, count)

elsif color == "orange"
count = candy_hash.fetch(:orange) + 1
candy_hash.store(:orange, count)

elsif color == "yellow"
count = candy_hash.fetch(:yellow) + 1
candy_hash.store(:yellow, count)

elsif color == "purple"
count = candy_hash.fetch(:purple) + 1
candy_hash.store(:purple, count)

end
end



p "#{candy_hash.fetch(:yellow)} yellow, #{candy_hash.fetch(:red)} red, #{candy_hash.fetch(:purple)} purple, #{candy_hash.fetch(:green)} green and #{candy_hash.fetch(:yellow)} orange."
52 changes: 52 additions & 0 deletions food_match_1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#Given the following data array of people returns an array of hashes which lists the names of the people and a count of the dishes that are the same as Laura. The output should be displayed as [{:name=>"Kevin", :like_count=>3}, {:name=>"Tom", :like_count=>5}, ext]

people = [{:name => "Laura", :likes => ["pizza", "cake", "tequila", "apples", "steak"]}, {:name => "Kevin", :likes => ["pizza", "chicken", "pasta", "cerial", "pop"]}, {:name => "Tom", :likes => ["beer", "icecream", "tequila", "apples", "steak"]}, {:name => "Pat", :likes => ["pizza", "cake", "coffee", "garlic", "soda"]}, {:name => "Raghu", :likes => ["pizza", "carbs", "wiskey", "grapes", "oranges"]}, {:name => "Bob", :likes => ["broccoli", "cheese", "bread", "hotdog", "chimchanga"]}, {:name => "Mike", :likes => ["cabbage", "kiwi", "tequila", "apples", "steak"]}, {:name => "Jealni", :likes => ["cookies", "freeFood", "sweets", "candy", "steak"]}]

laura_likes = people.at(0).fetch(:likes)

like_count = 0

like_tracker = []
people.each do |person|
like_count = 0
if person.fetch(:name) != "Laura"
laura_likes.each do |like|
if person.fetch(:likes).count(like) == 1
like_count = like_count + 1
end
end
like_count_per_person = {:name => person.fetch(:name), :like_count => like_count}
like_tracker.push(like_count_per_person)
end
end

p like_tracker

highest_person = []
like_tracker.each do |person|
if highest_person.at(0) == nil
highest_person.push(person)
else
if person.fetch(:like_count) > highest_person.at(0).fetch(:like_count)
highest_person = []
highest_person.push(person)
elsif person.fetch(:like_count) == highest_person.at(0).fetch(:like_count)
highest_person.push(person)
end
end
end

p highest_person

# if highest_person.count == 1
# p "The best match is #{highest_person.at(0).fetch(:name)}"
# elsif highest_person.count == 0
# p "Im sorry but no one likes the same things as you"
# else
# names = []
# highest_person.each do |person|
# name = person.fetch(:name)
# names.push(name)
# end
# p "The best matches are #{names.to_sentence}"
# end
52 changes: 52 additions & 0 deletions food_match_2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#Now taken what you have done in food_match_1 return an array with with the highest person/persons and their count. Example would be [[{:name=>"Tom", :like_count=>4}, {:name=>"Mike", :like_count=>4}]]

people = [{:name => "Laura", :likes => ["pizza", "cake", "tequila", "apples", "steak"]}, {:name => "Kevin", :likes => ["pizza", "chicken", "pasta", "cerial", "pop"]}, {:name => "Tom", :likes => ["beer", "icecream", "tequila", "apples", "steak"]}, {:name => "Pat", :likes => ["pizza", "cake", "coffee", "garlic", "soda"]}, {:name => "Raghu", :likes => ["pizza", "carbs", "wiskey", "grapes", "oranges"]}, {:name => "Bob", :likes => ["broccoli", "cheese", "bread", "hotdog", "chimchanga"]}, {:name => "Mike", :likes => ["cabbage", "kiwi", "tequila", "apples", "steak"]}, {:name => "Jealni", :likes => ["cookies", "freeFood", "sweets", "candy", "steak"]}]

laura_likes = people.at(0).fetch(:likes)

like_count = 0

like_tracker = []
people.each do |person|
like_count = 0
if person.fetch(:name) != "Laura"
laura_likes.each do |like|
if person.fetch(:likes).count(like) == 1
like_count = like_count + 1
end
end
like_count_per_person = {:name => person.fetch(:name), :like_count => like_count}
like_tracker.push(like_count_per_person)
end
end

p like_tracker

highest_person = []
like_tracker.each do |person|
if highest_person.at(0) == nil
highest_person.push(person)
else
if person.fetch(:like_count) > highest_person.at(0).fetch(:like_count)
highest_person = []
highest_person.push(person)
elsif person.fetch(:like_count) == highest_person.at(0).fetch(:like_count)
highest_person.push(person)
end
end
end

p highest_person

# if highest_person.count == 1
# p "The best match is #{highest_person.at(0).fetch(:name)}"
# elsif highest_person.count == 0
# p "Im sorry but no one likes the same things as you"
# else
# names = []
# highest_person.each do |person|
# name = person.fetch(:name)
# names.push(name)
# end
# p "The best matches are #{names.to_sentence}"
# end
64 changes: 64 additions & 0 deletions food_match_3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#Now taken the code that you have complete in food match 2, return a sentence which lists the person / persons with the highest match. Example "The highest match is Keven" or "The highest matches are Kevin and Bob"

people = [{:name => "Laura", :likes => ["pizza", "cake", "tequila", "apples", "steak"]}, {:name => "Kevin", :likes => ["pizza", "chicken", "pasta", "cerial", "pop"]}, {:name => "Tom", :likes => ["beer", "icecream", "tequila", "apples", "steak"]}, {:name => "Pat", :likes => ["pizza", "cake", "coffee", "garlic", "soda"]}, {:name => "Raghu", :likes => ["pizza", "carbs", "wiskey", "grapes", "oranges"]}, {:name => "Bob", :likes => ["broccoli", "cheese", "bread", "hotdog", "chimchanga"]}, {:name => "Mike", :likes => ["cabbage", "kiwi", "tequila", "apples", "steak"]}, {:name => "Jealni", :likes => ["cookies", "freeFood", "sweets", "candy", "steak"]}]

laura_likes = people.at(0).fetch(:likes)

like_count = 0

like_tracker = []
people.each do |person|
like_count = 0
if person.fetch(:name) != "Laura"
laura_likes.each do |like|
if person.fetch(:likes).count(like) == 1
like_count = like_count + 1
end
end
like_count_per_person = {:name => person.fetch(:name), :like_count => like_count}
like_tracker.push(like_count_per_person)
end
end

p like_tracker

highest_person = []
like_tracker.each do |person|
if highest_person.at(0) == nil
highest_person.push(person)
else
if person.fetch(:like_count) > highest_person.at(0).fetch(:like_count)
highest_person = []
highest_person.push(person)
elsif person.fetch(:like_count) == highest_person.at(0).fetch(:like_count)
highest_person.push(person)
end
end
end

p highest_person

if highest_person.count == 1
p "The highest match is #{highest_person.at(0).fetch(:name)}"
elsif highest_person.count == 0
p "Im sorry but no one likes the same things as you"
else
names = []
highest_person.each do |person|
name = person.fetch(:name)
names.push(name)
end
sentence = "The highest matches are #{names.at(0)}"
count = names.count
names.each_with_index do |name, index|
if index == count - 1
sentence = sentence + " and #{name}"
elsif index > 0 && index < count - 1
sentence = sentence + ", #{name}"

else
end

end
p sentence
end
64 changes: 64 additions & 0 deletions food_match_4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#Now can you take all of the code that are present and make it dynamic.

people = [{:name => "Laura", :likes => ["pizza", "cake", "tequila", "apples", "steak"]}, {:name => "Kevin", :likes => ["pizza", "chicken", "pasta", "cerial", "pop"]}, {:name => "Tom", :likes => ["beer", "icecream", "tequila", "apples", "steak"]}, {:name => "Pat", :likes => ["pizza", "cake", "coffee", "garlic", "soda"]}, {:name => "Raghu", :likes => ["pizza", "carbs", "wiskey", "grapes", "oranges"]}, {:name => "Bob", :likes => ["broccoli", "cheese", "bread", "hotdog", "chimchanga"]}, {:name => "Mike", :likes => ["cabbage", "kiwi", "tequila", "apples", "steak"]}, {:name => "Jealni", :likes => ["cookies", "freeFood", "sweets", "candy", "steak"]}]

laura_likes = people.at(0).fetch(:likes)

like_count = 0

like_tracker = []
people.each do |person|
like_count = 0
if person.fetch(:name) != "Laura"
laura_likes.each do |like|
if person.fetch(:likes).count(like) == 1
like_count = like_count + 1
end
end
like_count_per_person = {:name => person.fetch(:name), :like_count => like_count}
like_tracker.push(like_count_per_person)
end
end

p like_tracker

highest_person = []
like_tracker.each do |person|
if highest_person.at(0) == nil
highest_person.push(person)
else
if person.fetch(:like_count) > highest_person.at(0).fetch(:like_count)
highest_person = []
highest_person.push(person)
elsif person.fetch(:like_count) == highest_person.at(0).fetch(:like_count)
highest_person.push(person)
end
end
end

p highest_person

if highest_person.count == 1
p "The highest match is #{highest_person.at(0).fetch(:name)}"
elsif highest_person.count == 0
p "Im sorry but no one likes the same things as you"
else
names = []
highest_person.each do |person|
name = person.fetch(:name)
names.push(name)
end
sentence = "The highest matches are #{names.at(0)}"
count = names.count
names.each_with_index do |name, index|
if index == count - 1
sentence = sentence + " and #{name}"
elsif index > 0 && index < count - 1
sentence = sentence + ", #{name}"

else
end

end
p sentence
end
14 changes: 14 additions & 0 deletions secret_decoder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# We have a way to encode our messages, now can you write a way to decode them?

puts "Enter in the secret you want to decode"
message = gets.chomp
#message = "3 n22d t4 b2 m4r2 s2cr2t"
decode = message.downcase.gsub("1","a").gsub("2","e").gsub("3","i").gsub("4","o").gsub("5","u")

puts decode

cap_string = decode.capitalize



puts cap_string
7 changes: 7 additions & 0 deletions secret_encoder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#Create an encoder that will allow you to enter a string and replace the vowels. Here is our secret code, don't tell anyone... a = 1, e = 2, i = 3, o = 4, u = 5

puts "Enter in the secret you want to encode"
my_code = gets.chomp
new_code = my_code.downcase.gsub("a","1").gsub("e","2").gsub("i","3").gsub("o","4").gsub("u","5")

puts new_code.capitalize
12 changes: 12 additions & 0 deletions spec/scripts/candy_count_flex_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
describe "candy_count_flex.rb" do
it "Should return 'There are 37 red' when the input is red", points: 1 do

allow_any_instance_of(Object).to receive(:gets).and_return("red\n")





expect { require_relative '../../candy_count_flex.rb' }.to output(/There are 36 red/).to_stdout
end
end
12 changes: 12 additions & 0 deletions spec/scripts/candy_count_sort_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
describe "candy_count_sort.rb" do
it "Should return '11 yellow, 36 red, 28 purple, 19 green and 11 orange.'", points: 1 do







expect { require_relative '../../candy_count_sort.rb' }.to output(/11 yellow, 36 red, 28 purple, 19 green and 11 orange./).to_stdout
end
end
33 changes: 0 additions & 33 deletions spec/scripts/dummy_spec.rb

This file was deleted.

8 changes: 8 additions & 0 deletions spec/scripts/secret_decoder_1_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
describe "secret_decoder.rb" do
it "should output 'Our decoded message'", points: 1 do
allow_any_instance_of(Object).to receive(:gets).and_return("3 n22d t4 b2 m4r2 s2cr2t\n")
expect { require_relative '../../secret_decoder.rb' }.to output(/I need to be more secret/).to_stdout
end
end


Loading