Resource Locking - Circular Storage with Partial State Operations

1. Project Name

Resource Locking - Circular Storage with Partial State Operations

2. Project Description

This project involves creating a program than gains access to a resource. Resource access is controlled by a resource-locking software device that maintains a circular store of bits. The device unlocks the resource whenever all of the bits in the store have the same value.

In this document, the symbol F represents the value false. The symbol T represents the value true. Thus, a device unlocks a resource whenever all values in the store are set to T or all are set to F. The contents of a device are described by a pattern, shown as values within square brackets in this document; for example, [T T T F T F T]. The symbol – is used to represent an unknown or undisclosed valued. The symbol ? is used to represent a request to disclose a value.

3. Resource-Locking Software Device Specification

3.1 Device Commands

In the following examples, the number of bits stored by the device is 4 and the number of bits that may be observed/changed is 2.

3.1.1 Spin ≝ allBitsIdentical? ← SPIN

The device responds to a SPIN command by circularly-rotating the bits of the store, one position to the right, an unspecified number of times. Considering an initial state [T F F T], a single rotation would result in [T T F F]. Another rotation would yield [F T T F]. The actual number of rotation actions is unknowable. (For all intents, it is random.)

The SPIN command returns a boolean value of true if all bits of the store have the same value.

3.1.2 Peek ≝ result ← PEEK(request)

The device responds to a PEEK command by revealing partial state information. The PEEK command accepts a request pattern, indicating which of the bits are to be disclosed. For example, the request pattern, [– ? – ?], asks for the values of the bits at locations specified with a question mark.

The PEEK command returns a result pattern, indicating the values of the requested bits. For example, if the current state of the store was [F T T F], then the PEEK request pattern [– ? – ?] would result in the returned pattern [– T – F].

3.1.3 Poke ≝ POKE(pattern)

The device responds to a POKE command by potentially modifying the state of the device. After a PEEK command, the disclosed bits may be set by placing a T or F in the corresponding locations of the pattern parameter. For example, if the PEEK request parameter was [? – – ?], then a POKE with pattern [F – – T] would set the leftmost bit to F and the rightmost bit to T.

3.2 Algorithmic Processing Example

The following pseudocode expresses an algorithm that toggles one bit of the register.
SPIN
flippattern = PEEK([? ? - -])
if (flippattern[0] == F)
    then flippattern[0] = T
    else flippattern[0] = F
POKE(flippattern)

4. Unlocking the Resource

The resource is unlocked when all bits in the register are set to the same value; that is, either all are T or all are F.

5. Questions

5.1 Is there an algorithm to set all bits to 1 that uses only the SPIN, PEEK, and POKE commands?

5.1.1 If not:

  1. Why does no such algorithm exist?
  2. Is there a heuristic that can achieve success in most cases? Explain.

5.1.2 If so:

  1. Describe the approach such an algorithm would take.
  2. Describe an approach to an algorithm that requires the minimum number of commands to unlock the resource.

6. Device API

You are provided with the specified API for the Device class that implements the resource-locking software device.

7. Document the Development Process to Deliver an Unlocker of 4-Bit/2-Disclosure Devices

For this exploration, we will consider only a 4-bit/2-disclosure resource-locking device. That is, the circular store contains exactly 4 bits and excatly 2 of the bits may be observed/modified via the PEEK and POKE commands.

You are provided with the required API for the FourBitTwoDisclosureDeviceUnlocker class.

You must document your team's actual development activities and deliver source code for an implementation of the FourBitTwoDisclosureDeviceUnlocker class.