Commit d7e0c7f

mo <mokha@cisco.com>
2017-06-22 17:12:02
attempt map decoding.
1 parent 7a5fd0c
Changed files (1)
spec/map_decoding_spec.rb
@@ -52,6 +52,12 @@ describe "map_decoding" do
   10|1|2|21|10
   10|1|2|2|1|10
 
+  [1, 2, 3]
+
+  [1], [2, 3]  [1, 2, 3]
+  [2], [3]     [2], [3]
+  [3]          [3]
+
 
   THINK
   def map_decoding(message)
@@ -85,6 +91,23 @@ describe "map_decoding" do
     count % modulo
   end
 
+  def decode(chars, rest = [])
+    #puts [chars, rest].inspect
+    return chars if rest.empty?
+
+    results = []
+    first = rest[0]
+    results.push(decode([first], rest[1..rest.size]))
+
+    second = rest[1]
+    results.push(decode([first + second], rest[2..rest.size])) if second
+    results
+  end
+
+  def map_decoding(message)
+    decode([], message.chars)
+  end
+
   [
     { message: "123", expected: 3 },
     { message: "12", expected: 2 },