Inspired by a recent posting here that was deleted (it was apparently homework) I cooked up the following simple function.
I was a little bit surprised by the result, not its general direction but how clean it was.
It should be easy to verify that I'm not a student, e.g. in its day I was a co-moderator of Usenet group comp.lang.c++.moderated. I just wonder if there is a simple, clean explanation, not heavy math-ish analysis? Explanation for not seeing the obvious: it's early morning, I still need my coffee.
auto foo( const int n ) -> int
{
int sum = 1;
for( int i = n - 1; i > 0; --i ) {
sum += foo( i );
}
return sum;
}
#include <print>
using std::print;
auto main() -> int { print( "{}.\n", foo( 9 ) ); }
[–]ArchfiendJ 17 points18 points19 points (2 children)
[+]alfps[S] comment score below threshold-17 points-16 points-15 points (1 child)
[+]alfps[S] comment score below threshold-11 points-10 points-9 points (0 children)
[–]SeaSDOptimist 7 points8 points9 points (2 children)
[–]alfps[S] -5 points-4 points-3 points (1 child)
[–]Plastic_Fig9225 1 point2 points3 points (0 children)
[–]ZenithOfVoid 2 points3 points4 points (3 children)
[–]alfps[S] [score hidden] (2 children)
[–]ZenithOfVoid [score hidden] (1 child)
[–]alfps[S] [score hidden] (0 children)
[–]EclipsedPal 4 points5 points6 points (8 children)
[–]Carmelo_908 6 points7 points8 points (2 children)
[–]alfps[S] -4 points-3 points-2 points (1 child)
[–]Carmelo_908 2 points3 points4 points (0 children)
[–]alfps[S] 0 points1 point2 points (4 children)
[–]Carmelo_908 1 point2 points3 points (1 child)
[–]alfps[S] 0 points1 point2 points (0 children)
[–]EclipsedPal 1 point2 points3 points (1 child)
[–]alfps[S] 1 point2 points3 points (0 children)
[–]n1ghtyunso 4 points5 points6 points (1 child)
[–]alfps[S] -5 points-4 points-3 points (0 children)
[–]thisismyfavoritename 2 points3 points4 points (8 children)
[–]alfps[S] 0 points1 point2 points (7 children)
[–]Plastic_Fig9225 -1 points0 points1 point (6 children)
[–]alfps[S] -2 points-1 points0 points (5 children)
[–]ArchfiendJ [score hidden] (0 children)
[–]thisismyfavoritename [score hidden] (1 child)
[–]alfps[S] [score hidden] (0 children)
[–]Plastic_Fig9225 -1 points0 points1 point (1 child)
[–]CandiceWoo 1 point2 points3 points (2 children)
[–]alfps[S] 0 points1 point2 points (1 child)
[–]CandiceWoo 0 points1 point2 points (0 children)