Skip to content

Instantly share code, notes, and snippets.

@DiveInto
Created September 15, 2013 14:39
Show Gist options
  • Save DiveInto/6571329 to your computer and use it in GitHub Desktop.
Save DiveInto/6571329 to your computer and use it in GitHub Desktop.

Revisions

  1. DiveInto created this gist Sep 15, 2013.
    18 changes: 18 additions & 0 deletions permutations.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    object per extends App{
    def permutations(str: String):List[String] = {
    if(str.size == 0)
    List("")
    else{
    val res = {
    for{c <- str
    per <- permutations(str.replaceFirst(c.toString, ""))
    }yield c + per
    }
    ▫▫
    res.toList
    }
    }

    val res = permutations("abc")
    res.foreach(println)
    }