Skip to content

Instantly share code, notes, and snippets.

@fwrq41251
Created November 9, 2016 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fwrq41251/88a71c4fa80c7c4ab2b5aaa3aa8e0d25 to your computer and use it in GitHub Desktop.
Save fwrq41251/88a71c4fa80c7c4ab2b5aaa3aa8e0d25 to your computer and use it in GitHub Desktop.
SICP exercise 2.40.
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