GrassでLLGolf Hole 8

会場近くの漫画喫茶から。
新幹線の中でGrassでLLGolf Hole 8 準備 - * *scrap*のコードをirieさん作のgrass.el用に移植。
大宮までの1時間で9割がた書けて、会場についてからデバッグして完成。

wwWWwwWwwvwwWWWwWWWwvwWWwWwvwwwWWWwwWwwWWWWwvwvwWWwwwvwwWWwWWWwvwWWWWwwvwwwwWWW
wWwwwwwWwwwwwwwwwwwwwwwwwWWWWWWWWWWWWWWWWwWWWWwwwwWwwwwwwwWWWWWWWWWWWWWWWWWWWWw
wwwwwwWWwvwwwwwWWWWWWWWWWWWWWWWwWWWWwWWWWWWWWWWWWWWwWWWWWWWwwwwWWwwwwwwwwwWWwwW
wwwwwwwwWwwwwwwwWWWwwwwwwWwwwwwwwwwwwwwwvwWWWWWWWWWWWWWWWwvwWWWWWWWwWWWWWWwWWwW
WwWWwwwwWwwWWWWWwWWWwWWWWWWWWWWWWWWWwWwwwwWWWWWWWWWWWWWWWwWwwWWwwWWWwWwwwwwwWww
wwWWWWWWWWwWwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwWWWWWWWWWWWwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwWWWWWWWWWWWWWWWWWWWWWWWWWWWwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwWWWwWWWwwWW
WWWWWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWWWWWWWWWwwwWwwWWWWWWWWWWWWWWWWWWWWWWWW
WWWWWwwwwWWwWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWwWwwwwwwww

grass-mode用lisp

;llgolf8
'(
  (abs W (x y)
   ((app x x)		;; x x
    (app 1 y)		;; x x y
    ))
  (abs X (f x)
   ((app W x)		;; W x
    (app f 1)		;; f (W x)
    ))
  (abs Y (f)
   ((app X f)		;; X f
    (app 1 1)		;; X f (X f)
    ))
  (abs inc (n f x)
   ((app n f)		;; n f
    (app 1 x)		;; n f x
    (app f 1)		;; f (n f x) => inc n
    ))
  (abs id (n)
   ())
  (abs idinc (dummy)
   ((app id inc)        ;; id inc
    ))
  (abs <2> (f x)
   ((app f x)		;; f x
    (app f 1)		;; f (f x) => 2
    ))
  (abs id2 (dummy)
   ((app id <2>)        ;; id 2
    ))
  (abs plant (lf cn f ci)
   ((app cn ci)         ;;eq?
    (app 1 lf)
    (app 1 w)
    (app out 1)
    (app 4 4)
    (app 1 f)
    (app succ ci)
    (app 2 1)
    ))
  (abs loop (c1 cn _plant f ci)
   ((app succ ci)  ;; ci+1
    (app _plant 1)
    (app Y 1)      ;; __plant
    (app cn ci)    ;; eq?
    (app 2 c1)     ;; __plant ci
    (app 2 2)      ;; eq? eq?
    (app 1 f)      ;; eq? eq? self
    (app 1 7)      ;; eq? eq? self ci+1
    (app 3 6)      ;; eq? eq? __plant
    (app 1 c1)     ;; eq? eq? __plant ci
    ))
  (abs input (dummy)
   ((app in dummy)
    ))
  (abs main (n)
   ((app idinc 1)  ;; inc
    (app id2 1)    ;; 2
    (app 2 1)      ;; inc 2 =>3
    (app 2 1)      ;; 2 3 => 9
    (app 2 4)      ;; 3 inc
    (app 1 2)      ;; 3 inc 9 => 12
    (app 5 1)      ;; 2 12 => 144
    (app 3 1)      ;; 3 inc 144 => 147
    (app idinc 1)
    (app 1 4)      ;; inc 12 => 13
    (app id2 1)    ;; 2
    (app 1 2)      ;; 2 13 => 169
    (app 2 2)      ;; 2 2 => 4
    (app 3 1)      ;; 2 4 => 16
    (app 1 6)      ;; 16 inc
    (app 1 4)      ;; 16 inc 169 => 185
    (app 8 1)      ;; inc 185 => 186
    (app 1 succ)   ;; 186 succ
    (app 11 succ)  ;; 147 succ
    (app id w)
    (app 3 1)      ;; 186 succ w => c1
    (app 3 2)      ;; 147 succ w => lf
    (app input 1)  ;; input
    (app loop 3)   ;; loop c1
    (app 1 2)      ;; loop c1 cn
    (app plant 4)  ;; plant lf
    (app 2 1)      ;; loop c1 cn _plant
    (app Y 1)      ;; Y (loop c1 cn _plant)
    (app 1 8)      ;; Y (loop c1 cn _plant) c1
    ))
  )

grass.el便利すぐる。

一応本家grass.rbでも確認

youz$ echo 8 | ruby grass.rb llg8.w
w
ww
www
wwww
wwwww
wwwwww
wwwwwww
wwwwwwww
wwwwwww
wwwwww
wwwww
wwww
www
ww
w

会場裏の公園でのデバッグを終えて会場に入ろうとしたら目の前にLarry Wallが。
一瞬、電車の待ち時間に読んでいたよつばとを進呈しようかと思ったが自重した。
ref. #0 Perlの父 Larry Wall:小飼弾のアルファギークに逢いたい♥|gihyo.jp … 技術評論社