Canoe or Dinghy?

03May13

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.

Canoe or Dinghy?

A sailing company is temporarily closing down to build more boats. It takes them 1 day to build a canoe, and 2 days to build a sailing dinghy. They can only build one boat at a time. They work everyday and are always building either a canoe or a dinghy. If they closed for 4 days, they would have 3 options available to them: to build 4 canoes, to build 2 canoes and a dinghy or to build 2 dinghies. If the sailing company closed for a year (that is not a leap year), how many options would be available to them?

Solution and answer (Canoe or Dinghy?.pas):

{$R+}
program Canoe_or_Dinghy( output );
{
Solution and answer for problem "Canoe or Dinghy?" (3rd May 2013) of http://ContestCoding.WordPress.com/

There are 183 manufacturing options in a (non-leap) year.

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

type
  t_PositiveNonZeroInteger = 1..maxint;

function f( p : t_PositiveNonZeroInteger ) : t_PositiveNonZeroInteger;
begin
  f := ( p - p mod 2 + 2 ) div 2
end;

begin
  writeln( 'There are ', f( 365 ), ' manufacturing options in a (non-leap) year.' )
end.
Advertisements


No Responses Yet to “Canoe or Dinghy?”

  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: