decrementing arrays

R

Richard

Keith Thompson said:
Bill Cunningham said:
Wow. I think Richard says later in the thread that this kind of code is
dazzling and it is. Maybe something simple like the permutations of 1234.
That can be done by hand but how does C do it is the question.
[...]

You keep talking about "permutations". Are you sure that's the right
word? To be blunt, are you sure you know what the word means?

There are 24 permutations of 1234. Here they are:

1234 1243 1324 1342 1423 1432
2134 2143 2314 2341 2413 2431
3124 3142 3214 3241 3412 3421
4123 4132 4213 4231 4312 4321

(I did these manually, so there may be some errors.)

There are two important things to note. First, there are N! (N
factorial) permutations of N items; 4! is 24. Second, the definining
characteristic of each permutation is that no item is repeated.

You've been asking about 16 digits, with 10 possible values for each
digit. Given that description, there can be *no* permutations.

I've been able to figure out that you want to do *something* that
involves 16-digit decimal numbers (similar to credit card numbers).
I'm not sure whether you want to generate them randomly, generate all
possible numbers, or something else. I have no idea whether you want
to print each one as it's generated, or store them all, or do
something else.

Numerous people have spent considerable time and effort trying to help
you, based on *guesses* about what you're asking for. Throughout
this, you have been unable or unwilling to tell us just what you're
trying to do.

You have been wasting your time and ours.

Tell us what you want to do, and we'll try to help you do it.
Otherwise, I'm done.

He most certainly does not want to "randomly" generate all possible
numbers since that is just 0 to 16^10-1 anyway.

I suspect what he wanted was something completely different in order to
play with pointers and malloc.

On the other hand he might just wanted to have stored a single credit
card number.

Who knows? He most certainly doesn't. And as I, rather sagely if I say
so myself, pointed out people like Santosh throwing (uncommented) code
at an ill defined problem did nothing whatsoever to help anybody - least
of all Bill.
 
B

Bill Cunningham

Richard said:
Keith Thompson said:
Bill Cunningham said:
Wow. I think Richard says later in the thread that this kind of code
is
dazzling and it is. Maybe something simple like the permutations of
1234.
That can be done by hand but how does C do it is the question.
[...]

You keep talking about "permutations". Are you sure that's the right
word? To be blunt, are you sure you know what the word means?

Yes all the possibilities of changing the numbers or letters around.

Bill
 
K

Keith Thompson

Bill Cunningham said:
Richard said:
Keith Thompson said:
[...]
Wow. I think Richard says later in the thread that this kind of code
is
dazzling and it is. Maybe something simple like the permutations of
1234.
That can be done by hand but how does C do it is the question.
[...]

You keep talking about "permutations". Are you sure that's the right
word? To be blunt, are you sure you know what the word means?

Yes all the possibilities of changing the numbers or letters around.

Ok, now that we've established that you know what permutations are,
what do you want to do with them?

What do permutations have to do with 16-digit credit card numbers?

In a permutation, no elements can be repeated. In a 16-digit decimal
number, some of the digits *must* be repeated.

What you have asked about so far makes no sense as far as I can tell.

What are you trying to do? Either explain it to us in plain English,
showing a sample of the output you want to produce, or give it up and
find something else to do.

I'm still (barely) willing to help you if I can. But I am unwilling
to guess what you're trying to accomplish. I still don't think you're
a deliberate troll, but I'm willing to change my mind.
 
B

Bill Cunningham

There are 24 permutations of 1234. Here they are:

1234 1243 1324 1342 1423 1432
2134 2143 2314 2341 2413 2431
3124 3142 3214 3241 3412 3421
4123 4132 4213 4231 4312 4321

(I did these manually, so there may be some errors.)

There are two important things to note. First, there are N! (N
factorial) permutations of N items; 4! is 24. Second, the definining
characteristic of each permutation is that no item is repeated.
[snip]

Yes Keith that is what I want. I am looking closely at how to iterate in C.
Forget the 16 numbers I was looking for all the possibilities of.
What algorithm could be used in C to work with permutations of 4 digits.
And this learning experience is to learn the C not the permutations as such.
Would you use for for this ? You did it by hand.

Bill
 
K

Keith Thompson

Bill Cunningham said:
There are 24 permutations of 1234. Here they are:

1234 1243 1324 1342 1423 1432
2134 2143 2314 2341 2413 2431
3124 3142 3214 3241 3412 3421
4123 4132 4213 4231 4312 4321

(I did these manually, so there may be some errors.)

There are two important things to note. First, there are N! (N
factorial) permutations of N items; 4! is 24. Second, the definining
characteristic of each permutation is that no item is repeated.
[snip]

Yes Keith that is what I want. I am looking closely at how to iterate in C.
Forget the 16 numbers I was looking for all the possibilities of.
What algorithm could be used in C to work with permutations of 4 digits.
And this learning experience is to learn the C not the permutations as such.
Would you use for for this ? You did it by hand.

Ok. Since you continued posting in the same thread, I naturally
assumed you were still talking about the same problem, involving
16-digit numbers.

So, ignoring the collossal waste of time leading up to this ...

You want to "work with" permutations. What exactly does that mean?

Do you want to generate these permutations? Print them? Store them
in an array? Something else?

You still need to define the problem you're trying to solve.

And what have you tried?
 
B

Bill Cunningham

Ok. Since you continued posting in the same thread, I naturally
assumed you were still talking about the same problem, involving
16-digit numbers.

So, ignoring the collossal waste of time leading up to this ...

You want to "work with" permutations. What exactly does that mean?

Do you want to generate these permutations? Print them? Store them
in an array? Something else?

You still need to define the problem you're trying to solve.

And what have you tried?

Print to bash's stdout. Like normal output. Print to buffer also. The
math in C is what I don't know how to do. I am assuming you are speaking of
lowest factor of 24. How did you arrive that there were 24 permutations in
1234? I understand what permutations are but it's just a tool to learn C
code. I can't seem to get using malloc either so maybe permutations sent to
someplace in memory might help.

Bill
 
B

Bill Cunningham

When I spoke of the 16 digit numbers on cards it was because I was
interested how many possible different numbers there were with that base.

I think simple permutations will teach me more about C.

Bill
 
B

Bill Cunningham

The recursive nature of the problem is now obvious.

Use recursion huh. Well that's a new algorithm to me and I heard of it.
Heard that's all. I wonder if malloc can be used here.

Bill
 
K

Keith Thompson

Bill Cunningham said:
When I spoke of the 16 digit numbers on cards it was because I was
interested how many possible different numbers there were with that base.

There are 10000000000000000 possible 16-digit decimal numbers (which has
very little to do with C).

[...]
 
K

Keith Thompson

Bill Cunningham said:
The recursive nature of the problem is now obvious.

In most of your followups, quoted text is properly prefixed with "> ".
In this one, it isn't. Whatever you did this time, please don't do it
again.
Use recursion huh. Well that's a new algorithm to me and I heard of it.
Heard that's all. I wonder if malloc can be used here.

*Why* do you wonder if malloc can be used here? What makes you think
malloc is relevant to the problem?
 
B

Bill Cunningham

*Why* do you wonder if malloc can be used here? What makes you think
malloc is relevant to the problem?
In so far as I have read. malloc can be used like an array or buffer
instead of using an array.

Bill
 
B

Barry Schwarz

The recursive nature of the problem is now obvious.

Use recursion huh. Well that's a new algorithm to me and I heard of it.
Heard that's all. I wonder if malloc can be used here.

Use malloc for what?

Have you been listening at all to what the people are telling you?
Don't go running around writing code and calling functions until you
decide what you want to do.

Tell us: WHAT DO YOU WANT TO DO?


Remove del for email
 
R

Richard Bos

Bill Cunningham said:
How did you arrive that there were 24 permutations in 1234?
I understand what permutations are

These two statements are contradictory.

Richard
 
R

Richard

Richard Heathfield said:
Bill Cunningham said:


Permutations are easy, although it doesn't seem like it at first.

We start with the simple idea that 1 item only has one permutation.

To get all the permutations of N items (for N > 1), we can divide them into
N groups, with each group starting with a different item. For example, if
N=4 (e.g. we are permuting the letters A, B, C and D), we need four
groups. The first group consists of all those permutations that start with
A. The second consists of all those permutations that start with B, and so
on.

For each group, you now have one of its members positioned, and another N-1
items yet to place. You must permute all of those N-1 items.

To get all the permutations of N-1 items (for N-1 > 1), we can divide them
into N-1 groups, with each group starting with a different item. For
example, if N=3 (e.g. we are permuting the letters B, C and D), we need
three groups. The first group consists of all those permutations that
start with B. The second consists of all those permutations that start
with C, and so on.

For each group, you now have one of its members positioned, and another N-2
items yet to place. You must permute all of those N-2 items. And so on.

The recursive nature of the problem is now obvious.

*snigger*

Yup, that's really going to help Bill understand about loops in C. The
final line is a classic!
 
B

blmblm

Then why not try some other topic to learn C? Maybe an "address book",
that was requested in an other thread.

This strikes me as, in a way, more sensible advice than the
attempts to get the OP to define his requirements precisely:

Not saying that it's not important to define requirements --
it is! -- but I get the sense that the OP is just looking for
a problem that appeals to him and will teach him something
about a current topic of interest (which according to his
original post was something about multidimensional arrays,
pointers, and initialization).

So maybe suggestions about interesting practice problems,
such as the one made above by Santosh, would be helpful?
and such problems are probably readily available in most(?)
books purporting to teach C?

My two cents' worth.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top