Skip to main content
edited tags
Link
Johannes Kuhn
  • 7.5k
  • 5
  • 32
  • 44
Post Closed as "exact duplicate" by Peter Taylor, grc, primo, ugoren, manatwork
Source Link

Count characters in lo..ol and print a phrase

Assuming 'lol' with a variavle number of 'o's. Print a the following phrase:

What does 1st, 2nd, 3rd, 4th ... 'o' stand for?

Examples:

lol    -> What does 1st 'o' stand for?
loooool -> What does 1st, 2nd, 3rd, 4th, 5th 'o' stand for?

So far I managed to write a 128 characters solution in Perl:

$l=(<>=~tr/o//);print"What does ";print$_,$_==1?'st':$_==2?'nd':$_==3?'rd':'th',$_<$l?', ':''for(1..$l);print " 'o' stand for?";

and a 123 characters solution in Haskell:

p 1="1st";p 2="2nd";p 3="3rd";p n=show n++"th";main=putStr$"What does "++(foldr(++)"'o' stand for?"[p i++", "|i<-[1..23]]);

How short can you write it?