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 1053017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:11:10+00:00 2026-05-16T17:11:10+00:00

Here a couple of examples in a pseudocode to show what I mean. This

  • 0

Here a couple of examples in a pseudocode to show what I mean.

This produces the combinations (selections disregarding order without repetition) of 1,…,n taking 3 at a time.

Do[Print[i,j,k], {i,1...n-2}, {j,i+1...n-1}, {k,j+1...n}]

The loop works from left to right—for each i, the iterator j will go through its values and for each j, the iterator k will go through its. By adding more variables and changing n, we can generalize what we have above.

Question: can we do the same for permutations? In other words, can we find a way to tweak the iterators to produce the P(n,k)=n!/(p-k)! permutations of 1,…,n? For k=3,

Do[Print[i,j,k], {i, f_1 , g_1(i,n)}, {j, f_2(i), g_2(i,j,n)}, {k, f_3(i,j), g_3(i,j,k,n)}]

Use only basic arithmetic operations and things like modular arithmetic, floor/ceiling fcns.

Because this might smell like a homework problem to you, I’d settle on an answer of “yay” or “nay”; your estimate of the difficulty level would be helpful to me as well.

Thank you.

  • 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-05-16T17:11:11+00:00Added an answer on May 16, 2026 at 5:11 pm

    Do you mean generating permutations iteratively, without recursion? Yes, it’s possible:

    http://en.wikipedia.org/wiki/Permutation

    See the section “Algorithms to generate permutations”

    1. Find the largest index k such that a[k] < a[k + 1]. If no such index exists, the permutation is the last permutation.
    2. Find the largest index l such that a[k] < a[l]. Since k + 1 is such an index, l is well defined and satisfies k < l.
    3. Swap a[k] with a[l].
    4. Reverse the sequence from a[k + 1] up to and including the final element a[n].
    

    This follows your restriction to only use basic arithmetic operations (if you don’t like the swap, know that you can swap two numbers by using additions and subtractions).

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

Sidebar

Related Questions

I have been here for a couple of months learning python from examples, but
I've tried to follow a few examples from here and a couple other resources
I have a couple of other questions on here surrounding this area but they
Here's an example of what I'm trying to figure out. I have a couple
Here's the problem: I have couple of pages which gets its content from a
Firstly here is my ruby and rails version with a couple of the important
I've looked at a couple of similar questions here but I still can's seem
I've read up on couple of questions here on SO about passing data between
I've seen a couple of SQLite performance questions here on Stackoverflow, but the focus
I have seen a couple of question regarding creating datasets in DbUnit here on

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.