M A N
+ W O M A N
C H I L D
チャレンジしてみたが、場合分けが多くて挫折。
こんなんやってられるかぁ・・・ってんで コンピュータにやらせることに。
さて何が手っとり早い? ・・・とりあえず、SQL がいいか。
create table NumList(num integer primary key)
で、ここに 0〜9 の値を入れる。
INSERT INTO NumList(num) VALUES(0) INSERT INTO NumList(num) VALUES(1) INSERT INTO NumList(num) VALUES(2) INSERT INTO NumList(num) VALUES(3) INSERT INTO NumList(num) VALUES(4) INSERT INTO NumList(num) VALUES(5) INSERT INTO NumList(num) VALUES(6) INSERT INTO NumList(num) VALUES(7) INSERT INTO NumList(num) VALUES(8) INSERT INTO NumList(num) VALUES(9)
CREATE TABLE CharList(c char(1) primary key) INSERT INTO CharList(c) VALUES('A') INSERT INTO CharList(c) VALUES('C') INSERT INTO CharList(c) VALUES('D') INSERT INTO CharList(c) VALUES('H') INSERT INTO CharList(c) VALUES('I') INSERT INTO CharList(c) VALUES('L') INSERT INTO CharList(c) VALUES('M') INSERT INTO CharList(c) VALUES('N') INSERT INTO CharList(c) VALUES('O') INSERT INTO CharList(c) VALUES('W')
みたいなのを並べればいい。 ここで文字リストを使ってNumList AS A,
としてコピペ。SELECT 'NumList AS ' & c & ',' AS [FROM] FROM CharList
最後のコンマは手で消した。 続いて 数式の条件。べたがき。FROM NumList AS A, NumList AS C, NumList AS D, NumList AS H, NumList AS I, NumList AS L, NumList AS M, NumList AS N, NumList AS O, NumList AS W
で、SELECT句。WHERE ((100 * M.num + 10 * A.num + N.num) + (10000 * W + 1000 * O + 100 * M.num + 10 * A.num + N.num) = (10000 * C + 1000 * H + 100 * I.num + 10 * L.num + D.num))
でもいいのだがいまいちセンスがないのでやはりこうする。SELECT A.NumList AS A, C.NumList AS C, D.NumList AS D, H.NumList AS H, I.NumList AS I, L.NumList AS L, M.NumList AS M, N.NumList AS N, O.NumList AS O, W.NumList AS W
全部あわせてSELECT (100 * M.num + 10 * A.num + N.num) AS MAN, '+' AS [PLUS], (10000 * W + 1000 * O + 100 * M.num + 10 * A.num + N.num) AS WOMAN, '=' AS [EQUAL], (10000 * C + 1000 * H + 100 * I.num + 10 * L.num + D.num) AS CHILD
SELECT (100 * M.num + 10 * A.num + N.num) AS MAN, '+' AS [PLUS], (10000 * W + 1000 * O + 100 * M.num + 10 * A.num + N.num) AS WOMAN, '=' AS [EQUAL], (10000 * C + 1000 * H + 100 * I.num + 10 * L.num + D.num) AS CHILD FROM NumList AS A, NumList AS C, NumList AS D, NumList AS H, NumList AS I, NumList AS L, NumList AS M, NumList AS N, NumList AS O, NumList AS W WHERE ((100 * M.num + 10 * A.num + N.num) + (10000 * W.num + 1000 * O.num + 100 * M.num + 10 * A.num + N.num) = (10000 * C.num + 1000 * H.num + 100 * I.num + 10 * L.num + D.num))
SELECT (100 * M.num + 10 * A.num + N.num) AS MAN, '+' AS [PLUS], (10000 * W.num + 1000 * O.num + 100 * M.num + 10 * A.num + N.num) AS WOMAN, '=' AS [EQUAL], (10000 * C.num + 1000 * H.num + 100 * I.num + 10 * L.num + D.num) AS CHILD FROM NumList AS A, NumList AS C, NumList AS D, NumList AS H, NumList AS I, NumList AS L, NumList AS M, NumList AS N, NumList AS O, NumList AS W WHERE ((100 * M.num + 10 * A.num + N.num) + (10000 * W.num + 1000 * O.num + 100 * M.num + 10 * A.num + N.num) = (10000 * C.num + 1000 * H.num + 100 * I.num + 10 * L.num + D.num)) AND (M.num>=1) AND (W.num >= 1) AND (C.num>=1)
とすればあっというまに次の条件式ができあがるSELECT 'AND (' & L.c & '.num <> ' & R.c & '.num)' FROM CharList AS L, CharList AS R WHERE L.c < R.c
これを加えてAND (O.num <> W.num) AND (M.num <> W.num) AND (A.num <> W.num) AND (N.num <> W.num) AND (C.num <> W.num) AND (H.num <> W.num) AND (I.num <> W.num) AND (L.num <> W.num) AND (D.num <> W.num) AND (M.num <> O.num) AND (A.num <> O.num) AND (N.num <> O.num) AND (C.num <> O.num) AND (H.num <> O.num) AND (I.num <> O.num) AND (L.num <> O.num) AND (D.num <> O.num) AND (A.num <> M.num) AND (C.num <> M.num) AND (H.num <> M.num) AND (I.num <> M.num) AND (L.num <> M.num) AND (D.num <> M.num) AND (M.num <> N.num) AND (A.num <> N.num) AND (C.num <> N.num) AND (H.num <> N.num) AND (I.num <> N.num) AND (L.num <> N.num) AND (D.num <> N.num) AND (A.num <> C.num) AND (A.num <> H.num) AND (C.num <> H.num) AND (D.num <> H.num) AND (A.num <> I.num) AND (C.num <> I.num) AND (H.num <> I.num) AND (D.num <> I.num) AND (A.num <> L.num) AND (C.num <> L.num) AND (H.num <> L.num) AND (I.num <> L.num) AND (D.num <> L.num) AND (A.num <> D.num) AND (C.num <> D.num)
SELECT (100 * M.num + 10 * A.num + N.num) AS MAN, '+' AS [PLUS], (10000 * W.num + 1000 * O.num + 100 * M.num + 10 * A.num + N.num) AS WOMAN, '=' AS [EQUAL], (10000 * C.num + 1000 * H.num + 100 * I.num + 10 * L.num + D.num) AS CHILD FROM NumList AS A, NumList AS C, NumList AS D, NumList AS H, NumList AS I, NumList AS L, NumList AS M, NumList AS N, NumList AS O, NumList AS W WHERE ((100 * M.num + 10 * A.num + N.num) + (10000 * W.num + 1000 * O.num + 100 * M.num + 10 * A.num + N.num) = (10000 * C.num + 1000 * H.num + 100 * I.num + 10 * L.num + D.num)) AND (M.num>=1) AND (W.num >= 1) AND (C.num>=1) AND (O.num <> W.num) AND (M.num <> W.num) AND (A.num <> W.num) AND (N.num <> W.num) AND (C.num <> W.num) AND (H.num <> W.num) AND (I.num <> W.num) AND (L.num <> W.num) AND (D.num <> W.num) AND (M.num <> O.num) AND (A.num <> O.num) AND (N.num <> O.num) AND (C.num <> O.num) AND (H.num <> O.num) AND (I.num <> O.num) AND (L.num <> O.num) AND (D.num <> O.num) AND (A.num <> M.num) AND (C.num <> M.num) AND (H.num <> M.num) AND (I.num <> M.num) AND (L.num <> M.num) AND (D.num <> M.num) AND (M.num <> N.num) AND (A.num <> N.num) AND (C.num <> N.num) AND (H.num <> N.num) AND (I.num <> N.num) AND (L.num <> N.num) AND (D.num <> N.num) AND (A.num <> C.num) AND (A.num <> H.num) AND (C.num <> H.num) AND (D.num <> H.num) AND (A.num <> I.num) AND (C.num <> I.num) AND (H.num <> I.num) AND (D.num <> I.num) AND (A.num <> L.num) AND (C.num <> L.num) AND (H.num <> L.num) AND (I.num <> L.num) AND (D.num <> L.num) AND (A.num <> D.num) AND (C.num <> D.num)
MAN | PLUS | WOMAN | EQUAL | CHILD |
781 | + | 39781 | = | 40562 |
856 | + | 39856 | = | 40712 |
586 | + | 39586 | = | 40172 |
M I K O
+ M I K O
N U R S E