Comment detail
文字列の八方向検索 (Nested Flatten)「何処まで行数を減らせるか」に反応してつい書いてしまったので投稿。ついでに一行 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 #("リオウウリウ" "ウオリウオリ" "オリリオリウ" "リリオオウオ")
"ウオリ")
|





あにす
#4645()
[
C#
]
Rating0/0=0.00
"リリリ"の様な同じ文字が連続した文字列を検索すると不具合が出たので修正。 ついでに、何処まで行数を減らせるかテスト。可読性は二の次。
see: 貧脚レーサーのサボり日記
Rating0/0=0.00-0+
1 reply [ reply ]