PDA

View Full Version : Pascal's triangle



Dustin
01-06-2012, 06:57 AM
Motivated by the Hacker News challenge in http://news.ycombinator.com/item?id=3429466 I just made this.



#include <stdio.h>
#include <stdlib.h>
#define NTH_IN_ROW(r, n) (((r) * (r) + (r)) / 2 + (n))
int main() {
long *a, i, j, r;
scanf("%ld", &r);
a = malloc(sizeof(long) * ((r + 1) * (r + 1) + r + 1) / 2);
for (i = 0; i <= r; i++) {
a[NTH_IN_ROW(i, 0)] = 1;
a[NTH_IN_ROW(i, i)] = 1;
if (i > 1)
for (j = 1; j < i; j++)
a[NTH_IN_ROW(i, j)] =
a[NTH_IN_ROW(i - 1, j)] +
a[NTH_IN_ROW(i - 1, j - 1)];
}
for (j = 0; j <= r; j++)
printf("%ld ", a[NTH_IN_ROW(r, j)]);
putchar('\n');
return 0;
}


program Pascal;

var counter as integer;
var ptLine as integer[20];

procedure Step(istep as integer);
var couter as integer;
begin
ptLine[istep] := 1;
if (istep<>1) then write( " " + ptLine[1]);
if (istep>=3) then begin
for couter := 2 to istep-1 do begin
ptLine[couter] = ptLine[couter] + ptLine[couter-1];
write(" " + ptLine[couter]);
end;
end;
writeln(" " + ptLine[istep]);
end;

begin
for counter:=1 to 20 do begin
Step(counter);
end;
end.

Opinions? Post you're own solutions.

Desolation
01-06-2012, 07:05 AM
Looks like we have our very own zero cool! Watch your back, Milkshake

jon
01-06-2012, 07:44 AM
my first opinion is you're a faggot and my second opinion is anyone who writes a pascal program and calls it "Pascal" is thinking that other people won't recognize the language and is an even bigger faggot for being so condescending

so the only question is: do we have one faggot here, or one faggot who simply copied the comment another faggot made, and therefore two faggots

and if you get this question wrong you have failed the interview and may go home

jon
01-06-2012, 07:45 AM
plus you didn't newline between then/begin and you didn't use caps for the keywords so you're not even a very good pascal programmer, probably just one of those delphi faggots that pretends they used to use tp4

Dustin
01-06-2012, 07:46 AM
just one faggot, clay told me the limit was one so I couldn't bring my friends.

Dustin
01-06-2012, 07:48 AM
Also no need to be so mean gosh, I was under the impression that this is a friendly forum.

m0nde
01-06-2012, 08:57 AM
oh shit, terms and arrays!

clay
01-06-2012, 09:14 AM
You were trolled.

government was trolled when they wrote male on your birth cert

Dustin
01-06-2012, 09:25 AM
You were trolled.

Oh no not again

m0nde
01-06-2012, 09:26 AM
don't worry. you weren't really. he's just trying to troll you.

Dustin
01-06-2012, 09:38 AM
Well that's good to hear I was worried for a moment.

Dustin
01-06-2012, 09:47 AM
What a rude poster, clay you should make a new section called "I'm rude and I know it" and only let Cody post in it. Then you should make one about programming and Jon is forced to look at arrays I made in C++ that are all wrong. ( I don't know C++ ) heh

Dustin
01-06-2012, 10:00 AM
You should take a plastic bag, make a section of it covered in superglue, put it over your head, and smash it down on your face.

Typical, mad cuz bad.

Dustin
01-06-2012, 10:33 AM
literally went on a forum wide rant

maks
01-06-2012, 11:09 AM
people still use pascal?

m0nde
01-06-2012, 11:12 AM
\n

Dustin
01-06-2012, 11:21 AM
people still use pascal?
lolno

Dustin
01-06-2012, 11:22 AM
C is where its at anyway

m0nde
01-06-2012, 11:27 AM
#include <pascal.h>

rootbeer
01-06-2012, 12:35 PM
:snickerz:

Greg Blake Age: 41 (412) 824-6478 1700 James St Monroeville, PA 15146 racerx111@verizon.net
01-06-2012, 12:42 PM
^ faggot

Beef Sister
01-06-2012, 12:55 PM
government was trolled when they wrote male on your birth cert

:tarantulatino::tarantulatino:

blumpkin blownuts
01-06-2012, 08:08 PM
fuck HLL's other than lisp
machine code owns j00 if I cared id rewrite your routine in 68k and have like a tenth of your instructions in native code

Dustin
01-06-2012, 09:00 PM
do it then

maks
01-06-2012, 10:01 PM
fyi I compiled and ran your c code, it doesn't do shit

Plug Drugs
01-07-2012, 12:39 AM
was the point of this thread to show off our skills?
i only read the first 2 replies and glanced at the tarantino spider