Jump to content

Odd word problem: Difference between revisions

Added zkl
(promote: it's been a long time since any concern was raised on talk page)
(Added zkl)
Line 1,558:
what,si,the;gninaem,of:efil.Brian:
we,era;not,ni,kansas;yna,more.
</pre>
 
=={{header|zkl}}==
{{trans|D}}
<lang zkl>var [const] delim=",:;/?!@#$%^&*()_+", stop=".";
fcn oddly(inStream){
inStream=inStream.walker(3); // character iterator: string, file, etc
doWord:=fcn(inStream,rev,f){ // print next word forewards or reverse
c:=inStream.next();
if(not rev) c.print();
if(not (c==stop or delim.holds(c)))
return(self.fcn(inStream,rev,'{ c.print(); f(); }));
if(rev){ f(); c.print(); }
return(c!=stop);
};
tf:=Utils.Helpers.cycle(False,True); // every other word printed backwords
while(doWord(inStream, tf.next(), Void)) {}
println();
}</lang>
Showing two different input streams:
<lang zkl>oddly("what,is,the;meaning,of:life.");
oddly(Data(0,String,"we,are;not,in,kansas;any,more."));</lang>
{{out}}
<pre>
what,si,the;gninaem,of:efil.
we,era;not,ni,kansas;yna,more.
</pre>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.