g | x | w | all
Bytes Lang Time Link
025250313T225837ZJoao-3
021Uiua240622T010647ZJoao-3
009Jelly241221T233121ZUnrelate
016Uiua240620T133207Znoodle p
021Uiua240620T211225Zjan
013Dyalog APL220228T053000Zrabbitgr
016Japt230329T104813Znoodle p
011Pyth230329T182243ZCursorCo
123C gcc230329T173349Zevanstar
125Nibbles230328T133646Zxigoi
010Vyxal220228T002454Zlyxal
053Raku221003T003503ZSean
056Julia 1.0220303T155519ZMarcMush
042Wolfram Language Mathematica220301T085418Zatt
058Ruby220228T120846ZG B

, 25 chars

code

󰲡1+←x⭥󰑅󷺻xᙧ₀󰄎􍪴ᙧ⭥2ꟿ󷺹⨁≡⟝􍨄󷺿→⋀

Test the code here. Yes, I do know I already answered with Uiua, but I love this language so much that I couldn't resist.

Explanation

explanation

Uiua, 22 21 characters

⊢▽⤚≡(≍↘¯1≡/+⊃◫↘)+1⊃⍏¤

Try it in the pad!

Thanks to jan for -1 character!

Jelly, 9 bytes

UµṡJ§Ḋ€oi

Try it online!

This started as an attempt at suggesting a minor golf to Jonathan Allan's solution out of frustration at +⁹\ actually making sense to use over ṡ§ (being one fewer link to group), but by the time it was even close to saving anything it was barely recognizable!

U            Reverse the input.
   J         For each [1 .. length],
  ṡ          take all overlapping slices of that length
    §        and sum the elements in each slice.
     Ḋ€      Remove the first sum at each length,
       o     element-wise logical OR each list of remaining sums with
Uµ           the input reversed,
Uµ      i    and return the first index of the reversed input.

Relies on the guarantee of strictly positive input in order to use o for is-prefix checking, by exploiting Jelly's handling of mismatched lengths for dyadic operations: all elements of the longer element past the end of the shorter element are left unchanged, so for lists of truthy values x and y, x o y is equal to y iff x is a prefix of y. Hence, the input is reversed to transform suffix-checking into prefix-checking.

A late Ḋ€ after § is necessary rather than before in order to handle length-1 inputs appropriately. There are no possible slices of any length greater than the length of the argument to , so it produces an empty list in such cases. § vectorizes "at depth 1" in Jelly's dynamic nested ragged lists model, meaning it recurs on each element of its argument until it's called on a list with only scalar elements and sums that, so when it reaches that empty list it sums that to a flat 0. This is entirely unproblematic for input lengths greater than 1, because when that 0 is at the end of a list of lists of slice sums, the list has a greater depth than the (reversed) input, so o broadcasts over the entire list and subsequently broadcasts the 0 as a scalar to o with each element (and replace by that element, since it's falsy)... but with a length-1 input, removing its first element before slicing such that we attempt to get length-1 slices of an empty string, the entire list of lists of slice sums is just [0] which has the same depth as the input and zips with it with no broadcasting, producing the exact value of the input which is not contained within itself and thus gives a faulty index of 0. So, on that token, UµḊṡJ§o€i works equally well (and is arguably just overall sounder in principle) by replacing the unreliable broadcast with an explicit map, but then this explanation would feel even more gratuitous :P

Uiua, 21 16 bytes

⍢+₁(¬≍↘¯1⊃⧈/+↘)1

Try it!

Uiua, 21 characters

⊢⊚⇌⊂1≡(≍/+:°⊂⇌◫)+1⊃⍏¤

Try it here! This Generates the Range from 1 to len with the "rise is range len for monotonically increasing lists" trick taken from the APL solution. It also takes inspiration from seeing that match ≍ even exists in the competition.

Dyalog APL, 15 13 bytes

-2 thanks to @FrownyFrog. (Since the input is non-decreasing, can be used instead of ⍳∘≢ to save 2 bytes.)

⊃∘⍸⍋(⊃↓⍷+/)¨⊂

Try it online!

Taking the sequence 1 1 2 3 5 as an example:

   ⍋(     )¨⊂  For each n from 1 to the length of the sequence,  1           2        ...
      ↓        is the sequence with the first n terms removed    1 2 3 5     2 3 5    ...
       ⍷       a subsequence of
        +/     the sums of each n-sized window in the sequence   1 1 2 3 5   2 3 5 8  ...
     ⊃         at the first position?                            no          yes      ...
⊃∘⍸            What is the first index where this is true?       2

Japt, 18 16 bytes

@ãX mx ¯J eUtX}a

Try it

Port of @lyxal's Vyxal answer.

Explanation:

@             }a  # find the first positive integer X where:
 ãX               #   all overlapped sections of length X
    mx            #   sum each
       ¯J         #   remove the last item
          e       #   is this list equal to
           UtX    #   the last X elements of the input list?

Pyth, 11 bytes

fqsM.:PQT>Q

Try it online!

Explanation

fqsM.:PQT>QT    # implicitly add T
                # implicitly assign Q = eval(input())
f               # return the first integer which satisfies lambda T
         >QT    # all but the first T elements of Q
 q              # is equal to
  sM            # map to their sums
    .:  T       # all sublists of length T of
      PQ        # all but the last element of Q

C (gcc), 123 bytes

The function takes an array of ints for a and its length for z.

B(a,z,M,b,v,t,L)int*a;{int*c,*p;for(M=b=z;--b;M=v?M:b)for(c=a+z,v=0;c-b-a;v|=t)for(t=*--c,p=c-1,L=b;L--;)t-=*p--;return M;}

Try it online!

Nibbles, 12.5 bytes

/|,~==<*~$.`'.`,$>$_+$>@_

Attempt This Online! / All testcases

/|,~==<*~$.`'.`,$>$_+$>@_
/|,~                      Find first number n such that
    ==                     equals
      <*~                   take all except the last 
         $                   n items of
          .                  for each row of
           `'                 transpose
             .                 for each i in
              `,                range from 0 to (excluding)
                $                n
                 >              drop the first
                  $              i items of
                   _              input
                    +         sum of
                     $         the row
                      >     drop the first
                       @     n items of
                        _     input

Vyxal, 14 12 10 bytes

?lṠṪ?nȯ⁼)ṅ

Try it Online!

Man this new "lambda to newline" thing is cool.

-2 thanks to @emanresuA

Explained

?lṠṪ?nȯ⁼)ṅ
        )ṅ   # Get the first positive integer n where:
  Ṡ          #   the sums of all
?l           #   overlapping windows of the input of length n
   Ṫ         #   with the tail removed
       ⁼     #   exactly equals
    ?nȯ      #   input[n:]

Raku, 53 bytes

{first {none .rotor($^n+1=>-$n).map:{[R-] $_}},1..$_}

Try it online!

Julia 1.0, 56 bytes

\(L,l=[0L])=sum(l)!=L&&1+L[2:end]\(l=[l;[L]];pop!.(l);l)

Try it online!

recursive function. At step n, l stores the n first sub-lists of length length(L)-n and L is the last one. We iterate until sum(l)==L

Wolfram Language (Mathematica), 42 bytes

1//.a_/;MovingMap[Tr,#,a]!=2#~Drop~a:>a+1&

Try it online!

Uses the check from this answer to the challenge that inspired this one.

Ruby, 59 58 bytes

->l{1.step.find{|a|l.each_cons(a+1).all?{|*h,g|g==h.sum}}}

Try it online!

Let's check:

This exploits a couple of ruby-specific shortcuts to achieve the final result.

->l{1.step.find{|a|

This is easy: starting from 1, repeat until we find the right number.

l.each_cons(a+1).all?{|*h,g|

Take every possible subarray of length a+1 and check.

g==h.sum}}}

Is the last element the sum of all other elements?

So, what happens if no match is found?

After the last check, when a+1 is the length of the array, and each_cons returns the whole array, we try to get all subarray of length a+2 (length of the whole array plus 1), the list is empty, and that satisfies the all? check, so if no answer is found, the answer is the length of the array.