13 coins


[tag:]

3回だけ天秤を用いて、13枚のコインの中から、1枚だけ重さの異なるコインを探す。
Detect the one who weighs heavier or lighter out of 13 coins, using scales only 3 times.

コインに1~Dの番号を付す。
Number each coin from 1 to D.

oooo oooo oooo o 1234 5678 9ABC D

judge:1234-5678
case = :
    doubt={9ABCD}
    T={12345678}
    judge:9AB-TTT
    case = :
        doubt={CD}
        judge:C-T
        case = :
            return D
        case > :
            return C,>
        case < :
            return C,<
    case > :
        doubt={9AB,>}
        judge:9-A
        case = :
            return B,>
        case > :
            return 9,>
        case < :
            return A,>
    case < :
        doubt={9AB,<}
        judge:9-A
        case = :
            return B,<
        case > :
            return A,<
        case < :
            return 9,<
case > :
    doubt={12345678}
    T={9ABCD}
    judge:125-34T
    case = :
        doubt={678,<}
        judge:6-7
        case = :
            return 8,<
        case > :
            return 7,<
        case < :
            return 6,<
    case > :
        doubt={12,>}
        judge:1-2
        case > :
            return 1,>
        case < :
            return 2,>
    case < :
        doubt={34,>},{5,<}
        judge:3-4
        case = :
            return 5,<
        case > :
            return 3,>
        case < :
            return 4,>
case < :
    doubt={12345678}
    T={9ABCD}
    judge:125-34T
    case = :
        doubt={678,>}
        judge:6-7
        case = :
            return 8,>
        case > :
            return 6,>
        case < :
            return 7,>
    case > :
        doubt={5,>},{3,4,<}
        judge:3-4
        case = :
            return 5,>
        case > :
            return 4,<
        case < :
            return 3,<
    case < :
        doubt={12,<}
        judge:1-2
        case > :
            return 2,<
        case < :
            return 1,<

書式 format:
    judge:___-___:ハイフンの両側を天秤にかける
            /Weigh the right side against the left side.
    case =><:judgeの結果によって場合分け
            /Branch according to the result of judgement.
    doubt:答えの候補の集合。不等号は本物より重いか軽いかを表す
            /Candidates for the answer.
            /Inequality sign means whether the answer is heavier or lighter.
    T:doubtの補集合。judgeの部分ではこの集合の任意の要素を表す
            /Complement of doubt.
            /In judge part, `T' means an arbitrary element of T.
    return:答えを返す。重軽の別がわかっている場合はその情報も
            /Return the answer.
            /If known, with whether it is heavier or lighter.