Fortran Fortran 90 & elements array comparaison

AI Thread Summary
To efficiently identify the redundant element in a fixed-size array of four elements, one suggested method is to sort the array in numerical order, which allows for easy detection of duplicates due to their consecutive positioning. Another approach involves a brute force comparison of pairs, as only six comparisons are needed among the four elements. This method simplifies the process of finding the duplicate and allows for the construction of a new array with the remaining unique elements.
aihaike
Messages
52
Reaction score
0
Dear all,

I'm trying to figure about an efficient way to to get the redundant element in my array.
For instance, let's take the array [0,2,3,0].
I'd like to get out [2,0,3] (or 3,0,2 it doesn't matter).
So it find out which element is duplicated, an puts its value in between the 2 other elements.
The size of my initial array is always 4 and the final one always 3.
The duplicated element can have any index.
It's look very simple, and it certainly is, but I can not figure.
Some help would be very helpful.
Thanks in advance,

Eric.
 
Technology news on Phys.org
First sort the array in numerical order, using any of a number of sorting methods. Then it's easy to find duplicates because they're in consecutive positions.

(added) Ah, now I see that you always start with four elements. In that case you could even do it by brute force because you need to compare only six pairs of elements:

#1 with #2
#1 with #3
#1 with #4
#2 with #3
#2 with #4
#3 with #4
 
I'll try that, thanks!
 
yes!
you're right, i'll go that way.
Thans again
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.

Similar threads

Back
Top