-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRowWeights.java
More file actions
31 lines (25 loc) · 796 Bytes
/
RowWeights.java
File metadata and controls
31 lines (25 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.smlnskgmail.jaman.codewarsjava.kyu7;
import java.util.stream.IntStream;
// https://www.codewars.com/kata/5abd66a5ccfd1130b30000a9
public class RowWeights {
private final int[] weights;
public RowWeights(int[] weights) {
this.weights = weights;
}
public int[] solution() {
int firstTeamScores = IntStream
.range(0, weights.length)
.filter(i -> i % 2 == 0)
.map(i -> weights[i])
.sum();
int secondTeamScores = IntStream
.range(0, weights.length)
.filter(i -> i % 2 != 0)
.map(i -> weights[i])
.sum();
return new int[]{
firstTeamScores,
secondTeamScores
};
}
}