Odd word problem: Difference between revisions
Content added Content deleted
(promote: it's been a long time since any concern was raised on talk page) |
(Added zkl) |
||
Line 1,558: | Line 1,558: | ||
what,si,the;gninaem,of:efil.Brian: |
what,si,the;gninaem,of:efil.Brian: |
||
we,era;not,ni,kansas;yna,more. |
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> |
</pre> |