Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def listWithoutRepetitions(s: Int, used: List[Int], available: List[Int], acc: List[List[Int]]): List[List[Int]] = {
- if (s == 0) used :: acc else
- if (s < 0 || available.isEmpty) acc
- else available match {
- case d :: ds => {
- val left = listWithoutRepetitions(s, used, ds, acc)
- listWithoutRepetitions(s-d, d :: used, ds, left)
- }
- }
- } //> listWithoutRepetitions: (s: Int, used: List[Int], available: List[Int], acc
- //| : List[List[Int]])List[List[Int]]
- countWithoutRepetitions(10, List(1, 2, 3, 5)) //> res1: Int = 1
- listWithoutRepetitions(10, List(), List(1, 2, 3, 5), Nil : List[List[Int]])
- The problem is that I am getting empty list in the output always, in addition to the items collected. Assignment https://class.coursera.org/progfun-004/assignment/view?assignment_id=17 misteriously says "Note that the anagram of the empty sentence is the empty sentence itself." I do not know what does it mean.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement