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() 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