g | x | w | all
Bytes Lang Time Link
041Ruby240707T085242Zint 21h
010Uiua231105T071814Zchunes
nanTypeScript 4.9.4 79 Bytes230118T044929ZAsleepac
021Raku230118T073801ZSean
035Arturo230118T015730Zchunes
026Zsh210829T110614Zroblogic
112BrainFlak210828T083147ZWheat Wi
nanTIBASIC210729T182622Zorangey
008Japt210728T165835ZEtheryte
005Vyxal ṡ210728T161957ZAaroneou
00705AB1E210728T130142ZKevin Cr
151Kotlin210728T150806ZDavid Ba
057C gcc210605T084454Zgastropn
036R210604T115137ZDominic
089PHP210606T152705ZHackinet
011Pip p210606T005541ZDLosc
093Desmos210605T180525ZAiden Ch
030Scala210603T212153Zuser
003Vim210605T000336ZD. Ben K
169Lolwho.Cares210605T080450ZRobot
011BQN210603T232151Zfrasiyav
006Jelly210604T224436ZUnrelate
038PowerShell210604T203754Zmazzy
041Python 3210604T210226Zhyper-ne
018><>210604T201219Zkops
044Clojure210604T192408ZKirill L
007Jelly210603T210947Zhyper-ne
040Python 3.8210604T143335ZGriffin
046Red210604T133555Z9214
013APL Dyalog Unicode210604T113255ZAdá
035Zsh210604T084426Zpxeger
021><>210604T102502ZJo King
010Stax210604T085649ZRazetime
031JavaScript ES6210604T015013Ztsh
007Vyxal210603T210810Zemanresu
008Vyxal210604T091851ZWasif
014AWK210604T003638Zcnamejj
012Husk210604T090817ZRazetime
017Retina 0.8.2210603T235716ZNeil
026Wolfram Language Mathematica210603T211731ZZaMoC
045Python 2210604T082009ZElPedro
067Red210604T072736ZGalen Iv
066C gcc210604T071617Zatt
026Haskell210604T050416Zxnor
057PowerShell Core210603T232109ZJulian
063MATLAB/Octave210603T223911Zelementi
035Factor210603T223925Zchunes
011K ngn/k210603T223947Zcoltim
1716J210603T214842ZJonah
056Haskell210603T211743Zuser
034JavaScript ES6210603T212235ZArnauld
054JavaScript V8210603T211044ZRydwolf
041Python 3.8210603T211734ZNoodle9

Ruby, 41 bytes

->a{[a[..x=a[1..].index(a[0])],a[x+1..]]}

Attempt This Online!

No tricks: find the index of the second occurence -> output an array of two parts of the original array.

Uiua, 10 bytes

⊃↘↙⊡1⊚=⊢..

Try it!

⊃↘↙⊡1⊚=⊢..
        ..  # duplicate twice
       ⊢    # first
      =     # mask where input is equal to its first element
     ⊚      # which indices are true?
   ⊡1       # get the second one
⊃↘↙         # split input at this index

TypeScript (4.9.4) - 161 79 Bytes

Note this is only using the type system, so computation is done at compile time

type S<N,H=[]>=N extends[,...infer R]?N[0]extends H[0]?[H,N]:S<R,[...H,N[0]]>:0

example usage:

type TestOne = Split<[1, 1, 9]>

ungolfed version (original):

type Split<Nums extends any[], Comp extends any = null, Head extends any[] = []> =
  // get first element of nums and rest
  Nums extends [infer First, ...infer Rest] ?
  // check if compare is not set
  Comp extends null ?
  // set comp to first and nums to rest call recursively
  Split<Rest, First> :
  // check if first and comp are equal
  First extends Comp ?
  // return [Head, Nums] if true
  [[Comp, ...Head], Nums] :
  // move First into Head and call recursively
  Split<Rest, Comp, [...Head, First]> :
  // return null if nothing
  null

Try it online!

Raku, 21 bytes

{S[(.).*?<()>$0]="
"}

Try it online!

A regex-based approach. Input is a string of space-separated digits, output is the same string but with the space between the digits where the list should be broken replaced with a newline.

Arturo, 35 bytes

$[a][split.at:+1index drop a 1a\0a]

Try it

$[a][               ; a function taking an arg a
  split.at: ... a   ; split a at a particular index
  +1                ; add one to
  index ... a\0     ; the index of the first elt of a in ...
  drop a 1          ; a without its first elt
]                   ; end function

Zsh, 37 26 bytes

Using Zsh array parsing. The separator is an underscore, _

A=$@
<<<${(SI:2:)A/$1/_$1}

Try it Online! 37 bytes

Brain-Flak, 112 bytes

((({})<>)<>){{}({}<(({})<>)<>>)({<({}[()]<({}[()])>)>()}{}<>)<>({}<<>({}<>)>)}{}((()()()()()){})<>{}{({}<>)<>}<>

Try it online!

TI-BASIC, 69 bytes (on-calc) / 104 bytes (as text)

Ans→A
2→I
While ⌊A(I)≠⌊A(1
I+1→I
End
Disp seq(⌊A(J),J,1,I-1
seq(⌊A(J),J,I,dim(⌊A

Explanation

Earlier overcomplicated solution, 78 bytes (on-calc) / 130 bytes (as text)

Ans→A
Ans=Ans(1:Ansseq(I,I,1,dim(Ans→B
SortD(⌊B
⌊B(sum(Ans>0)-1
Disp seq(⌊A(I),I,1,Ans-1
seq(⌊A(I),I,Ans,dim(⌊A

Japt, 8 bytes

Feels like there should be a shorter way for this, but can't seem to find it right now.

Selecting the right-hand element ensures we don't select the first letter itself, the check on the incremented variable ensures we only split once.

óϦUΪT°
ó        // Split the input string between char pairs where it's not true that
 Ï       // the right-hand element
  ¦      // is different than
   UÎ    // the first char of the input
     ª   // or
      T° // T, initially equals zero, plus plus.

Try it here.

Vyxal , 5 bytes

hẆḢḣf

Try it Online!

Explanation:

h      # Get the first element of the list
 Ẇ     # Split list on head, without removing it from the list
  Ḣḣ   # Get the first element from the resulting list
    f  # Flatten the rest of the resulting list
       # 'ṡ' flag - print both lists, separated by a space

05AB1E, 8 7 bytes

ćk>Ig‚£

Try it online or verify all test cases.

7 bytes alternative provided by @ovs:

ćk>°RÅ¡

Try it online or verify all test cases.

Explanation:

ć       # Extract head of the (implicit) input-list; pop and push remainder-list and
        # first item separated to the stack
 k      # Get the first 0-based index of this item in the remainder-list
  >     # Increase it by 1 to make it a 1-based index
   Ig   # Get the length of the input-list
     ‚  # Pair them together
      £ # And split the (implicit) input-list into parts of that size
        # (after which the result is output implicitly as result)

ćk>     # Same as above
   °    # Pop and push 10 to the power this 1-based index
    R   # Reverse it, so we have a 1 with some leading 0s
     Å¡ # Split the (implicit) input-list at the truthy indices (or singular index in
        # this case: the 1)
        # (after which the result is output implicitly as result)

Kotlin, 151 bytes

Takes a List<Int> as input and returns a Pair<List<Int>, List<Int>>

{l:List<Int>->val u=mutableListOf<Int>()
var d=l.size
l.forEachIndexed{i,n->if(!u.contains(n))u.add(n)else d=i}
l.slice(0..d-1)to l.slice(d..l.size-1)}

C (gcc), 58 57 bytes

-1 byte thanks to ceilingcat

Takes input as a string. Outputs to STDOUT.

l;f(char*s){l=index(s+1,*s)-s;printf("%.*s %s",l,s,s+l);}

Try it online!

R, 38 37 36 bytes

Edit: -1 byte thanks to pajonk, as well as outputting the right-way-around now, and then -1 byte thanks to digEmAll

function(l)by(l,cumsum(l==l[1])>1,c)

Try it online!

PHP, 89 bytes

function($x){$y=array_keys($x,$x[0])[1];return[array_slice($x,0,$y),array_slice($x,$y)];}

Try it online!

Explanation:

Pip -p, 11 bytes

a^@(a@*@a1)

Takes a string of digits and outputs a list of two digit-strings. Try it online!

Explanation

             a is first command-line arg (implicit)
    a@*      In a, find all indices of
       @a    the first character of a
   (     1)  Get the second index in the list (0-indexed)
a^@          Split a at that index

Desmos, 93 bytes

a=length(l)
b=\min([2...a](9sign(l[2...a]-l[1])^2+1))
f(l)=join(l[1...b-1],join(-1,l[b...a]))

Test on \$f(l)\$, where \$l\$ is the inputted list.

Outputs the two lists combined into one, separated by a \$-1\$ element in between. This is allowed.

For example, [1,1,9] -> [[1], [1,9]] -> [1,-1,1,9]

Try It On Desmos!

Try It On Desmos! - Prettified

Scala, 35 30 bytes

Saved 5 bytes thanks to @cubic lettuce!

x=>x splitAt x.indexOf(x(0),1)

Try it in Scastie!

Hopefully, I'm not FGITW'ing this.

Vim, 3 bytes/keystrokes

*O<esc>

Jump to next occurrence of word and make a new line.


V (vim), 2 bytes

*O

Try it online!

Since V has implicit escape after O (?), we can use just 2 bytes.


Old (general) 8-byter:

Y/<C-r>"<BS><CR>O<esc>

Input is each list item on a single line. Output is two lists separated by a blank line.

Uses vim notation for the keystrokes (<C-r> is Ctrl-R, etc.; see :help key-notation).

Explanation:

This generalizes to any type of list as long as each element is a single line.


I don't think we can use POSIX vi for this, since I don't think it has <C-r> to insert registers. It doesn't have the search register "/, but that doesn't end up mattering.

Lolwho.Cares, 169 bytes

*2*+210021**+102201*1*1>*2+011021`02**+2101,12000002001v                 v<0210002,<
                       ^120<210<021<<<<<<<<`---020-----,120120*101+201021>*2+00210>^
0210002

Note: The last line is not counted as code, it is the input.

BQN, 12 11 bytesSBCS

⊢⊔˜·∨`·»⊑=«

Try it here.

Explanation:

⊢⊔˜·∨`·»⊑=«   # tacit function which can take input as either a list or a string
          «   # the input list shifted left
         =    # equality comparison with
        ⊑     # the first element of the input
      ·»      # shift the result right
   ·∨`        # 'or' scan
⊢⊔˜           # group the input according to those values

Jelly, 6 bytes

CiḢ$Ṭk

Try it online!

Took me embarrassingly long to realize that œṖ splits before, but k splits after...

C         Subtract each element from 1, creating a new list object.
  Ḣ       Remove its first element and then
 i $      find its first index in that list.
    Ṭ     Create an array containing a 1 at that index,
     k    and split the original array after that 1.

With no mutation at all:

Jelly, 6 bytes

Ḋiḷ/Ṭk

Try it online!

PowerShell, 47 42 39 38 bytes

$args-split"(?<=.)(?=$("$args"[0]))",2

Try it online!

Python 3, 41 bytes

def f(a):a.insert(a[1:].index(a[0])+1,-1)

Try it online!

Another Python approach using the allowed flexible output format. Not any shorter than the existing solution.

><>, 18 bytes

i:vi
=?\o:i:@
oa<^

Try it online!

Saves a copy of the first character x at the bottom of the stack, compares the read character to that, and then prints a line feed and enters an infinite io loop when it finds the second instance of x.

This was a nice instance of being able to use the 2D-ness of ><> by reusing the singular o for both a horizontal and a vertical loop.

Clojure, 44 bytes

#(split-at(inc(.indexOf(rest %)(first %)))%)

Try it online!

Jelly, 7 bytes

œṡḢ©®;Ɱ

Try it online!

œṡḢ©®;Ɱ  Main Link
œṡ       Split at the first occurence of
  Ḣ      The first element (pops the element)
   ©     (also copies that element to the register)
      Ɱ  For each block
    ®;   Prepend the register

As pointed out by Nick Kennedy in the comments (full credit to them), Ḣ;Ɱœṡ@¥ also works and is slightly more functionally pure (though still modifies the list itself, so it's not entirely pure):

Ḣ;Ɱœṡ@¥  Main Link
Ḣ        Cut off and return the first element
      ¥  Last two as a dyad (for chaining; this makes the right argument the modified list for both inner dyads rather than applying consecutively)
 ;Ɱ      Prepend the first element to each of
   œṡ@   The modified list, split at the first occurrence of the first element

Python 3.8, 40 chars

If outputting a list of two strings is allowed...

lambda s:[s[:(i:=s.find(s[0],1))],s[i:]]

Red, 49 46 bytes

func[x][reduce[take/part x find next x x/1 x]]

Try it online!

APL (Dyalog Unicode), 13 bytes (SBCS)

Anonymous tacit prefix function

⊢⊂⍨1,⊃<\⍤=1↓⊢

Try it online!

 the argument

1↓ drop first element

…  apply the following tacit infix function to that, with the first element of the argument as left argument:

⍤= Boolean mask indicating where they are equal

<\ cumulative right-associative less-than scan (effectively zeroes any one after the first one)

1, prepend a one

⊢⊂⍨ use that to partition the argument, starting a new segment on every 1

Zsh, 35 bytes

shift>$1
ls
for x
(rm $x&&od;<<<$x)

Try it online!

Explanation:

With some loose interpretation of what is allowed as a separator, we could have:

Zsh, 33 bytes

shift>$1
ls
for x
rm -v $x||<<<$x

Try it online!

><>, 21 bytes

<0o{oa.0*3+)3l=}:{::i

Try it online!

Takes input as a list of characters (though you are free to put whatever you want in-between digits). Managed to reuse my check that we're not splitting on the first input with the jump quite nicely.

Explanation

<                      Go left from the start
                  ::i   Get the input and duplicate it twice
              =}:{      Compare it with the first character of the input
           )3l          Check if this is not the first char
        *3+             Add these checks together and multiply by 3
                        This will be 3 if the digit is not the same, or if it is the first digit, otherwise 6
      .0                Jump to that point on the first line
   {oa                  If it is the split point, print a newline and clear the first digit
  o                     Print the current digit
 0                      Push a zero to increase the stack height for the first digit check

Stax, 10 bytes

τÄ∩T╕(û▒(Ç

Run and debug it

annoyingly long, but i guess it works.

Stax, 12 bytes(regex)

êt┴≈∟·M╤\+6)

Run and debug it

Stax, 22 bytes(tsh's regex)

"^(.).*?(?=\1)|.+$"|Fm

Run and debug it

JavaScript (ES6), 31 bytes

Thanks Razetime for -1 byte.

a=>a.match(/^(.).*?(?=\1)|.+/g)

Try it online!

Vyxal, 18 7 bytes

Ṙṫ:‟€vp

Try it Online!

Vyxal, 8 bytes

ḣ$£¥€ƛ¥p

Try it Online!

This is possible in 8 bytes Imao

AWK, 17 14 bytes

sub(FS$1,RS$1)

Try it online!

Thanks to Pedro Maimere for the hint to lop off 3 bytes

The interactions of the rules in the contest allow for pretty trivial AWK solution... Assuming the input can be a blank delimited string of numbers, this will work. If it has to include the brackets and commas (which I wasn't sure about from the linked article about convenient input), then it would be this instead.

sub(", "(a=substr($1,2)),"]\n["a)

And here's one in ><> which might be shrinkable still... It's the first time I've managed to get something to work in that language, so I wouldn't be surprised to learn there some trick I don't know yet.

><>, 41 bytes

i:o&0v
?(0:i<o$v?<=1:+{=&:&:;
 0+1o+19< ^

Try it online!

I can add a more detail description if anyone is interested, but here's an overview of how it works.

The input it expects is a string of digits. Since the challenge specified that the list was made up of single digit numbers, I chose not to include a delimiter. If that's a requirement, some additional stuff would have to be added...

The first line reads in the first number, uses it to set the register (for comparison as the rest of the list is read in), then pushes a counter that tracks the number of times the first number has been seen. Then it passed control down to the next line.

i:o&0v

That line reads one digit at a time, starting with the second digit, and prints it. There's a conditional code to add a \n when the counter hits 1 (meaning it found the second occurrence of the first digit). The code is interpreted right to left to save characters.

?(0:i<o$v?<=1:+{=&:&:;

The last line is effectively like a "function" call to print a linefeed and tweak the counter so that it will never be called again.

0+1o+19< ^

Husk, 12 bytes

Fȯ:;:←¹↕≠←¹t

Try it online!

no split at index builtin, but (span) helps a bit.

it's similar to xnor(and Zgarb)'s answer, but argument destructuring and functors don't exits, so it just uses a fold.

Retina 0.8.2, 18 17 bytes

^((.).*?)\2
$1¶$2

Try it online! Link is to test suite that double-spaces the output for convenience. Takes input as a string of digits. Explanation: Simply finds the earliest next match of the first character and inserts a newline before it. Edit: Saved 1 byte thanks to @Jakque.

Wolfram Language (Mathematica), 26 bytes

g[b_,a___,b_,c___]=b.a|b.c

Try it online!

-10 bytes thanks to @att

Python 2, 45 bytes

i=input()
a=i.index(i[0],1)
print i[:a],i[a:]

Try it online!

Red, 67 bytes

func[b][collect[keep/only take/part b find next b b/1 keep/only b]]

Try it online!

C (gcc), 66 bytes

k;f(d,l)int*d;{k=printf(" %d"+(!l||d[l]-f(d,l)),k=d[--l])-1?-1:k;}

Try it online!

Haskell, 26 bytes

f(x:y)=([x],0)*>span(/=x)y

Try it online!

Shortens Zgarb's OG solution

f(x:y)|(a,b)<-span(/=x)y=(x:a,b)

by prepending x to the first element of (a,b) in a pointfree way, that is without explicitly binding (a,b).

It would be nice it we could do (x:)<$>(a,b), but that gives (a,x:b) -- the Functor instance of tuples lets us act on the second element but not the first.

However, Applicative lets us combine tuples as:

(p, f) <*> (a, b) = (p++a, f b)
([x], id) <*> (a, b) = (x:a, b)

It suffices to use *> which ignores f and leaves b unchanged.

((x:), 0) *> (a, b) = (x:a, b)

The 0 could be anything -- it doesn't matter. It would also work to use >> in place of *>.

26 bytes

f(x:y)=([x],y)>>=span(/=x)

Try it online!

A alternative, this time using the Monad instance and (>>=) :: Monoid a => (a, a0) -> (a0 -> (a, b)) -> (a, b)

27 bytes

f(x:y)=([x],[])<>span(/=x)y

Try it online!

Using <> to do concatenate elementwise (a, b) <> (c, d) = (a++c, b++d). This is available in Prelude without an import starting in version 8.4.1.

PowerShell Core, 60 57 bytes

$a,$b=$args
$r=(,$a),$y
$b|%{$r[$r[1]-or$_-eq$a]+=,$_}
$r

Try it online!

It takes the input as an array of ints, returns two arrays

Another approach for 59 bytes

param($a)$a[0..(($i=$a|% i*f $a[0] 1)-1)],$a[$i..$a.Length]

Try it online!

Takes the input as a string, returns two arrays

MATLAB/Octave, 63 bytes

function y=f(x)
l=find(x==x(1));y={x(1:l(2)-1),x(l(2):end)};end

Try it online!
Outputs cell aray with 2 cells, which hold appropriate vectors. I've chosen such output because rules say 2 lists must be distinguished, not necessarily be separate variables. And outputting 2 variables turned out to give a little longer code.

Ungolfed/explained:

function y = f(x)
l = find( x==x(1) );   % indices of elements equal to first element
l2 = l(2);             % index of second occurence
y = { x(1:(l2-1)),...  % vector containing elements before 2nd occurence
      x(l2:end) };     % vector containing elements from 2nd occurence
end

Interestingly, it's also possible to create anonymous function that does the same, but it's 2 bytes longer:

@(x){x(1:find(x(2:end)==x(1),1)),x(find(x(2:end)==x(1),1)+1:end)}

Try it online!
It is possible to shorten it more as flawr noticed, resulting in 42 bytes but it's an Octave-only solution, not working for MATLAB:

@(x){x(1:(l=find(x==x(1))(2))-1),x(l:end)}

Try it online!

Factor, 37 35 bytes

[ dup first 1 pick index-from cut ]

Try it online!

Explanation:

K (ngn/k), 11 bytes

{(2#*=x)_x}

Try it online!

J, 17 16 bytes

(]{.,<@;@}.)<;.1

Try it online!

In a sentence:

Cut on first element and then meld together the tail elements.

Consider f 0 2 2 3 0 1 0 1

Haskell, 56 bytes

f(h:t)=(h#t)[h]
(h#(x:y))a|x==h=(a,x:y)|0<1=(h#y)$a++[x]

Try it online!

Because why not?

flawr's suggestion, 33 bytes

f(x:y)|(a,b)<-break(==x)y=(x:a,b)

Try it online!

This is based on Zgarb's solution (f(x:y)|(a,b)<-span(/=x)y=(x:a,b)).

JavaScript (ES6), 34 bytes

a=>[a,a.splice(a.indexOf(a[0],1))]

Try it online!

JavaScript (V8), 54 bytes

x=>[x[s="slice"](0,i=x[s](1).indexOf(x[0])+1),x[s](i)]

Try it online!

Python 3.8, 41 bytes

lambda l:[l[:(i:=l.index(l[0],1))],l[i:]]

Try it online!