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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ assignment_ruby_warmup
Dice, dice, baby.

[A Ruby assignment from the Viking Codes School](http://www.vikingcodeschool.com)

<br>
Mariah Schneeberger
13 changes: 13 additions & 0 deletions anagrams.rb
Original file line number Diff line number Diff line change
@@ -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.upcase.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"])
22 changes: 22 additions & 0 deletions dice_outcomes.rb
Original file line number Diff line number Diff line change
@@ -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
products.each {|key,value| print "#{key}: #{value}\n"}
end


dice_outcomes(3, 100)
21 changes: 21 additions & 0 deletions fibonacci.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

#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 = []
fib_index = 1
a, b = 1, 1
while fib_index <= n
c = a
a = b
b = c + b
fib_array << c
fib_index += 1
end
return fib_array
end

print fibonacci(10)
print fibonacci(14)
13 changes: 13 additions & 0 deletions roll_dice.rb
Original file line number Diff line number Diff line change
@@ -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)
29 changes: 29 additions & 0 deletions stock_picker.rb
Original file line number Diff line number Diff line change
@@ -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])