// this triple-nested for-loop (including sumOfSlice) cannot be the fastest way to do this...
funcfindMinMax(tint,s[]int)(int,int){
foro:=ranges{
forq:=ranges[o+1:]{
ift==sumOfSlice(s[o:o+1+q]){
winner:=s[o:o+1+q]
sort.Slice(winner,func(i,jint)bool{
returnwinner[i]<winner[j]
})
returnwinner[0],winner[len(winner)-1]
}
}
}
return0,0
}
funcsumOfSlice(s[]int)int{
sum:=0
for_,a:=ranges{
sum=sum+a
}
returnsum
}
// XMAS starts by transmitting a preamble of 25 numbers.
// After that, each number you receive should be the sum of any two of the 25 immediately previous numbers.
// The two numbers will have different values, and there might be more than one such pair.
// For example, suppose your preamble consists of the numbers 1 through 25 in a random order.
// To be valid, the next number must be the sum of two of those numbers:
// 26 would be a valid next number, as it could be 1 plus 25 (or many other pairs, like 2 and 24).
// 49 would be a valid next number, as it is the sum of 24 and 25.
// 100 would not be valid; no two of the previous 25 numbers sum to 100.
// 50 would also not be valid; although 25 appears in the previous 25 numbers, the two numbers in the pair must be different.
// The first step of attacking the weakness in the XMAS data is to find the first number in the list (after the preamble) which is not the sum of two of the 25 numbers before it.
// What is the first number that does not have this property?