g | x | w | all
Bytes Lang Time Link
038Uiua240602T022935ZJoao-3
093R231003T090733ZEvargalo
162Scala231002T233857Z138 Aspe
010Brachylog231002T231750ZDLosc
053Curry PAKCS220408T025138Zalephalp
00505AB1E220314T074245ZKevin Cr
004Vyxal220314T042307Zemanresu
006Jelly220313T180215ZJonathan
278C++ gcc220317T050818ZSpectral
088Python 3220313T185352Zsolid.py
053Ruby220314T090202ZG B
073PARI/GP220314T061926Zzoomlogo
090JavaScript ES6220313T211111ZArnauld
035BQN220313T181739Zovs
059Factor + grouping.extras math.combinatorics220313T202504Zchunes
069Haskell220313T201821ZAZTECCO
030J220313T200528ZJonah

Uiua, 38 bytes

▽⊸≡(/×≡/≠◫2)∧(☇1⊞⍜⊙↻⊂¤⊙(⇡+1⊡1△.))⊙[[]]

Try it in the pad!

You can optionally add ◴ deduplicate to generate the solution without duplicates.

R, 93 bytes

\(v,m=permute::allPerms(v))for(i in 1:nrow(m)){l=v[m[i,]];if(all(l!=lag(l),na.rm=T))print(l)}

Prints in console, including duplicates:

v=c(0,-2,1,0) ; a(v)

[1] 0 -2 0 1
[1] 0 1 -2 0
[1] 0 1 0 -2
[1] -2 0 1 0
[1] -2 0 1 0
[1] 1 0 -2 0
[1] 1 0 -2 0
[1] 0 -2 0 1
[1] 0 -2 1 0
[1] 0 1 0 -2
[1] 0 1 -2 0

Scala, 162 bytes

Port of @G B's Ruby answer in Scala.


Golfed version. Try it online!

def u(l:List[Int])=l.permutations.filter(i).toList
def i(l:List[Int]):Boolean=l match{case Nil=>true case _::Nil=>true case x::y::xs=>if(x==y)false else i(y::xs)}

Ungolfed version. Try it online!

object Main {
  def uniquePermutations(list: List[Int]): List[List[Int]] = {
    list.permutations.filter(isUniqueConsecutive).toList
  }

  def isUniqueConsecutive(list: List[Int]): Boolean = {
    list match {
      case Nil => true
      case _::Nil => true
      case x::y::xs => if (x == y) false else isUniqueConsecutive(y::xs)
    }
  }

  def main(args: Array[String]): Unit = {
    println(uniquePermutations(List(0, 1, 1, 0)))
    println(uniquePermutations(List(1, 1, 1)))
  }
}

Brachylog, 10 bytes

p.{s₂=}ᶜ0∧

A generator predicate that takes a list through its input parameter and produces permutations (including duplicates) through its output parameter. Try it online!

Explanation

p.{s₂=}ᶜ0∧
p           Get a permutation of the input list
 .          This is the output
  {   }ᶜ    Count the number of ways to:
   s₂        Get a length-2 sublist
     =       whose elements are equal
        0   Assert that the result is 0
         ∧  Don't try to unify 0 with the output

Curry (PAKCS), 53 bytes

[]#s=s
(x++a:y)#s|s==[]||a/=head s=(x++y)#(a:s)
(#[])

Try it online!

Curry supports non-deterministic operations which can return different values for the same input. This is a non-deterministic function whose different return values are the all complex permutations (including duplicates).

05AB1E, 5 bytes

œʒ¥ĀP

Includes duplicated items.

Try it online or verify all test cases.

Explanation:

œ      # Get all permutations of the (implicit) input-list
 ʒ     # Filter it by:
  ¥    #  Get the deltas/forward-differences
   Ā   #  Check for each whether it's NOT 0
    P  #  Product: check if all of them are truthy
       # (after which the result is output implicitly)

¥Ā could alternatively be üÊ for the same byte-count:

  ü    #  For each overlapping pair:
   Ê   #   Check that they are not equal

Vyxal, 4 bytes

Ṗ'¯A

Try it Online!

Port of Jonathan Allan's Jelly answer.

-1 thanks to ovs.

Jelly, 6 bytes

Œ!IẠ$Ƈ

Try it online!

How?

Œ!IẠ$Ƈ - Link: list of numbers, A
Œ!     - all permutations of A
     Ƈ - filter keep those for which:
    $  -   last two links as a monad:
  I    -     forward differences
   Ạ   -     all non-zero?

C++ (gcc), 310 301 283 278 bytes

EDIT: -22 bytes thanks to ceilingcat and -1 byte from the label statement.

#include"bits/stdc++.h"
#define c std::cout<<
#define Q&a[0],&*end(a))
#define T;for(j=0;j<a.size()
int j,k;l(std::deque<int>a){auto p=[&]{c"["T;)c","+!j<<a[j++];c"]";};p();c"->";for(std::sort(Q;std::next_permutation(Q;){T-1;)if(a[j]==a[++j])goto e;c","+1/++k;p();e:;}k||c"[]";}

Try it online!

Python 3, 88 bytes

Thanks to user loopy walt for -7 bytes and user pxeger for -1 byte.
Returns a set of non-duplicate tuples. For the nothing case an empty set() is returned.

lambda l:{p for p in permutations(l)if p[:len([*groupby(p)])]==p}
from itertools import*

Attempt This Online!

Python 3.10, 95 bytes

Thanks to user LeopardShark for -1 byte.

lambda l:{p for p in permutations(l)if all(i!=j for i,j in pairwise(p))}
from itertools import*

Attempt This Online!

Ruby, 55 53 bytes

->l{[]|l.permutation.select{|r,*f|f.all?{|x|r!=r=x}}}

Try it online!

Thanks AZTECCO for -2 bytes

PARI/GP, 73 bytes

f(x)=r=[];forperm(vecsort(x),p,prod(i=2,#p,p[i]-p[i-1])&&r=concat(r,p));r

Attempt This Online!

After a lot of head scratching and asking @alephalpha in chat, here it is.

JavaScript (ES6), 90 bytes

Returns a set of strings.

f=(a,p=[],s=new Set)=>a.map((v,i)=>v==p[0]||f(a.filter(_=>i--),[v,...p],s))+a?s:s.add(p+a)

Try it online!

BQN, 35 bytesSBCS

{(∧´1«»≠⊢)¨⊸/⍷𝕩⊏˜⚇1⍋∘⍋⊸≡˜¨⊸/⥊↕⥊˜≠𝕩}

Run online!

Factor + grouping.extras math.combinatorics, 59 bytes

[ [ [ = ] 2clump-map vnone? ] filter-permutations members ]

Try it online!

Haskell, 69 bytes

import Data.List
f=(filter$and.(zipWith(/=)<*>tail)).nub.permutations

Try it online!

J, 30 bytes

[:~.@(#~0=1#.2=/\"1])i.@!@#A.]

Try it online!