Skip to main content
3 of 7
added 2 characters in body
Chas Brown
  • 9.8k
  • 1
  • 13
  • 39

Python 2, 129 126 bytes

def f(n,k,p=0):q=int('7367355777e0d93bf0fb'[n%10::10],16);return n and k*bin(p^q).count('1')+f(n/10,k,q)or k*bin(p).count('1')

Try it online!

Chas Brown
  • 9.8k
  • 1
  • 13
  • 39