Excluded Letters

02Feb14

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.

Excluded Letters

Of the twenty six letters in the alphabet, how many of them do not appear in this puzzle – excluding the reminder below?

Solution and answer (Excluded Letters.pas):

Uses: lib_seal_toLowercase.

{$R+}
program Excluded_Letters( output );
{
Solution and answer for problem "Excluded Letters" (2nd February 2014) of http://ContestCoding.WordPress.com/

4 of the twenty-six letters of the alphabet do not appear in the puzzle; those letters are: j, k, q, & v.

Solution programmed in Pascal using Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition); solution took ~1s to run on a 80MHz PowerPC 601.
}
uses
  lib_seal_toLowercase;
var
  i : 1..26;
  letter_used : array[ 1..26 ] of boolean;
  f : text;
  c : char;
  number_of_letters_unused : 0..26;
begin
  for i := 1 to 26 do
    letter_used[ i ] := false;
  assign( f, 'Excluded Letters.txt' );
  reset( f );
  while not eof( f ) do begin
    read( f, c );
    c := f_ToLowercase( c );
    if c in [ 'a'..'z' ] then
      letter_used[ ord( c ) - ord( 'a' ) + 1 ] := true
  end;
  close( f );
  number_of_letters_unused := 0;
  for i := 1 to 26 do
    if not letter_used[ i ] then
      number_of_letters_unused := number_of_letters_unused + 1;
  write( number_of_letters_unused, ' of the twenty-six letters of the alphabet do' );
  if number_of_letters_unused = 1 then
    write( 'es' );
  write( ' not appear in the puzzle; th' );
  if number_of_letters_unused = 1 then
    write( 'at' )
  else
    write( 'ose' );
  write( ' letter' );
  if number_of_letters_unused = 1 then
    write( ' is' )
  else
    write( 's are' );
  write( ': ' );
  for i := 1 to 26 do
    if not letter_used[ i ] then begin
      write( chr( i + ord( 'a' ) - 1 ));
      if number_of_letters_unused > 1 then begin
        write( ', ' );
        if number_of_letters_unused = 2 then  
          write( '& ' );
      end;
      number_of_letters_unused := number_of_letters_unused - 1
    end;
  writeln( '.' )
end.
Advertisements


No Responses Yet to “Excluded Letters”

  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: