Text · 2654 bytes Raw Blame History
1 module large_conflict_test
2 implicit none
3 private
4
5 public :: process_array
6
7 contains
8
9 ! Version A: Bubble sort implementation
10 subroutine process_array(arr, n)
11 integer, intent(in) :: n
12 real, intent(inout) :: arr(n)
13 integer :: i, j
14 real :: temp
15 logical :: swapped
16
17 do i = 1, n-1
18 swapped = .false.
19 do j = 1, n-i
20 if (arr(j) > arr(j+1)) then
21 temp = arr(j)
22 arr(j) = arr(j+1)
23 arr(j+1) = temp
24 swapped = .true.
25 end if
26 end do
27 if (.not. swapped) exit
28 end do
29
30 ! Normalize array
31 temp = maxval(arr)
32 if (temp > 0.0) then
33 arr = arr / temp
34 end if
35
36 ! Apply transformation
37 do i = 1, n
38 arr(i) = sqrt(abs(arr(i)))
39 end do
40 ! Version B: Quicksort implementation
41 subroutine process_array(arr, n)
42 integer, intent(in) :: n
43 real, intent(inout) :: arr(n)
44
45 call quicksort(arr, 1, n)
46
47 ! Standardize array
48 real :: mean, stddev
49 mean = sum(arr) / real(n)
50 stddev = sqrt(sum((arr - mean)**2) / real(n))
51
52 if (stddev > 0.0) then
53 arr = (arr - mean) / stddev
54 end if
55
56 ! Apply logarithmic transformation
57 integer :: i
58 do i = 1, n
59 if (arr(i) > 0.0) then
60 arr(i) = log(arr(i) + 1.0)
61 else
62 arr(i) = 0.0
63 end if
64 end do
65
66 end subroutine process_array
67
68 recursive subroutine quicksort(arr, left, right)
69 real, intent(inout) :: arr(:)
70 integer, intent(in) :: left, right
71 integer :: pivot_idx
72
73 if (left < right) then
74 pivot_idx = partition(arr, left, right)
75 call quicksort(arr, left, pivot_idx - 1)
76 call quicksort(arr, pivot_idx + 1, right)
77 end if
78 end subroutine quicksort
79
80 function partition(arr, left, right) result(pivot_idx)
81 real, intent(inout) :: arr(:)
82 integer, intent(in) :: left, right
83 integer :: pivot_idx, i, j
84 real :: pivot, temp
85
86 pivot = arr(right)
87 i = left - 1
88
89 do j = left, right - 1
90 if (arr(j) <= pivot) then
91 i = i + 1
92 temp = arr(i)
93 arr(i) = arr(j)
94 arr(j) = temp
95 end if
96 end do
97
98 temp = arr(i + 1)
99 arr(i + 1) = arr(right)
100 arr(right) = temp
101 pivot_idx = i + 1
102 end function partition
103
104 end module large_conflict_test
105