diff --git a/README.md b/README.md index 45aa284..041458a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ assignment_ruby_warmup ====================== +Nawar Yossef Dice, dice, baby. diff --git a/anagrams.rb b/anagrams.rb new file mode 100644 index 0000000..699505f --- /dev/null +++ b/anagrams.rb @@ -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") == [] + + diff --git a/dice_outcomes.rb b/dice_outcomes.rb new file mode 100644 index 0000000..2849351 --- /dev/null +++ b/dice_outcomes.rb @@ -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) diff --git a/fibonacci.rb b/fibonacci.rb new file mode 100644 index 0000000..f299d37 --- /dev/null +++ b/fibonacci.rb @@ -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) + diff --git a/roll_dice.rb b/roll_dice.rb new file mode 100644 index 0000000..d1973ec --- /dev/null +++ b/roll_dice.rb @@ -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) diff --git a/stock_picker.rb b/stock_picker.rb new file mode 100644 index 0000000..2e2b286 --- /dev/null +++ b/stock_picker.rb @@ -0,0 +1,5 @@ +def stock_picker(arr) + [arr.min, arr.max] +end + +stock_picker([44, 30, 24, 32, 35, 30, 40, 38, 15]) \ No newline at end of file