Skip to main content
1 of 2
nimi
  • 35.9k
  • 4
  • 34
  • 99

Haskell, 54 bytes

k#(a:b:c)=k+(last$b:[k*2|a==b])#(b:c)
k#_=k
(#)=<<head

Try it online!

A simple recursion that either doubles the accumulator k or resets it to 1/-1 and adds the values of each step.

nimi
  • 35.9k
  • 4
  • 34
  • 99