def naf(n):
 while n:
  z = ((2 - (n % 4)) if (n & 1) else 0)
  n = ((n - z) // 2)
  (yield z)

def naf ( n ) : while n : z = ( ( 2 - ( n % 4 ) ) if ( n & 1 ) else 0 ) n = ( ( n - z ) // 2 ) ( yield z )
naf -> int generator returns a generator for the non-adjacent form of a number .