Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
08-01-2008, 04:24 PM #1
- Join Date
- May 2006
- Thanked 0 Times in 0 Posts
How can I make a hash table for my sequences?
I have the numbers 1,2,3,4,5,6 and 7 and can arrange them in any order. Thus there are 7! ways to do this meaning 5040 possibilites.
I have a program that works out whether to assign a 1 or 0 to each combination, depending on some long piece of code. To do this I currently have an array 7654321 ints long where I use arr[number], where number = the sequence, eg 1234567 and set that value to either 0 or 1. However, doing this means I have an array with 7654321 ints in it, and not 5040.
I need a nice hash function that maps each of my combinations onto a number from 1 to 5040 inclusive. Is there a nice way to do this?
PS the numbers fit nicely into base 8 - and thus base 2.
1234567 can be written as:
(001)(010)(100). . . (111)
08-07-2008, 09:54 AM #2
What have you got so far? Or we going from the start?