Motivated by the Hacker News challenge in http://news.ycombinator.com/item?id=3429466 I just made this.
Code:#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; }Opinions? Post you're own solutions.Code: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.
Thread: Pascal's triangle
Results 1 to 26 of 26
-
01-06-2012
Last edited by Dustin; 01-06-2012 at 06:05 AM.
-
01-06-2012
Looks like we have our very own zero cool! Watch your back, Milkshake
-
01-06-2012
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
-
01-06-2012
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
-
01-06-2012
just one faggot, clay told me the limit was one so I couldn't bring my friends.
-
01-06-2012
Also no need to be so mean gosh, I was under the impression that this is a friendly forum.
-
01-06-2012
oh shit, terms and arrays!
-
-
-
01-06-2012
don't worry. you weren't really. he's just trying to troll you.
-
01-06-2012
Well that's good to hear I was worried for a moment.
-
01-06-2012
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
-
-
-
-
01-06-2012
\n
-
-
-
01-06-2012
#include <pascal.h>
-
-
-
-
01-06-2012
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
-
-
01-06-2012
fyi I compiled and ran your c code, it doesn't do shit
-
01-06-2012
was the point of this thread to show off our skills?
i only read the first 2 replies and glanced at the tarantino spider
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)