[Question]
  [
Given a list of positive digits, return that list with consecutive elements grouped together. For example:
```
[1, 2, 3, 5, 6, 5, 4, 4, 1] -> [[1, 2, 3], [5, 6, 5, 4], [4], [1]]
```
Essentially, all adjacent elements whose absolute difference is 1 should be grouped together.
The input array will only ever contain positive digits (`123456789`) and it's length will always fit within your language's integer limit. You may take input in any reasonable format, including as a string or a single integer (so the example would be \$123565441\$). The input will never be empty and will always contain at least 1 element
You may output in any reasonable format that clearly shows the separate groups. There must be clear, non-digit delimiters between the groups. There doesn't have to be clear delimiters between the elements of the groups. If there are, the delimiters between groups and the elements of groups should be distinct (basically, you can't just print the input saying that both are separated by `,`  or whatever).
One example output is shown above. Another could be outputting each group on a separate line, as single strings of digits such as
```
123
5654
4
1
```
The input is not guaranteed to be sorted. The order of the outputs, or the elements in the outputs, does not have to match the order of the inputs, so long as the groups and elements are correct.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest code in bytes wins.
## Test cases
```
[1] -> [1]
[1, 2] -> [[1, 2]]
[1, 3] -> [[1], [3]]
[2, 1] -> [[2, 1]]
[2, 4, 1, 2, 7, 6, 5, 1] -> [[2], [4], [1, 2], [7, 6, 5], [1]]
[4, 1, 8, 1, 3, 5, 3, 7, 1] -> [[4], [1], [8], [1], [3], [5], [3], [7], [1]]
[1, 2, 3, 4, 5, 6, 7, 9, 8] -> [[1, 2, 3, 4, 5, 6, 7], [9, 8]]
[1, 2, 3, 5, 6, 5, 4, 4, 1] -> [[1, 2, 3], [5, 6, 5, 4], [4], [1]]
[6, 1, 4, 4, 1, 2, 1, 4, 3, 2, 9, 2, 7, 5, 7, 3, 1, 7, 6, 5] -> [[6], [1], [4], [4], [1, 2, 1], [4, 3, 2], [9], [2], [7], [5], [7], [3], [1], [7, 6, 5]]
[6, 1, 4, 4, 1, 2, 3, 4, 3, 2, 9, 2, 7, 5, 7, 3, 1, 7, 6, 5] -> [[6], [1], [4], [4], [1, 2, 3, 4, 3, 2], [9], [2], [7], [5], [7], [3], [1], [7, 6, 5]]
```
  
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 13 bytes
```
⊢⊂⍨1,1≠∘|2-/⊢
```
```
⊢⊂⍨1,1≠∘|2-/⊢
         2-/⊢  pairwise differences
     1≠∘|      1 not equal to absolute value
⊢⊂⍨1,          prepend 1 and partition
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn//1HXokddTY96VxjqGD7qXPCoY0aNka4@UPR/2qO2CY96@x51NT/qXfOod8uh9caP2iY@6psaHOQMJEM8PIP/pykYKhgpGCuYKpgBsQkQGgIA "APL (Dyalog Extended) – Try It Online")
[Answer]
# [convey](http://xn--wxa.land/convey/), 36 bytes
Outputs the groups separated by newlines.
```
{"">>v>v}
1~?`]>^,`
 >-|=.!`
   _1 _
```
[Try it online!](https://xn--wxa.land/convey/run.html#eyJjIjoie1wiXCI+PnY+dn1cbjF+P2BdPl4sYFxuID4tfD0uIWBcbiAgIF8xIF8iLCJ2IjoxLCJpIjoiMSAyIDMgNSA2IDUgNCA0IDEifQ==)
Copies `"` each element, delays it by one step `1~`, so it matches up at `-` with the next element. The first element gets discarded with `?`]`. Take the absolute value of the difference `|_`, is it different from 1 `1=.`? Then take either 0 or 1 `_` values, which will be interpreted as newline by the output.
Meanwhile the original outputs trots along the upper line, so its output is aligned with the newlines.
[![example run](https://i.stack.imgur.com/nku2R.gif)](https://i.stack.imgur.com/nku2R.gif)
[Answer]
# [J](http://jsoftware.com/), 17 bytes
```
<;.1~1,1~:&|2-/\]
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/baz1DOsMdQzrrNRqjHT1Y2L/a3KlJmfkK6QpGOkomOgoGOqAGOY6CmY6CqZALkwWImUBJo3BUsZgZXAFEI3GYENMwdqBspZALXDzkdQqGMGZqNZjccF/AA "J – Try It Online")
Thanks to rak for pointing out that repeated elements should start a new group
* `2-/\]` Take successive deltas
* `1~:&|` Is the absolute value not equal to 1?
* `1,` Append one (since first element always starts a new group)
* `<;.1~` Group by that mask (ie, start new group every time there's a one)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
I²’k
```
[Try it online!](https://tio.run/##y0rNyan8/9/z0KZHDTOz/x9uPzrp4c4ZKo@a1kT@/x9tGKujEG2oo2AEpY1BtJGOgiGUNgEygbI6CuY6CmY6CqZQGYiwBZg0Bgsbg5XAjQMLmIBlzMAylkDlKJKmMANNILaAJM3ABpogWQvhGoPZljCHmIJJY7As1F3YdRsTqxsA "Jelly – Try It Online")
~~Possibly~~ caird's solution:
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
IACk
```
[Try it online!](https://tio.run/##y0rNyan8/9/T0Tn7/@H2o5Me7pyh8qhpTeT//9GGsToK0YY6CkZQ2hhEG@koGEJpEyATKKujYK6jYKajYAqVgQhbgEljsLAxWAncOLCACVjGDCxjCVSOImkKM9AEYgtI0gxsoAmStRCuMZhtCXOIKZg0BstC3YVdtzGxugE "Jelly – Try It Online")
```
   k    Split the input after
I       the deltas of the input
 ……     equal to ±1:
 ²      square each
  ’     and decrement each
 A      take the absolute value of each
  C     and subtract from 1
```
[Answer]
# [R](https://www.r-project.org/), 38 bytes
```
split(a<-scan(),diffinv(diff(a)^2!=1))
```
[Try it online!](https://tio.run/##K/r/v7ggJ7NEI9FGtzg5MU9DUyclMy0tM69MA0RrJGrGGSnaGmpq/jdUMFIwVjBVMANiEyA0/A8A "R – Try It Online")
[Answer]
# [Factor](https://factorcode.org/), ~~33~~ 32 bytes
```
[ [ - sq 1 = ] monotonic-split ]
```
[Try it online!](https://tio.run/##fVDBCoJAFLz7FfMDCrmuZtE5unSJTuLBZCtJV3O3Q4jfvj23Eoto4bHDzLwZeMcs13Vr9rvNdr3ARbRSlKgyfYYS15uQuVBoWqH1vWkLqaGastC6kCevqmWta1nkWDqdA3odZuhH5E8wG7E/8fgIrC9CCD7hB3ZutzhN9JXKSOe0ESEm16fCbVJgE95KSDh4NQ2I0R/bVk7DiHv2//Kzv/7eJEjgIjsoYldIMd7EtXdCaqqsgWce "Factor – Try It Online")
*Saved a byte by peeking at @xnor's [Haskell answer](https://codegolf.stackexchange.com/a/223801/97916)! Take the square instead of the absolute value.*
## Explanation:
It's a quotation (anonymous function) that takes a sequence from the data stack as input and leaves a sequence (of sequences) on the data stack as output. Assuming `{ 1 2 4 }` is on the data stack when this quotation is called...
* `[ - sq 1 = ]` Push a quotation for `monotonic-split` to use later. It's a function that tests whether two numbers have an absolute difference of 1.
**Stack:** `{ 1 2 4 } [ - sq 1 = ]`
* `monotonic-split` Take a sequence and a quotation and apply the quotation to each pair of adjacent members of the sequence, splitting the sequence when the result is `f` but grouping elements together when the result is `t`. Inside the quotation during the first iteration now...
**Stack:** `1 2`
* `-` Subtract.
**Stack:** `-1`
* `sq` Raise to the power of 2.
**Stack:** `1`
* `1` Push `1`.
**Stack:** `1 1`
* `=` Test whether two objects are equal.
**Stack:** `t`, thus 1 and 2 belong to the same group.
Now the next iteration begins, `2` and `4` produce `f`, so `4` is in a different group from `1` and `2`.
[Answer]
# [Haskell](https://www.haskell.org/), 74 bytes
```
p%(a:b:t)|abs(a-b)/=1=(p++[a]):[]%(b:t)|x<-p++[a]=x%(b:t)
p%t=[p++t]
([]%)
```
[Try it online!](https://tio.run/##jZBLDoIwEIb3nGI2JG0sGiygEHsET9B0UYwoEU1ju2Dh2a11ikYTF27m8X/zyhy1Pe2HwXuTEt20jaM33Vqis5YuRC6Imc2kVrSRKiVIx00WNTFGJTGpEzJoTiWdIKGQere3zoIAKXPFQOYMlpPnT79kkE@@CGGgDFYMKgblRKK8RstR5ljyHodCgaRCUofyL1i@BhZxyxNWOLD4WBtTjnH9OqREy5FOd/3u5v92q@Ss@0v4yFmbLRBz7S9u3lHAR/n7rhv0wfpsZ8wD "Haskell – Try It Online")
I don't like the repetition here, but I can't see a way to get around it.
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 54 bytes
```
\B
¶
.
$&$&
%T`d`_d`^.
(?<=(.)(.))¶(\2|.(?=\1))
%`^.
```
[Try it online!](https://tio.run/##K0otycxL/P8/xonr0DYuPS4VNRU1LtWQhJSE@JSEOD0uDXsbWw09TSDSPLRNI8aoRk/D3jbGUFOTi0sVJP//v6GRsamZqYmJIQA "Retina 0.8.2 – Try It Online") No test suite because the multiline output makes it confusing. Explanation:
```
\B
¶
```
Split the string into individual digits.
```
.
$&$&
%T`d`_d`^.
```
Duplicate each digit and decrement the first digit of each pair.
```
(?<=(.)(.))¶(\2|.(?=\1))
```
Merge together consecutive digits, removing the decremented duplicate of the second digit.
```
%`^.
```
Remove the remaining decremented duplicates.
[Answer]
# [Branch](https://github.com/hyper-neutrino/branch-lang/), 28 bytes
```
/,^\b[N^-b;c;^*{[10.0]\n.b,]
```
Try it on the [online Branch interpreter](https://branch.hyper-neutrino.xyz/#WyIvLF5cXGJbTl4tYjtjO14qe1sxMC4wXVxcbi5iLF0iLCI2MTQ0MTIzNDMyOTI3NTczMTc2NSIsIiJd)!
Takes input as a string of digits. Outputs with groups newline-separated and elements of a group joined in one string on each line. There is a leading newline; hopefully that's acceptable.
## Explanation
```
/,                       Go to the left child and read a character (stores codepoint)
^\                       Go to the right child (just creates this node for operating on)
b                        Go to register B; this is the left child since it was created second
[                     ]  While [the left child] is true
 N                       Save the most recently inputted byte as register N
  ^-                     Go to the root and perform (left child) - (right child); the right child saves the previous input; initially codepoint 0
    b;c;                 Go to register B (left child) and copy parent; go to C (right child) and copy parent
        ^*               Go to parent and perform (left child) * (right child) (this could've been done with b;c2^' as well to square with conventional exponentiation)
          {              Decrement; this is now 0 if the absolute difference was 1 and non-zero otherwise
           [   0]        While statement; zeroes the value at the end so this is transformed into an if statement
            10.          Set value 10 and output as character (outputs a newline if the difference isn't 1 / -1)
                 \n      Go to the right child and save N
                   b,    Go to the left child and read a new character, setting the state for the next iteration of the while loop
```
Reading from STDIN when nothing is left gives 0, so this terminates once input ends.
[Answer]
# [Haskell](https://www.haskell.org/), 59 bytes
```
f[]=[]
f(x:y)|(a:b):t<-f y,(x-a)^2==1=(x:a:b):t|0<1=[x]:f y
```
[Try it online!](https://tio.run/##rVDLboMwELznK/ZQKbZk2oIhDxrnXql/YLmSK6BFTQAlHEDKv1N7XTuk6qVSL@vZ9czs40OfP8vDYZoqqYRUi4oM@UgvROdvNO93UQUjI0Ok6WsiRCzMr/u5PO5iIQeVG8J01HUjinYBQGrWUqM66o4Up7aDhN6fO92QB7GMlnR3t38v@5e6KQ33UPYwiFOpC6jzXD43vXoaXd6aHAvK8LpT3fSkMlwxsoGN1NRsx0nGCqI9SPOqhYwZJD630JV4oDCQ3BYTBl6H0JVSA42KwZrBikE2I1llagPamvebgiUrd9oNRo5ajj7ewYlt2ATEbcgCWgczNwXHiTJsZJy2xn62249/q0XGXJ75PVK33K0cuwfGdUNrscJF0tlNXMoRb/2VMowcf/1FXI9V2DK9uZ2dwubOCqe2IQkHyALiwcJb/zoY/6/BrkZ/HesL "Haskell – Try It Online")
The relevant function is `f`, which takes a list as input and returns a list of lists as output.
---
Unfortunately the builtin
```
groupBy(\x y->(x-y)^2==1)
import Data.List
```
doesn't work, since Haskell's `groupBy` always compares new elements to the first element of the group.
[Answer]
# [Vim](https://www.vim.org), ~~43~~ 38 bytes
*-5 bytes thanks to @DLosc by using clever hyphen evaluating shenanigans.*
```
qqy3ll:if abs(<C-r>0)!=1
norm r|
en
l@qq@q
```
[Try it online!](https://tio.run/##K/v/v7Cw0jgnxyozTSExqVhDyEBT0daQKy@/KFehqIYrNY8rx6Gw0KHw/39DXSNdY11TXTMgNgFCQwA "V (vim) – Try It Online")
Takes input as a hyphen-separated list of numbers.
Explanation:
```
qq                        # Start recording macro 'q'
  y3l                     # Yank this character and the next two; this will be 'X-X'
     l                    # Move right one character
      :if                 # If...
          abs(      )     # The absolute value of...
              <C-r>0      # The previously yanked text, evaluated...
                     !=1  # Does not equal 1:
norm r|                   #   Replace the current character with '|'
en                        #   End if
l                         # Move right one character
 @q                       # Call macro 'q' recursively
   q                      # End macro
    @q                    # Call macro 'q'
```
[Answer]
# [brainfuck](https://github.com/TryItOnline/brainfuck), 51 bytes
This beats some of the mainstream language answers!
(byte count excludes 4 unnecessary newlines added for clarity.)
```
,[[<->>+<-]<
-[>]>[>+<<]<+
+[>]>[>+<<]<-
>>>-[.-]
<.>,]
```
[Try it online!](https://tio.run/##SypKzMxLK03O/v9fJzraRtfOTttGN9aGSzfaLtYuGsixibXR5tJG4uly2dnZ6Ubr6cZy2ejZ6cT@/29oZGxqZmpiYggA "brainfuck – Try It Online")
Outputs each group of characters preceded by an ASCII 1 for example as below
```
123565441
```
The digits are interpreted as ASCII characters and the initial ASCII 1 separator appears because the ASCII codes 48-57 of the digits are not consecutive to the zeroes which fill the Brainfuck memory at the start. Removing the initial separator would take another few bytes of code (I think it's no more of an issue than a trailing newline separator. Others may disagree.)
**Commented code**
```
,[[<->>+<-]<  Take input in cell 0 and copy it to the cell 1 while subtracting from cell minus 1
-[>]>[>+<<]<+ Subtract 1 from cell minus 1 and if it is not now zero add 1 to cell 2 (relies on the fact that cell 0 is zero and cell 1 is positive) 
+[>]>[>+<<]<- Add 1 to cell minus 1 and if it is not now zero add 1 to cell 2
>>>-[.-]      Subtract 1 from cell 2 and if not now zero both tests above failed so output ascii 1 and then zero the cell  
<.>,]         Output the input character now in cell 1 and loop again until a zero byte terminator is encountered
              Second input character will go into cell 2 and will be copied into cell 3 and compared with the previous character in cell 1 and so on advancing 2 cells each time
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 5 bytes
```
ġo=1≠
```
[Try it online!](https://tio.run/##yygtzv7//8jCfFvDR50L/v//H22oY6RjrGOqYwbEJkBoGAsA "Husk – Try It Online")
group on absolute difference = 1.
[Answer]
# JavaScript (ES7), 43 bytes
*Saved 4 bytes thanks to @tsh*
Expects an array of digit characters. Returns a string with the groups separated with commas.
```
a=>a.map(p=v=>(p-(p=v))**2-1?[,v]:v).join``
```
[Try it online!](https://tio.run/##nZFda4MwFIbv9ytCr7TElHNOPnRg90NCoNK1o6VTWYd/35nIMkajsHlxPArP45vXazM09@PHpf8s2u71NJ7rsan3jXhv@qyvh3qf9YVf8ny7xQJeLB/c85CLa3dpD4fx2LX37nYSt@4tO2dWCLGBjctzlrh2O2bBPaUQXGA8YoEzdGmOVjnHmaU0ibBGImewwElAo9UjPXP@i9KPkHm6G840Zyq8ShsllECKzIMyGGeZH2XcyA8VN7MiBySptKnKpNyH5Iw4k1PEEDS4Ks7KRZ3SSkpY04V087En808jaaWGSYcgCSs0yhBM7QZ7UOp4aPmrWv9//HNIH4qu/MDYh4obRcX3v1jJQX/OMbf3nxTjFw "JavaScript (Node.js) – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 6 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Outputs a 2D array.
```
òÈaY É
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=8shhWSDJ&input=WzEsMiwzLDUsNiw1LDQsNCwxXQotUQ)
```
òÈaY É     :Implicit input of array
ò          :Partition between pairs that return falsey (0)
 È         :When passed through this function as X & Y
  aY       :  Absolute difference
     É     :  Minus 1
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 23 bytes
```
Split[#,!-1!=#2-#!=1&]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7P7ggJ7MkWllHUddQ0VbZSFdZ0dZQLVbtf0BRZh5QXNcuzUE5Vq0uODkxr66aq9qwVgdI6CgYQWljEG2ko2AIpU2ATKCsjoK5joKZjoIpVAYibAEmjcHCxmAlcOPAAiZgGTOwjCVQOYqkKcxAE4gtIEkzsIEmSNZCuMZgtiXMIaZg0hgsC3UXdt3GxOrmqv0PAA "Wolfram Language (Mathematica) – Try It Online")
`Split` can take a second argument, which is applied to adjacent pairs to see if they should be in the same group.
`!-1!=#2-#!=1` has the same length as `Abs[#2-#]==1`, and asserts that `-1`, `#2-#`, and `1` are not all unequal - that is, `-1==1 || -1==#2-# || #2-#==1`.
[Answer]
# [K (oK)](https://github.com/JohnEarnest/ok), ~~24~~ 21 bytes
-3 bytes thanks to streetster!
```
{(?0,&~1=d*d:-':x)_x}
```
[Try it online!](https://tio.run/##dY07DoQwDESv4mr5iEgYJywkQhyFBtFQbIuE4OphHLQFBYXt8dOMvZrfGuPi93ysq8/Jw1zO3mR@K6btiEuWVxyIqdEmgRpibVYRfaklp0DXTg1YBfiOQFqAFqCn7o9cClnNBEi@pR7GFMw@XXYoAUs/nkZ5NxbxAg "K (oK) – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 48 bytes
```
->l{y=0;l.chunk{|x|$.+=(y-y=x)**2-1}.map &:last}
```
[Try it online!](https://tio.run/##jZDRCoIwFIbve4pzEVE2Jd20LNaLDC9WIEIWUgkOt2df86goQdDN2X/2nfPvZ8/6omzOrX8uW8V3pzK4FvXj1upGL4MtXytf8WbjeZEfmuAuK1gdS/l6GysARJiRBXQngWiSdJARgXCSzHVujMCeQEIgnmBPDlgpEopTc3e8YwgThKnb@Obx6Mz65waeoDObRehbijodQ8VYKdIh408D@q9B1v1Zq6WuIBcyM/YD "Ruby – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 52 bytes
```
p=0
for n in input():print"X"*p*(abs(n-p)!=1),n,;p=n
```
The program separates the input with the character `"X"`.
[Try it online!](https://tio.run/##K6gsycjPM/r/v8DWgCstv0ghTyEThApKSzQ0rQqKMvNKlCKUtAq0NBKTijXydAs0FW0NNXXydKwLbPP@/4821lEw0lEAkiY6CqYwNpA0hIjEAgA "Python 2 – Try It Online")
# 55 bytes
```
lambda n:reduce(lambda a,b:a+[abs(a[-1]-b)==1,b],n,[0])
```
Alternate **55 byte** solution that uses reduce.
[Try it online!](https://tio.run/##LcdLCoAgEADQq8xSaYS0z0LwJOZippKCsuiz6PQG0ebB259r2pLJ0XV5oZUHgmSPcbj7UfwnZEuFJz4FeaWDYumcRg6Y0JdB5v2Y0yWi8BrBIFQI9WeL0AQp8ws "Python 2 – Try It Online")
[Answer]
# [PHP](https://php.net/) -F, 59 bytes
```
for(;$n=$argn[$i++];$m=$n)$a.=abs($n-$m)-1?",$n":$n;echo$a;
```
[Try it online!](https://tio.run/##DcRLCoAgFAXQvcgdJGVg9IFMmrWJaGDRx4FPydafdQYnXCENY/g//J0pkIa5T5ph83xRcBrEYUpt1piBBBwXcmQFiPUgtW@Xh1EpVbWsuraRrw@P9RSTmD4 "PHP – Try It Online")
Takes a string of digits, outputs a string with delimiter ",". Has a preceding delimiter except when first digit is 1.
Well, at least it beats the Scratch answer :P
[Answer]
# [Racket](https://racket-lang.org/), 241 bytes
```
(λ(s)(letrec([d(λ(t n c)(if(null?(cdr t))(reverse c)(if(=(sqr(-(car t)(cadr t)))1)(d(cdr t)(+ 1 n)c)(d(cdr t)1(cons n c)))))][g(λ(t c a)(if(null? c)(cons t a)(g(drop t(car c))(cdr c)(cons(take t(car c))a))))])(reverse(g s(d s 1'())'()))))
```
[Try it online!](https://tio.run/##fU5LTsMwFNz3FE9i0bEQCzcf2gXiIBULy3aiqpELttvLcQeuFN5zoyQghCXL82bmzTgae/Z5fBhM6CmWYQPnu1Pw1I34@kRSGHyO3uLoZM4UyCqcOoTrMLzCukhZKUR/8zH5SXtB@oh4gjWi8nN3Ka3gphU8kqag7MJo2EtIJV/O27G/F1oyS6EUFFsWtoeLl3fKpYjXStLkQDZnv0imZM4fRU8JjhLpLZSSy2dUG3S0hVYT4C/uVria8Y70Ctfio2dqqVnxwu5li9mK1R@pzNTMt8wfaP9LaUpSLQmz0rJWT02CKn4PpbXhWzFX@v/0V//5x28 "Racket – Try It Online")
What a monstrosity! I won't be surprised if it can be done in under 100 bytes.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~56~~ 54 bytes
```
f(char*n){for(;*n;~-abs(putchar(*n)-*++n)&&puts(""));}
```
[Try it online!](https://tio.run/##nZDPboMwDMbvPIWFtCqhQZXzh4CQ9iKIA2Oj62G0AtZL1b06S8IWmva0cTCOv/z8xW7TfdvOc0fa92ZIenrpjgMpk778SpuXkZw@JysQo6TJdtvTzcaURhLHlJbX@Xw8vML0Nk4L3tBLBOY7DYd@6kj8NEL6DDFraNkRE6JrZAT4aA49sUkz7FsGDk3s4fzDu44xxrQE2O2gwvq2zG3dlitkwOtAE6tWM6hEoHL0KmeAoSaR60zd3LC8tMG5mL9mkDFQrhSwEnMUSugVXjgbcp8JG5TP9GMf5EKqTBd5MCADwUAaY2fvsIJBfk@qTEmJ96TzXN5tmqwjBXSGhuQoBS@4VlqgWYRvlPkBZLARu0B7ds9z@yls4H425TPhW/yu8NFd/NV9Wcq/vK/zNw "C (gcc) – Try It Online")
Takes a string of digits as input; prints output to STDOUT with each group on a separate line.
*-2 thanks to @ceilingcat*
[Answer]
# [Julia](http://julialang.org/), ~~47~~ 46 bytes
```
f(s,p='a')=join(s.|>i->' '^((p-i)^2!=1)*(p=i))
```
[Try it online!](https://tio.run/##rVJNi4MwEL37K2ZPJiUVNGrbQ/pHxIK0dkmRVqoLXdj/7k5mTGqXvSzsZT7fe5kZcvnobJM@puksBtWbuImludzsVQzJ196u9zHEByH6tZWH7M2kciV6Y6WcxnYYBzBQRVVag9kDOgwVZJxxyCXtS7WCSrtipmBmccilHENkKdgoKBUUC5Bj5s6QLPoZQiVHZ@6WrCauJh2vwGRntiHSzhQh2gQxnkLTRAU9hEo7lF/s9qPvuIRY0gu/R87LvdLp9YB4bugkSlokX9yEU03xzl@pIKup6y/Cb5Rhy/zldm4Kl7MUTe1MFg5QhEgHCS/962D6vwZ7Cv15rDqKxhR/4/HWde1xTIT7wok42/uACf1VKWXUPnoEvbejvZ7ax9xQmW/gX09WzKzYWQnn2x0s2CsgplYIkVF0skPfNZ8eNaYIW7rEGIeW0zc "Julia 1.0 – Try It Online")
Input is a list of `Chars` and output is a string with spaces to delimit groups, example:
`f(['2','4','1','2','7','6','5','1']) = " 2 4 12 765 1"`
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 21 bytes
```
Ｐ§θ⁰ＦΦθκ«¿⊖↔⁻ＩＫＫι⸿→Ｐι
```
[Try it online!](https://tio.run/##TY6xDoIwFEVn@IqG6TXBRBQcdCIaEwcS4uyC8JAXaqvtg5gYv72Ck3c7Zzi5dVfZ2lTK@2JQTA9LmiHnk27wBc9YLKXcha2xAo6kGO3seinFOwyoFXDA2uIdNWMD@dUZNTBCQXpwsK8cQ4nYg5SxIDlNlL98dLHRVA1QORSFGRG2Z7p1PLu/FzTxx/tktc42WZomfjGqLw "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
Ｐ§θ⁰
```
Output the first character of the input without moving the cursor.
```
ＦΦθκ«
```
Loop over the remaining characters.
```
¿⊖↔⁻ＩＫＫι
```
If the current character is not a neighbour of the character under the cursor, then ...
```
⸿
```
... move to the start of the next line, ...
```
→
```
... otherwise move right one character.
```
Ｐι
```
Output the current character without moving the cursor.
[Answer]
# [><>](http://esolangs.org/wiki/Fish), 19 bytes
```
:n$:@-:1=$i=+1$-a*o
```
Looks like TIO's `-v` flag support broke, and fishlanguage.com is down, so no link.
Takes the list on the stack, from top to bottom.
[Answer]
# [Zsh](https://www.zsh.org/) `-o extendedglob`, 38 bytes
```
>-1;for a {wc<^*$[b?a-b:1];b=$a;<<<$a}
```
[Try it online!](https://tio.run/##qyrO@F@cWqKgm6@QWlGSmpeSmpKek5/EBRIzVTBTMFQwAUJDBSMFYyBtDKTNgaKm/@10Da3T8osUEhWqy5Nt4rRUopPsE3WTrAxjrZNsVRKtbWxsVBJr//8HAA "Zsh – Try It Online")
I really feel like there's some way to shave off 1 or 2 bytes from the `$[b?a-b:1]`.
* `>-1`: create the empty file `-1`
* `for a {}`: for each input element:
	+ `$[]`: arithmetic expansion
		- `a-b`: take the difference between this element and the previous `b`
		- `b?:1`: if `b` is not defined (because we're on the first iteration), then assume the difference is 1
	+ `*...`: match files that end with that difference. This is so the file `-1` will be matched by a difference of either `1` or `-1`
	+ `^*...`: inverted match; matches files that *don't* end with that difference
	+ `<`: and feed them as input to:
	+ `wc` word count; outputs `0 0 0` (our separator) since the file is empty
	+ So if the difference is `1` or `-1`, it will not match, so there will be no files as input to `wc` and it won't output the separator
	+ `b=$a`: set `b` for the next iteration
	+ `<<<$a`: print `a`
[Answer]
# [Scratch](https://scratch.mit.edu/), (by @att) 184 bytes
[Try it online!](https://scratch.mit.edu/projects/518043965/)
All credit goes to @att
```
define(x
set[a v]to(
set[i v]to(
repeat(length of(x
change[i v]by(1
set[t v]to(letter(i)of(x
set[a v]to(join(a)((t)*(((2)*<(-1)contains((t)-(letter(length of(a))of(a)))?>)-(1
end
say(a
```
[Answer]
# [Arn 1.0](https://github.com/ZippyMagician/Arn), [6 bytes](https://github.com/ZippyMagician/Arn/wiki/Carn)
```
PWº··,
```
# Explained
Unpacked: `::-.|=1`
```
  _         Input; implied
::          Sort adjacent by
        _   First value
      -     Minus
        _   Second value
    .|      Absolute value
  =         Equals
    1       One
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 7 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
üα≠0šÅ¡
```
[Try it online](https://tio.run/##yy9OTMpM/f//8J5zGx91LjA4uvBw66GF//9HG@oY6RjrmOqYAbEJEBrGAgA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfaXL/8N7zm181LnA4OjCw62HFv7X@R8dbRiroxBtqGMEoYxBlJGOIYQy0QFK6JjrmOmYQoRAAhZAbAwUMAZKwDQDOSZAITOgkKWOBULQFKzVBGQQSNAMqNUEaiqIZQykLcE2mAKxMVAMbBe6UmM8SmMB).
**Explanation:**
```
ü        # For each overlapping pair in the (implicit) input-list:
 α       #  Get the absolute difference
  ≠      # Check for each that they're NOT 1 (0 if 1; 1 otherwise)
   0š    # Prepend a 0 to the list
     Å¡  # Split the (implicit) input-list at the truthy indices
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 14 bytes
```
aWV(k1N_-BMPa)
```
Takes input via command-line argument as a string of digits. Outputs with separator `,` between groups and  within groups. [Try it online!](https://tio.run/##K8gs@P8/MTxMI9vQL17XyTcgUfP///@GRsamZqYmJoYA "Pip – Try It Online")
### Explanation
```
          MPa   Map this function to each pair of digits in the input:
     1N          Count the number of 1's in
       _-B       the first digit minus the second (1 if the difference is +/-1, 0 otherwise)
   (k        )  Use that list of 1's and 0's to index into the preset variable k == ", "
                We now have a list of length len(a)-1 containing spaces and commas
aWV             Weave the input string with that list
                Autoprint (implicit)
```
]