Odd word problem

From Rosetta Code
Revision as of 17:19, 3 November 2011 by rosettacode>Ledrug (oddball task: blame Dijkstra)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Odd word problem is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Write a program that solves the odd word problem.

Description: You are promised an input stream consisting of English letters and punctuations. It is guaranteed that

  • the words (sequence consecutive letters) are delimited by on and only one punctuation; that
  • the words will be at least one letter long; and that
  • a full stop (.) appears after, and only after, the last word.

For example, what,is,the;meaning,of:life. is such a stream with six words. Your task is to reverse the letters in every other word while leaving punctuations intact, producing e.g. "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;
  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, coroutinnes, etc.

Test case: work on both the "life" example given above, and the text we,are;not,in,kansas;any,more.