- Translate each rule into one explicit state update.
- Maintain the invariant after every processed item.
- Return the accumulated state once all relevant input has been handled.
Code notes
- 59 lines of Turing from the credited upstream file ccc10j2.t.
- The implementation keeps its working state in language-native values and containers.
- No explicit loop blocks detected.
Complexity
Count the number and nesting of passes over the input, then include the maintained containers in the memory estimate.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
12345678910 11var a, b, c, d, s : int12var nikkySteps, nikkyDistance : int13var byronSteps, byronDistance : int14var next, sgn : int15 16get a, b, c, d, s17 18nikkySteps := 019nikkyDistance := 020next := a21sgn := 122loop23 exit when nikkySteps + next >= s24 nikkySteps := nikkySteps + next25 nikkyDistance := nikkyDistance + sgn * next26 if sgn = 1 then27 next := b28 else29 next := a30 end if31 sgn := sgn * -132end loop33nikkyDistance := nikkyDistance + sgn * (s - nikkySteps)34 35byronSteps := 036byronDistance := 037next := c38sgn := 139loop40 exit when byronSteps + next >= s41 byronSteps := byronSteps + next42 byronDistance := byronDistance + sgn * next43 if sgn = 1 then44 next := d45 else46 next := c47 end if48 sgn := sgn * -149end loop50byronDistance := byronDistance + sgn * (s - byronSteps)51 52if nikkyDistance > byronDistance then53 put "Nikky"54elsif nikkyDistance < byronDistance then55 put "Byron"56else57 put "Tied"58end if59