Calculate unique value for any word

This is a discussion on Calculate unique value for any word within the General AI Programming forums, part of the Cprogramming.com and AIHorizon.com's Artificial Intelligence Boards category; Has anyone written an algorithm that can calculate a unique value for any word. Let's say the word "Today" will ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    Calculate unique value for any word

    Has anyone written an algorithm that can calculate a unique value for any word. Let's say the word "Today" will produce 109283773, then this number will always reflect the word Today. Please note that I am not looking for a dictionary like or database of values, but for an algorithm or a formula etc...

    Thanks,

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,663
    How many words?
    What range of numbers?

    For example, if you've got 1000 words, and you want a unique number in the range 0 to 999, then I would suggest you use a std::map< std::string, int >
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User lattica's Avatar
    Join Date
    Aug 2008
    Location
    Spacelike Hyperplane
    Posts
    16
    Alternatively, you could think of the string as a number in base 26 then convert to base 10 and back in the usual ways. Of course, this limits the allowed length of words, e.g., for uint32 the limit is 6 but does allow around 300 million strings.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading text-and-numbers file word by word
    By bored_guy in forum C Programming
    Replies: 22
    Last Post: 10-26-2009, 10:59 PM
  2. please help with binary tree, urgent.
    By slickestting in forum C Programming
    Replies: 2
    Last Post: 07-22-2007, 07:55 PM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  4. Passing structures to a function
    By earth_angel in forum C++ Programming
    Replies: 5
    Last Post: 07-13-2005, 06:13 AM
  5. Clueless about linked list
    By killerasp in forum C++ Programming
    Replies: 4
    Last Post: 02-14-2002, 10:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21