Finding all possible case permutations in Python [duplicate]

def all_casings(input_string): if not input_string: yield “” else: first = input_string[:1] if first.lower() == first.upper(): for sub_casing in all_casings(input_string[1:]): yield first + sub_casing else: for sub_casing in all_casings(input_string[1:]): yield first.lower() + sub_casing yield first.upper() + sub_casing >>> [x for x in all_casings(“foo”)] [‘foo’, ‘Foo’, ‘fOo’, ‘FOo’, ‘foO’, ‘FoO’, ‘fOO’, ‘FOO’] >>> list(all_casings(“foo”)) [‘foo’, ‘Foo’, ‘fOo’, … Read more

Code to enumerate permutations in Scala

Given a Seq, one can already have permutations by invoking the permutations method. scala> List(1,2,3).permutations.mkString(“\n”) res3: String = List(1, 2, 3) List(1, 3, 2) List(2, 1, 3) List(2, 3, 1) List(3, 1, 2) List(3, 2, 1) Furthermore there is also a method for combinations: scala> List(1,2,3).combinations(2).mkString(“\n”) res4: String = List(1, 2) List(1, 3) List(2, 3) … Read more

Finding all permutations of array elements as concatenated strings

A fun problem! I wanted to implement using generators. This allows you to work with the permutations one-by-one as they are generated, rather than having to compute all permutations before the entire answer is provided – const input = [“🔴”,”🟢”,”🔵”,”🟡”] for (const p of permutations(input)) console.log(p.join(“”)) 🔴🟢🔵🟡 🟢🔴🔵🟡 🟢🔵🔴🟡 🟢🔵🟡🔴 🔴🔵🟢🟡 🔵🔴🟢🟡 🔵🟢🔴🟡 🔵🟢🟡🔴 🔴🔵🟡🟢 … Read more

Permutation algorithm for array of integers in Java

//Here is a recursive version that was not to hard to commit to human memory ! O(n!) permutations. public static Set<Integer[]> getPermutationsRecursive(Integer[] num){ if (num == null) return null; Set<Integer[]> perms = new HashSet<>(); //base case if (num.length == 0){ perms.add(new Integer[0]); return perms; } //shave off first int then get sub perms on remaining … Read more

How to list all permutations without repetition?

The limitations described below are because of lambda functions. The first solution can be successfully implemented without lambda: =ARRAYFORMULA(QUERY(BASE(SEQUENCE(PERMUTATIONA(7,7)),7,7),”where not Col1 matches ‘.*((“&JOIN(“)|(“,SEQUENCE(7,1,0)&”.*”&SEQUENCE(7,1,0))&”)).*'”,0)) The trick here is to use regex to find unique elements using query…match. The only problem with this is memory size needed will exceed 10 million for 8 items PERMUTATIONA(8,8). But that … Read more