### Square Triangles

12Jan14

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 4^{th} 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 TrianglesA 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):**

{$R+} program Square_Triangles( output ); { Solution and answer for problem "Square Triangles" (12th January 2014) of http://ContestCoding.WordPress.com/ 48024900 Solution programmed in Pascal using Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition); solution took ~1s to run on a 80MHz PowerPC 601. } var i : 1..maxlongint; k : 2..maxlongint; number_of_square_triangles_found : 0..6; square_root_of_i : double; begin i := 1; k := 2; number_of_square_triangles_found := 0; repeat 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 ) end.

Advertisements

Filed under: Uncategorized | Leave a Comment

Tags: computer science, computing, contest, Contest Coding, Lewis Cornwall, Pascal

Advertisements

## No Responses Yet to “Square Triangles”