Re: Calculate Last Digits
- From: "Robert Morley" <rmorley@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 20 Oct 2007 17:36:55 -0400
Okay, I think I get it now...you're counting each of the last digits, and checking for similarity/difference between them, so in my
original example (1 12 23 34 45 46), the last digits would be:
1 2 3 4 5 6
....which in your system is all different, so 111111. And just to be sure I'm understanding:
1 11 12 22 33 44
....would correspond to 221100 (2 one's, 2 two's, 1 three, 1 four, and the 0's for padding). Is that correct?
In terms of counting each digit, the best way I can think of is to set up an array from 0 to 9 and count each of the 6 digits, then
use a sort on the array (removing the 0's first so you're only sorting on what's left). A shell sort might work well here...I'm a
little rusty on my sorting algorithms, but it seems like that SHOULD be quick for something like this.
Another possibility that might end up working well is instead of an array, use a 10-digit string to count instead, then remove the
0's when you're done and sort the remainder. I think that would end up being slower in the long run, but might be worth a look.
Finally, you may want to consider optimizing the routine to only count each digit AS it changes. Not sure if there's a good way to
do that, but you might be able to save a considerable amount of time if you're not re-counting every last digit every time.
Rob
.
- References:
- Calculate Last Digits
- From: Paul Black
- Re: Calculate Last Digits
- From: Robert Morley
- Calculate Last Digits
- Prev by Date: Re: VB6 LISTBOX problem
- Next by Date: Re: Calculate Last Digits
- Previous by thread: Re: Calculate Last Digits
- Next by thread: Re: Calculate Last Digits
- Index(es):
Relevant Pages
|