diff --git a/candy_count_flex.rb b/candy_count_flex.rb new file mode 100644 index 0000000..c6d98f0 --- /dev/null +++ b/candy_count_flex.rb @@ -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}" \ No newline at end of file diff --git a/candy_count_sort.rb b/candy_count_sort.rb new file mode 100644 index 0000000..7b2ad04 --- /dev/null +++ b/candy_count_sort.rb @@ -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." diff --git a/food_match_1.rb b/food_match_1.rb new file mode 100644 index 0000000..2a0cdb0 --- /dev/null +++ b/food_match_1.rb @@ -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 diff --git a/food_match_2.rb b/food_match_2.rb new file mode 100644 index 0000000..614c982 --- /dev/null +++ b/food_match_2.rb @@ -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 diff --git a/food_match_3.rb b/food_match_3.rb new file mode 100644 index 0000000..085dba9 --- /dev/null +++ b/food_match_3.rb @@ -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 diff --git a/food_match_4.rb b/food_match_4.rb new file mode 100644 index 0000000..7af2485 --- /dev/null +++ b/food_match_4.rb @@ -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 diff --git a/secret_decoder.rb b/secret_decoder.rb new file mode 100644 index 0000000..da868fa --- /dev/null +++ b/secret_decoder.rb @@ -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 \ No newline at end of file diff --git a/secret_encoder.rb b/secret_encoder.rb new file mode 100644 index 0000000..56713d4 --- /dev/null +++ b/secret_encoder.rb @@ -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 \ No newline at end of file diff --git a/spec/scripts/candy_count_flex_spec.rb b/spec/scripts/candy_count_flex_spec.rb new file mode 100644 index 0000000..fccb8fa --- /dev/null +++ b/spec/scripts/candy_count_flex_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/scripts/candy_count_sort_spec.rb b/spec/scripts/candy_count_sort_spec.rb new file mode 100644 index 0000000..a7a6806 --- /dev/null +++ b/spec/scripts/candy_count_sort_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/scripts/dummy_spec.rb b/spec/scripts/dummy_spec.rb deleted file mode 100644 index 041381a..0000000 --- a/spec/scripts/dummy_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ - -# describe "integer_math.rb" do -# it "should output '1'", points: 1 do -# math_file = "integer_math.rb" -# file_contents = File.read(math_file) -# File.foreach(math_file).with_index do |line, line_num| -# if line.include?("p") || line.include?("puts") -# expect(line).to_not match(/1/), -# "Expected 'integer_math.rb' to NOT literally print '1', but did anyway." -# end -# end -# expect { require_relative '../../integer_math' }.to output("1\n").to_stdout - -# end -# end - -# describe "test_file.rb" do -# it "should output 'true' if the entered number is odd", points: 1 do -# # Un-require test_file.rb -# test_file = $".select{|r| r.include? 'test_file.rb'} -# $".delete(test_file.first) - -# allow_any_instance_of(Object).to receive(:gets).and_return("input\n") - -# expect { require_relative '../../test_file' }.to output(/output/i).to_stdout -# end -# end - -describe "dummy" do - it "this project is not graded", points: 1 do - expect(true).to be true - end -end diff --git a/spec/scripts/secret_decoder_1_spec.rb b/spec/scripts/secret_decoder_1_spec.rb new file mode 100644 index 0000000..66f4cb0 --- /dev/null +++ b/spec/scripts/secret_decoder_1_spec.rb @@ -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 + + diff --git a/spec/scripts/secret_decoder_2_spec.rb b/spec/scripts/secret_decoder_2_spec.rb new file mode 100644 index 0000000..a5f4949 --- /dev/null +++ b/spec/scripts/secret_decoder_2_spec.rb @@ -0,0 +1,11 @@ +describe "secret_decoder.rb" do + it "should output 'Our decoded message'", points: 1 do + + # Un-require secret_decoder.rb + secret_decoder = $".select{|r| r.include? 'secret_decoder.rb'} + $".delete(secret_decoder.first) + + allow_any_instance_of(Object).to receive(:gets).and_return("D4n't t2ll 1ny4n2 45r c4d2\n") + expect { require_relative '../../secret_decoder.rb' }.to output(/Don't tell anyone our code/).to_stdout + end +end \ No newline at end of file diff --git a/spec/scripts/secret_encoder_1_spec.rb b/spec/scripts/secret_encoder_1_spec.rb new file mode 100644 index 0000000..67f5aec --- /dev/null +++ b/spec/scripts/secret_encoder_1_spec.rb @@ -0,0 +1,6 @@ +describe "secret_encoder.rb" do + it "should output 'Our encoded message'", points: 1 do + allow_any_instance_of(Object).to receive(:gets).and_return("I need to be more secret\n") + expect { require_relative '../../secret_encoder.rb' }.to output(/3 n22d t4 b2 m4r2 s2cr2t/).to_stdout + end +end \ No newline at end of file diff --git a/spec/scripts/secret_encoder_2_spec.rb b/spec/scripts/secret_encoder_2_spec.rb new file mode 100644 index 0000000..cc7c9dc --- /dev/null +++ b/spec/scripts/secret_encoder_2_spec.rb @@ -0,0 +1,11 @@ +describe "secret_encoder.rb" do + it "should output 'don't tell anyone our code'", points: 1 do + + # Un-require secret_encoder.rb + secret_encoder = $".select{|r| r.include? 'secret_encoder.rb'} + $".delete(secret_encoder.first) + + allow_any_instance_of(Object).to receive(:gets).and_return("don't tell anyone our code\n") + expect { require_relative '../../secret_encoder.rb' }.to output(/D4n't t2ll 1ny4n2 45r c4d2/).to_stdout + end +end \ No newline at end of file