Message-ID: <3ABF56A2.17C6B746@dyce.NOSPAM.expro.co.uk> Date: Mon, 26 Mar 2001 15:48:02 +0100 From: Bruce J Clark Organization: Expro North Sea Ltd X-Mailer: Mozilla 4.6 [en] (WinNT; I) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: borland.public.delphi.non-technical Subject: Re: Pascal's Pyramid - algorithm References: <3ABF4F2E.96959E30@adldata.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 194.202.44.145 X-Trace: 26 Mar 2001 06:49:49 -0800, 194.202.44.145 Lines: 64 Path: dnews!194.202.44.145 Xref: dnews borland.public.delphi.non-technical:203398 >> Had an interview question recently to write an algorithm to construct the Pascal Pyramid. It stumped me does any one have the algorithm they can post, I am curious?? << The code below is very inefficient but effective. However, the use of recursion means that it'll bomb if the level to be displayed is too big. Hope this helps, Bruce J Clark [Aberdeen, Scotland] P.S. I hope I haven't just completed somebody's homework assignment. program PascalPyramidProject; {\$APPTYPE CONSOLE} uses SysUtils; function GetPascalPyramidValue (const X, Y : Integer) : Integer; begin if (X = 0) and (Y = 0) then Result := 1 else if (Y = 0) then Result := 0 else Result := GetPascalPyramidValue (X, Y - 1) + GetPascalPyramidValue (X - 1, Y - 1); end; // of function GetPascalPyramidValue procedure PascalPyramid (const aLevel : Integer); var X, Y : Integer; Value : Integer; begin for Y := 0 to (aLevel - 1) do begin for X := 0 to Y do begin Value := GetPascalPyramidValue (X, Y); Write (Format ('%3d ', [Value])); end; // of for X Writeln; end; // of for Y end; // of procedure PascalPyramid begin PascalPyramid (6); end. AH wrote: > > Hi All: > > Had an interview question recently to write an algorithm > to construct the Pascal Pyramid. It stumped me does any one > have the algorithm they can post, I am curious?? > > 1 > 11 > 121 > 1331 > 14641 > 151051 > > Thanks, > AH