Shorthand

24Nov13

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.

Shorthand

Shorthand systems are used, as oppose to longhand systems, to quickly transcribe spoken words. Many shorthand systems follow the following rules:

  • Omit vowels in the middle and at the end of words (make becomes mk, but am remains am)
  • Omit one of double letters (letter becomes ltr)

For example, “This is shorthand.” becomes “Ths is shrthnd.” Find the shorthand equivalent of the following passage:

Friends, Romans, countrymen, lend me your ears!
I come to bury Caesar, not to praise him.
The evil that men do lives after them,
The good is oft interrèd with their bones:
So let it be with Caesar. The noble Brutus
Hath told you Caesar was ambitious;
If it were so, it was a grievous fault,
And grievously hath Caesar answered it.
Here, under leave of Brutus and the rest –
For Brutus is an honourable man,
So are they all, all honourable men –
Come I to speak in Caesar’s funeral.

Solution and answer (Shorthand.pas):

Uses: lib_seal_toLowercase.

{$R+}
program Shorthand( output );
{
Solution and answer for problem "Shorthand" (24th November 2013) of http://ContestCoding.WordPress.com/

Frnds, Rmns, cntrymn, lnd m yr ers!
I cm t bry Csr, nt t prs hm.
Th evl tht mn d lvs aftr thm,
Th gd is oft intrd wth thr bns:
S lt it b wth Csr. Th nbl Brts
Hth tld y Csr ws ambts;
If it wr s, it ws a grvs flt,
And grvsly hth Csr answrd it.
Hr, undr lv of Brts and th rst -
Fr Brts is an hnrbl mn,
S ar thy al, al hnrbl mn -
Cm I t spk in Csr's fnrl.

Solution programmed in Pascal using Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition); solution took ~4s to run on a 80MHz PowerPC 601.
}
uses
  lib_seal_toLowercase;
var
  f : text;
  word_begun : boolean;
  c, last_c : char;
begin
  assign( f, 'Shorthand.txt' );
  reset( f );
  word_begun := false;
  while not eof( f ) do
    if eoln( f ) then begin
        readln( f );
        writeln;
        word_begun := false
      end
    else
      begin
        read( f, c );
        if not ( f_ToLowercase( c ) in [ 'a'..'z', 'è' ] ) then begin
            write( c );
            word_begun := false
          end
        else
          if not word_begun then begin
              write( c );
              last_c := c;
              word_begun := true
            end
          else
            if not ( f_ToLowercase( c ) in [ 'a', 'e', 'i', 'o', 'u', 'è' ] ) then
              if c <> last_c then begin
                write( c );
                last_c := c
              end
      end;
  close( f )
end.
Advertisements


No Responses Yet to “Shorthand”

  1. Leave a Comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s


%d bloggers like this: