Skip to main content
Commonmark migration
Source Link

#SWI-Prolog, 165 162 159 bytes

SWI-Prolog, 165 162 159 bytes

b(Z,C,[D|E]):-Z=[A|B],(A=:=D+1,(B=[],put(45),print(A);b(B,C,[A,D|E]));(E=[],tab(1),print(A);writef('-%t %t',[D,A])),b(B,A,[A]));!.
a(A):-sort(A,B),b(B,_,[-1]).

Pretty bad but then again Prolog is a terrible golfing language

Example: a([9,13,3,11,8,4,10,15,6]). outputs 3-4 6 8-11 13 15

#SWI-Prolog, 165 162 159 bytes

b(Z,C,[D|E]):-Z=[A|B],(A=:=D+1,(B=[],put(45),print(A);b(B,C,[A,D|E]));(E=[],tab(1),print(A);writef('-%t %t',[D,A])),b(B,A,[A]));!.
a(A):-sort(A,B),b(B,_,[-1]).

Pretty bad but then again Prolog is a terrible golfing language

Example: a([9,13,3,11,8,4,10,15,6]). outputs 3-4 6 8-11 13 15

SWI-Prolog, 165 162 159 bytes

b(Z,C,[D|E]):-Z=[A|B],(A=:=D+1,(B=[],put(45),print(A);b(B,C,[A,D|E]));(E=[],tab(1),print(A);writef('-%t %t',[D,A])),b(B,A,[A]));!.
a(A):-sort(A,B),b(B,_,[-1]).

Pretty bad but then again Prolog is a terrible golfing language

Example: a([9,13,3,11,8,4,10,15,6]). outputs 3-4 6 8-11 13 15

deleted 2 characters in body
Source Link
Fatalize
  • 39.3k
  • 5
  • 70
  • 162

#SWI-Prolog, 165 162 161159 bytes

b(Z,C,[D|E]):-Z=[A|B],(A=:=D+1,(B=[],printput(-45),print(A);b(B,C,[A,D|E]));(E=[],tab(1),print(A),;writef('-%t %t',[D,A])),b(B,A,[A]));!.
a(A):-sort(A,B),b(B,_,[-1]).

Pretty bad but then again Prolog is a terrible golfing language

Example: a([9,13,3,11,8,4,10,15,6]). outputs 3-4 6 8-11 13 15

#SWI-Prolog, 165 162 161 bytes

b(Z,C,[D|E]):-Z=[A|B],(A=:=D+1,(B=[],print(-),print(A);b(B,C,[A,D|E]));(E=[],tab(1),print(A),;writef('-%t %t',[D,A])),b(B,A,[A]));!.
a(A):-sort(A,B),b(B,_,[-1]).

Pretty bad but then again Prolog is a terrible golfing language

Example: a([9,13,3,11,8,4,10,15,6]). outputs 3-4 6 8-11 13 15

#SWI-Prolog, 165 162 159 bytes

b(Z,C,[D|E]):-Z=[A|B],(A=:=D+1,(B=[],put(45),print(A);b(B,C,[A,D|E]));(E=[],tab(1),print(A);writef('-%t %t',[D,A])),b(B,A,[A]));!.
a(A):-sort(A,B),b(B,_,[-1]).

Pretty bad but then again Prolog is a terrible golfing language

Example: a([9,13,3,11,8,4,10,15,6]). outputs 3-4 6 8-11 13 15

added 10 characters in body
Source Link
Fatalize
  • 39.3k
  • 5
  • 70
  • 162

#SWI-Prolog, 165 162162 161 bytes

b(Z,C,[D|E]):-Z=[A|B],(A=:=D+1,(B=[],writefprint('-%t'),[A]print(A);b(B,C,[A,D|E]));(E=[],writeftab(' %t'1),[A]print(A),;writef('-%t %t',[D,A])),b(B,A,[A]));!.
a(A):-sort(A,B),b(B,_,[-1]).

Pretty bad but then again Prolog is a terrible golfing language

Example: a([9,13,3,11,8,4,10,15,6]). outputs 3-4 6 8-11 13 15

#SWI-Prolog, 165 162 bytes

b(Z,C,[D|E]):-Z=[A|B],(A=:=D+1,(B=[],writef('-%t',[A]);b(B,C,[A,D|E]));(E=[],writef(' %t',[A]);writef('-%t %t',[D,A])),b(B,A,[A]));!.
a(A):-sort(A,B),b(B,_,[-1]).

Pretty bad but then again Prolog is a terrible golfing language

Example: a([9,13,3,11,8,4,10,15,6]). outputs 3-4 6 8-11 13 15

#SWI-Prolog, 165 162 161 bytes

b(Z,C,[D|E]):-Z=[A|B],(A=:=D+1,(B=[],print(-),print(A);b(B,C,[A,D|E]));(E=[],tab(1),print(A),;writef('-%t %t',[D,A])),b(B,A,[A]));!.
a(A):-sort(A,B),b(B,_,[-1]).

Pretty bad but then again Prolog is a terrible golfing language

Example: a([9,13,3,11,8,4,10,15,6]). outputs 3-4 6 8-11 13 15

added 3 characters in body
Source Link
Fatalize
  • 39.3k
  • 5
  • 70
  • 162
Loading
Source Link
Fatalize
  • 39.3k
  • 5
  • 70
  • 162
Loading