| Bytes | Lang | Time | Link |
|---|---|---|---|
| 025 | ☾ | 250313T225837Z | Joao-3 |
| 021 | Uiua | 240622T010647Z | Joao-3 |
| 009 | Jelly | 241221T233121Z | Unrelate |
| 016 | Uiua | 240620T133207Z | noodle p |
| 021 | Uiua | 240620T211225Z | jan |
| 013 | Dyalog APL | 220228T053000Z | rabbitgr |
| 016 | Japt | 230329T104813Z | noodle p |
| 011 | Pyth | 230329T182243Z | CursorCo |
| 123 | C gcc | 230329T173349Z | evanstar |
| 125 | Nibbles | 230328T133646Z | xigoi |
| 010 | Vyxal | 220228T002454Z | lyxal |
| 053 | Raku | 221003T003503Z | Sean |
| 056 | Julia 1.0 | 220303T155519Z | MarcMush |
| 042 | Wolfram Language Mathematica | 220301T085418Z | att |
| 058 | Ruby | 220228T120846Z | G B |
☾, 25 chars
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
Jelly, 9 bytes
UµṡJ§Ḋ€oi
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
⍢+₁(...)1Starting with 1, increment until:¬≍there is no match between↘¯1dropping the last of⧈/+the sums of the n-wise windows of the input
↘and dropping the first n rows of the input
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.)
⊃∘⍸⍋(⊃↓⍷+/)¨⊂
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
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
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;}
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ȯ⁼)ṅ
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..$_}
first { ... }, 1 .. $_returns the first number from 1 up to the size of the input list for which the brace-delimited anonymous function returns a true result. Within that function,$^n/$nis the number being tested.$_continues to refer to the input parameter to the outer function..rotor($^n + 1 => -$n)produces a moving window of size$n + 1across the input list. For example, if the input list is1, 3, 4, 7, 11, 18and we're testing whether the list is 2-bonacci-like, the rotor method returns a list of the lists1, 3, 4,3, 4, 7,4, 7, 11, and7, 11, 18..map: { [R-] $_ }reduces each of those lists with the reversed subtraction operatorR-. (a R- bmeansb - a.) Because the regular subtraction operator-is left-associative, the reversed subtraction operator is right-associative, and so to continue the above example, it produces the numbers4 - 3 - 1,7 - 4 - 3,11 - 7 - 4, and18 - 11 - 7.- Finally,
nonereturns a truthy result if none of the reduced lists has a truthy value; that is, if all of them are zero.
Julia 1.0, 56 bytes
\(L,l=[0L])=sum(l)!=L&&1+L[2:end]\(l=[l;[L]];pop!.(l);l)
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&
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}}}
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.

