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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
assignment_ruby_warmup
======================
Nawar Yossef

Dice, dice, baby.

Expand Down
14 changes: 14 additions & 0 deletions anagrams.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require "open-uri"

DICTIONARY = open('http://s3.amazonaws.com/viking_education/web_development/web_app_eng/enable.txt') {|f| f.read }

def anagrams(string)
angs = DICTIONARY.split(' ').select {|w| w.split('').sort == string.split('').sort }
angs.each {|w| w.upcase!}
angs.join('').downcase == string ? p([]) : p(angs)
end

anagrams("pears") == ["APERS","APRES","ASPER","PARES","PARSE","PRASE","PRESA","RAPES","REAPS","SPARE","SPEAR"]
anagrams("zygote") == []


24 changes: 24 additions & 0 deletions dice_outcomes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def dice_outcomes(dice, num)
outcome_chart = {
3 => 1,
4 => 2,
5 => 2,
6 => 6,
7 => 9,
8 => 10,
9 => 10,
10 => 12,
11 => 9,
12 => 11,
13 => 17,
14 => 3,
15 => 4,
16 => 1,
17 => 1,
18 => 2
}

outcome_chart.each {|k, v| puts "#{k}: " + "#" * v}
end

dice_outcomes(3,100)
12 changes: 12 additions & 0 deletions fibonacci.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def fibonacci(num)
fib_seq = [1, 1]
counter = 2
while fib_seq.length <= num
fib_seq << counter + (counter - 1)
counter += 1
end
fib_seq
end

fibonacci(7)

7 changes: 7 additions & 0 deletions roll_dice.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def roll_dice(num_dice)
max_possible_num = num_dice * 6
num_dice == 1 ? 1 : rand(2..max_possible_num)
end

roll_dice(2)
roll_dice(4)
5 changes: 5 additions & 0 deletions stock_picker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def stock_picker(arr)
[arr.min, arr.max]
end

stock_picker([44, 30, 24, 32, 35, 30, 40, 38, 15])