Floyd's triangle: Difference between revisions

Content added Content deleted
Line 4,257: Line 4,257:


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
<lang parigp>{floyd(m)=my(lastrow_a,lastrow_e,lastrow_len=m,fl,idx);

{{incorrect|PARI/GP|It does not ensure that there is exactly one space between the columns in the last row.}}
\\ +++ fl is a vector of fieldlengths in the last row
lastrow_e=m*(m+1)/2;lastrow_a=lastrow_e+1-m;

fl=vector(lastrow_len);
<lang parigp>{floyd(m)=my(lastrowa,lastrowe,vecFieldLen,idx);
for(k=1,m,fl[k] = 1 + #Str(k-1+lastrow_a) );
lastrowe=m*(m+1)/2;lastrowa=lastrowe+1-m;lastrowlen=m;
\\
vecfieldlen=vector(lastrowlen);
idx=0;
for(k=1,m,fl[k]=1+#Str(k-1+lastrowa));
for(i=1,m,
il=1; printf(Str("%" fl[1]-1 "d"),il);print();
for(i=2,m,
for(j=1,i,
for(j=1,i,
il++;
idx++;
printf(Str("%" fl[j]-(il==1) "d"),il)
printf(Str("%" fl[j] "d"),idx)
);
);
print()
print()
);
);
return()}
return();}
floyd(5)
floyd(5)
floyd(14)
floyd(14)