Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9091797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:41:44+00:00 2026-06-16T22:41:44+00:00

I read this post which is quite close to the problem I’m having, but

  • 0

I read this post which is quite close to the problem I’m having, but couldn’t generalize it.
I’m trying to solve the Traveling Sales Person by searching all paths using multiple CPU’s.
What I need, is a way to encode a path prefix to integer and distribute it to each CPU so it would know what paths it’s supposed to scan.
For example, if the number of cities is 10 one possible 3-prefix (suppose prefix length is fixed and known) is 4-10-3 (there are 10*9*8 prefixes), so the CPU which would receive it, would search all paths that begin with 4-10-3.
Since the number of cities is quite large, I can’t compute n! thus I can’t use the post above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:41:45+00:00Added an answer on June 16, 2026 at 10:41 pm

    The standard representation of a permutation as a number uses Lehmer codes represented in the factorial number system. The idea is that every permutation of n elements can be mapped to a sequence of n numbers, the first of which is in the range 0 to (n – 1), the second of which is in the range 0 to (n – 2), etc. This sequence of numbers can then be represented as a single integer in the factorial number system.

    I believe that it should be possible to adapt this trick to work with prefixes of permutations rather than entire permutations. Suppose that you have n elements and want to choose a permutation of k of them. To do this, start off by computing the Lehmer code for the partial permutation. Instead of getting a sequence of n numbers, you’ll get back a sequence of k numbers. For example, given the partial permutation c a d drawn from a b c d e f g, your Lehmer code would be found as follows:

    • c is the second (zero-indexed) element of a b c d e f g
    • a is the zeroth (zero-indexed) element of a b d e f g
    • d is the first (zero-indexed) element of b d e f g

    So the Lehmer code would be (2, 0, 1).

    Once you have this Lehmer code, you can try to encode it as a single integer. To do this, you can use a modified factorial number system encoding. Specifically, you can try doing the following. If you have n elements and want a permutation of k of them, then there will be a total of (n – k + 1) possible choices for the very last element. There are a total of (n – k + 2) possible choices for the second-to-last element, (n – k + 3) possible choices for the third-to-last element, etc. Consequently, you could take your Lehmer code and do the following:

    1. Keep the final digit unchanged.
    2. Multiply the second-to-last element by (n – k + 1).
    3. Multiply the third-to-last element by (n – k + 1)(n – k + 2)
      4 …
    4. Multiply the first element by (n – k + 1)(n – k + 2)…(n – 1)
    5. Sum up these values.

    This produces a unique integer code for the permutation.

    For example, our Lehmer code was (2, 0, 1), n = 7, and k = 3. Therefore, we’d compute

    1 + 0 × (7 – 3 + 1) + 2 × (7 – 3 + 2)(7 – 3 + 3)

    = 1 + 2 × (5 × 6)

    = 5 + 2 × 30

    = 61

    To invert this process, you can take the integer and run it backwards through this procedure to recover the partial Lehmer code. To do this, start off by taking the number and dividing by (n – k + 1)(n – k + 2)…(n – 1) to get back the very first digit of the Lehmer code. Then, mod the number by (n – k + 1)(n – k + 2)…(n – 1) to drop off the first digit. Then, divide the number by (n – k + 1)(n – k + 2)…(n – 2) to get back the second digit of the Lehmer code, then mod by (n – k + 1)(n – k + 2)…(n – 2) to drop off the second digit. Repeat this until all the digits of the Lehmer code have been reconstructed.

    For example, given prefix 61, n = 7, and k = 3, we would start off by dividing 61 by 7 × 6 = 30. This gives 2, remainder 1. Thus the first digit of the Lehmer code is 2. Modding by 30, we get back the number 1. Next, we divide by 6. This gives 0, remainder 1. Thus the second digit is 0. Finally, we read off the remaining number, which gives the last digit of the Lehmer code, 1. We have recovered our Lehmer code (2, 0, 1), from which we can easily reconstruct the permutation.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario Having already read a post on this on the same site, which didn't
I've read every post about this issue, but nothing solved the problem. I'll be
I read this post but I can't get it working: Change Background Color... I
I've read this post: ( NSDateFormatter leak question ) which states that NSDateFormatter leaks
I read this post , but I cannot figure out how to make what
So I've read this post But it doesn't seem to deal with the issue
I read this post where the author advices to store session files in a
Okay so I read this post http://facebook.stackoverflow.com/questions/10373897/deleting-a-previosly-posted-article-with-opengraph-or-check-if-said-article-has but I'm using the news.reads action type.
I was reading about buffer, stack and heap overflows. I read this post as
On this post , I read about the usage of XMPP. Is this sort

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.