Friday, December 11, 2009

The Hoppity Problem

Here's the first problem I'd like to post in the new Code Snippet series. Thanks goes to Facebook for providing this one!


Hoppity Hop!
Write a program that takes as input a single argument on the command line. This argument must be a file name, which contains a single positive integer. The program should read this file and obtain the integer within, and then output a sequence of strings based upon the number (details below).

Input specifications
The input file will contain a single positive integer (in base 10) expressed as a string using standard ASCII text (e.g. for example, the number "15" but without the double quotes). This number may or may not be padded on either side with white space. There will be no commas, periods, or any other non-numeric characters present within the number. The file may or may not terminate in a single new line character ("\n"). An example input file is below:


Output specifications
The program should iterate over all integers (inclusive) from 1 to the number expressed by the input file. For example, if the file contained the number 10, the submission should iterate over 1 through 10. At each integer value in this range, the program may possibly (based upon the following rules) output a single string terminating with a newline.

* For integers that are evenly divisible by three, output the exact string Hoppity, followed by a newline.
* For integers that are evenly divisible by five, output the exact string Hophop, followed by a newline.
* For integers that are evenly divisble by both three and five, do not do any of the above, but instead output the exact string Hop, followed by a newline.

Example output (newline at end of every line):



waling-waling said...

i'll probably be back to read more your site carries good data all in favor of readers.

Cindy Dy said...

First time I commented in a blog! I really enjoy it. You have an awesome post. Please do more articles like this. I'm gonna come back surely. God bless.


Nikolay ebardeev said...

Oh my goodness! a tremendous article dude. Thanks Nonetheless I'm experiencing situation with ur rss . Don’t know why Unable to subscribe to it. Is there anyone getting equivalent rss problem? Anybody who knows kindly respond. Thnkx online casino slots