Minimal sparse rulers

Wolfram Language (Mathematica), 65 bytes

Tr[1^#]&@@Cases[Subsets[n=0~Range~#],k_/;[email protected]@Abs[k-#&/@k]==n]&

Try it online!


Python 2, 129 128 126 bytes

thanks to totallyhuman for -1 byte

from itertools import*
r=range(1,input()+2)
[{a-b+1for a in l for b in l}>set(r)>exit(i)for i in r for l in combinations(r,i)]

Try it online!

output is via exit code


Pyth, 14 bytes

lh.Ml{-M^Z2ySh

Try it here!

Pyth, 21 19 bytes

hlMf!-SQmaFd.cT2ySh

Try it here!

How it works

I'll update this after golfing.

hSlMfqSQS{maFd.cT2ySh ~ Full program. Q = input.

                   Sh ~ The integer range [1, Q + 1].
                  y   ~ Powerset.
    f                 ~ Filter (uses a variable T).
              .cT2    ~ All two-element combinations of T.
          m           ~ Map.
           aFd        ~ Reduce by absolute difference.
        S{            ~ Deduplicate, sort.
     qSQ              ~ Is equal to the integer range [1, Q]?
  lM                  ~ Map with length.
hS                    ~ Minimum.

Thanks to isaacg for saving a byte for my second approach and inspiring me to golf 3 bytes off my current approach!