Searching Latin


In the twelve months from March 2013 to March 2014, I programmed solutions to the problems posted on the Contest Coding blog run by Lewis Cornwall, solving 33 problems (out of 47) and achieving a position of 4th on the leaderboard (out of 23).

As that blog has now been discontinued, I’m posting here the solutions I programmed to those problems.

Searching Latin

Assuming “lorem” is the 1st word, find the 1865th word of the Lorem Ipsum found here.

Solution and answer (Searching Latin.pas):

program Searching_Latin( output );
Solution and answer for problem "Searching Latin" (9th February 2014) of

The 1865th word is 'purus'.

Solution programmed in Pascal using Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition); solution took ~3s to run on a 80MHz PowerPC 601.

function f_ReadWordFromFile( var p : text ) : string;
  word : string;
  end_of_word : boolean;
  c : char;
  word := '';
  end_of_word := false;
  while not eof( p ) and not end_of_word do begin
    read( p, c );
    if c in [ 'a'..'z', 'A'..'Z' ] then
      word := word + c
      end_of_word := true
  f_ReadWordFromFile := word

  f : text;
  word_index : 0..1865;
  c : char;
  word : string;
  assign( f, 'Searching Latin.txt' );
  reset( f );
  word_index := 0;
  while not eof( f ) and ( word_index < 1865 ) do begin
    read( f, c );
    if c in [ 'a'..'z', 'A'..'Z' ] then begin
      word_index := word_index + 1;
      word := c + f_ReadWordFromFile( f )
  close( f );
  writeln( 'The 1865th word is ''', word, '''.' )

No Responses Yet to “Searching Latin”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: