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
33 changes: 33 additions & 0 deletions Dice_Outcomes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
def roll_dice(num_dice=0)
dice_numbers= [1,2,3,4,5,6]
sum=0
num_dice.times do
sum += dice_numbers.sample
end
return sum
end

def dice_outcomes(num_dice,roll_times)
dice_results= []
roll_times.times do
dice_results << roll_dice(num_dice)
end
dice_results.sort!
total_counts=Hash.new(0)
dice_results.each {|key| total_counts[key] += 1}
total_counts.each do |key, value|
if value==1
puts "#{key} was rolled #{value} time"
else
puts "#{key} was rolled #{value} times"
end
end
end

puts "Please select number of dice to roll"
num_dice=gets.chomp.to_i
puts "Please select a number of times to roll them"
roll_times=gets.chomp.to_i
puts ""
puts ""
dice_outcomes(num_dice,roll_times)
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ assignment_ruby_warmup
Dice, dice, baby.

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

Allen Anderson has completed this project.
19 changes: 19 additions & 0 deletions Roll_Dice.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def roll_dice(num_dice=0)
dice_numbers= [1,2,3,4,5,6]
sum=0
num_dice.times do
sum += dice_numbers.sample
end
if num_dice==1
puts "The value of #{num_dice} die rolled, is #{sum}."
elsif num_dice > 1
puts "The total value of #{num_dice} dice rolled, is #{sum}."
else
puts "Invalid entry."
end
end


puts "Please select number of dice to roll"
num_dice=gets.chomp.to_i
roll_dice(num_dice)
15 changes: 15 additions & 0 deletions anagrams.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def anagram(input_word)
anagram_list = []
dictionary = IO.readlines('enable.txt')
dictionary.each do |word|
if input_word.chars.sort.join == word.chomp.chars.sort.join then
anagram_list << word.chomp
end
end
anagram_list.delete(input_word)
puts "The anagrams for #{input_word} are #{anagram_list}"
end

puts "Please enter any word:"
input_word=gets.chomp
anagram(input_word)
44 changes: 44 additions & 0 deletions easy_fib.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
fib1=1
fib2=2
total=0
counter=0
fib_seq=[1, 2]

puts "How much fibbin' are we doing?"
puts "Please enter a number, greater than 0."
total=gets.chomp.to_i
while total<=0 do
puts ""
puts "WHAT DID I JUST TELL YOU, SON?!"
sleep(5)
puts ""
puts "YOU ARE A DISGRACE TO ME,"
puts "TO YOUR MOTHER,"
puts "TO THE ENTIRE HUMAN RACE!!!"
puts ""
sleep (5)
puts "NOW GO TO YOUR ROOM, AND THINK ABOUT WHAT YOU DONE!"
puts "I don't want to see you out here for at least an HOUR!"
puts "DO I MAKE MYSELF CLEAR?!"
sleep(3600)
puts ""
puts "How much fibbin' are we doing?"
puts "Please enter a number, greater than 0."
total=gets.chomp.to_i
end

if total==1
fib_seq=[1]
elsif total==2
else
remaining=total-2
remaining.times do
counter = fib1 + fib2
fib_seq << counter
fib1 = fib2
fib2 = counter
end
end

puts "The Fibonacci sequence, out to #{total} is"
puts "#{fib_seq}"
Loading