Created
March 2, 2018 19:23
-
-
Save anonymous/3e2fe1aa8f3f0cdccebbae2aa4ef12d7 to your computer and use it in GitHub Desktop.
Snippet from https://play.nim-lang.org
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 algorithm, sequtils | |
proc permutations(v: seq[int]): seq[seq[int]] = | |
let nbMaxPerms = toSeq(1..v.len).foldr(a * b) # nb permutations max = (len v)! | |
result = @[v] | |
var temp = v | |
for cpt in 1..<nbMaxPerms: | |
temp.nextPermutation() | |
result.add(temp) | |
var v = toSeq(1..5) | |
echo permutations(v) | |
echo v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment