Re: Project Programmer Wanter

new topic     » goto parent     » topic index » view thread      » older message » newer message

Ret Law wrote:
> 
> That sounds good.
> 
> Basically what I want is to create output, both as a data text file and as
> screen
> display of the full permutation of a given number of items over a given number
> of digits according to a given rule of sucession.
> 
> For example:
> 
> Items:
> A,B,C,D
> 
> # of Digits:
> 3
> 
> Order:
> A,B,C,D, beginning with AAA, ending with DDD and rotating in successive order
> across right to left.
> 
> Output:
> AAA
> AAB
> AAC
> AAD
>
[snipped]

> DDB
> DDC
> DDD
> 
> How would that function be implemented to achieve that?

Here is another implementation:
function VariationsRep(integer n, sequence s)
integer len
atom lin,lines,rep
object si
sequence p

   len = length(s)
   lines = power(len,n)
   p = repeat(repeat(0,n),lines)
   rep = 1
   for col = n to 1 by -1 do
      lin = 1
      while lin <= lines do
         for i = 1 to len do
            si = s[i]
            for k = 1 to rep do
               p[lin][col] = si
               lin += 1
            end for
         end for
      end while
   rep *= len
   end for
   return p
end function

sequence v

-- a) your example:
v = VariationsRep(3,"ABCD")
for i = 1 to length(v) do
   printf(1,"%3d = %s\n", {i,v[i]})
end for

-- b) get all possible combinations of two 6-sided dice:
v = VariationsRep(2,{1,2,3,4,5,6})
for i = 1 to length(v) do
   printf(1,"%3d = %d,%d\n", {i,v[i][1],v[i][2]})
end for

-- c) show all 8 bits binary numbers:
v = VariationsRep(8,{'0','1'})
for i = 1 to length(v) do
   printf(1,"%3d = %s\n", {i-1,v[i]})
end for


Regards,
   Fernando

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu