954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to eliminate number

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++

shamila08
Junior Poster in Training
51 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

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.

littlestone
Light Poster
42 posts since Mar 2008
Reputation Points: 14
Solved Threads: 6
 
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.

shamila08
Junior Poster in Training
51 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

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.

littlestone
Light Poster
42 posts since Mar 2008
Reputation Points: 14
Solved Threads: 6
 

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

l4z3r
Newbie Poster
18 posts since Aug 2008
Reputation Points: 10
Solved Threads: 1
 

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

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 
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[code=cplusplus]
void shift(int *x, int i, int j)
{
int t;
t = x[i];
x[i] = x[j];
x[j] = t;
}
[code]

shamila08
Junior Poster in Training
51 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 
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.

shamila08
Junior Poster in Training
51 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You