Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completed assignment #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
26 changes: 26 additions & 0 deletions anagrams.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def anagrams(search_word)
search_word.upcase!
search_word_letters = search_word.split('')
anagrams = []

File.foreach('./enable.txt') do |dict_word|
dict_word.upcase!
dict_word.strip!
anagram = true

if dict_word.length == search_word.length
next if dict_word == search_word
search_word_letters.each do |letter|
unless dict_word.include?(letter)
anagram = false
break
end
end
anagrams << dict_word if anagram
end
end
anagrams
end

answer = %w[APERS APRES ASPER PARES PARSE PRASE PRESA RAPES REAPS SPARE SPEAR]
p anagrams('pears') == answer
34 changes: 34 additions & 0 deletions dice.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
def roll_dice(num_of_dice = 1)
num_of_dice = num_of_dice.to_i
total = 0
num_of_dice.times { total += rand(1..6) }
total
end

def dice_outcomes(num_of_dice, times_to_roll)
roll_chart = {}
1.upto(num_of_dice * 6) { |i| roll_chart[i] = 0 }

times_to_roll.times do
num_rolled = roll_dice(num_of_dice)
roll_chart[num_rolled] += 1
end

tot = 0
roll_chart.each do |roll, times|
puts "#{roll}: #{'#' * times}"
tot += times
end
end

def fib(n)
current = 1
prev = 0
fib_nums = []
n.times do
fib_nums << current
current += prev
prev = current - prev
end
fib_nums
end
Loading