← Complete problem index

PROJECT EULER · #0941

de Bruijn's Combination Lock

Statement only · UnsolvedOriginal problem ↗

de Bruijn has a digital combination lock with k buttons numbered 0 to k1 where k10.
The lock opens when the last n buttons pressed match the preset combination.

Unfortunately he has forgotten the combination. He creates a sequence of these digits which contains every possible combination of length n. Then by pressing the buttons in this order he is sure to open the lock.

Consider all sequences of shortest possible length that contains every possible combination of the digits.
Denote by C(k,n) the lexicographically smallest of these.

For example, C(3,2)= 0010211220.

Define the sequence an by a0=0 and
an=(920461an1+800217387569)mod1012 for  n>0 Interpret each an as a 12-digit combination, adding leading zeros for any an with less than 12 digits.

Given a positive integer N, we are interested in the order the combinations a1,,aN appear in C(10,12).
Denote by pn the place, numbered 1,,N, in which an appears out of a1,,aN. Define F(N)=n=1Npnan.

For example, the combination a1=800217387569 is entered before a2=696996536878. Therefore: F(2)=1800217387569+2696996536878=2194210461325 You are also given F(10)=32698850376317.

Find F(107). Give your answer modulo 1234567891.

Write-up coming later

The complete problem is available here. An approach, code, and answer will be added later.