summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-08-22 15:35:19 -0600
committermo khan <mo.khan@gmail.com>2020-08-22 15:35:19 -0600
commit8b56ea944de3ae79dbf7c7badfda7434cdf3a5df (patch)
tree069c2b7d08e39f9b1bb4e4d017cdffaa6f864a3d
parent64b0dd164b5f6c0ff067ba2ed399284f82f890f9 (diff)
Quick and dirty implementation
-rw-r--r--2020/08/22/main.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/2020/08/22/main.rb b/2020/08/22/main.rb
new file mode 100644
index 0000000..6042464
--- /dev/null
+++ b/2020/08/22/main.rb
@@ -0,0 +1,35 @@
+def assert_equal(x, y)
+ raise [x, y].inspect unless x == y
+end
+
+class MaxStack
+ def initialize
+ @items = []
+ end
+
+ def push(value)
+ @items.push(value)
+ end
+
+ def pop
+ @items.pop
+ end
+
+ def max
+ @items.max
+ end
+end
+
+stack = MaxStack.new
+stack.push(1)
+stack.push(2)
+stack.push(3)
+stack.push(2)
+
+assert_equal 3, stack.max
+
+stack.pop
+stack.pop
+assert_equal 2, stack.max
+
+puts 'Yay!'