summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-10-20 13:23:57 -0600
committermo khan <mo.khan@gmail.com>2020-10-20 13:23:57 -0600
commit40cc5665bcca9b3ecd7f38d39ec5a3ff6e412bed (patch)
treeee493ac36c115f189850f520106f07a6e3c7ff1c
parent8490914034d2f733b099de282d84e043da794476 (diff)
Complete jump to end problem
-rw-r--r--2020/10/20/main.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/2020/10/20/main.rb b/2020/10/20/main.rb
new file mode 100644
index 0000000..a1cb836
--- /dev/null
+++ b/2020/10/20/main.rb
@@ -0,0 +1,18 @@
+require 'minitest'
+require 'minitest/autorun'
+
+class Solution
+ def self.run(items, jumps = 0)
+ return jumps if items.nil? || items.empty?
+
+ run(items[items[1..items[0]].max..-1], jumps+1)
+ end
+end
+
+
+class SolutionTest < MiniTest::Test
+ def test_simple_example
+ # 3 -> 5 -> 4
+ assert_equal Solution.run([3, 2, 5, 1, 1, 9, 3, 4]), 2
+ end
+end