Square Triangles


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.

Square Triangles

A Square Triangular Number is number which is both triangular and a perfect square (36 for example). Find the sixth Square Triangular Number (including 1, but excluding 0).

Solution and answer (Square Triangles.pas):

program Square_Triangles( output );
Solution and answer for problem "Square Triangles" (12th January 2014) of http://ContestCoding.WordPress.com/


Solution programmed in Pascal using Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition); solution took ~1s to run on a 80MHz PowerPC 601.
  i : 1..maxlongint;
  k : 2..maxlongint;
  number_of_square_triangles_found : 0..6;
  square_root_of_i : double;
  i := 1;
  k := 2;
  number_of_square_triangles_found := 0;
    square_root_of_i := sqrt( i );
    if square_root_of_i = trunc( square_root_of_i ) then
      number_of_square_triangles_found := number_of_square_triangles_found + 1;
    i := i + k;
    k := k + 1
  until number_of_square_triangles_found = 6;
  k := k - 1;
  i := i - k;
  writeln( i )

No Responses Yet to “Square Triangles”

  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 )

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: