Skip to main content
4 of 7
deleted 7 characters in body
Chas Brown
  • 9.8k
  • 1
  • 13
  • 39

Python 2, 129 126 111 bytes

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

Try it online!

Chas Brown
  • 9.8k
  • 1
  • 13
  • 39