Skip to main content
added 80 characters in body
Source Link
Chas Brown
  • 9.8k
  • 1
  • 13
  • 39

Python 2, 129 126 119119 104 bytes

def f(n,k,p=0):z=p<1or n>0;q=intn>0;q=-~ord('7367355777e0d93bf0fb'[n%10::10],16'}/lx2Z^o~z'[n%10])*z;return(z and f(n/10,k,q))+k*bin(p^q).count('1')

Try it online!Try it online!

Thx for a big 15 bytes from ovs.

As specified, takes a non-negative number and a positive sign length, and returns total changes.

Python 2, 129 126 119 bytes

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

Try it online!

As specified, takes a non-negative number and a positive sign length, and returns total changes.

Python 2, 129 126 119 104 bytes

def f(n,k,p=0):z=p<1or n>0;q=-~ord('}/lx2Z^o~z'[n%10])*z;return(z and f(n/10,k,q))+k*bin(p^q).count('1')

Try it online!

Thx for a big 15 bytes from ovs.

As specified, takes a non-negative number and a positive sign length, and returns total changes.

added 100 characters in body
Source Link
Chas Brown
  • 9.8k
  • 1
  • 13
  • 39

Python 2, 129 126 119 bytes

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

Try it online!

As specified, takes a non-negative number and a positive sign length, and returns total changes.

Python 2, 129 126 119 bytes

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

Try it online!

Python 2, 129 126 119 bytes

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

Try it online!

As specified, takes a non-negative number and a positive sign length, and returns total changes.

added 15 characters in body
Source Link
Chas Brown
  • 9.8k
  • 1
  • 13
  • 39

Python 2, 129 126 111119 bytes

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

Try it online!Try it online!

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!

Python 2, 129 126 119 bytes

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

Try it online!

deleted 7 characters in body
Source Link
Chas Brown
  • 9.8k
  • 1
  • 13
  • 39
Loading
added 2 characters in body
Source Link
Chas Brown
  • 9.8k
  • 1
  • 13
  • 39
Loading
deleted 12 characters in body
Source Link
Chas Brown
  • 9.8k
  • 1
  • 13
  • 39
Loading
Source Link
Chas Brown
  • 9.8k
  • 1
  • 13
  • 39
Loading