From 635bea8912047b87ffcc8abbae06f358d83cc5f5 Mon Sep 17 00:00:00 2001 From: Danielotieno Date: Wed, 23 May 2018 01:50:34 +0300 Subject: [PATCH 01/10] creating a file for task 2 --- task2.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 task2.rb diff --git a/task2.rb b/task2.rb new file mode 100644 index 0000000..e69de29 From da3ba6f53fd9c129bad942d8ed35cb53511fbdce Mon Sep 17 00:00:00 2001 From: Danielotieno Date: Wed, 23 May 2018 01:54:31 +0300 Subject: [PATCH 02/10] adding a simple test for method no_divide --- task2.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/task2.rb b/task2.rb index e69de29..b075535 100644 --- a/task2.rb +++ b/task2.rb @@ -0,0 +1 @@ +puts no_divide(1,1) == divide(1,1) \ No newline at end of file From 76dc736d7ec76b2e2422b9254603faa205815f3f Mon Sep 17 00:00:00 2001 From: Danielotieno Date: Wed, 23 May 2018 01:59:32 +0300 Subject: [PATCH 03/10] adding no_divide method --- task2.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/task2.rb b/task2.rb index b075535..2475ce0 100644 --- a/task2.rb +++ b/task2.rb @@ -1 +1,5 @@ -puts no_divide(1,1) == divide(1,1) \ No newline at end of file +def no_divide(num, den) + +end + +puts no_divide(4,2) == divide(4,2) \ No newline at end of file From d87d45acc779db566a543bca5e6c707c89d2d5c4 Mon Sep 17 00:00:00 2001 From: Danielotieno Date: Wed, 23 May 2018 02:05:15 +0300 Subject: [PATCH 04/10] creating a while loop to remove number of denominator from the numerator --- task2.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/task2.rb b/task2.rb index 2475ce0..c64a8de 100644 --- a/task2.rb +++ b/task2.rb @@ -1,5 +1,11 @@ def no_divide(num, den) - + count = 0 + + while num - den >= 0 + num -= den + + count += 1 + end end puts no_divide(4,2) == divide(4,2) \ No newline at end of file From 0767e28e7b345c5eeeafe32affe3b5467f75f436 Mon Sep 17 00:00:00 2001 From: Danielotieno Date: Wed, 23 May 2018 02:07:06 +0300 Subject: [PATCH 05/10] return count --- task2.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/task2.rb b/task2.rb index c64a8de..2cc38a8 100644 --- a/task2.rb +++ b/task2.rb @@ -6,6 +6,9 @@ def no_divide(num, den) count += 1 end + + count + end puts no_divide(4,2) == divide(4,2) \ No newline at end of file From 6e3fa8f813e55c6a4417962e944925d7e5562e45 Mon Sep 17 00:00:00 2001 From: Danielotieno Date: Wed, 23 May 2018 02:11:36 +0300 Subject: [PATCH 06/10] calling the no_divide method to test --- task2.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/task2.rb b/task2.rb index 2cc38a8..0b3ca9f 100644 --- a/task2.rb +++ b/task2.rb @@ -8,7 +8,7 @@ def no_divide(num, den) end count - + end -puts no_divide(4,2) == divide(4,2) \ No newline at end of file +puts no_divide(10,2) \ No newline at end of file From 8ff60aa6d405c9894f4c26282d41ef61cba592da Mon Sep 17 00:00:00 2001 From: Danielotieno Date: Wed, 23 May 2018 06:59:57 +0300 Subject: [PATCH 07/10] adding test variables --- task3.rb | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 task3.rb diff --git a/task3.rb b/task3.rb new file mode 100644 index 0000000..42ae7a7 --- /dev/null +++ b/task3.rb @@ -0,0 +1,3 @@ +good = "abcdef" +bad = "abc abc" + From d36da56a246091ebb708ed315fc87d6b6e775035 Mon Sep 17 00:00:00 2001 From: Danielotieno Date: Wed, 23 May 2018 07:01:36 +0300 Subject: [PATCH 08/10] creating a method test_for_uniqueness --- task3.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/task3.rb b/task3.rb index 42ae7a7..a4a922c 100644 --- a/task3.rb +++ b/task3.rb @@ -1,3 +1,7 @@ good = "abcdef" bad = "abc abc" +def test_for_uniqueness(str) + + +end \ No newline at end of file From 13ae489d5d813d27ab480fad010c5c094bd858c6 Mon Sep 17 00:00:00 2001 From: Danielotieno Date: Wed, 23 May 2018 07:03:49 +0300 Subject: [PATCH 09/10] creating array of characters --- task3.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/task3.rb b/task3.rb index a4a922c..f37aba1 100644 --- a/task3.rb +++ b/task3.rb @@ -2,6 +2,16 @@ bad = "abc abc" def test_for_uniqueness(str) - + + # get array of characters, sort them + arr = str.chars.to_a.sort + + last_char = nil # previous value + + # now go thru each element of the array, if one matches the next then you have a winner + arr.each_with_index do |item, index| + + + end \ No newline at end of file From 8a9fa3db49952b67363dd4e2abb183ee7df63c92 Mon Sep 17 00:00:00 2001 From: Danielotieno Date: Wed, 23 May 2018 07:09:40 +0300 Subject: [PATCH 10/10] adding test for the algorithm --- task3.rb | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/task3.rb b/task3.rb index f37aba1..5e64040 100644 --- a/task3.rb +++ b/task3.rb @@ -1,5 +1,5 @@ -good = "abcdef" -bad = "abc abc" +good = "talking" +bad = "programming" def test_for_uniqueness(str) @@ -11,7 +11,20 @@ def test_for_uniqueness(str) # now go thru each element of the array, if one matches the next then you have a winner arr.each_with_index do |item, index| + if (item == last_char) + raise ArgumentError, "string is not unique, sorry" + else - -end \ No newline at end of file + last_char = item + + end + + end + + puts "all shiny, nothing to fret." + +end + +test_for_uniqueness(good) +test_for_uniqueness(bad) \ No newline at end of file