Changelog:

Your Task

  1. Go to the custom code environment.

  2. Solve as many of the puzzles as you can during the lab time (or in a roughly equivalent amount of time outside of lab) using a restricted subset of C (described below). We expect everyone to complete the first two puzzles, and most to complete the first three. We expect very few students to attempt all six puzzles within the lab time.

    (For the lab, you do not need to complete all the puzzles; we intend to give full credit as long as your submissions to the coding environment are consistent with spending an appropriate amount of effort on the puzzles.)

  3. These puzzles should help you understand the following homework, which, unlike the lab, must be completed individually and its entirety.

The C Subset

  1. You are restricted to a subset of C

    • Constants cannot exceed a single byte (between 0 and 255, or 0x00 and 0xff)
    • You cannot have any control constructs (no if, for, etc)
    • You can only use int-type values. You can use temporary variables and multiple statements, and we encourage you to do this.
    • All temporary variables must be initialized on declaration (e.g. int temporary = 0;)
    • All >> operators are arithmetic shifts
    • Each puzzle has a limited set of operators you are allowed to use
    • Each puzzle has a limit on the number of operators you are allowed to use. Assignments to variables do not count towards this limit.
  2. Solutions violating any of the above rules except the number of operators will result in 0 points. A partial score is awarded if you have the correct functionality following all of the rules except the operator count.

Hints

Testing outside the Coding environment

Specific advice for the puzzles

thirdBits

bang

isEqual

bitMask

isLessOrEqual

bitCount