Hi all....

i have problem with number:
example:
1234 is equivalent to 1432 ( based on maths concept), then erase/delete 1432
2143 is equivalent to 2341, then erase/ delete 2341, and so on

How to program it in C++

Which container do you use to store the number? vector? list?
if you use list, you can use the unique(op) function to eliminate the duplicate number. the op is a function or a functional object used to predicate whether two number is equivalent.

Which container do you use to store the number? vector? list?
if you use list, you can use the unique(op) function to eliminate the duplicate number. the op is a function or a functional object used to predicate whether two number is equivalent.

thanks. here example on what i use.

void equiv(int *x,  int start, int n)
{
  write(x, n);
  if (start < n) {
    int i, j;
    for (i = n-2; i > start; i--) {
      for (j = i + 1; j <n; ++j) {
	shift(x, i, j);
	equiv(x, i, n);
      } 
      shiftleft(x, i, n);
    } }}

sorry i 'm not familiar about op function. could you give some example based on my code here?
the output is same as before.

I did not understand your algorithm for predicate whether two number are equivalent.
I think at least the equivalent function should return a bool value.

i'm sort of getting the idea, shamila. If you would post the shift() function, i think I might be able to help.

You aren't talking about sofic shifts, are you? If so, how are you representing your graphs?

i'm sort of getting the idea, shamila. If you would post the shift() function, i think I might be able to help.

to I4Z3r: here my shift function

void shift(int *x, int i, int j)
{
  int t;
  t = x[i];
  x[i] = x[j];
  x[j] = t;
} 

Edited 3 Years Ago by mike_2000_17: Fixed formatting

You aren't talking about sofic shifts, are you? If so, how are you representing your graphs?

yes, it's refer to how array the number. not a complicated one. example from my output as follows :
1234
1243
1423
1432.
but i dont want all this four because there is equivalent among them.
for example 1234 ==1432. i have to delete 1432.

This article has been dead for over six months. Start a new discussion instead.