def duplicate_digit_bonus(n): Some people ascribe deep significance to numerical coincidences, so that consecutive repeated digits or other low description length patterns, such as a digital clock blinking 11:11, seem special and personal to them. Such people then find numbers with repeated digits to be more valuable and important than all the ordinary and pedestrian numbers without any obvious pattern. For example, getting inside a taxicab flashing an exciting number such as 1234 or 6969 would be far more instagrammable than a more pedestrian taxicab adorned with some dull number such as 1729. Assume that some such person assign a meaningfulness score to every positive integer so that every maximal block of k consecutive digits with k>1 scores 10**(k-2) points for that block. A block of two digits scores one point, three digits score ten points, four digits score a hundred points, and so on. However, just to make this more interesting, there is also a special rule in effect that if this block of digits is at the lowest end of the number, that block scores twice as many points as it would in any other position. Given a positive integer n>0, this function should compute and return its meaningfulness score as the sum of its individu
Duplicate digit bonus
def duplicate_digit_bonus(n):
Some people ascribe deep significance to numerical coincidences, so that consecutive repeated digits or other low description length patterns, such as a digital clock blinking 11:11, seem special and personal to them. Such people then find numbers with repeated digits to be more valuable and important than all the ordinary and pedestrian numbers without any obvious pattern. For example, getting inside a taxicab flashing an exciting number such as 1234 or 6969 would be far more instagrammable than a more pedestrian taxicab adorned with some dull number such as 1729.
Assume that some such person assign a meaningfulness score to every positive integer so that every maximal block of k consecutive digits with k>1 scores 10**(k-2) points for that block. A block of two digits scores one point, three digits score ten points, four digits score a hundred points, and so on. However, just to make this more interesting, there is also a special rule in effect that if this block of digits is at the lowest end of the number, that block scores twice as many points as it would in any other position. Given a positive integer n>0, this function should compute and return its meaningfulness score as the sum of its individual block scores.
n | Expected result |
43333 | 200 |
2223 | 10 |
777777777 | 20000000 |
3888882277777731 | 11001 |
2111111747111117777700 | 12002 |
9999997777774444488872222 | 21210 |
1234**5678 | 15418 |
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images