## Tribonacci sequence

**A** simplistic puzzle from The Riddler when applying brute force:

A Tribonacci sequence is based on three entry integers a ≤ b ≤ c, and subsequent terms are the sum of the previous three. Among Tribonacci sequences containing 2023, which one achieves the smallest fourth term, a+b+c ?

The R code

tri<-function(a,b,e){ while(F<2023){ F=a+b+e;a=b;b=e;e=F} return(F<2024)} sol=NULL;m=674 for(a in 1:m) for(b in a:m) for(e in b:m) if(tri(a,b,e)){ sol=rbind(sol,c(a,b,e))}

leads to (1,1,6) as the solution… Incidentally, this short exercise led me to finally look for a fix to entering vectors as arguments of functions requesting lists:

do.call("tri",as.list(sol[2023,]))

January 3, 2023 at 1:19 pm

Note that if you remove the constraint, you can get the solution (4, 1, 1), which coincides with your (1, 1, 6) solution at the next step.

You can also push further back, and end up with negative integers (which don’t seem disallowed!). For example, starting with (-23, 3, 14) gives you -6 as the 4th value. You can get an arbitrarily low negative integer: (-90, -50, 91) gives -49, and eventually get to (1, 1, 6).

January 4, 2023 at 2:25 pm

Thanks, I omitted the positivity constraint…!

January 3, 2023 at 10:34 am

I suppose the entry (-2023,0,2023) also counts since the problem does not seem to ask for positive integer numbers.