Created
November 9, 2016 03:13
-
-
Save fwrq41251/88a71c4fa80c7c4ab2b5aaa3aa8e0d25 to your computer and use it in GitHub Desktop.
SICP exercise 2.40.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.mutable.ListBuffer | |
/** | |
* Created by User on 11/9/2016. | |
*/ | |
object UniquePairs { | |
def uniquePairs(n: Int): List[List[Int]] = { | |
(1 to n).flatMap(i => (1 until i).map(j => List(i, j))).toList | |
} | |
def main(args: Array[String]): Unit = { | |
println(uniquePairs(5).mkString("\n")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment