8000 Add hints on how the pair functions work · AbdulRehman56/AdventOfCode-Java@6245496 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6245496

Browse files
committed
Add hints on how the pair functions work
1 parent 2afe0a8 commit 6245496

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/main/java/com/sbaars/adventofcode/util/AoCUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,22 @@ public static <A> Stream<Pair<A, A>> connectedPairs(Stream<A> l) {
6666
}).filter(p -> p.a() != null);
6767
}
6868

69+
// [A,B,C] -> [(A,B), (B,C)]
6970
public static <A> Stream<Pair<A, A>> connectedPairs(List<A> l) {
7071
return range(1, l.size()).mapToObj(i -> pair(l.get(i - 1), l.get(i)));
7172
}
7273

74+
// [A,B,C] -> [(A,B)]
7375
public static <A> Stream<Pair<A, A>> pairs(List<A> l) {
7476
return range(0, l.size() / 2).mapToObj(i -> new Pair<>(l.get(i * 2), l.get(i * 2 + 1)));
7577
}
7678

79+
// [A,B,C] -> [(A,B), (A,C), (B,C)]
7780
public static <A> Stream<Pair<A, A>> allPairs(List<A> l) {
7881
return range(0, l.size()).boxed().flatMap(i -> range(i + 1, l.size()).mapToObj(j -> new Pair<>(l.get(i), l.get(j))));
7982
}
8083

84+
// [A,B,C] [D,E,F] -> [(A,D), (A,E), (A,F), (B,D), (B,E), (B,F), (C,D), (C,E), (C,F)]
8185
public static <A, B> Stream<Pair<A, B>> allPairs(List<A> l1, List<B> l2) {
8286
return range(0, l1.size()).boxed().flatMap(i -> l2.stream().map(b -> new Pair<>(l1.get(i), b)));
8387
}

0 commit comments

Comments
 (0)
0