[alt.hackers] Puzzle

lwall@jato.Jpl.Nasa.Gov (Larry Wall) (02/03/90)

In article <13960@reed.UUCP> justin@reed.UUCP (the breakdown voltage) writes:
: Ok, hackers, let's see just how good you REALLY are:
: 
: What does the following shell/sed script do (hint: it was called rlrbw :-)?
: You could run it, but that'd be too easy.
: 
: #!/bin/sh
: string=''
: if test -n "$1"
: then
: 	value=$1
: 	while test $value -gt 1
: 	do
: 		value=`expr $value - 1`
: 		string=${string}0
: 	done
: fi
: sed 'x
:      s/.*/'$string'/
:      x
:      : begin
:      s/\(.*\)[ 	]\([^ 	][^ 	]*\)[ 	]*/\2 \1/
:      t fake
:      : fake
:      x
:      s/0/1/
:      x
:      t begin'

At a guess, I'd say it does something like:

#!/usr/bin/perl
while(<STDIN>){split;for(1..$ARGV[0]){unshift(@_,pop(@_));}print"@_\n";}

Larry Wall
lwall@jpl-devvax.jpl.nasa.gov