kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

02_control.c (503B)


      1 /* Control flow: nested loops, break/continue, conditional accumulation.
      2  * Computes a Collatz-step total. Returns a value in [0,127]. */
      3 static int collatz_steps(unsigned n) {
      4   int s = 0;
      5   while (n != 1u) {
      6     if (n & 1u)
      7       n = 3u * n + 1u;
      8     else
      9       n = n / 2u;
     10     if (++s > 1000) break;
     11   }
     12   return s;
     13 }
     14 
     15 int bounce_main(void) {
     16   long total = 0;
     17   for (unsigned i = 1; i <= 50u; ++i) {
     18     if (i % 7u == 0u) continue;
     19     total += collatz_steps(i);
     20   }
     21   return (int)(total & 0x7f);
     22 }