1. Computing & Technology

Discuss in my forum

Programming Contest 49 - Create Book Code

Deadline August 31

By , About.com Guide

A book code is a list of three coordinates for every word in a specified sentence, referenced in a particular book. The coordinates are page, line and word count. The first line of each page (line 1) is the line containing the page number.

For example, on page 4 of the classic text Pinocchio which starts 4 INTRODUCTION, line 6, word 2 is Goethe. Note, not all pages have words (eg page 11) and the page numbering appears to be on the left of even pages and right of odd numbered pages except for 11 and where is page 23?

Feel free to to tidy up the book (but don't add lines within a page). If you you do tidy it up, please email it me and I'll republish it and use it.

Help me break out of Prison before the end of May and you will get a wonderful reward

The zip file linked below which contains two files. Pinocchio.txt is the text file, obtained from archive.org containing the traditional story. The other file code.txt has the message below.

Note that when the contest is run I may use a different code.txt but every word in that file will still exist in pinocchio.txt and the pinocchio.txt provided is the one that will be used, unless a tidied up one is obtained.

Also, the case of any word is irrelevant so for example may or MAY or May is fine. Also, where the same word occurs more than once in the code.txt file, please make sure that if it occurs more than once in Pinocchio.txt that you output different book codes.

Both input files will be in the same location as your exe.

The Contest

Your program must read in pinocchio.txt and code.txt then for every word in code.txt, it must create a list of book codes (page, line, word) for every word in code.txt.

Output File

Please generate a csv file called output.csv in the same location as your exe where each line in output.csv has the page, line and word number (for one word ) separated by commas. So if Goethe were in the phrase, its line in the might be:

4,6,2

Which reads as page 4, on the sixth line, the second word. All numbers are one based not zero. The first line is 1 etc.

Winning Criteria

The fastest generator of the code book wins. I will write a program that reads your csv and outputs the sentence to check. Multiple answers are possible.

Timing Code

Please time from the start of the run, after reading in both files until just before the output file is opened for writing. This code below will do high speed timing for Windows (first three) and the fourth one for Linux.

Rules

This is for glory only. About.com does not permit prizes to be given.

Please submit your source code and the output file to the cplus.guide@about.com?subject=Programming Contest 49 email address with the subject line Programming Contest 49.

It must compile with Open Watcom, Microsoft Visual C++ 2008/2010 Express Edition/Microsoft Visual Studio 2008/2010 or Borland Turbo C++ Explorer, Microsoft Visual C# 2008/2010 Express Edition or GCC/G++. If it doesn't compile, it can't be run so is automatically disqualified.

Please include your name, age (optional), blog/website url (optional) and country. Your email address will not be kept, used or displayed except to acknowledge your challenge entry. You can submit as many entries as you like before the deadline which is August 31st 2011.

The top ten entries will be listed, judged purely on points. A condition of entry is that you allow your source code to be published on this website, with full credits to you as the author.

©2012 About.com. All rights reserved.

A part of The New York Times Company.