Comment detail

ピラミッドを作る (Nested Flatten)
まだ文字列置換を使うのは出てないようなんで。 文字列を副作用で加工してった方が短くなると思うけど、とりあえずGaucheで。
1
2
3
4
(define (pyramid n)
  (define (p s n) (q (regexp-replace* s #/ \*/ "***" #/ $/ "*") n))
  (define (q s n) (when (> n 0) (print s) (p s (- n 1))))
  (p (make-string n) n))
同じアイディアをsedで。
ピラミッドの段数分のスペースからなる行を標準入力から与えます。

$ echo "     " | sed -n -f t.sed
    *
   ***
  *****
 *******
*********
1
2
3
4
s/ $/*/p
:x
s/ \*/***/p
tx

Index

Feed

Other

Link

Pathtraq

loading...