first, you spend a few hours thinking about the problem, not in terms of java or C++ or Ada, but in whatever natural language you choose.
You write down on paper or in a text document the steps you would personally take if you had to do this.
You revise those steps several times, making them clearer and more detailed.
Once that is done, you simply convert it into code, since each line should be simple enough it translates almost directly into whatever language you want to use.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

Rahul Abrol
Greenhorn

Joined: Jun 06, 2012
Posts: 4

posted

0

Bear Bibeault wrote:Where's your code? What problems are you having with it?

Please follow the link in my signature below or the one in Bear's signature above for some guidelines on how to ask questions in these forums so that you can increase the likelihood of getting an answer.

Thanks and we hope you have a wonderful experience in our community.

Rahul Abrol wrote:I found this program on net but unable to understand...

I wouldn't bother trying...that not the best way to learn.

A permutation means a re-arrangement of the 'things'. if you have a number like 123, you have three things: the digit '1', the digit '2', and the digit '3'. and you have correctly identified all the possible permutations of that in your prior post.

How does one do this? As I explained above, you start by thinking about it and writing it down in English (or whatever). There is no code at first. I would start like this:

1) get the number
2) pick it apart into pieces
3) print all permutations.

So now I have three slightly simpler problems. All three need to be solved, but also note that all three are independent of one another. So, I'd focus on part 1, and refine it into steps:

1a) prompt the user for input
1b) read value in
1c) validate data (i.e. error if they input something with non-digits).

Ok..so 1a and 1b are pretty straightforward (well, 1b may be a little tricky if you've never done any code, but 1a is covered in just about every book on page 1). So i'd now revise 1c - or possibly decide that I don't care about validation and cross it off.

you do this for each and every step. break down part 2 into pieces, then revise again. Then start on part 3.

Work on that, post what you get, and we'll be happy to help some more.

How about starting with a 2 digit permutation to write your code, that I think would be easy and then you can add more digits and see how that works.

So if you have two digits 12 then your permutations would be "12","21".

Just out of curiosity and not depriving you of the pleasure of your homework, I came across this URL - List Permuation Algorithm

You could possibly use the weaving concept they are talking about.

To give a better understanding of permutation, I recommend Khan Academy. The stuff on wiki is freaky.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39884

28

posted

0

Abdulla S Mamuwala wrote: . . .
How about starting with a 2 digit permutation to write your code, . . . then you can add more digits and see how that works. . . .

I bet this could be solved without resorting to String manipulation; just using plain arithmetic operations and recursion. Probably not for beginners but surely not that difficult of a challenge... any takers?

Junilu Lacar wrote: I bet this could be solved without resorting to String manipulation; just using plain arithmetic operations and recursion. Probably not for beginners but surely not that difficult of a challenge... any takers?

It might be possible, but it would also be bad-faith code. The task is to rearrange the digits, and our code should express that with maximum clarity. Using arithmetic to accomplish the rearrangement would be adding an unnecessary and confusing layer that would serve to conceal the actual intent.

Dennis Deems wrote:...our code should express that with maximum clarity. Using arithmetic to accomplish the rearrangement would be adding an unnecessary and confusing layer that would serve to conceal the actual intent.