Skip to content

Commit a745eb3

Browse files
committed
fixed median calculation
1 parent a3c3a9c commit a745eb3

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/hsutils/BAMParser.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,24 @@ public Integer getMedianAmplificationLevel(Integer[] inArr) {
229229

230230
Integer freqSum = inList.stream().mapToInt(e -> e).sum();
231231

232-
Integer middleVal = freqSum / 2;
232+
Integer freqByLevel[] = new Integer[inArr.length];
233+
int count = 1;
234+
for (int i = 0; i < inList.size(); i++) {
235+
freqByLevel[i] = count * inList.get(i);
236+
count++;
237+
}
238+
Integer freqByLevelSum = sum(freqByLevel);
239+
240+
Integer middleVal = freqByLevelSum / 2;
233241
Integer cumSum = 0, median = 0;
234-
235-
for (int i = 0; i < inArr.length; i++) {
242+
System.out.println(freqByLevelSum+" "+middleVal);
243+
for (int i = 0; i < freqByLevel.length; i++) {
236244
if (cumSum > middleVal) {
245+
System.out.println(cumSum);
237246
break;
238247
}
239-
cumSum += inArr[i];
248+
System.out.println(cumSum);
249+
cumSum += freqByLevel[i];
240250
median++;
241251
}
242252

280 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)