I realize permutations in programming language is a very frequently asked question, however I feel like my question is sort of unique.
I have received input of a certain length integer N
and stored each digit in an array where the index of the array stores the number of times that digit occurs in N
.
now I want to test if some function holds true with all permutations of N's original length with no leading zeroes. Ex:
int[] digits = new int[10];
String n = "12345675533789025";
for (char c : n.toCharArray())
digits[c-'0']++;
for (Long f : allPermutationsOf(digits))
if (someCondition(f))
System.out.println(f);
a precondition to the following code is that N
must be less than 2^64-1, (long
's maximum value.)
The question is, how would I take all permutations of the digits array and return a Long[]
or long[]
without using some kind of String
concatenation? Is there a way to return a long[]
with all permutations of digits[]
in the "Integer scope of things" or rather using only integer arithmetic?