Skip to content

Commit 1f74cdb

Browse files
committed
p26 stub
1 parent f802d30 commit 1f74cdb

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// references:
2+
// 1. http://aperiodic.net/phil/scala/s-99/p26.scala
3+
4+
package problems.p26
5+
6+
object P26 {
7+
8+
def main(args: Array[String]): Unit = {
9+
}
10+
11+
def combinations[A](k: Int, ls: List[A]): List[List[A]] = ???
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# P26. Generate the combinations of K distinct objects chosen from the N elements of a list.
2+
3+
In how many ways can a committee of 3 be chosen from a group of 12 people? We all know that there are C(12,3) = 220 possibilities (C(N,K) denotes the well-known binomial coefficient). For pure mathematicians, this result may be great. But we want to really generate all the possibilities.
4+
5+
## Example
6+
7+
``` scala
8+
scala> combinations(3, List('a, 'b, 'c, 'd, 'e, 'f))
9+
res0: List[List[Symbol]] = List(List('a, 'b, 'c), List('a, 'b, 'd), List('a, 'b, 'e), ...
10+
```

0 commit comments

Comments
 (0)