# オフラインリアルタイムどう書く第四回の参考問題 解答(Arc)

More than 5 years have passed since last update.

ちょっと面白そうな勉強会 ( http://atnd.org/events/32979 ) を見つけたので、

realtime_doukaku4.arc
```(= x 5 n (- (* x x) 1))

(def get-tbl bans
(let o (map [rem nil `(,(if (< (mod _ x) (- x 1)) (+ _ 1)) ;right
,(if (< (/ _ x) (- x 1)) (+ _ x)) ; bottom
,(if (> (mod _ x) 0) (- _ 1)) ;left
,(if (>= (/ _ x) 1) (- _ x)))] ; about
(range 0 n))
(aif (car bans)
(each x it (= (o (x 0)) (rem (x 1) (o (x 0)))
(o (x 1)) (rem (x 0) (o (x 1)))))) o))

(def count (i h tbl)
(if (is i n) 1
(apply + (mappend [if (no (mem _ h)) `(,(count _ (cons i h) tbl))]
(tbl i)))))

(def solve (xs)
(let ban-syms (read (+ "(" xs ")"))
(let bans (map [map [- (coerce _ 'int) 97]
(coerce (coerce _ 'string) 'cons)] ban-syms)
(count 0 nil (get-tbl bans)))))

```

（回答を出してる中では最短に近いのではないか。自然に書いてこうなる。）

realtime_doukaku_4_result.arc
```(solve "") ;; -> 8512
(solve "af") ;; -> 4256
(solve "xy") ;; -> 4256
(solve "pq qr rs st di in ns sx") ;; -> 184
(solve "af pq qr rs st di in ns sx") ;; -> 92
(solve "bg ch di ij no st") ;; -> 185
(solve "bc af ch di no kp mr ns ot pu rs") ;; -> 16
(solve "ab af") ;; -> 0
(solve "ty xy") ;; -> 0
(solve "bg ch ej gh lm lq mr ot rs sx") ;; -> 11
(solve "ty ch hi mn kp mr rs sx") ;; -> 18
(solve "xy ch hi mn kp mr rs sx") ;; -> 32
(solve "ch hi mn kp mr rs sx") ;; -> 50
(solve "ab cd uv wx") ;; -> 621
(solve "gh mn st lq qr") ;; -> 685
(solve "fg gl lm mr rs") ;; -> 171
```

うまく動いている。