From 3fc5d33f7cfc4334ca719f416b8131a6cedfd053 Mon Sep 17 00:00:00 2001 From: Mariah Schneeberger Date: Sat, 11 Mar 2017 09:34:14 -0600 Subject: [PATCH 1/9] added name to README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 45aa284..61d19e3 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,6 @@ assignment_ruby_warmup Dice, dice, baby. [A Ruby assignment from the Viking Codes School](http://www.vikingcodeschool.com) + +
+Mariah Schneeberger From df35b7c3f6073a9de57885f4b679c19096c7b7b8 Mon Sep 17 00:00:00 2001 From: Mariah Schneeberger Date: Sat, 11 Mar 2017 09:57:29 -0600 Subject: [PATCH 2/9] added roll_dice method --- roll_dice.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 roll_dice.rb diff --git a/roll_dice.rb b/roll_dice.rb new file mode 100644 index 0000000..2dad5f7 --- /dev/null +++ b/roll_dice.rb @@ -0,0 +1,13 @@ +def roll_dice(n=1) + dice = [1,2,3,4,5,6] + results_of_roll = [] + n.times do results_of_roll << dice.sample + end + sum = 0 + results_of_roll.each {|num| sum += num} + print results_of_roll + print sum +end + +roll_dice(4) +roll_dice(12) From 6a88634c53f05a163e18046e0ca06120a46ccfd0 Mon Sep 17 00:00:00 2001 From: Mariah Schneeberger Date: Sat, 11 Mar 2017 17:30:17 -0600 Subject: [PATCH 3/9] finished dice_outcomes.rb --- dice_outcomes.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 dice_outcomes.rb diff --git a/dice_outcomes.rb b/dice_outcomes.rb new file mode 100644 index 0000000..4a7d703 --- /dev/null +++ b/dice_outcomes.rb @@ -0,0 +1,22 @@ +def dice_outcomes(number_of_dice, roll_times) + dice = [1,2,3,4,5,6] + results_of_roll = [] + products = {} + roll_times.times do + results_of_roll << dice.sample(number_of_dice) + end + while results_of_roll.length > 0 + sum = 0 + results_of_roll[0].each {|num| sum += num} + if products.has_key?(sum) != true + products[sum] = 1 + else + products[sum] += 1 + end + results_of_roll.delete_at(0) + end + print products +end + + +dice_outcomes(3, 100) From cb3ef96a3591ed8fa99192850cd0e040f46407e2 Mon Sep 17 00:00:00 2001 From: Mariah Schneeberger Date: Sat, 11 Mar 2017 17:35:05 -0600 Subject: [PATCH 4/9] added code to print each key/value pair in a list --- dice_outcomes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dice_outcomes.rb b/dice_outcomes.rb index 4a7d703..1d5a5e7 100644 --- a/dice_outcomes.rb +++ b/dice_outcomes.rb @@ -15,7 +15,7 @@ def dice_outcomes(number_of_dice, roll_times) end results_of_roll.delete_at(0) end - print products + products.each {|key,value| print "#{key}: #{value}\n"} end From bd39fa05faf8597628bde45efc3c7c84d2692110 Mon Sep 17 00:00:00 2001 From: Mariah Schneeberger Date: Sun, 12 Mar 2017 10:48:41 -0500 Subject: [PATCH 5/9] basic fib equation returns just the outcome for n so far --- fibonacci.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 fibonacci.rb diff --git a/fibonacci.rb b/fibonacci.rb new file mode 100644 index 0000000..4307cba --- /dev/null +++ b/fibonacci.rb @@ -0,0 +1,20 @@ + +#fibonacci +#takes n +#returns n numbers in the fib sequence +#fib sequence each product is the product of the prior two products +def fibonacci(n) + fib_array = [] + return 1 if n <= 2 + fib_index = 3 + a, b = 1, 1 + while fib_index <= n + c = a + b + a = b + b = c + fib_index += 1 + end + fib_array << c +end + +print fibonacci(10) From 0ee30b3c5ac8e8bda030e226c17d56a70dc6e965 Mon Sep 17 00:00:00 2001 From: Mariah Schneeberger Date: Mon, 13 Mar 2017 12:53:46 -0500 Subject: [PATCH 6/9] fibonacci.rb done --- fibonacci.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fibonacci.rb b/fibonacci.rb index 4307cba..973414f 100644 --- a/fibonacci.rb +++ b/fibonacci.rb @@ -5,16 +5,17 @@ #fib sequence each product is the product of the prior two products def fibonacci(n) fib_array = [] - return 1 if n <= 2 - fib_index = 3 + fib_index = 1 a, b = 1, 1 while fib_index <= n - c = a + b + c = a a = b - b = c + b = c + b + fib_array << c fib_index += 1 end - fib_array << c + return fib_array end print fibonacci(10) +print fibonacci(14) From d70edf83a688cef9e7ede397a6c3642e9361b8a4 Mon Sep 17 00:00:00 2001 From: Mariah Schneeberger Date: Wed, 15 Mar 2017 18:44:36 -0500 Subject: [PATCH 7/9] finished stock_picker.rb --- stock_picker.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 stock_picker.rb diff --git a/stock_picker.rb b/stock_picker.rb new file mode 100644 index 0000000..ab8e6cd --- /dev/null +++ b/stock_picker.rb @@ -0,0 +1,29 @@ +#stock_picker method +#takes an array of stock prices +#finds most profitable two days to buy stocks +#then finds two most profitable days to sell those stocks +def stock_picker(prices) + answer_array = [] + day_to_buy = 0 + day_to_sell = 0 + profit = prices[1] - prices[0] + prices.each_with_index do |buy_price, buy_day| + prices.each_with_index do |sell_price, sell_day| + if sell_day > buy_day + if sell_price - buy_price > profit + profit = sell_price - buy_price + day_to_buy = buy_day + day_to_sell = sell_day + end + end + end + end + answer_array << day_to_buy + answer_array << day_to_sell + print answer_array +end + + +stock_picker([44, 30, 24, 32, 35, 30, 40, 38, 15]) +stock_picker([65, 55, 65, 43, 32, 44, 56, 68, 23, 5]) +stock_picker([33,54,57,23,12,40,68,32,46,60,35,79,34,5]) From 7869b0edd94e821f3bec90d70338a4e522e81ca0 Mon Sep 17 00:00:00 2001 From: Mariah Schneeberger Date: Thu, 16 Mar 2017 11:27:48 -0500 Subject: [PATCH 8/9] got anagrams.rb to work, but don't know how to import the text doc as the dictionary --- anagrams.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 anagrams.rb diff --git a/anagrams.rb b/anagrams.rb new file mode 100644 index 0000000..46a0743 --- /dev/null +++ b/anagrams.rb @@ -0,0 +1,13 @@ +def anagrams(word,anagrams_array) + answer_array = [] + new_word = word.upcase.split("") + print new_word + anagrams_array.each do |w| + if w.split("") & new_word == w.split("") + answer_array << w + end + end + print answer_array +end + +anagrams("pears",["APERS","APRES","ASWIR","ASPER","PARES","PARSE","PRASE","PRESA","RAPES","REAPS","SPARE","SPEAR"]) From a2966754a6bb916c9971a665365b57a11ddf4854 Mon Sep 17 00:00:00 2001 From: Mariah Schneeberger Date: Thu, 16 Mar 2017 11:30:28 -0500 Subject: [PATCH 9/9] added upcase --- anagrams.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anagrams.rb b/anagrams.rb index 46a0743..b190ece 100644 --- a/anagrams.rb +++ b/anagrams.rb @@ -3,7 +3,7 @@ def anagrams(word,anagrams_array) new_word = word.upcase.split("") print new_word anagrams_array.each do |w| - if w.split("") & new_word == w.split("") + if w.upcase.split("") & new_word == w.split("") answer_array << w end end