After giving back the results of the last topology exam to his students, Pr. Manifold was worried about complaints.

Since he is aware his students know where his office is located, Prof. Manifold decided to transform his office into a bunker with a 10 digit password (all characters are digits).

But he suspected his students to be very clever (despite having tremendously bad grades).

Knowing that, he's not going to pick a password containing certain sequences, such as his StackExchange ID, university parking spot number, and annual salary.

Your task

Your program or function will take as input an array of integers. No single integer will contain duplicate digits, which implies that none of the integers will have more than 10 digits.

Your code will output how many unique 10 digit passwords Prof. Manifold can choose, taking into account that correct passwords

  • must contain each digit 0-9 exactly once, and
  • must not contain any of the sequences present in the input array.


Input: [18062,6042,35876]

  • 1806234579, 6042135789, 3587612409, 3418062579, 1237896042, and 1243587609 are all incorrect passwords, because they each contain at least one of the sequences present in the input array.

  • 0113456789 is an incorrect password, because the professor's password must contain each digit exactly once.

  • 0123456789 is a correct password, because it doesn't contain any sequence present in the array, and it contains each digit exactly once.

Test case:

[18062,6042,35876] -> 3622326

This is , so the shortest answer in bytes wins!

  • 1
    \$\begingroup\$ You should add test cases. \$\endgroup\$
    – Luke
    Commented Apr 29, 2017 at 12:40
  • \$\begingroup\$ @Luke Ok But since i'm on my phone I only have the calculator ^^ \$\endgroup\$
    – user68509
    Commented Apr 29, 2017 at 12:47

1 Answer 1


Jelly, 14  11 bytes

-3 bytes thanks to Dennis (avoid a chain separation allowing some implicit actions; use a filter to avoid the two byte œ& multi-set intersection I was using.)


Try it online! - the specified version is far too slow for the online interpreter, so this is a proof of concept test suite:
- it does the same thing for only 5 digits 01234,
- the first example is the empty list, yielding 120 as expected (5!),
- the last returns 1 as the only permutation still available to the professor is 04321,
- an offline run of the full version with input [18062,6042,35876] yielded 3622326 as expected.


⁵ḶŒ!Ẇf¥ÐḟDL - Main link: list a
⁵           - literal 10
 Ḷ          - lowered range: [0,1,2,3,4,5,6,7,8,9]
  Œ!        - all permutations
         D  - decimal list (vectorises across a)
       Ðḟ   - filter discard (from the permutations) if: (note - non-empty is truthy)
      ¥     -   last two links as a dyadic operation:
    Ẇ       -     all sublists (of the current permutation)
     f      -     filter keep (if in the decimal list)
          L - length
  • 1
    \$\begingroup\$ ⁵ḶŒ!Ẇf¥ÐḟDL saves a few bytes. \$\endgroup\$
    – Dennis
    Commented Apr 30, 2017 at 21:36
  • \$\begingroup\$ Thanks Dennis, amazing how often I still miss some tacit tricks. \$\endgroup\$ Commented May 1, 2017 at 5:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.