[Date Index]
[Thread Index]
[Author Index]
combinations problem
*To*: mathgroup at smc.vnet.net
*Subject*: [mg58563] combinations problem
*From*: hrocht at mail15.com
*Date*: Thu, 7 Jul 2005 05:35:54 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
hi
at first here is my program
<< DiscreteMath`Combinatorica`
lst1 = Table[i, {i, 100}]
Do[
lst2 = Table[Random[Integer, {1, 300}], {i, 100}];
lst3 = Transpose[{lst1, lst2}];
a = KSubsets[lst3, 2];
num = 0; Do[
If[
Abs(a[[i]][[1]][[2]] - a[[i]][[1]][[1]]) ==
Abs(a[[i]][[2]][[2]] - a[[i]][[2]][[1]]) || (a[[i]][[1]]
[[2]] +
a[[i]][[1]][[1]]) == (a[[i]][[2]][[2]] + a[[i]][[2]]
[[1]]),
num++;]
, {i, 1, 4950}];
If[num > 40, Print[num]; Print[lst2]];
, {j, 1, 2000}]
lst3 will have each element in lst2 together with its ordering
such as :
Take[lst3, {1, 3}]
{{1, 48}, {2, 295}, {3, 74}}
if we take all the possible combinations in lst3 taken in pairs as in
a = KSubsets[lst3, 2]
one sublist may be for a[[1]]
{{1, 6}, {29, 34}}
the length of "a" will be 4950 which is number of possible
combinations for 100 elements taken in pairs.
the mission is to count the sublists such as
{{1, 6}, {29, 34}} in which abs[1-6]=abs[29-34]
or the sublists such as
{{1, 206}, {35, 172}}
in wich 1+206=35+172
and what is the biggest possible number for such sublists when we
supply our random or carefully designed lst2 ?
in the program above we want to display only the lst2 wich will give
num>40
how could i make my program more speedy and more efficient?
thanks
Anton
Prev by Date:
**Re: Urgent**
Next by Date:
**Set of strings reducing problem**
Previous by thread:
**Re: Don't understand behaviour of Solve[]**
Next by thread:
**Re: combinations problem**
| |