Sometimes, when I'm really bored I like to take the sum of an array of non-negative integers. I only take the sum of arrays of lengths that are powers of two. Unfortunately I often make mistakes. Fortunately I keep track of my work as I go along in the following way:
I add pairs of adjacent numbers until there's only one left. For example:
6 + 18 + 9 + 6 + 6 + 3 + 8 + 10
= 24 + 15 + 9 + 18
= 39 + 27
= 66
You're job is to determine if I've made a mistake somewhere. You may either get input passed to your function or read from standard in. Output can be printed or returned.
Input: An array/list/etc. of non-negative integers, and possibly also the length of that array if your language requires it. That array will be all the numbers read left to right then top to bottom. For example the array above would become:
[[6, 18, 9, 6, 6, 3, 8, 10], [24, 15, 9, 18], [39, 27], [66]]
or
[6, 18, 9, 6, 6, 3, 8, 10, 24, 15, 9, 18, 39, 27, 66]
if you prefer.
Output: a single boolean representing whether or not a mistake was made. The boolean can be represented using any mapping provided that all inputs where a mistake is made return/print an identical result and all input which contain no mistakes return/print an identical result. This should go without saying, but those two outputs cannot be the same.
Some Examples of Correct Summations:
6
5+6
=11
3 + 2 + 4 + 5
= 5 + 9
= 14
[0, 1, 2, 3, 1, 5, 6]
[[1, 2, 4, 8], [3, 12], [15]]
Some Examples of Incorrect Summation:
5+4
=8
4 + 4 + 4 + 4
= 9 + 7
= 16
[[1, 2, 3, 4], [7, 3], [10]]
[3, 4, 5, 6, 7, 8, 9]
Keep in mind that I can make mistakes and still get the right answer. If I do make a mistake it'll never result in an extra number or a missing number in the final array, only a wrong number.
Standard loopholes are forbidden. Shortest answer in each language is a winner. The older answer will win in the case of a tie. I retain the right to decide what the "same language" is, but I'll say upfront a point can't be earned in both Python 2, and Python 3.
[0,1,2,3,1,5,6]
is invalid because "Input: An array/list/etc. of positive integers". \$\endgroup\$