# Boustrophedonise

Related but very different.

A boustrophedon is a text where every other line of writing is flipped or reversed, with reversed letters.

In this challenge, we will just reverse every other line, but leave the actual characters used intact. You may chose which lines to reverse, as long as it is every other one.

You may take the text in any suitable format as long as you support zero or more lines of printable ASCII, each with zero or more characters.

### Examples:

["Here are some lines","of text for you","to make a","boustrophedon"]:

["Here are some lines","uoy rof txet fo","to make a","nodehportsuob"] or ["senil emos era ereH","of text for you","a ekam ot","boustrophedon"]

["My boustrophedon"]:

["My boustrophedon"] or ["nodehportsuob yM"]

[]:
[]

["Some text","","More text","","","Last bit of text"]:

["Some text","","More text","","","txet fo tib tsaL"] or ["txet emoS","","txet eroM","","","Last bit of text"]

• Can't understand if return and input need to be text separated lines or it can be a file or a list of lines. – sergiol Dec 8 '17 at 12:30
• @sergiol Default PPCG I/O rules apply. – Adám Dec 8 '17 at 12:35
• Can my code behave inconsistently, i.e. sometimes start reversing from the first line and sometimes from the second? – Erik the Outgolfer Dec 8 '17 at 13:02
• @EriktheOutgolfer Yes, I asked about this earlier and the wording of "You may chose which lines to reverse, as long as it is every other one." was actually changed to what it is now to make it general enough for that behaviour. – Martin Ender Dec 8 '17 at 13:12
• @totallyhuman Yes, as per OP. – Adám Dec 9 '17 at 20:07

# Befunge-93, 48 bytes

 <~,#_|#*-+92:+1:
#^_@  >:#,_"#"40g!*40p91+,~:1+


Try It Online

Prints first line in reverse. Has a trailing newline.

Basically, it works by alternating between printing as it gets input and storing the input on the stack. When it reaches a newline or end of input, it prints out the stack, prints a newline, and modifies the character at 0,4 to be either a # or a no-op to change the mode. If it was the end of input, end the program

# MATL, 7 bytes

"@gNo?P


Try it online!

Takes a cell array of strings, and leaves the result on the stack.

### Explanation

"         % Loop over cell array
@g     %   Push new string, and 'unwrap' it from its cell array.
No?  %   Yes? Maybe so? (push stack size N, check if odd o, if so,...
P %     Flip


As the implicit print function in MATL does not display an empty line for an empty item on the stack, we explicitly end the if-statement and loop and print the stack in the TIO footer:

]]X#


But this is not part of the program, as per the IO default

• @LuisMendo Thanks (overlooked this comment for quite some time) – Sanchises Dec 21 '17 at 9:08

# C,  118  103  101 bytes

Thanks to @gastropner for saving 15 bytes and thanks to @ceilingcat for saving a byte!

i;f(l,n)char**l;{for(;n--;++l,n&1&&puts(""))for(i=strlen(*l);(n&1||!puts(*l))*i;putchar((*l)[--i]));}


Try it online!

# C, 147 bytes

i,j;f(char*s){char t[strlen(s)];for(i=0;;t[j++]=*s++)if(!*s|*s==10){t[j]=0;i=!i;for(i&&(j=!puts(t));j;j||puts(""))putchar(t[--j]);if(!*s++)break;}}


Try it online!

• 103 bytes if you go with clang or include string.h: f(l,n)char**l;{for(;n--;++l,puts(""))for(char*s=*l+strlen(*l);(n&1||printf(*l)*0)&s>*l;putchar(*--s));} – gastropner Dec 9 '17 at 9:45
• 100 bytes and GCC is happy again: i;f(l,n)char**l;{for(;n--;++l,puts(""))for(i=strlen(*l);(n&1||!printf(*l))&i>0;putchar((*l)[--i]));} – gastropner Dec 9 '17 at 10:04
• @gastropner Thanks! I don't think using printf to print *l works, though, because the string might for example contain %d. – Steadybox Dec 10 '17 at 15:00

# Japt, 4 bytes

ËzEÑ


Try it

ËzEÑ     :Implicit input of array
Ë        :Map each string at 0-based index E
z       :  Rotate 90 degrees clockwise
EÑ     :    E*2 times


## Pip, 16 bytes

Flg{Po?lRVlo!:o}


This loops over each line and reverses it based on the value of variable o(Predefined to 1), which is inverted each time the loop runs.

Try it online!

Fi,#gPi%2?RVg@ig@i


This one is based on the indices of each line instead.

# Pyth, 6 bytes

.e@_Bb


Try it here!

• .e ~ Enumerated map. k is the index, b is the current element.

• _Bb ~ Bifurcate b with its reverse.

• @ ~ Modular index in ^ with k.

proc B L {lmap e $L {expr [incr i]%2?"$e":"[string rev $e]"}}  Try it online! # Stacked, 18 bytes [{x i:x$revi*}map]


Try it online!

This simply reverses each string in the array according to its position.

[:#':>#,tr[...$rev*]map]  Same approach, but generates indices manually. # Python 2, 45 bytes lambda k:[r[::i%-2|1]for i,r in enumerate(k)]  Try it online! # Python 2, 46 bytes f=lambda k:k and[k[0][::len(k)%-2|1]]+f(k[1:])  Try it online! # Red, 68 bytes f: func[s][forall s[g: first s if odd? length? s[reverse g]print g]]  Try it online! # PHP, 54 bytes function(&$a){foreach($a as&$s)$i++&1&&$s=strrev($s);}  function works on argument (call by reference) # Röda, 33 bytes {enum|[_[::-1]]if[_%2=0]else[_1]}  Try it online! Explanation: { enum| /* Zip elements in the stream with [0,1,...] */ /* For each string _1 and index _2: */ [_[::-1]] /* Push _1 reversed */\ if[_%2=0] /* if the index is even */ else[_1] /* else push _1 */ }  # SNOBOL4 (CSNOBOL4), 89 bytes R X =X + 1 N =INPUT :F(END) OUTPUT =EQ(REMDR(X,2)) N :S(R) OUTPUT =REVERSE(N) :(R) END  Try it online! R X =X + 1 ;*Increment X N =INPUT :F(END) ;*Read in input; when it's EOF, goto END OUTPUT =EQ(REMDR(X,2)) N :S(R) ;*if mod(X,2)==0, output N and goto R OUTPUT =REVERSE(N) :(R) ;*otherwise output reverse(n) and goto R END  # JavaScript (ES6), Firefox, 42 bytes, optimized from Arnauld's a=>a.map(s=>[...s].sort(_=>a,a=!a).join)  # Clean, 59 bytes import StdEnv @t=[if(n rem 2<1)s(reverse s)\\s<-t&n<-[0..]]  Try it online! # Julia 0.6, 34 bytes ~x=x[2:2:end]=reverse.(x[2:2:end])  Try it online! Function modifying the input in place. # Java 8, 53 bytes a->{for(int i=1;i<a.length;i+=2)a[i]=a[i].reverse();}  Reverses every odd 0-indexed item. Input as an array of StringBuffers. Modifies the input-array instead of returning a new one to save bytes. Try it online. Explanation: a->{ // Method with StringBuffer-array parameter and no return-type for(int i=1;i<a.length; // Loop i in the range [1, input_length) i+=2) // And increase i by 2 after every iteration a[i]=a[i].reverse();} // Reverse the StringBuffer at index i  # Zsh+coreutils, 31 bytes for s;((i^=1))&&<<<$s||rev<<<$s  Try it online! Repeated xoring will switch i between 0 and 1, so we alternate our output. Because the ternary chains our commands together, surrounding { } are unnecessary. ## Zsh+coreutils, 23 bytes (almost correct) for a b;<<<$a&&rev<<<\$b


Try it online!

for sets b to the empty string if there are no more arguments. This unfortunately means that for an odd number of inputs, an extra empty line will be printed at the end.

# C#, 64 54 + 18 bytes

Try It Online!

a=>a.Select((x,i)=>i%2<1?x:string.Concat(x.Reverse())).ToArray()


Saved 10 bytes by returning IEnumerable

# Jelly, 3 bytes

UÐe


Try it online!

(or UÐo, reversing the other lines.)

U      (Vectorized) reverse
Ðe    the even numbered lines.


Essentially Mr. Xcoder's 5-byter, but with what I assume is a newer addition to the language.

# Brachylog, 4 bytes

i↔ⁱ⁾


Try it online!

Doesn't feel entirely honest to call this generator a 4-byter considering it costs 3 more bytes to actually use it.

i       Take an element from the input paired with its 0-index,
↔ ⁾    and reverse the element
ⁱ     repeatedly
⁾    a number of times equal to the index.
`