Die

Interview

Time limit2sMemory limit512 MB

Summary
Classify a 3x3 grid of o and : as one of the five standard die faces 1-5, up to rotation, or output unknown if it matches none.
Level

Medium5 of 10

Topics
Implementation, Simulation, Math, Brute force
Solved
No attempts yet

Problem

The boss of Binary Casino wants to have control over the games played in his casino. This matters most for dice games, since people sometimes try to cheat their way to victory by manipulating dice even after a throw has happened. So a camera is installed to monitor every single dice game. Dice recognition is not easy, though, and sometimes the camera produces a faulty image that makes recognition impossible.

Rasterized data is available from a camera that took pictures of several dice. Write a program that determines the value of the top side of the die in the picture, or detects that the picture is corrupted. The picture is transformed so that the sides incident to the captured top side are parallel to the x and y axes. It is unknown which of the four possible rotations of the top side is shown.

Input

The input specifies the top side of a captured die. It consists of three lines, each with three characters: “o” for a dent or “:” for a smooth surface.

Output

Output a single line with either the number represented by the captured top side of the die or “unknown” if the image is incorrect.

Examples3

  1. Example 1

    Input
    o:o
    :o:
    o:o
    
    Expected output
    5
    
  2. Example 2

    Input
    ::o
    :o:
    o::
    
    Expected output
    3
    
  3. Example 3

    Input
    ooo
    :::
    o:o
    
    Expected output
    unknown