No Duplicates!

Problem

Read 5 random one-digit numbers. Exactly one of the numbers appears twice. Find and print the duplicate number.

39. No duplicates!, Comet 64
39. No duplicates!, Comet 64

Solution

Reuse the array solution to the problem No Duplicates!.

str = oooooooooo;         // Array of 10 elements.
loop:                     // Start of "loop".
    int = input;          // Read a one-digit integer i.
    char = str[int];      // Character at index i of string.
    check char = x;       // Is character = x?
    jump if true: print;  // If so, go to "print".
    char = x;             // Otherwise, have not seen i yet.
    str[int] = char;      // Set character to x.
    jump to: loop;        // Go to "loop".
print:                    // The "print" branch.
    output = int;         // Print the duplicate integer.

results matching ""

    No results matching ""