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
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)

Matthew Miner
28 changes: 28 additions & 0 deletions anagrams.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def anagrams(input_word)
anagrams = []

# split and alphabetize input_word
alpha_input_word = input_word.split("").sort

# load dictionary
file = File.open('enable.txt', 'r')
dictionary = file.read.split("\n")
file.close

# split words from dictionary and alphabetize chars
dictionary.each do | dictionary_word |
alpha_dictionary_word = dictionary_word.split("").sort

# checks if alphabetized chars of dictionary word match input_word
if dictionary_word == input_word
next
elsif alpha_dictionary_word == alpha_input_word
anagrams.push(dictionary_word)
end
end

puts anagrams

end

anagrams("pears")
32 changes: 32 additions & 0 deletions dice_roll_outcomes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def dice_roll_outcomes(dice, rolls)
# set up hash
results = {}

min = dice * 1
max = dice * 6

# populate hash with possible outcomes
(min..max).each do | outcome |
results[outcome] = ""
end

rolls.times do

sum = 0

dice.times do
sum+= rand(1..6)
end

# add pound sign for each outcome
results[sum] += "#"
end

# print outcomes
results.each do | outcome, count |
puts "#{outcome}: #{count}\n"
end
end

dice_roll_outcomes(3, 100)

Loading