Skip to main content
1 of 7
Chas Brown
  • 9.8k
  • 1
  • 13
  • 39

Python 2, 140 bytes

def f(n,k):s=[0]+[int('73673557770e0d93bf0fb0'[d::11],16)for d in map(int,`n`)]+[0];return sum(bin(x^y).count('1')for x,y in zip(s,s[1:]))*k

Try it online!

Chas Brown
  • 9.8k
  • 1
  • 13
  • 39