6
\$\begingroup\$

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.

Example

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!

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

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.)

⁵ḶŒ!Ẇf¥ÐḟDL

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.

How?

⁵ḶŒ!Ẇ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
\$\endgroup\$
  • 1
    \$\begingroup\$ ⁵ḶŒ!Ẇf¥ÐḟDL saves a few bytes. \$\endgroup\$ – Dennis Apr 30 '17 at 21:36
  • \$\begingroup\$ Thanks Dennis, amazing how often I still miss some tacit tricks. \$\endgroup\$ – Jonathan Allan May 1 '17 at 5:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy