Advertisement
Guest User

Quasari [Medium] String Decompression Solutions Counter

a guest
Aug 27th, 2023
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.44 KB | None | 0 0
  1. input = ARGV[0]
  2.  
  3. module Fib
  4.   @@memo = {0 => 0, 1 => 1, 2 => 1}
  5.  
  6.   def self.calc(value)
  7.     return @@memo[value] if @@memo[value]
  8.     @@memo[value] = self.calc(value - 1) + self.calc(value - 2)
  9.     @@memo[value]
  10.   end
  11. end
  12.  
  13. anchor = 0
  14. combos = 1
  15.  
  16. while anchor < input.length
  17.   anchor += 1
  18.   runner = anchor
  19.   runner += 1 while input[runner]&.match? /[0-9]/
  20.   combos *= Fib.calc  runner - anchor
  21.   anchor = runner
  22. end
  23.  
  24. puts combos
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement