Create a program which determines the total amount of dubs for a given range of numbers. Keep in mind that 00, 11, 22, etc. aren't the only kind of dubs you can have; 3 is 11 in binary, 1414 is 2-digit dubs, 257257 is 3-digit dubs, etc.
Name:
Anonymous2012-02-01 10:32
def count_dubs(n, base):
size = base; m = 0
while size < n:
if n % size == n / size % size:
m += 1
size *= base
return m
def dub_range(a, b):
m = 0
for n in range(a, b):
for base in range(2, n):
m += count_dubs(n, base)
return m
print dub_range(0, 1001)
This counts 122122 as both 1-digit and 3-digit dubs; is it supposed to?