Advancedkill

08-01-2008, 04:24 PM

Hi

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?

Thanks

PS the numbers fit nicely into base 8 - and thus base 2.

1234567 can be written as:

(001)(010)(100). . . (111)

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?

Thanks

PS the numbers fit nicely into base 8 - and thus base 2.

1234567 can be written as:

(001)(010)(100). . . (111)