Add tags

Add tags to the following comment

「何処まで行数を減らせるか」に反応してつい書いてしまったので投稿。ついでに一行 80 文字で。あんまり無理はしてないつもりなんですが、可読性はこちらの方が低いかも……。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
(defun 8search (strings pattern)
  (loop with x = (length (elt strings 0)) and y = (length strings)
    with array = (make-array (list y x) :initial-contents strings)
    for (dx dy) in '((-1 -1) (-1 0) (-1 1) (0 -1) (0 1) (1 1) (1 0) (1 -1)) do
    (loop with m = (1- (length pattern))
      for a from (max 0 (- (* dx m))) below (min x (- x (* dx m))) do
      (loop for b from (max 0 (- (* dy m))) below (min y (- y (* dy m))) do
        (loop for i from a by dx and j from b by dy and c across pattern
          unless (char= c (aref array j i)) return nil finally
          (format t "(~D, ~D), ~[~;右~:;左~]~[~;下~:;上~]~%" a b dx dy))))))

(8search #("リオウウリウ" "ウオリウオリ" "オリリオリウ" "リリオオウオ")
         "ウオリ")

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...