とある覆面算

twitter で見かけた覆面算
※元のツイートが見つけられない orz

```
□□÷□=□□÷□=□×□=□□

各□には 0 から 9 の数字が入る。
十の位には 0 は入らない。
```

虫食い算の見かけだが、実質的には覆面算。

[SEND MORE MONEY](https://qiita.com/KAZAMAI_NaruTo/items/27a0af62cf239cb76ff0)
を流用した。

SQLite3 の SQL

```
WITH X(n) AS (
        SELECT 0
        UNION ALL SELECT n + 1 FROM X WHERE n < 9)
SELECT
    CAST(A.n * 10 + B.n AS TEXT)
        || '÷'
        ||  CAST(C.n AS TEXT)
        || '='
        || CAST(D.n * 10 + E.n AS TEXT)
        || '÷'
        || CAST(F.n AS TEXT)
        || '='
        || CAST(G.n AS TEXT)
        || '×'
        || CAST(H.n AS TEXT)
        || '='
        || CAST(I.n * 10 + J.n AS TEXT)
    AS "□□÷□=□□÷□=□×□=□□"
FROM
    X AS A
    , X AS B
    , X AS C
    , X AS D
    , X AS E
    , X AS F
    , X AS G
    , X AS H
    , X AS I
    , X AS J    
WHERE
    (A.n * 10 + B.n)  =  G.n * H.n * C.n
    AND (D.n * 10 + E.n) = G.n * H.n * F.n
    AND G.n * H.n = I.n * 10 + J.n
    AND A.n > 0
    AND C.n > 0
    AND D.n > 0
    AND F.n > 0
    AND I.n > 0
    AND G.n > 0
    AND H.n > 0
    --AND A.n < D.n
    --AND G.n < H.n
    AND A.n <> B.n
    AND A.n <> C.n
    AND A.n <> D.n
    AND A.n <> E.n
    AND A.n <> F.n
    AND A.n <> G.n
    AND A.n <> H.n
    AND A.n <> I.n
    AND A.n <> J.n
    AND B.n <> C.n
    AND B.n <> D.n
    AND B.n <> E.n
    AND B.n <> F.n
    AND B.n <> G.n
    AND B.n <> H.n
    AND B.n <> I.n
    AND B.n <> J.n
    AND C.n <> D.n
    AND C.n <> E.n
    AND C.n <> F.n
    AND C.n <> G.n
    AND C.n <> H.n
    AND C.n <> I.n
    AND C.n <> J.n
    AND D.n <> E.n
    AND D.n <> F.n
    AND D.n <> G.n
    AND D.n <> H.n
    AND D.n <> I.n
    AND D.n <> J.n
    AND E.n <> F.n
    AND E.n <> G.n
    AND E.n <> H.n
    AND E.n <> I.n
    AND E.n <> J.n
    AND F.n <> G.n
    AND F.n <> H.n
    AND F.n <> I.n
    AND F.n <> J.n
    AND G.n <> H.n
    AND G.n <> I.n
    AND G.n <> J.n
    AND H.n <> I.n
    AND H.n <> J.n
    AND I.n <> J.n
;
```

Python3 で Wrap すると

```order_zero_to_nine.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sqlite3


def main():
    try:
        conn = sqlite3.connect(':memory:')
        strSQL = '''
WITH X(n) AS (
        SELECT 0
        UNION ALL SELECT n + 1 FROM X WHERE n < 9)
SELECT
    CAST(A.n * 10 + B.n AS TEXT)
        || '÷'
        ||  CAST(C.n AS TEXT)
        || '='
        || CAST(D.n * 10 + E.n AS TEXT)
        || '÷'
        || CAST(F.n AS TEXT)
        || '='
        || CAST(G.n AS TEXT)
        || '×'
        || CAST(H.n AS TEXT)
        || '='
        || CAST(I.n * 10 + J.n AS TEXT)
    AS "□□÷□=□□÷□=□×□=□□"
FROM
    X AS A
    , X AS B
    , X AS C
    , X AS D
    , X AS E
    , X AS F
    , X AS G
    , X AS H
    , X AS I
    , X AS J    
WHERE
    (A.n * 10 + B.n)  =  G.n * H.n * C.n
    AND (D.n * 10 + E.n) = G.n * H.n * F.n
    AND G.n * H.n = I.n * 10 + J.n
    AND A.n > 0
    AND C.n > 0
    AND D.n > 0
    AND F.n > 0
    AND I.n > 0
    AND G.n > 0
    AND H.n > 0
    --AND A.n < D.n
    --AND G.n < H.n
    AND A.n <> B.n
    AND A.n <> C.n
    AND A.n <> D.n
    AND A.n <> E.n
    AND A.n <> F.n
    AND A.n <> G.n
    AND A.n <> H.n
    AND A.n <> I.n
    AND A.n <> J.n
    AND B.n <> C.n
    AND B.n <> D.n
    AND B.n <> E.n
    AND B.n <> F.n
    AND B.n <> G.n
    AND B.n <> H.n
    AND B.n <> I.n
    AND B.n <> J.n
    AND C.n <> D.n
    AND C.n <> E.n
    AND C.n <> F.n
    AND C.n <> G.n
    AND C.n <> H.n
    AND C.n <> I.n
    AND C.n <> J.n
    AND D.n <> E.n
    AND D.n <> F.n
    AND D.n <> G.n
    AND D.n <> H.n
    AND D.n <> I.n
    AND D.n <> J.n
    AND E.n <> F.n
    AND E.n <> G.n
    AND E.n <> H.n
    AND E.n <> I.n
    AND E.n <> J.n
    AND F.n <> G.n
    AND F.n <> H.n
    AND F.n <> I.n
    AND F.n <> J.n
    AND G.n <> H.n
    AND G.n <> I.n
    AND G.n <> J.n
    AND H.n <> I.n
    AND H.n <> J.n
    AND I.n <> J.n
;
'''
        lines = conn.execute(strSQL).fetchall()
        for line in lines:
            print(line)
    finally:
        conn.close()


if __name__ == '__main__':
    main()
```

答えは秘密☆