blob: 060e5c83c8c483e65e75b61d83cd1eb495c2f94b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#! /bin/sed -nf
# $OpenBSD: sierpinski.sed,v 1.1 2008/10/10 14:33:34 millert Exp $
# From http://sed.sourceforge.net/grabbag/scripts
# Public Domain
# Sierpinski triangle in 10 commands + 2 labels.
# Start with a line like this
# _______________________________X_____________________________
# Put an equal number of underscores on both sides.
s/^\(_*\).*/\1X\1/p
# Construct the last three lines of the triangle
:start
/^X/!s/_X_/X_X/gp
/^X/!s/_X_X_/X___X/gp
/^X/!s/_X___X_/X_X_X_X/gp
/^X/ d
# Now replace the consecutive X's with an X and many colons
# X_X_X_X --->
# X::::::
:loop
s/\(X:*\)_X/\1::/g
tloop
# And now create two new "seeds", one to the left and one to the right
# _X::::::_ --->
# X:::::::X --->
# X_______X
s/_X\(::*\)_/X:\1X/g
s/:/_/gp
bstart
|