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)

Aaron G.
27 changes: 27 additions & 0 deletions anagram.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# # Write a method anagrams which returns an array
# of anagrams that can be made with the specified
# string. Assume the input is only a single word
# (e.g. "loot" not "William Shakespeare").

# # Download enable.txt, a popular Scrabble dictionary,
# and load it in as your dictionary of choice.
# If you haven't encountered Ruby's file I/O yet,
# you can test your method by simply providing an
# array of known anagrams like those below to check
# that it works properly.

# # You can use Dir.pwd to output the current
# directory. If you can't find the dictionary,
# double check the directory you're executing your
# script from within.

def anagrams(word)
sort_word = word.split("").sort.join
anagrams_array = []
IO.foreach("enable.txt") {|line| anagrams_array << line.chomp}
anagrams_array.select do |anagram|
anagram.split("").sort.join == sort_word
end
end

puts anagrams("enable")
32 changes: 32 additions & 0 deletions diceoutcomes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#Now write a method dice_outcomes which takes the
#number of dice to roll and the number of
#times to roll them, then outputs a visual chart
#of how many times each possible number comes up.

def roll_dice(n=1)
result = 0
n.times do
dice = rand(6) + 1
result += dice
end
return result
end

def dice_outcomes(num_dice, num_times)
result = Hash.new(0)
num_times.times do
roll = roll_dice(num_dice)
result[roll] += 1
end
(num_dice * 6).times do |index|
visual = []
puts result[index + 1]
visual << "#"
#visual output
puts count_string
end
end


dice_outcomes(1,20)

Loading