473,466 Members | 1,334 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ushort[] myBigKey = new ushort[100]; //how do I use myBigKey as one long key??

I just bought Visual Studio 2008, I'm new to C# and trying to learn it. I'm
stuck and would appreciate some help.

I need to make the fastest code I can to work with a large key (it's 200
bytes wide) and add only the unique keys to a List<T>, Dictionary, Array...
whatever is fastest because I'll be doing trillions of compares.

The key is: ushort[] myBigKey = new ushort[100];

I want to treat the entire array (all 100 instances) as one long key. Once
I've set all the values within the myBigKey[] array, I want to call a method
that will check for uniqueness and insert it if it's unique to the list. It
would be nice to do something like:

AllUniqueKeys.AddIfUnique(myBigKey[])

I've tried looking at nested classes, which was over my head, and I just
can't seem to get anything to work. Any help is appreciated. Thanks.

Mark

---- Posted via Pronews.com - Premium Corporate Usenet News Provider ----
http://www.pronews.com offers corporate packages that have access to 100,000+ newsgroups
Aug 9 '08 #1
8 1694
Mark Main wrote:
I just bought Visual Studio 2008, I'm new to C# and trying to learn it.
I'm stuck and would appreciate some help.

I need to make the fastest code I can to work with a large key (it's 200
bytes wide) and add only the unique keys to a List<T>, Dictionary,
Array... whatever is fastest because I'll be doing trillions of compares.

The key is: ushort[] myBigKey = new ushort[100];

I want to treat the entire array (all 100 instances) as one long key.
Once I've set all the values within the myBigKey[] array, I want to call
a method that will check for uniqueness and insert it if it's unique to
the list. It would be nice to do something like:

AllUniqueKeys.AddIfUnique(myBigKey[])

I've tried looking at nested classes, which was over my head, and I just
can't seem to get anything to work.
I don't think List<is the optimal data structure for this.

HashSet<maybe.

Arne
Aug 9 '08 #2
I do not no anything about the speed of things like this and there is
probably a much better approach but I would have set something up like
this.

Note I have only very briefly tested it and it seams to work ok. Sorry
I haven’t much time.

<code>

public static class program
{
[System.STAThread]
static void Main()
{
UniqueList list = new UniqueList();
// Add an Item
list.Add(new Modeler.Temp.myBigKey(new ushort[100]
{
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1, 1
}));
// Add an Item
list.Add(new Modeler.Temp.myBigKey(new ushort[100]
{
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1, 5
}));
// Add Items only if it is Unique.
list.AddIfUnique(new Modeler.Temp.myBigKey(new ushort[100]
{
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1, 6
}));
// Add Items only if it is Unique. (THIS WILL NOT BE ADDED)
list.AddIfUnique(new Modeler.Temp.myBigKey(new ushort[100]
{
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1, 5
}));

System.Windows.Forms.MessageBox.Show(list.Count.To String());
}
}
public class myBigKey
{
public myBigKey()
{
}

public myBigKey(ushort[] items)
{
if (items.Length != 100)
{
throw new System.Exception("ushort array must be of length
100.");
}
this.items = items;
}

public ushort this[int index]
{
get { return this.items[index]; }
set { this.items[index] = value; }
}

public int Length
{
get { return this.items.Length; }
}

private ushort[] items = new ushort[100];
}
public class UniqueList : System.Collections.Generic.List<myBigKey>
{
public UniqueList()
{
}

public void AddIfUnique(myBigKey item)
{
bool add = true;
int count = 0;
while (count < this.Count)
{
bool isMatch = true;
int count2 = 0;
while (count2 < item.Length)
{
if (this[count][count2] != item[count2])
{
ushort u = this[count][count2];
ushort u2 = item[count2];
isMatch = false;
}
count2++;
}
if (isMatch == true) add = false;
count++;
}
if (add == true)
{
base.Add(item);
}
}

}

</code>
Aug 9 '08 #3
Thanks for your email it helped me learn more about classes since I'm
learning. I was able to play with it and unfortunately not able to get it to
work for my needs because it won't let me treat each element of the myBigKey
Array like they were fields.

I wish that I could do something like this:
public class myBigKey
{
ushort myKeyElements[] = new ushort[100];
}

HashSet<MyBigKeyClassUniqueList = new HashSet<MyBigKeyClass>;
for (h = 0; h < 100; h++)
{
for (i = 0; i < 100; i++)
myKeyElements[i] = i * h; // I'll really have some calculations
here, but this is an easy example
UniqueList.Add myBigKey //myBigKey contains the entire collection of
myKeyElements[]
}

I don't know how to setup a class called myBigKey that hold the 100 ushort
elements called myKeyElements so that I can load up each of the
myKeyElements and the reference the entire collection using the name
myBigKey; I've been trying to set this up and failing.

"Jay Dee" <fi******@gmail.comwrote in message
news:5b**********************************@m3g2000h sc.googlegroups.com...
I do not no anything about the speed of things like this and there is
probably a much better approach but I would have set something up like
this.

Note I have only very briefly tested it and it seams to work ok. Sorry
I haven’t much time.

<code>

public static class program
{
[System.STAThread]
static void Main()
{
UniqueList list = new UniqueList();
// Add an Item
list.Add(new Modeler.Temp.myBigKey(new ushort[100]
{
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1, 1
}));
// Add an Item
list.Add(new Modeler.Temp.myBigKey(new ushort[100]
{
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1, 5
}));
// Add Items only if it is Unique.
list.AddIfUnique(new Modeler.Temp.myBigKey(new ushort[100]
{
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1, 6
}));
// Add Items only if it is Unique. (THIS WILL NOT BE ADDED)
list.AddIfUnique(new Modeler.Temp.myBigKey(new ushort[100]
{
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1,
1,
3, 2, 5, 1, 1, 1, 1, 1, 1, 1, 3, 2, 5, 1, 1, 1, 1, 1, 1, 5
}));

System.Windows.Forms.MessageBox.Show(list.Count.To String());
}
}
public class myBigKey
{
public myBigKey()
{
}

public myBigKey(ushort[] items)
{
if (items.Length != 100)
{
throw new System.Exception("ushort array must be of length
100.");
}
this.items = items;
}

public ushort this[int index]
{
get { return this.items[index]; }
set { this.items[index] = value; }
}

public int Length
{
get { return this.items.Length; }
}

private ushort[] items = new ushort[100];
}
public class UniqueList : System.Collections.Generic.List<myBigKey>
{
public UniqueList()
{
}

public void AddIfUnique(myBigKey item)
{
bool add = true;
int count = 0;
while (count < this.Count)
{
bool isMatch = true;
int count2 = 0;
while (count2 < item.Length)
{
if (this[count][count2] != item[count2])
{
ushort u = this[count][count2];
ushort u2 = item[count2];
isMatch = false;
}
count2++;
}
if (isMatch == true) add = false;
count++;
}
if (add == true)
{
base.Add(item);
}
}

}

</code>

---- Posted via Pronews.com - Premium Corporate Usenet News Provider ----
http://www.pronews.com offers corporate packages that have access to 100,000+ newsgroups
Aug 9 '08 #4
On 9 Aug, 21:25, "Mark Main" <em...@markmain.comwrote:
Thanks for your email it helped me learn more about classes since I'm
learning. I was able to play with it and unfortunately not able to get itto
work for my needs because it won't let me treat each element of the myBigKey
Array like they were fields.

I wish that I could do something like this:

public class myBigKey
{
* * ushort myKeyElements[] = new ushort[100];

}

HashSet<MyBigKeyClassUniqueList = new HashSet<MyBigKeyClass>;
for (h = 0; h < 100; h++)
{
* * for (i = 0; i < 100; i++)
* * * * myKeyElements[i] = i * h; // I'll really have some calculations
here, but this is an easy example
* * UniqueList.Add myBigKey //myBigKey contains the entire collectionof
myKeyElements[]

}

I don't know how to setup a class called myBigKey that hold the 100 ushort
elements called myKeyElements so that I can load up each of the
myKeyElements and the reference the entire collection using the name
myBigKey; I've been trying to set this up and failing.


I don’t know what you mean by “it won't let me treat each element of
the myBigKey
Array like they were fields”.

Adding this

<code>

public ushort this[int index]
{
get { return this.items[index]; }
set { this.items[index] = value; }
}

</code>

Gives the ability to access each element like this.

myBigKey[6] // 6 being the index of the inner array.

So if this key was contained in a list itself for example list I set
up

System.Collections.Generic.List<myBigKeylist;

Then calling the element would be.

ushort value = list[5][6];
// 5 representing the list item as a myBigKey,
// 6 representing ushort element 6 of the myBigKey itself.
If you needed to access the inner ushort array then simply add a
method to the myBigKey class something like

public ushort[] ToArray()
{
return myKeyElements;
// or if necessary copy the elements to a new array and return
that instead of actually returning the inner array. To save being able
to edit the inner array from outside.
}

Is this not what you wear after if not then I don’t know what you
mean.
Aug 10 '08 #5
Mark Main wrote:
It ends up being trillions of calculations, but the part that checks for
uniqueness will probably in the millions and the final results will be
in the thousands. I'm doing lots of factorization of prime numbers
Factorization *into* primes, surely. Factoring primes is trivial. :-)
to compute the best gear ratios to use for unusual wooden clock designs
that use rather large gears and also a large number of small gears; the
standard clock gearing is easy, but these clocks will also show phases of
the Moon and the approximation of this is a fun project. I'm looking at
all ratios that have an error of 1 second or less per Moon Phase.

I take a series of prime numbers (typically about 2 to 10 of them) and
factor every combination and then check for all kinds of things to weed
out the junk; e.g. the resulting gear size would be too large or small,
the gear and pinion teeth would not have even wear with each other,
ect.). So, for example, the series of prime numbers 2*2*3*11 have the
following unique combinations of factors:

2*2*3*11
2*6*11
2*3*22
2*2*33
6*22
4*33
132
This definitely sounds like you're using a brute force approach where a more
clever one would work as well -- and even if you're using a brute force
approach, I'm fairly sure your current approach is more brute than
necessary. :-)
I need to write a routine that will be very fast at factoring as well,
but it's still going to be lots of number crunching because there's
2551442.9 seconds in an average Moon Phase and I may decide to have 2 or
4 Moon phase devices, which means that I need to compare ratios that
work for 5102886 seconds and 10205772 seconds.
That's going to be a tough nut to crack, because 2551443 is 3 * 850481. I'd
go with 2551444, which is 2 * 2 * 7 * 293 * 311. 10205772 is harder, because
10205771 = 761 * 13411 and 10205773 = 79 * 129187. A pure ratio-based
approach wouldn't work very well here. You could probably use it to get the
"wrong" numbers and another circuit to do corrections (or some form of
addition), but I'm no expert on mechanical clocks.
If you or anyone here knows of a great factorization routine, I'd love
to see it, because I've got tons of factoring that I'll be doing.
Your numbers aren't that large, and they're most likely composite. This
means trial division, while horribly naive, is still likely to give
acceptable results. For example, factoring 2551443 by trial division takes
923 divisions (2 to find out 3 and 921 more to find out that 850481 is
prime). This is not fast, but not particularly challenging to a modern
computer either. On my machine, factoring every number from 2 to 1,000,000
takes about 2.5 seconds, and this is far more naive than necessary because
it doesn't reuse results.

--
J.
Aug 10 '08 #6
I'm sorry, but you just don't get it, and would rather poke at me. The
purpose of this is to have something that I can use as a fun project to
learn c#. And the goal of the project is not to just come up with an answer
that work. The purpose is to see just how close I can come to the best
numbers possible, and that happens to be a lot of calculating. For the
numerator I start with 1 and increment upward to compute the optimal
denominator by rounding to the nearest whole number using a ratio of 43200 /
2551442.9 (assuming this is going to be used for a 1 Moon phase mechanism,
remember I'm going to do this for a 2 and a 4 Moon phase mechanism as well,
so bigger numbers). Then I compute the error of this ratio and continue with
anything that's within +-1 second error per Moon phase. Then I compute the
prime factors for numerator and denominator, and then I compute all the
possible factors for both using the primes--making sure to throw away any
series of results that contain a number that's too small (e.g. can't have a
gear with 2 teeth) or too large (e.g. anything beyond 2500 would be larger
than a typical wall). And then save this long result set as long as it's a
unique key.

What's interesting is that although the rounded integer of 43200/2551442.9
is optimal and will produce the best error ratio for that particular
numerator, as the numerator increases I can adjust the denominator slightly
up and down away from optimal and still come within my 1 second error
range... and sometimes 1 or 2 away from optimal produces numbers that
provide great gear ratios that mesh well with each other, and many times
something slightly away from optimal will still beat out a number that was
optimal from a smaller numerator. And once I have my set of unique keys I
need to use the same number of gears and pinions and so that means that I
need to have the same number of factors for both the numerator and
denominator, and so that throws away lots of number... and you wouldn't know
that you can throw them away or not unless you've already calculated all the
factors to discover if they will work together or not. And then the final
check is to make sure that the gears and pinions can be matched up so that
they will provide even wear (e.g. matching an 8 tooth pinion with a 20 tooth
gear would not give even wear)... and so I have to disagree with your
opinion. I'm optimizing at obtaining my ratios, I'm optimizing in my prime
calcs and factorization. There no single magic bullet math formula that's
going to give me my answer. If I'm going to go through the trouble of doing
this, then I should do it right, and I learn c# in the process.

"Jeroen Mostert" <jm******@xs4all.nlwrote in message
news:48*********************@news.xs4all.nl...
Mark Main wrote:
>It ends up being trillions of calculations, but the part that checks for
uniqueness will probably in the millions and the final results will be
in the thousands. I'm doing lots of factorization of prime numbers

Factorization *into* primes, surely. Factoring primes is trivial. :-)
>to compute the best gear ratios to use for unusual wooden clock designs
that use rather large gears and also a large number of small gears; the
standard clock gearing is easy, but these clocks will also show phases of
the Moon and the approximation of this is a fun project. I'm looking at
all ratios that have an error of 1 second or less per Moon Phase.

I take a series of prime numbers (typically about 2 to 10 of them) and
factor every combination and then check for all kinds of things to weed
out the junk; e.g. the resulting gear size would be too large or small,
the gear and pinion teeth would not have even wear with each other,
ect.). So, for example, the series of prime numbers 2*2*3*11 have the
following unique combinations of factors:

2*2*3*11
2*6*11
2*3*22
2*2*33
6*22
4*33
132
This definitely sounds like you're using a brute force approach where a
more clever one would work as well -- and even if you're using a brute
force approach, I'm fairly sure your current approach is more brute than
necessary. :-)
>I need to write a routine that will be very fast at factoring as well,
but it's still going to be lots of number crunching because there's
2551442.9 seconds in an average Moon Phase and I may decide to have 2 or
4 Moon phase devices, which means that I need to compare ratios that work
for 5102886 seconds and 10205772 seconds.
That's going to be a tough nut to crack, because 2551443 is 3 * 850481.
I'd go with 2551444, which is 2 * 2 * 7 * 293 * 311. 10205772 is harder,
because 10205771 = 761 * 13411 and 10205773 = 79 * 129187. A pure
ratio-based approach wouldn't work very well here. You could probably use
it to get the "wrong" numbers and another circuit to do corrections (or
some form of addition), but I'm no expert on mechanical clocks.
>If you or anyone here knows of a great factorization routine, I'd love to
see it, because I've got tons of factoring that I'll be doing.
Your numbers aren't that large, and they're most likely composite. This
means trial division, while horribly naive, is still likely to give
acceptable results. For example, factoring 2551443 by trial division takes
923 divisions (2 to find out 3 and 921 more to find out that 850481 is
prime). This is not fast, but not particularly challenging to a modern
computer either. On my machine, factoring every number from 2 to 1,000,000
takes about 2.5 seconds, and this is far more naive than necessary because
it doesn't reuse results.

--
J.
---- Posted via Pronews.com - Premium Corporate Usenet News Provider ----
http://www.pronews.com offers corporate packages that have access to 100,000+ newsgroups
Aug 10 '08 #7
Mark Main wrote:
I'm sorry, but you just don't get it,
That's entirely possible.
and would rather poke at me.
No, I've got better things to do. If my suggestions are useless or
irrelevant, I'm sorry. I think the confusion is caused by me interpreting
"factorization" as "unique prime factorization", when you meant "all
possible factorizations". I had no idea what you could be needing that for.
The purpose of this is to have something that I can use as a fun project
to learn c#. And the goal of the project is not to just come up with an
answer that work.
I'm doing this in my spare time as well. That's why I'm not content
answering your question directly. That would be "just coming up with an
answer that works" for *me*. I'm trying to understand what sort of situation
would lead you to use a container with 200-byte keys requiring trillions of
lookups, because I'd expect very few problems to require this. I wouldn't
optimize this approach until I had confirmed that it needed optimizing,
because it's likely to demand a lot of time and effort that would have
yielded much more return on investment if they'd been spent elsewhere.

Think of it this way. If someone said "I need a way to transport one
trillion pebbles from Bloomington, Indiana to Paris, France, on a bicycle,
in the fastest way possible" I wouldn't immediately come up with ways to do
this, I would first ask "why?". You can hardly blame me for that.
The purpose is to see just how close I can come to the best numbers
possible, and that happens to be a lot of calculating. For the numerator
I start with 1 and increment upward to compute the optimal denominator by
rounding to the nearest whole number using a ratio of 43200 / 2551442.9
(assuming this is going to be used for a 1 Moon phase mechanism, remember
I'm going to do this for a 2 and a 4 Moon phase mechanism as well, so
bigger numbers).
Then I compute the error of this ratio and continue with anything that's
within +-1 second error per Moon phase. Then I compute the prime factors
for numerator and denominator, and then I compute all the possible
factors for both using the primes--making sure to throw away any series
of results that contain a number that's too small (e.g. can't have a gear
with 2 teeth) or too large (e.g. anything beyond 2500 would be larger
than a typical wall). And then save this long result set as long as it's
a unique key.

What's interesting is that although the rounded integer of
43200/2551442.9 is optimal and will produce the best error ratio for
that particular numerator, as the numerator increases I can adjust the
denominator slightly up and down away from optimal and still come within
my 1 second error range... and sometimes 1 or 2 away from optimal
produces numbers that provide great gear ratios that mesh well with each
other, and many times something slightly away from optimal will still
beat out a number that was optimal from a smaller numerator.
Alright, let me see if I've understood you so far: you're computing all
integer ratios close enough to 43200 / 2551442.9 (which is 0.016931596 or
thereabouts). I'm still not quite sure what your definition of "error" (and
hence "close enough") is, though. What does "+-1 second error per Moon
phase" translate to, numerically?

You then produce all possible factorizations of numerator and denominator
and eliminate those factorizations with terms smaller than 3 or greater than
2500.
And once I have my set of unique keys I need to use the same number of
gears and pinions and so that means that I need to have the same number
of factors for both the numerator and denominator, and so that throws
away lots of number... and you wouldn't know that you can throw them away
or not unless you've already calculated all the factors to discover if
they will work together or not.
You now eliminate all ratio factorization pairs with an unequal number of
factors for numerator and denominator.

I still don't understand why you need to store them and look them up,
though. So far, it seems to me like you could produce factorization pairs
and eliminate them without looking at the other factorization pairs,
requiring no additional storage beyond that for the factorization pairs
themselves.
And then the final check is to make sure that the gears and pinions can
be matched up so that they will provide even wear (e.g. matching an 8
tooth pinion with a 20 tooth gear would not give even wear)...
And now you eliminate more pairs, but I'm not sure how. What gear/pinion
combinations give even wear, according to your definition?
and so I have to disagree with your opinion.
The only opinion I expressed was that you're probably doing more brute force
than necessary, and I'm pretty sure I'm right. I'm not *criticizing* your
approach, mind you. If it works, it works. I get my kicks out of wondering
if it could be better and I don't care about implementing it in C#, so we're
working at slightly cross purposes here.

For example: you first generate ratios, then determine the prime
factorizations of numerator and denominator. You could combine these steps
by generating numerator and denominator *from* prime products. But since you
need all factorizations anyway, you could also generate them from
non-primes. Instead of using your criteria as filters, you can use them as
generators (if numerator and denominator must have the same number of
factors, then there's no point generating any factorization pairs where
that's not the case).
I'm optimizing at obtaining my ratios, I'm optimizing in my prime calcs
and factorization.
I'm just trying to make sure we're not building the fastest, sleekest
bicycle possible for pebble transportation. Even if we manage to do that,
the solution might be unfeasibly inefficient (as in taking a few days when
we'd like to have the answer in a few minutes at most).
There no single magic bullet math formula that's going
to give me my answer.
There probably isn't, and it's not what I was going for.

--
J.
Aug 10 '08 #8
I've been doing more playing around with your code... thanks again by the
way. And I was able to tighten it up a bit with a few tweaks that exits the
loop immediately when a match is found:

public void AddIfUnique(myBigKey item)
{
bool uniqueItem= true;
int count = 0;
while (count < this.Count & uniqueItem == true)
{
int count2 = 0;
while (count2 < item.Length & uniqueItem == true)
{
if (this[count][count2] == item[count2])
{
uniqueItem = false;
}
count2++;
}
if (uniqueItem == true)
base.Add(item);
}
}
}
</code>
I would like to play around with doing an insert and keeping it sorted, but
that will be harder (and fun to do).

I was hoping to be able to do this, but it didn't work:

public void AddIfUnique(myBigKey item)
{
int index = base.BinarySearch(item);
if (index < 0)
base.Insert(~index, item);
}

It would be really slick to be able to do that! 3 lines of code.

---- Posted via Pronews.com - Premium Corporate Usenet News Provider ----
http://www.pronews.com offers corporate packages that have access to 100,000+ newsgroups
Aug 10 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
by: Shawn B. | last post by:
Greetings, I am simulating an assembly language bit rotation in C# and it works wonderfully --------- .... public uint Value; .... public uint RotateRight(byte count) {
10
by: Axel Dahmen | last post by:
Hi, I want to start a technical discussion on the fact that C# doesn't define any mathematical operators on other integral types than int. Simple things like the following just aren't possible...
17
by: Andreas Huber | last post by:
What follows is a discussion of my experience with .NET generics & the ..NET framework (as implemented in the Visual Studio 2005 Beta 1), which leads to questions as to why certain things are the...
4
by: JuLiE Dxer | last post by:
Perhaps, I skipped over learning this particular tidbit. I ran across an odd error while trying to add to ushort variables together and assigning it to a 3rd ushort variable. I get this...
3
by: Ben | last post by:
Hi There I am doing some unit testing at the moment, and the majority of the leg work involves taking two objects (expected vs actual) and verifying that their properties are equal. The objects...
14
by: Sheldon | last post by:
Hi, I have a python script that uses a C extention. I keep getting a recurring problem that causes a core dump a few lines after the C extention return data back tp python. I tried using pbd and...
22
by: Yakov | last post by:
What would be the nicest way to write the loop for all values of unsigned short (0..0xffff), usnig 'unsigned short port;' as an index ? For comparison, there is just one way to write the for(k=0;...
21
by: Bart C | last post by:
I've always had a problem knowing exactly how wide my integer variables were in C, and the little program below has increased my confusion. Run on 3 compilers on the same cpu (32-bit pentium),...
34
by: raylopez99 | last post by:
StringBuilder better and faster than string for adding many strings. Look at the below. It's amazing how much faster StringBuilder is than string. The last loop below is telling: for adding...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.