**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,]))

### Like this:

Like Loading...