Problem solution · Turing

CCC 2007 J3 - Deal or No Deal Calculator

CCC 2007 J3 - Deal or No Deal Calculator: a Turing solution using direct simulation. Learn the idea, check the complexity, and read the full code, with credit to CCCSolutions.

Technique
Direct simulation
Source
CCCSolutions
Length
37 lines
Start with the idea.

Try the problem first. If you get stuck, read the approach below, then write your own solution. The full code is at the bottom.

Approach

Direct simulation

For CCC 2007 J3 - Deal or No Deal Calculator, the implementation follows the problem’s operations directly while maintaining only the state needed for the next decision.

  1. Translate each rule into one explicit state update.
  2. Maintain the invariant after every processed item.
  3. Return the accumulated state once all relevant input has been handled.

Code notes

  • 37 lines of Turing from the credited upstream file ccc07j3.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.

Source

Code and credit

This code comes from CCCSolutions by CCCSolutions contributors · Milliken Mills High School and is used under the MIT licence.

Full codeCCC 2007 J3 - Deal or No Deal Calculator · TuringTuring
Use this to learn the idea, then write your own version.
% CCC 2007 J3: Deal or No Deal Calculator%% simple 1D array processing% var a : array 1 .. 10 of intvar n, x, sum, offer : intvar avg : real a (1) := 100a (2) := 500a (3) := 1000a (4) := 5000a (5) := 10000a (6) := 25000a (7) := 50000a (8) := 100000a (9) := 500000a (10) := 1000000 get nfor i : 1 .. n    get x    a (x) := 0end forsum := 0for i : 1 .. 10    sum := sum + a (i)end foravg := sum / (10 - n)get offerif offer > avg then    put "deal"else    put "no deal"end if 

Did this explanation save you time? I'm a Grade 11 student building this free library to make difficult algorithms easier to understand.

Buy me a coffee ↗