Practice ยท 2 of 4
Invariant Leaves the Loop
CHALLENGE
Difficulty: advanced+25 XP
Implement long long hoisted(int base, size_t n) totaling base*2 + i for i in 0..n-1, computed with the invariant base*2 *outside* the loop (store it in a local first). Implement long long naive(int base, size_t n) recomputing base*2 inside the loop. Both return the same value โ the optimizer may hoist the naive one anyway; the discipline is yours to keep.
Press Submit to check your solution.
Back to lesson: Practice: Assembly Evidence Drills