// you’re reading...
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Solutions 151 - 200

Project Euler 172 Solution

Project Euler 172 Solution

Project Euler 172: Investigating numbers with few repeated digits

How many 18-digit numbers n (without leading zeros) are there such that no digit occurs more than three times in n?

Project Euler 172 Solution

Runs < 2 seconds in Python.
from Euler import binomial
digits, base, max_r = 18, 10, 3

def nd(d,b):
   if b>1: 
      return sum(nd(d-r, b-1)*binomial(d,r) for r in xrange(min(d+1, max_r+1)))
   return d <= max_r

print "There are", nd(digits, base) * (base-1)/base,
print digits, "digit numbers such that no digit occurs more than", max_r,
print "times in base", base
download arrowUse this link to get the Project Euler 172 Solution Python source.


Slowly swipe from either end beginning with the white vertical bar to get an idea of the starting or ending digits. For less drama, just double click the answer area. The distance between the two bars will give you an idea of the magnitude. Touch devices can tap and hold the center of the box between the two bars and choose define to reveal the answer.


    No afterthoughts yet.


No comments yet.

Post a comment