From 87a991f2ce17dba8e50af865f9763fcfc443f503 Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Wed, 19 Oct 2016 15:57:28 +1100 Subject: [PATCH 01/24] init commit power.rb --- power.rb | 1 + 1 file changed, 1 insertion(+) create mode 100644 power.rb diff --git a/power.rb b/power.rb new file mode 100644 index 0000000..c1efb5a --- /dev/null +++ b/power.rb @@ -0,0 +1 @@ +power(3,4) # returns 81 \ No newline at end of file From d383f03a9f5dda6da78df111adedb762725a95c7 Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Wed, 19 Oct 2016 16:04:17 +1100 Subject: [PATCH 02/24] solved power.rb --- power.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/power.rb b/power.rb index c1efb5a..f8b235a 100644 --- a/power.rb +++ b/power.rb @@ -1 +1,12 @@ -power(3,4) # returns 81 \ No newline at end of file +def power(a,b) # define method taking two arguments + base = a # variable base is first argument + power = b # variable power is second argument + sum = a # variable created to store answer + while b > 1 # start while loop to multiply base + sum *= base # value of base time base added to sum + b -= 1 # power used as count and reduced by one + end # end of while loop run "power" number of times +puts sum # result output +end + +power(5,5) # returns 81 \ No newline at end of file From ed07236f6660cffb48cf419bd0e641272abd2cfb Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Wed, 19 Oct 2016 16:09:04 +1100 Subject: [PATCH 03/24] refactored solution --- power.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/power.rb b/power.rb index f8b235a..655209c 100644 --- a/power.rb +++ b/power.rb @@ -1,12 +1,10 @@ def power(a,b) # define method taking two arguments - base = a # variable base is first argument - power = b # variable power is second argument - sum = a # variable created to store answer - while b > 1 # start while loop to multiply base - sum *= base # value of base time base added to sum + sum = a # variable created, first number and final answer + while b > 1 # start while loop to multiply base by power repeatedly + sum *= a # value of base times base added to sum b -= 1 # power used as count and reduced by one end # end of while loop run "power" number of times puts sum # result output -end +end # end of method -power(5,5) # returns 81 \ No newline at end of file +power(3,4) # returns 81 \ No newline at end of file From 916ca3822b7c3ba2d2be6a5d5d7f36782edf8a92 Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Wed, 19 Oct 2016 16:13:05 +1100 Subject: [PATCH 04/24] add factorial.rb --- factorial.rb | 1 + 1 file changed, 1 insertion(+) create mode 100644 factorial.rb diff --git a/factorial.rb b/factorial.rb new file mode 100644 index 0000000..3101e14 --- /dev/null +++ b/factorial.rb @@ -0,0 +1 @@ +factorial(5) # => 120 \ No newline at end of file From 29fbe1de62636231fc13ac073761d8d688c17dfc Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Wed, 19 Oct 2016 16:53:33 +1100 Subject: [PATCH 05/24] solved factorial.rb --- factorial.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/factorial.rb b/factorial.rb index 3101e14..b755c93 100644 --- a/factorial.rb +++ b/factorial.rb @@ -1 +1,11 @@ -factorial(5) # => 120 \ No newline at end of file + +def factorial(num) # define method that takes one argument + sum = 1 # define variable to store answer and start equation + while num > 0 # start while loop to count down to smallest number + sum = num * sum # start recurring equation + num-=1 # lower the number being multipied each time + end # end the "while" loop +puts sum # outpu the answer +end + +factorial(5) # => 120 \ No newline at end of file From fd69c4be6bbe12314f1a916865660ff234f1082f Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Wed, 19 Oct 2016 16:54:51 +1100 Subject: [PATCH 06/24] add uniques.rb --- uniques.rb | 1 + 1 file changed, 1 insertion(+) create mode 100644 uniques.rb diff --git a/uniques.rb b/uniques.rb new file mode 100644 index 0000000..6b124db --- /dev/null +++ b/uniques.rb @@ -0,0 +1 @@ +uniques([1,5,”frog”, 2,1,3,”frog”]) # => [1,5,"frog",2,3] \ No newline at end of file From 0f9d1afe1a54cb986fb1521923cfdf5678034ee9 Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Wed, 19 Oct 2016 22:39:26 +1100 Subject: [PATCH 07/24] uniques method solved --- uniques.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/uniques.rb b/uniques.rb index 6b124db..8d13c76 100644 --- a/uniques.rb +++ b/uniques.rb @@ -1 +1,9 @@ -uniques([1,5,”frog”, 2,1,3,”frog”]) # => [1,5,"frog",2,3] \ No newline at end of file +def uniques(array) # define uniques method + no_dupes = [] # create new array for duplicate free array + array.each do |x| # start interation on array + no_dupes << x unless no_dupes.include?(x) # push all items to new array unless it + end # array item is already included. end. + puts no_dupes.inspect # display the array (in array format) +end # end of method + +uniques([1,5,"frog",2,1,3,"frog"]) # returns [1, 5, "frog", 2, 3] \ No newline at end of file From 8912bc6b36098822c83d042ebe1e8cdc6e4b35a9 Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Wed, 19 Oct 2016 22:42:14 +1100 Subject: [PATCH 08/24] add combination.rb --- combinations.rb | 1 + 1 file changed, 1 insertion(+) create mode 100644 combinations.rb diff --git a/combinations.rb b/combinations.rb new file mode 100644 index 0000000..1f2a3ec --- /dev/null +++ b/combinations.rb @@ -0,0 +1 @@ +combinations(["on","in"],["to","rope"]) \ No newline at end of file From bfb9451ae9994cbc3938cfda319ee55f7248f05c Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Wed, 19 Oct 2016 23:04:23 +1100 Subject: [PATCH 09/24] comibinates solved (although not very DRY) --- combinations.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/combinations.rb b/combinations.rb index 1f2a3ec..e48962c 100644 --- a/combinations.rb +++ b/combinations.rb @@ -1 +1,10 @@ +def combinations(a, b) # define method that takes two arrays + combined_array = [] # create new empty array + combined_array << a[0]+b[0] # these four lines are not very "DRY" + combined_array << a[0]+b[1] # but they do concatenate the strings + combined_array << a[1]+b[0] # from the 2D arrays in the correct order + combined_array << a[1]+b[1] # will only work though for two srings in each + puts combined_array.inspect +end + combinations(["on","in"],["to","rope"]) \ No newline at end of file From d64cf7a37954682a7d033d88f1200d4be09e1e1c Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Wed, 19 Oct 2016 23:05:31 +1100 Subject: [PATCH 10/24] add primes.rb --- primes.rb | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 primes.rb diff --git a/primes.rb b/primes.rb new file mode 100644 index 0000000..7a59779 --- /dev/null +++ b/primes.rb @@ -0,0 +1,2 @@ +is_prime?(7) +is_prime?(14) \ No newline at end of file From 9c8017ddc2f02b61fd7b62018eb3e667c0e603fd Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Wed, 19 Oct 2016 23:20:06 +1100 Subject: [PATCH 11/24] define method only --- primes.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/primes.rb b/primes.rb index 7a59779..9d7c2ee 100644 --- a/primes.rb +++ b/primes.rb @@ -1,2 +1,10 @@ +def is_prime?(number) + + + + +end + + + is_prime?(7) -is_prime?(14) \ No newline at end of file From 7e25f9072938e5206169ac3e5ad4f09842e8b881 Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Thu, 20 Oct 2016 11:43:15 +1100 Subject: [PATCH 12/24] solved primes.rb --- primes.rb | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/primes.rb b/primes.rb index 9d7c2ee..7a12546 100644 --- a/primes.rb +++ b/primes.rb @@ -1,10 +1,19 @@ -def is_prime?(number) +def is_prime?(number) # define is_prime? method + prime_checker = [] # empty array to store divisable numbers + range_of_nums = Array(1..number) # array of integars between one and possible prime + range_of_nums.each do |x| # iterate over the array + if (number % x == 0) # check if number eqully divisable + prime_checker << x # if it is, push to prime_checker array + end # end of "if" block + end # end of "do" block + if (prime_checker.length > 2) # check if more than "1" or "number" are in checker array + puts "No, #{number} is not a prime" # if more than that are in there, it's not a prime + else + puts "Yes, #{number} is a prime!" # if 2 number in there, it must be a prime + end +end # decided to return a more descriptive string than just + # boolean value +is_prime?(7) +is_prime?(14) - - -end - - - -is_prime?(7) From d6f389508d23bb3180d78ae68a8c1f529e6067b7 Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Thu, 20 Oct 2016 11:43:46 +1100 Subject: [PATCH 13/24] add overlap.rb --- overlap.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 overlap.rb diff --git a/overlap.rb b/overlap.rb new file mode 100644 index 0000000..e69de29 From f065067ef9e359b6f1728db6b9f3e2065ff7a82a Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Thu, 20 Oct 2016 11:51:15 +1100 Subject: [PATCH 14/24] update overlap.rb --- overlap.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/overlap.rb b/overlap.rb index e69de29..7b25e1f 100644 --- a/overlap.rb +++ b/overlap.rb @@ -0,0 +1,10 @@ +# Write a method overlap which takes two rectangles defined +# by the coordinates of their corners, and determines whether they overlap. +# You can assume all coordinates are positive integers. + + + + +overlap([[0,0],[3,3]], [[1,1],[4,5]]) + +overlap([[0,0],[1,4]], [[1,1],[3,2]]) \ No newline at end of file From c2d943044c8bfd6e83dbbbc248ec3c55969b242d Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Thu, 20 Oct 2016 12:34:34 +1100 Subject: [PATCH 15/24] overlap.rb solved --- overlap.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/overlap.rb b/overlap.rb index 7b25e1f..651b3a6 100644 --- a/overlap.rb +++ b/overlap.rb @@ -2,9 +2,22 @@ # by the coordinates of their corners, and determines whether they overlap. # You can assume all coordinates are positive integers. +def overlap(rectangle_one, rectangle_two) + if rectangle_one[1][0] > rectangle_two[0][0] && rectangle_one[1][1] > rectangle_two[0][0] + puts "Rectangles overlap" # both the bottom left hand x and y axes of rectangle_two + else # must be higher than the top right hand x and y axes + puts "Rectangles do not overlap" # of rectangel_one to be sure that don't overlap + end +end -overlap([[0,0],[3,3]], [[1,1],[4,5]]) +overlap([[0,0],[3,3]], [[1,1],[4,5]]) # returns true/overlap -overlap([[0,0],[1,4]], [[1,1],[3,2]]) \ No newline at end of file +overlap([[0,0],[1,4]], [[1,1],[3,2]]) # returns false/do not overlap + +# additional tests + +overlap([[0,0],[3,1]], [[1,1],[4,5]]) # returns false/do not overlap + +overlap([[0,0],[2,4]], [[1,1],[3,2]]) # returns true/overlap \ No newline at end of file From 15a882c5f974044629d1562801307fe9fa505ca1 Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Thu, 20 Oct 2016 15:08:08 +1100 Subject: [PATCH 16/24] overlaps solved --- overlap.rb | 58 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/overlap.rb b/overlap.rb index 651b3a6..28c1bff 100644 --- a/overlap.rb +++ b/overlap.rb @@ -2,22 +2,62 @@ # by the coordinates of their corners, and determines whether they overlap. # You can assume all coordinates are positive integers. -def overlap(rectangle_one, rectangle_two) - if rectangle_one[1][0] > rectangle_two[0][0] && rectangle_one[1][1] > rectangle_two[0][0] - puts "Rectangles overlap" # both the bottom left hand x and y axes of rectangle_two - else # must be higher than the top right hand x and y axes - puts "Rectangles do not overlap" # of rectangel_one to be sure that don't overlap +def overlap(arr_one, arr_two) + # if rectangle_one starts lower than rectangle_two + if (arr_one[0][0] + arr_one[0][1] == arr_two[0][0] + arr_two[0][1]) && (arr_one[0][0] < arr_two[0][0]) + rec_one = arr_one # bottom left sum is equal therefore act as though first rectangle lower + rec_two = arr_two + elsif arr_one[0][0] + arr_one[0][1] < arr_two[0][0] + arr_two[0][1] # first box is lower + rec_one = arr_one + rec_two = arr_two + else # second box lower + rec_one = arr_two + rec_two = arr_one end -end + if (rec_one[1][0] > rec_two[0][0]) && (rec_one[1][1] > rec_two[0][0]) + puts "Rectangles overlap" # both the bottom left hand x and y axes of rec_two + puts arr_one.inspect + puts arr_two.inspect + puts "" + else # must be higher than the top right hand x and y axes + puts "Rectangles do not overlap" # of rec_one to be sure they don't overlap + puts arr_one.inspect + puts arr_two.inspect + puts "" + end +end overlap([[0,0],[3,3]], [[1,1],[4,5]]) # returns true/overlap overlap([[0,0],[1,4]], [[1,1],[3,2]]) # returns false/do not overlap -# additional tests - +puts "" +puts "####################################################################" +puts "# Additional tests below to cover second box being closer to x #" +puts "# axis or where boxes could be completely inside other boxes #" +puts "# These scenarios were not given as possiblities #" +puts "# in excercise question but are possible #" +puts "####################################################################" +puts "" overlap([[0,0],[3,1]], [[1,1],[4,5]]) # returns false/do not overlap -overlap([[0,0],[2,4]], [[1,1],[3,2]]) # returns true/overlap \ No newline at end of file +overlap([[6,0],[7,5]], [[0,0],[1,1]]) # returns false/do not overlap + +overlap([[1,1],[2,2]], [[0,0],[1,1]]) # returns false/do not overlap + +overlap([[2,2],[4,4]], [[0,0],[3,3]]) # returns true/overlap + +overlap([[0,2],[2,10]], [[2,0],[10,2]]) # returns false/do not overlap + +overlap([[2,0],[3,1]], [[0,2],[2,100]]) # returns false/do not overlap + +overlap([[1,0],[5,1]], [[0,1],[1,5]]) # returns false/do not overlap + +overlap([[0,1],[1,5]], [[1,0],[5,1]]) # returns false/do not overlap +puts "first box inside second box" +overlap([[3,3],[6,6]], [[2,2],[8,8]]) # returns true/overlap (this is first box inside second box) +puts "second box inside first box" +overlap([[2,2],[8,8]], [[3,3],[6,6]]) # returns true/overlap (this is second box inside first box) + From 540bffae8a41c47d117c34f571595ef51c5764b9 Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Thu, 20 Oct 2016 15:09:19 +1100 Subject: [PATCH 17/24] fixed comments --- overlap.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/overlap.rb b/overlap.rb index 28c1bff..33228c6 100644 --- a/overlap.rb +++ b/overlap.rb @@ -17,11 +17,11 @@ def overlap(arr_one, arr_two) if (rec_one[1][0] > rec_two[0][0]) && (rec_one[1][1] > rec_two[0][0]) puts "Rectangles overlap" # both the bottom left hand x and y axes of rec_two - puts arr_one.inspect - puts arr_two.inspect + puts arr_one.inspect # must be higher than the top right hand x and y axes + puts arr_two.inspect # of rec_one to be sure they don't overlap puts "" - else # must be higher than the top right hand x and y axes - puts "Rectangles do not overlap" # of rec_one to be sure they don't overlap + else + puts "Rectangles do not overlap" puts arr_one.inspect puts arr_two.inspect puts "" From 6e25f083ea7936ae1ed646f928e2faa579c262b5 Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Thu, 20 Oct 2016 16:16:43 +1100 Subject: [PATCH 18/24] add couting_game.rb --- counting_game.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 counting_game.rb diff --git a/counting_game.rb b/counting_game.rb new file mode 100644 index 0000000..e69de29 From fdf8c4b24316d1f704c702596ffbbeb5e5d15c59 Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Thu, 20 Oct 2016 17:06:34 +1100 Subject: [PATCH 19/24] renamed files for easier viewing --- README.md => 0. README.md | 0 power.rb => 1. power.rb | 0 factorial.rb => 2. factorial.rb | 0 uniques.rb => 3. uniques.rb | 0 combinations.rb => 4. combinations.rb | 0 primes.rb => 5. primes.rb | 0 overlap.rb => 6. overlap.rb | 0 counting_game.rb => 7. counting_game.rb | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename README.md => 0. README.md (100%) rename power.rb => 1. power.rb (100%) rename factorial.rb => 2. factorial.rb (100%) rename uniques.rb => 3. uniques.rb (100%) rename combinations.rb => 4. combinations.rb (100%) rename primes.rb => 5. primes.rb (100%) rename overlap.rb => 6. overlap.rb (100%) rename counting_game.rb => 7. counting_game.rb (100%) diff --git a/README.md b/0. README.md similarity index 100% rename from README.md rename to 0. README.md diff --git a/power.rb b/1. power.rb similarity index 100% rename from power.rb rename to 1. power.rb diff --git a/factorial.rb b/2. factorial.rb similarity index 100% rename from factorial.rb rename to 2. factorial.rb diff --git a/uniques.rb b/3. uniques.rb similarity index 100% rename from uniques.rb rename to 3. uniques.rb diff --git a/combinations.rb b/4. combinations.rb similarity index 100% rename from combinations.rb rename to 4. combinations.rb diff --git a/primes.rb b/5. primes.rb similarity index 100% rename from primes.rb rename to 5. primes.rb diff --git a/overlap.rb b/6. overlap.rb similarity index 100% rename from overlap.rb rename to 6. overlap.rb diff --git a/counting_game.rb b/7. counting_game.rb similarity index 100% rename from counting_game.rb rename to 7. counting_game.rb From eb47e30e5ab65dba544a3f22121627f63d917da3 Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Fri, 21 Oct 2016 10:50:07 +1100 Subject: [PATCH 20/24] add description for counting_game.rb --- 7. counting_game.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/7. counting_game.rb b/7. counting_game.rb index e69de29..54fec0a 100644 --- a/7. counting_game.rb +++ b/7. counting_game.rb @@ -0,0 +1,24 @@ +# 10 friends are sitting in a circle around a table and decide to +# play a new game. In it, they count up through the numbers from 1 +# to 100. The first person says "1", the second says "2" and so +# on... but with a few catches: + +# Whenever the number is divisible by 7, they switch directions. +# So person 6 will say "6", person 7 will say "7", then person 6 +# again will say "8". + +# Whenever the number is divisible by 11, they skip the next person +# for the following number. For instance, if person 3 says "33", +# person 5 will say "34" instead (person 4 gets skipped). + +# Your job is to code a program which outputs each number and which +# person said it. Use it to show that player 1 will say the number +# "100". + + + + + + + + From 6564e5b2a97167e195f4be48a8f1d9fd8408f6dd Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Fri, 21 Oct 2016 10:55:49 +1100 Subject: [PATCH 21/24] Need to refactor combinations.rb --- 4. combinations.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/4. combinations.rb b/4. combinations.rb index e48962c..286c6f6 100644 --- a/4. combinations.rb +++ b/4. combinations.rb @@ -1,3 +1,6 @@ +# needs to be recatored to iterate over both arrays (an codeblock within a codeblock) + + def combinations(a, b) # define method that takes two arrays combined_array = [] # create new empty array combined_array << a[0]+b[0] # these four lines are not very "DRY" From 754afc80f9ec822d15791cb1172facbb84bde783 Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Fri, 21 Oct 2016 15:29:43 +1100 Subject: [PATCH 22/24] count game solved --- 7. counting_game.rb | 9 +++++ counting_game.rb | 66 +++++++++++++++++++++++++++++++++++++ 6. overlap.rb => overlap.rb | 2 +- 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 counting_game.rb rename 6. overlap.rb => overlap.rb (99%) diff --git a/7. counting_game.rb b/7. counting_game.rb index 54fec0a..4380f1e 100644 --- a/7. counting_game.rb +++ b/7. counting_game.rb @@ -14,6 +14,15 @@ # Your job is to code a program which outputs each number and which # person said it. Use it to show that player 1 will say the number # "100". +puts "hello" + +person_number = 1 +game_number = 1 + while person_number < 101 + puts "Person Number #{person_number}. says #{game_number}" + person_number += 1 + game_number +=1 + end diff --git a/counting_game.rb b/counting_game.rb new file mode 100644 index 0000000..ab7f208 --- /dev/null +++ b/counting_game.rb @@ -0,0 +1,66 @@ +# 10 friends are sitting in a circle around a table and decide to +# play a new game. In it, they count up through the numbers from 1 +# to 100. The first person says "1", the second says "2" and so +# on... but with a few catches: + +# Whenever the number is divisible by 7, they switch directions. +# So person 6 will say "6", person 7 will say "7", then person 6 +# again will say "8". + +# Whenever the number is divisible by 11, they skip the next person +# for the following number. For instance, if person 3 says "33", +# person 5 will say "34" instead (person 4 gets skipped). + +# Your job is to code a program which outputs each number and which +# person said it. Use it to show that player 1 will say the number +# "100". + +count = 0 +person_number = 0 +game_number = 0 +direction = -1 # backwards +direction = 1 # forwards + +while count < 100 + + count += 1 + + if direction == 1 # direction is forward + person_number += 1 # person number increased by 1 + end + + if direction == -1 # direction reversed + person_number -= 1 # person number decreased by 1 + end + + game_number += 1 # game number increases by 1 + + if game_number % 7 == 0 # change direction if game number + direction = direction * -1 # divisable by 7 + end + + if person_number < 1 # if looped around group of peopl + person_number += 100 # subtract total to get back + end + + if person_number > 100 # same as above in other direction + person_number -= 100 + end + +puts "Person Number #{person_number}. says #{game_number}" + + if game_number % 11 == 0 && direction == 1 # if game number multiple + person_number += 1 # of 11 skip a person + end + + if game_number % 11 == 0 && direction == -1 # same as above but in other + person_number -= 1 # direciton + end + +end + + + + + + diff --git a/6. overlap.rb b/overlap.rb similarity index 99% rename from 6. overlap.rb rename to overlap.rb index 33228c6..704391a 100644 --- a/6. overlap.rb +++ b/overlap.rb @@ -1,7 +1,7 @@ # Write a method overlap which takes two rectangles defined # by the coordinates of their corners, and determines whether they overlap. # You can assume all coordinates are positive integers. - +puts "test" def overlap(arr_one, arr_two) # if rectangle_one starts lower than rectangle_two if (arr_one[0][0] + arr_one[0][1] == arr_two[0][0] + arr_two[0][1]) && (arr_one[0][0] < arr_two[0][0]) From ce074cb9c8ca251a802f088d1a02f682dd68cda6 Mon Sep 17 00:00:00 2001 From: Andrew Dutton Date: Fri, 21 Oct 2016 15:31:00 +1100 Subject: [PATCH 23/24] rename file names (remove spaces) --- .DS_Store | Bin 0 -> 6148 bytes 0. README.md => 0_README.md | 0 1. power.rb => 1_power.rb | 0 2. factorial.rb => 2_factorial.rb | 0 3. uniques.rb => 3_uniques.rb | 0 4. combinations.rb => 4_combinations.rb | 0 5. primes.rb => 5_primes.rb | 0 overlap.rb => 6_overlap.rb | 0 7. counting_game.rb | 33 ------------------------ counting_game.rb => 7_counting_game.rb | 0 10 files changed, 33 deletions(-) create mode 100644 .DS_Store rename 0. README.md => 0_README.md (100%) rename 1. power.rb => 1_power.rb (100%) rename 2. factorial.rb => 2_factorial.rb (100%) rename 3. uniques.rb => 3_uniques.rb (100%) rename 4. combinations.rb => 4_combinations.rb (100%) rename 5. primes.rb => 5_primes.rb (100%) rename overlap.rb => 6_overlap.rb (100%) delete mode 100644 7. counting_game.rb rename counting_game.rb => 7_counting_game.rb (100%) diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Fri, 21 Oct 2016 15:47:19 +1100 Subject: [PATCH 24/24] some refactoring, additional comments and file renames --- 1_power.rb => 1.power.rb | 0 2_factorial.rb => 2.factorial.rb | 6 +++--- 3_uniques.rb => 3.uniques.rb | 6 +++--- 4_combinations.rb => 4.combinations.rb | 9 ++++----- 5_primes.rb => 5.primes.rb | 12 ++++++------ 6_overlap.rb => 6.overlap.rb | 0 7_counting_game.rb => 7.counting_game.rb | 0 7 files changed, 16 insertions(+), 17 deletions(-) rename 1_power.rb => 1.power.rb (100%) rename 2_factorial.rb => 2.factorial.rb (77%) rename 3_uniques.rb => 3.uniques.rb (70%) rename 4_combinations.rb => 4.combinations.rb (59%) rename 5_primes.rb => 5.primes.rb (63%) rename 6_overlap.rb => 6.overlap.rb (100%) rename 7_counting_game.rb => 7.counting_game.rb (100%) diff --git a/1_power.rb b/1.power.rb similarity index 100% rename from 1_power.rb rename to 1.power.rb diff --git a/2_factorial.rb b/2.factorial.rb similarity index 77% rename from 2_factorial.rb rename to 2.factorial.rb index b755c93..6eaeac2 100644 --- a/2_factorial.rb +++ b/2.factorial.rb @@ -5,7 +5,7 @@ def factorial(num) # define method that takes one argument sum = num * sum # start recurring equation num-=1 # lower the number being multipied each time end # end the "while" loop -puts sum # outpu the answer -end +puts sum # outpuythe answer +end # end -factorial(5) # => 120 \ No newline at end of file +factorial(5) # returns 120 \ No newline at end of file diff --git a/3_uniques.rb b/3.uniques.rb similarity index 70% rename from 3_uniques.rb rename to 3.uniques.rb index 8d13c76..cf0684e 100644 --- a/3_uniques.rb +++ b/3.uniques.rb @@ -1,8 +1,8 @@ def uniques(array) # define uniques method no_dupes = [] # create new array for duplicate free array - array.each do |x| # start interation on array - no_dupes << x unless no_dupes.include?(x) # push all items to new array unless it - end # array item is already included. end. + array.each do |x| # start iteration on array + no_dupes << x unless no_dupes.include?(x) # push all items to new array unless array item is already included. + end # end of "do" block puts no_dupes.inspect # display the array (in array format) end # end of method diff --git a/4_combinations.rb b/4.combinations.rb similarity index 59% rename from 4_combinations.rb rename to 4.combinations.rb index 286c6f6..9764480 100644 --- a/4_combinations.rb +++ b/4.combinations.rb @@ -1,5 +1,4 @@ -# needs to be recatored to iterate over both arrays (an codeblock within a codeblock) - +# after som investigation this needs to be refacatored to iterate over both arrays (a codeblock within a codeblock) def combinations(a, b) # define method that takes two arrays combined_array = [] # create new empty array @@ -7,7 +6,7 @@ def combinations(a, b) # define method that takes two arrays combined_array << a[0]+b[1] # but they do concatenate the strings combined_array << a[1]+b[0] # from the 2D arrays in the correct order combined_array << a[1]+b[1] # will only work though for two srings in each - puts combined_array.inspect -end + puts combined_array.inspect # outputs in array format +end # end of method -combinations(["on","in"],["to","rope"]) \ No newline at end of file +combinations(["on","in"],["to","rope"]) # returns ["onto", "onrope", "into", "inrope"] \ No newline at end of file diff --git a/5_primes.rb b/5.primes.rb similarity index 63% rename from 5_primes.rb rename to 5.primes.rb index 7a12546..5895d20 100644 --- a/5_primes.rb +++ b/5.primes.rb @@ -7,12 +7,12 @@ def is_prime?(number) # define is_prime? method end # end of "if" block end # end of "do" block if (prime_checker.length > 2) # check if more than "1" or "number" are in checker array - puts "No, #{number} is not a prime" # if more than that are in there, it's not a prime - else - puts "Yes, #{number} is a prime!" # if 2 number in there, it must be a prime - end -end # decided to return a more descriptive string than just - # boolean value + puts "No, #{number} is not a prime" # if more than those two numbers are in there, cannot be prime + else # else + puts "Yes, #{number} is a prime!" # if just two numbers in there, it must be a prime + end # end of if/else block +end # end of method + is_prime?(7) is_prime?(14) diff --git a/6_overlap.rb b/6.overlap.rb similarity index 100% rename from 6_overlap.rb rename to 6.overlap.rb diff --git a/7_counting_game.rb b/7.counting_game.rb similarity index 100% rename from 7_counting_game.rb rename to 7.counting_game.rb