Skip to content

Instantly share code, notes, and snippets.

View searope's full-sized avatar

Sea Rope searope

View GitHub Profile
@searope
searope / gist:cb6742acaa0b17a844f00d208f4071e7
Created July 14, 2017 17:59 — forked from istepura/gist:9222616
Generating permutations of arr in lexicographic order in C#
public IEnumerable<int[]> Permut(int[] arr){
while (true){
yield return arr;
var j = arr.Length - 2;
while (j >= 0 && arr[j] >= arr[j+1]) j--;
if (j < 0) break;
var l = arr.Length -1;
while (arr[j] >= arr[l]) l--;
@searope
searope / gist:34e787b49683d9ee725a3f7c07f944c3
Created July 14, 2017 17:59 — forked from istepura/gist:9222616
Generating permutations of arr in lexicographic order in C#
public IEnumerable<int[]> Permut(int[] arr){
while (true){
yield return arr;
var j = arr.Length - 2;
while (j >= 0 && arr[j] >= arr[j+1]) j--;
if (j < 0) break;
var l = arr.Length -1;
while (arr[j] >= arr[l]) l--;