Post History
posix SH + GNU sed, 43 bytes seq $1|tac|sed -zE 's/(\n.+)(\n.+)/\2\1/mg' seq $1 # 1..the argument (inclusive) |tac| # reverse sed # replace...
Answer
#5: Post edited
# posix SH, 50 bytes- ```
seq $1|tac|sed -zE 's/([^\n]+)([^\n]+)/\2\1/g'- ```
- ```bash
- seq $1 # 1..the argument (inclusive)
- |tac| # reverse
- sed # replace
- -z # null terminated. basically this means that \n is
- # treated as a normal character, needed because
- # seq and tr operate on lines
- E # extended regex so we can use () instead of \(\)
' do this replacement 's/([^]+)([^]+)/\2\1/gs/ / /g # replace all occurences of\n[^\n]+ # a newline followed by non-newlines( )(........) # twice/ # with\2\1 # swap their places- ```
- Old 52 bytes, outputting spaces:
- ```
- seq -s' ' $1 -1 1|sed -r 's/( [^ ]+)( [^ ]+)/\2\1/g'
```
- # posix SH + [GNU sed], 43 bytes
- ```
- seq $1|tac|sed -zE 's/(
- .+)(
- .+)/\2\1/mg'
- ```
- ```bash
- seq $1 # 1..the argument (inclusive)
- |tac| # reverse
- sed # replace
- -z # null terminated. basically this means that \n is
- # treated as a normal character, needed because
- # seq and tr operate on lines
- E # extended regex so we can use () instead of \(\)
- ' do this replacement '
- s/(\n.+)(\n.+)/\2\1/mg
- s/ / /mg # replace all occurences of
- \n.+ # a newline followed by non-newlines
- # the (GNU extension) m modifier makes
- # . not match a newline
- ( )(....) # twice
- / # with
- \2\1 # swap their places
- ```
- # posix SH, 50 bytes
- ```
- seq $1|tac|sed -zE 's/(
- [^
- ]+)(
- [^
- ]+)/\2\1/g'
- ```
- Old 52 bytes, outputting spaces:
- ```
- seq -s' ' $1 -1 1|sed -r 's/( [^ ]+)( [^ ]+)/\2\1/g'
- ```
- [GNU sed]: https://www.gnu.org/software/sed/manual/sed.html#The-_0022s_0022-Command "using the 'm' regex modifier"
#4: Post edited
# bash, 50 bytes- ```
seq $1|tac|sed -zr 's/([^]+)([^]+)/\2\1/g'- ```
- Old 52 bytes, outputting spaces:
- ```
- seq -s' ' $1 -1 1|sed -r 's/( [^ ]+)( [^ ]+)/\2\1/g'
- ```
- # posix SH, 50 bytes
- ```
- seq $1|tac|sed -zE 's/(
- [^
- ]+)(
- [^
- ]+)/\2\1/g'
- ```
- ```bash
- seq $1 # 1..the argument (inclusive)
- |tac| # reverse
- sed # replace
- -z # null terminated. basically this means that \n is
- # treated as a normal character, needed because
- # seq and tr operate on lines
- E # extended regex so we can use () instead of \(\)
- ' do this replacement '
- s/(\n[^\n]+)(\n[^\n]+)/\2\1/g
- s/ / /g # replace all occurences of
- \n[^\n]+ # a newline followed by non-newlines
- ( )(........) # twice
- / # with
- \2\1 # swap their places
- ```
- Old 52 bytes, outputting spaces:
- ```
- seq -s' ' $1 -1 1|sed -r 's/( [^ ]+)( [^ ]+)/\2\1/g'
- ```
#3: Post edited
# bash, 51 bytes- ```
seq $1 -1 1|sed -zr 's/([^]+)([^]+)/\2\1/g'- ```
Old, outputting spaces:- ```
- seq -s' ' $1 -1 1|sed -r 's/( [^ ]+)( [^ ]+)/\2\1/g'
- ```
- # bash, 50 bytes
- ```
- seq $1|tac|sed -zr 's/(
- [^
- ]+)(
- [^
- ]+)/\2\1/g'
- ```
- Old 52 bytes, outputting spaces:
- ```
- seq -s' ' $1 -1 1|sed -r 's/( [^ ]+)( [^ ]+)/\2\1/g'
- ```