Skip to main content
5 of 15
added 1 character in body
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282

Jelly, 16 bytes

‘ŒPŒcIQLƲÐṀLÐṂṬṚ

A monadic Link that accepts the ruler length, \$N\$, and yields all perfect rulers of length \$N\$ as lists of binary marks ordered numerically.

Try it online! Or see the test-suite.

How?

‘ŒPŒcIQLƲÐṀLÐṂṬṚ - Link: non-negative integer, N
‘                - increment {N} -> N+1
 ŒP              - powerset {[1..N+1]}
                   -> [[],[1],[2],...,[N+1],[1,2],[1,3],...,[1..N+1]]
         ÐṀ      - keep those maximal under:
        Ʋ        -   last four links as a monad:
   Œc            -     unordered pairs
     I           -     forward deltas
      Q          -     deduplicate
       L         -     length
            ÐṂ   - keep those minimal under:
           L     -   length
              Ṭ  - untruth (convert each to their binary representation)
               Ṛ - reverse (equivalent to sorting by binary representation)
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282