From 3f771668cb386a97ca7274b86a859c8541a3bb02 Mon Sep 17 00:00:00 2001 From: Ola Dan Date: Sun, 9 Oct 2016 16:02:29 +0100 Subject: [PATCH 1/2] the solutions --- ruby_solutions.txt | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 ruby_solutions.txt diff --git a/ruby_solutions.txt b/ruby_solutions.txt new file mode 100644 index 0000000..5f66cc2 --- /dev/null +++ b/ruby_solutions.txt @@ -0,0 +1,43 @@ +1. +def power(base, exponent) + result = 1 + exponent.times do result *= base + end + result +end + + +2. +def factorial(number) + if number == 0 + else + number * factorial(number - 1) + end +end + +3. + def unique(array) +response = Array.new +array.each do |element| +response << element unless response.include?(element) +end +response +end + + + +4. +def combinations(array_a, array_b) +a.product(b).map do |a| a[0] + a[1] +end +end + + + +5. +require 'prime' + +def prime?(number) +number.prime? +end + From 3e3c8a4b9e96f14f728064d110d140aa84b872ba Mon Sep 17 00:00:00 2001 From: Ola Dan Date: Wed, 12 Oct 2016 15:41:28 +0100 Subject: [PATCH 2/2] last 2 answers --- last2_solutions.txt | 205 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 last2_solutions.txt diff --git a/last2_solutions.txt b/last2_solutions.txt new file mode 100644 index 0000000..46748fa --- /dev/null +++ b/last2_solutions.txt @@ -0,0 +1,205 @@ + 6. + def overlap(rectangle_1, rectangle_2) + if (rectangle_2 [1][1] < rectangle_1 [0][0]) || + (rectangle_1 [1][0] < rectangle_2 [0][1]) + false + else + true + end + end + + overlap() + + + + 7.# table for the game, it was an awry paste from the text edit. I keyed in the players again on the right.the table depicts player 10 saying '100'. see the code below. + + + players +10 +9 +8 +1 +2 +3 +4 +5 +6 +7 +count players + + + +'1' 1 +'2' 2 +'3' 3 +'4' 4 +'5' 5 +'6' 6 +'7' 7 + + +'14' 9 +'13' 8 +'12' 1 +- 2 +'11' 3 +'10' 4 +'9' 5 +'8' 6 + + + + +'15' 8 +'16' 1 +'17' 2 +'18' 3 +'19' 4 +'20' 5 +'21' 6 + + +'28' 10 +'27' 9 +'26' 8 +'25' 1 +'24' 2 +'23' 3 +- 4 +'22' 5 + + + + +'29' 9 +'30' 8 +'31' 1 +'32' 2 +'33' 3 +- 4 +'34' 5 +'35' 6 + + + +'42' 9 +'41' 8 +'40' 1 +'39' 2 +'38' 3 +'37' 4 +'36' 5 + + + + + +'43' 8 +'44' 1 +- 2 +'45' 3 +'46' 4 +'47' 5 +'48' 6 +'49' 7 + + +'56' 9 +- 8 +'55' 1 +'54' 2 +'53' 3 +'52' 4 +'51' 5 +'50' 6 + + + + +'57' 8 +'58' 1 +'59' 2 +'60' 3 +'61' 4 +'62' 5 +'63' 6 + + +'70' 10 +'69' 9 +'68' 8 +'67' 1 +- 2 +66' 3 +'65' 4 +'64' + + + + +'71' 9 +'72' 8 +'73' 1 +'74' 2 +'75' 3 +'76' 4 +'77' 5 + + + +'83' '84' 10 +'82' 9 +'81' 8 +'80' 1 +'79' 2 +'78' 3 +- 4 + + + + + +'85' 9 +'86' 8 +'87' 1 +'88' 2 +- 3 +'89' 4 +'90' 5 +'91' 6 + + + +'98' 9 +'97' 8 +'96' 1 +'95' 2 +'94' 3 +'93' 4 +'92' 5 + + + + + +'99' 8 +"100" 1 + + + + +def counting_game(players, counting) +while players <= 10 && counting <= 100 do +players += 1 +counting += 1 +if counting % 7 == 0 +player -= 1 +elsif counting % 11 == 0 +next +end +end +end + + +