- 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
- 91 lines of Turing from the credited upstream file ccc01s1.t.
- The implementation visibly relies on sequence storage.
- 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.
123 4567 8910 11 12131415procedure Points (var s : string, var p : int)16 var i : int17 i := 118 p := 019 loop20 exit when i > length (s) or s (i) = "C" or s (i) = "D" or s (i) =21 "H" or s (i) = "S"22 put s (i), " " ..23 if s (i) = "J" then24 p := p + 125 elsif s (i) = "Q" then26 p := p + 227 elsif s (i) = "K" then28 p := p + 329 elsif s (i) = "A" then30 p := p + 431 end if32 i := i + 133 end loop34 if i = 1 then35 p := p + 336 elsif i = 2 then37 p := p + 238 elsif i = 3 then39 p := p + 140 end if41 s := s (i .. *)42end Points43 44 454647 48var p, tp : int49var s : string50 51put "Enter cards:"52get s53 54tp := 055put ""56put "Cards Dealt Points"57 585960s := s (2 .. *)61put "Clubs " ..62Points (s, p)63Text.Locate (Text.WhatRow, 37)64put p : 265tp := tp + p66 67s := s (2 .. *)68put "Diamonds " ..69Points (s, p)70Text.Locate (Text.WhatRow, 37)71put p : 272tp := tp + p73 74s := s (2 .. *)75put "Hearts " ..76Points (s, p)77Text.Locate (Text.WhatRow, 37)78put p : 279tp := tp + p80 81s := s (2 .. *)82put "Spades " ..83Points (s, p)84Text.Locate (Text.WhatRow, 37)85put p : 286tp := tp + p87 88put " Total ", tp : 289 90 91