From a35683d01918b506d25d941bd58a44993b05d286 Mon Sep 17 00:00:00 2001 From: "engr.hasanuzzaman" Date: Wed, 19 Feb 2020 23:52:28 +0600 Subject: [PATCH 1/2] Implement basic queue with ruby --- problems/queue/queue.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 problems/queue/queue.rb diff --git a/problems/queue/queue.rb b/problems/queue/queue.rb new file mode 100644 index 00000000..519bf28d --- /dev/null +++ b/problems/queue/queue.rb @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + +class Queue + def initialize + @queue = [] + end + + def add(val) + @queue << val + end + + def remove + @queue.shift + end +end + +q = Queue.new +q.add(1) +q.add(2) +q.add(3) +puts q.remove() +puts q.remove() +puts q.remove() +puts q.remove() From 63ae51a8bed1d92dfca9a2b864a72a7c688c04eb Mon Sep 17 00:00:00 2001 From: "engr.hasanuzzaman" Date: Thu, 20 Feb 2020 00:42:49 +0600 Subject: [PATCH 2/2] Solve substrings problem --- problems/substrings/substrings.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 problems/substrings/substrings.rb diff --git a/problems/substrings/substrings.rb b/problems/substrings/substrings.rb new file mode 100644 index 00000000..f124a6d0 --- /dev/null +++ b/problems/substrings/substrings.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby + +def sub_strings(str) + sub_strs = str.split('') + + str.size.times do |i| + for j in (i+1...str.size) + sub_strs << str[i..j] + end + end + + sub_strs +end + +puts sub_strings('abc').inspect \ No newline at end of file