Skip to content

Commit 5cf4652

Browse files
committed
refactor copeland in a more functional way
1 parent 62b2882 commit 5cf4652

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/main/scala/copeland.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@ case class CopelandResult(
88
)
99

1010
def level_of_dominance(v1: Vec, v2: Vec): Int =
11-
var lod = 0
12-
val n = v1.length
13-
for (i <- 0 until n)
14-
if (v1(i) < v2(i))
15-
lod += 1
11+
v1.zip(v2).filter((a, b) => a < b).length
1612

17-
lod
1813

1914
def dominance_scores(ordering_mat: Mat): Mat =
15+
2016
val n = ordering_mat.length
2117
Array.tabulate(n, n)((i, j) =>
2218
level_of_dominance(ordering_mat(i), ordering_mat(j))
2319
)
2420

21+
2522
def winloss_scores(dommat: Mat): Mat =
23+
2624
val n = dommat.length
2725
Array.tabulate(n, n)((i, j) => (dommat(i)(j) - dommat(j)(i)).sign)
2826

0 commit comments

Comments
 (0)