Fortran 90 & elements array comparaison

Click For Summary

Discussion Overview

The discussion revolves around finding an efficient method to identify and extract a redundant element from a fixed-size array in Fortran 90. Participants explore different approaches to achieve this goal, focusing on an array of four elements and the desired output of three elements.

Discussion Character

  • Exploratory, Technical explanation, Homework-related

Main Points Raised

  • One participant, Eric, seeks assistance in removing a duplicate element from an array of four elements, resulting in an array of three elements.
  • Another participant suggests sorting the array to easily identify duplicates, noting that duplicates will appear in consecutive positions after sorting.
  • A further suggestion is made to use a brute force method to compare pairs of elements, given the limited number of comparisons required with a fixed-size array.
  • Subsequent replies indicate agreement with the proposed methods, with participants expressing intent to try the suggested approaches.

Areas of Agreement / Disagreement

Participants generally agree on the proposed methods for identifying the redundant element, with no significant disagreement noted in the responses.

Contextual Notes

The discussion assumes a fixed array size of four elements and does not address potential edge cases or variations in input beyond this constraint.

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
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 17 ·
Replies
17
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 19 ·
Replies
19
Views
7K
  • · Replies 7 ·
Replies
7
Views
3K
Replies
20
Views
2K
Replies
235
Views
15K