Jump to content

Odd word problem: Difference between revisions

No edit summary
Line 863:
}
}</lang>
=={{header|Perl 6}}==
A recursive solution, with the added feature that it treats each line separately.
<lang perl6>my &in = { $*IN.getc // last }
 
loop {
ew(in);
ow(in).print;
}
 
multi ew ($_ where /\w/) { .print; ew(in); }
multi ew ($_) { .print; next when "\n"; }
 
multi ow ($_ where /\w/) { my $r = ow(in); .print; $r; }
multi ow ($_) { $_; }</lang>
{{out}}
<pre>$ ./oddword
we,are;not,in,kansas;any,more.
we,era;not,ni,kansas;yna,more.
what,is,the;meaning,of:life.
what,si,the;gninaem,of:efil.</pre>
Note how the even/oddness is reset on the line boundary; if not, the second line might have started out in an odd state and reversed "what" instead of "is". The call to <tt>next</tt> prevents that by sending the loop back to its initial state.
 
=={{header|PicoLisp}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.