Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Registered User
    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)

  • #2
    Regular Coder borntoslow's Avatar
    Join Date
    Aug 2008
    Thanked 9 Times in 9 Posts
    What have you got so far? Or we going from the start?


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts