Sequences of distinct positive integers

Python 2, 78 bytes

f=lambda n,l=[]:sum([f(n,l+[i+1])for i in range(n)if~-(i+1in l)],[l]*(n in l))

Try it online!

Python 3 lets us save some bytes with set unpacking.

Python 3, 74 bytes

f=lambda n,l=[]:sum([f(n,l+[i])for i in{*range(1,n+1)}-{*l}],[l]*(n in l))

Try it online!

Husk, 9 bytes


Try it online!


       ´π     All length n combinations of 1..n
     mu       Get the unique values of each list
    u         Get the unique lists
 f€¹          Filter by those that contain n
O             And sort lexographically

Brachylog, 10 bytes


Try it online!

  • {…}ᶠo: order all results of:
  • ⟦₆: from [1,2,…,N-1]
  • : try a subset (e.g. [1,2] then [2] then [1] then [])
  • ,?: append the input [1,2,3]
  • p: permute the list