|
| <prev next> |
Re: Fibonacci Series Printer: msg#00080editors.sed.user
On Sun, 01 Jan 2006 00:18:20 +0800, hq00e wrote: > Happy New Year, Sedders! Dream works! I just make a dream and was told that I can shorten the script by changing these, > :lpm > s/m\([^m].*\)$/\1m/ > tlpm > :lpl > s/l\([^l].*\)$/\1l/ > tlpl > :lpk > s/k\([^k].*\)$/\1k/ > tlpk > :lpj > s/j\([^j].*\)$/\1j/ > tlpj > :lpi > s/i\([^i].*\)$/\1i/ > tlpi > :lph > s/h\([^h].*\)$/\1h/ > tlph > :lpg > s/g\([^g].*\)$/\1g/ > tlpg > :lpf > s/f\([^f].*\)$/\1f/ > tlpf > :lpe > s/e\([^e].*\)$/\1e/ > tlpe > :lpd > s/d\([^d].*\)$/\1d/ > tlpd > :lpc > s/c\([^c].*\)$/\1c/ > tlpc > :lpb > s/b\([^b].*\)$/\1b/ > tlpb > :lpa > s/a\([^a].*\)$/\1a/ > tlpa > to, s/\(\(.\)\2*\)/\1 /g :lpsort s/\(\([^ ]\)\2\{0,\}\)\( .*\)\2/\1\2\3/ tlpsort s/ //g Here is the new edition: ===== filename: fib.sed ===== start # Fibonacci Series Printer # To know more on how the numbers are represented by # letters here, you should read Greg Ubben's tutorials # on word counting and adding numbers which you can # find here: # http://sed.sourceforge.net/grabbag/tutorials/ # Initialize the series to "1,1" # gfedcbaa=1 gfedcbaaa=2 ... gfedccbaa=101 1{s/.*/ qponmlkjihgfedcbaa qponmlkjihgfedcbaa /;h;d} # get last two numbers from hold space g s/.* \(.*\) \(.*\) $/\1\2/ # and sort them so that we can do carry operation s/\(\(.\)\2*\)/\1 /g :lpsort s/\(\([^ ]\)\2\{0,\}\)\( .*\)\2/\1\2\3/ tlpsort s/ //g # do some adjustments # in analog add we have : # edcbaa + edcbaaa = edcbaaaa # 1 + 2 = 3 # but we get "eeddccbbaaaaa" after sorting # so adjustment is needed s/\(.\)\(\1\{1,19\}\)/\2/g # do carry operation # change "baaaaaaaaaaa" into "bba" :doCarry s/\(.\)\(\(.\)\3\{9\}\)\3/\1\1\3/ t doCarry # a loose check on overflow. /^\(.\)\1\{9\}/{g;s/$/ ++OVERFLOW++/; b2digi} # save to holdspace and add a SPACE at the end G s/\(.*\)\n\(.*\)/\2\1 / $!{h;d} g # translate analog numbers to digits :2digi s/\([a-z]\)\1\{9\}/9/g s/\([a-z]\)\1\{8\}/8/g s/\([a-z]\)\1\{7\}/7/g s/\([a-z]\)\1\{6\}/6/g s/\([a-z]\)\1\{5\}/5/g s/\([a-z]\)\1\{4\}/4/g s/\([a-z]\)\1\{3\}/3/g s/\([a-z]\)\1\1/2/g s/\([a-z]\)\1/1/g s/\([a-z]\)/0/g s/ 0*/ /g # q command is necessary for overflow check q ===== end However it runs much slower than the first script. -- Regard, hq00e ------------------------ Yahoo! Groups Sponsor --------------------~--> Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life. http://us.click.yahoo.com/KIlPFB/vlQLAA/TtwFAA/dkFolB/TM --------------------------------------------------------------------~-> -- Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/sed-users/ <*> To unsubscribe from this group, send an email to: sed-users-unsubscribe@xxxxxxxxxxxxxxx <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/ |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Fibonacci Series Printer: 00080, hq00e |
|---|---|
| Previous by Thread: | Fibonacci Series Printeri: 00080, hq00e |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |