オセロ必勝法 Part3
(defun Othello () (setq table nil) (setq sq 8) (setq r nil) (defun initable () (defun initableat () (cond ((not table) (setq table '((0 0)))) ((= (caar table) (1- sq)) (setq table (push `(0 ,(1+ (cadr (car table)))) table))) (t (setq table (push `(,(1+ (caar table)) ,(cadr (car table))) table))))) (defun nest (f n) (if (zerop n) nil (progn (funcall f) (nest f (1- n))))) (nest 'initableat (* sq sq)) (setq table (reverse table)) (setq table (mapcar (lambda (x) (list x 0)) table))) (defun setdisk (x y disk) (setq table (mapcar (lambda (z) (cond ((and (eq (caar z) x) (eq (cadr (car z)) y)) (list (list x y) disk)) (t z))) table))) (defun subsetdisk (x y disk) (setq subtable (mapcar (lambda (z) (cond ((and (eq (caar z) x) (eq (cadr (car z)) y)) (list (list x y) disk)) (t z))) subtable))) (defun begintable () (initable) (setdisk 3 3 nil) (setdisk 3 4 t) (setdisk 4 3 t) (setdisk 4 4 nil) (display)) (defun neighbor (x) (cond ((= x 0) '(-1 -1)) ((= x 1) '(0 -1)) ((= x 2) '(1 -1)) ((= x 3) '(-1 0)) ((= x 4) '(1 0)) ((= x 5) '(-1 1)) ((= x 6) '(0 1)) ((= x 7) '(1 1)))) (defun getdisk (x y) (cadr (elt table (+ (* sq y) x)))) (defun turnover (x y color) (let ((dir nil) (flag nil) (i 0) (subtable table) (nei 8) (sq 8)) (if (not (checkturnover x y color)) '(cant put here) (progn (setdisk x y color) (defun turnoverat (x y color dir flag) (let ((neix (+ x (car (neighbor dir)))) (neiy (+ y (cadr (neighbor dir))))) (if (or (> 0 (+ (* sq neiy) neix)) (<= (* sq sq) (+ (* sq neiy) neix)) (eq (getdisk neix neiy) 0)) (setq subtable table) (if (not flag) (if (eq (getdisk neix neiy) (not color)) (progn (subsetdisk neix neiy color) (turnoverat neix neiy color dir t))) (cond ((eq (getdisk neix neiy) 0) (setq subtable table)) ((eq (getdisk neix neiy) (not color)) (progn (subsetdisk neix neiy color) (turnoverat neix neiy color dir t))) ((eq (getdisk neix neiy) color) (setq table subtable))))))) (while (< i nei) (turnoverat x y color i flag) (setq i (1+ i))) (display))))) (defun checkturnover (x y color) (let ((dir nil) (flag nil) (i 0) (subtable table) (nei 8) (sq 8) (checkflag nil)) (defun checkturnoverat (x y color dir flag) (let ((neix (+ x (car (neighbor dir)))) (neiy (+ y (cadr (neighbor dir))))) (if (or (> 0 (+ (* sq neiy) neix)) (<= (* sq sq) (+ (* sq neiy) neix)) (eq (getdisk neix neiy) 0)) nil (if (not flag) (if (eq (getdisk neix neiy) (not color)) (checkturnoverat neix neiy color dir t)) (cond ((eq (getdisk neix neiy) 0)) ((eq (getdisk neix neiy) (not color)) (checkturnoverat neix neiy color dir t)) ((eq (getdisk neix neiy) color) (setq checkflag t))))))) (while (< i nei) (checkturnoverat x y color i flag) (setq i (1+ i))) checkflag)) (defun displaycolor () (mapcar (lambda (x) (cond ((eq (cadr x) 0) 0) ((eq (cadr x) nil) '●) ((eq (cadr x) t) '○) (t '.))) table)) (defun cutoff (table i j) (cond ((eq i nil) (progn (setq i 0) (setq j 0) (setq p nil) (setq q nil) (cutoff table i j))) ((< i sq) (progn (push (car table) p) (cutoff (cdr table) (1+ i) j))) ((< j sq) (progn (push (reverse p) q) (setq i 0) (setq p nil) (cutoff table i (1+ j)))) (t (reverse q)))) (defun displaynewline (table) (if (eq table nil) nil (progn (setq r (concat r (format "%s" (car table)) (string ?\n))) (displaynewline (cdr table)))) r) (defun display () (setq r (string ?\n)) (displaynewline (cutoff (displaycolor) nil nil))))
石をひっくり返す関数と石を置けるかどうかチェックする関数と、
石を表示する関数を作りました。
表示例
(Othello) display (begintable) " (0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0) (0 0 0 ● ○ 0 0 0) (0 0 0 ○ ● 0 0 0) (0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0) " (turnover 3 2 t) " (0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0) (0 0 0 ○ 0 0 0 0) (0 0 0 ○ ○ 0 0 0) (0 0 0 ○ ● 0 0 0) (0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0) " (turnover 2 2 nil) " (0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0) (0 0 ● ○ 0 0 0 0) (0 0 0 ● ○ 0 0 0) (0 0 0 ○ ● 0 0 0) (0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0) " (turnover 0 0 nil) (cant put here)
次で終わると思います。
遅れてゴメンネ(><)
素因数展開 1から100
1
2
3
4→22→211
5
6→23
7
8→222→2337→31941→33371313→...
9→33→311
10→25→55→511→773
11
12→223
13
14→27→333→3337→4771→13367
15→35→57→319→1129
16→2222→211101→3116397→31636373→...
17
18→233
19
20→225→3355→51161→114651→3312739→...
21→37
22→211
23
24→2223→331319
25→55→511→773
26→213→371→753→3251
27→333→3337→4771→13367
28→227
29
30→235→547
31
32→22222→241271
33→311
34→217→731→1743→3783→31397
35→57
36→2233→71129
37
38→219→373
39→313
40→2225→5589→3333323→77591153→...
41
42→237→379
43
44→2211→31167→333463→13113227→...
45→335→567→33337→173753→239727→3411949→...
46→223
47
48→22223→71313→3112161→313199401→...
49→77→711→3379→31109→132393→344131→1731653→71143523→...
50→255→3517
51→317
52→2213
53
54→2333
55→511→773
56→2227→17131→37463
57→319→1129
58→229
59
60→2235→35149
61
62→231→3711→31237
63→337
64→222222→237111337→...
65→513→33319→1113233→11101203→...
66→2311
67
68→2217→3739
69→323→1719→33191
70→257
71
72→22233→37411→1119179
73
74→237→379
75→355→571
76→2219→7317→333271
77→711→3379→31109→132393→344131→1731653→...
78→2313→33257→74751→324917→1013217→...
79
80→22225→557127→33103601→...
81→3333→311101→777907→13134603→...
82→241
83
84→2237
85→517→1147→3137
86→243→33333→341271→3375417
87→329→747→3383→17199→3337713→333123619→...
88→22211→719167
89
90→2335→5467→71171
91→713→2331→33737→113067→3317739→31105913→...
92→2223→331319
93→331
94→247→1319
95→519→3173→19167→36389
96→222223→613643→1932297→...
97
98→277
99→3311→71143
100→2255→51141→317047