diff --git a/task2.rb b/task2.rb new file mode 100644 index 0000000..0b3ca9f --- /dev/null +++ b/task2.rb @@ -0,0 +1,14 @@ +def no_divide(num, den) + count = 0 + + while num - den >= 0 + num -= den + + count += 1 + end + + count + +end + +puts no_divide(10,2) \ No newline at end of file diff --git a/task3.rb b/task3.rb new file mode 100644 index 0000000..5e64040 --- /dev/null +++ b/task3.rb @@ -0,0 +1,30 @@ +good = "talking" +bad = "programming" + +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| + + if (item == last_char) + raise ArgumentError, "string is not unique, sorry" + + else + + 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