|
 |
While I was trying to generate and list a huge array with pairs of
numbers of this style,
/*
#declare T_arr = array [n]]2]
{
{1,1},
{1,2},
{1,3},
{1,4},
{1,5},
...
{2,2},
{2,3},
{2,4},
...
{n,n},
}
*/
testing and failing again and again ... Well, in addition to some error
messages that I had not seen before
/*
"Invalid dimension size for an array"
"array subscript out of range"
"Negative subscript"
"std: bad_alloc"
*/
I ended up giving with a code that besides being wrong kicked my Ubuntu
in the face, (with pov under Wine it took a while to recover, but it
comes out.) Be careful not to have anything important open if you try
it, the lines that generate the error are in comment lines on purpose I
do not ask for a solution and I do not think that it is exactly a
mistake of the program, but I leave it there as a curiosity.
BGimeno
pd. Factorial(n) code isn't mine, I've found it today, and very useful.
#include "math.inc"
// ************************************
#macro ArrayWriter (filename,n_sides)
// --------------------------------------
#local n_sides = int(n_sides);
#macro Factorial(N)
#local Result = 1;
#local Ind = 2;
#while(Ind <= N)
#local Result = Result*Ind;
#local Ind = Ind+1;
#end
Result
#end
// -----------------------------------------------------------
/* // BEWARE OF NEXT CODE
// Creates an array with every pair of numbers
// #local Pairs_arr = array [Factorial(n_sides*2)][(n_sides*2)-1]
// #local C = 0 ; #while (C<=(n_sides*2)-1)
// #local C2 = 0 ; #while (C2<=(n_sides*2)-1)
//
// #local Pairs_arr [C][C2] = C2 ;
//
// #local C2 = C2 + 1 ; #end
// #local C = C + 1 ; #end
*/
// --------------------------------------
#fopen My_arr concat(filename,".txt") write #fclose My_arr
#fopen My_arr concat(filename".txt") append
// ---------Header ---------------------
#write (My_arr,concat("#declare The_",str(n_sides,0,0),"_array ["
str(Factorial(n_sides),0,0)"],["
str(n_sides*2,0,0)"]{\n"))
// ---------Array -----------------------
#local n_sides_r=1;
#while (n_sides_r<=n_sides*2)
#write (
My_arr,concat(
#if (n_sides_r=1) " {" #end
#if (odd(n_sides_r)=true)
"T"str(n_sides,0,0)"_"#end
str(Pairs_arr[n_sides_r-1],-2,0),
#if (even(n_sides_r)=true) #if
(n_sides_r<(n_sides*2)-1)"," #else "}\n" #end
#else "_" #end
)
)
#local n_sides_r=n_sides_r+1;
#end
#write (My_arr,concat("}\n"))
// --------------------------------------
#fclose My_arr
#end // end of macro
ArrayWriter("test",6)
Post a reply to this message
|
 |