user
Task

Write a program that solves the odd word problem with the restrictions given below.

Description

You are promised an input stream consisting of English letters and punctuations.

It is guaranteed that:

* the words (sequence of consecutive letters) are delimited by one and only one punctuation,
* the stream will begin with a word,
* the words will be at least one letter long,   and
* a full stop (a period, [**.**]) appears after, and only after, the last word.

Example

A stream with six words:

:   :   `what,is,the;meaning,of:life.`

The task is to reverse the letters in every other word while leaving punctuations intact, producing:

:   :   `what,si,the;gninaem,of:efil.`

while observing the following restrictions:

1. Only I/O allowed is reading or writing one character at a time, which means: no reading in a string, no peeking ahead, no pushing characters back into the stream, and no storing characters in a global variable for later use;
2. You **are not** to explicitly save characters in a collection data structure, such as arrays, strings, hash tables, etc, for later reversal;
3. You **are** allowed to use recursions, closures, continuations, threads, co-routines, etc., even if their use implies the storage of multiple characters.

Test cases

Work on both the   "life"   example given above, and also the text:

:   :   `we,are;not,in,kansas;any,more.`
assistant
(formerly Perl 6)
A recursive solution, with the added feature that it treats each line separately.

```
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/) { ow(in) x .print; }
multi ow ($_)            { $_; }

```

Output:

```
$ ./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.
```

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 next prevents that by sending the loop back to its initial state.

There is one clever trick here with the x operator; it evaluates both its arguments in order, but in this case only returns the left argument because the right one is always 1 (True). You can think of it as a reversed C-style comma operator.