Java generate all possible permutations of a String
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Should be faster (generates way above million outputs per second), and at least it's definitely more pleasant to read: final long count = 36L * 36L * 36L * 36L * 36L * 36L * 36L * 36L;
for (long i = 0; i < count; ++i) {
String name = StringUtils.leftPad(Long.toString(i, 36), 8, '0');
}
final int MAX = 36;
final long count = 1L * MAX * MAX * MAX * MAX * MAX * MAX * MAX * MAX * MAX * MAX;
final char[] alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
final int[] digits = new int[8];
final char[] output = "00000000".toCharArray();
for (long i = 0; i < count; ++i) {
final String name = String.valueOf(output);
// "increment"
for (int d = 7; d >= 0; d) {
digits[d] = (digits[d] + 1) % MAX;
output[d] = alphabet[digits[d]];
if (digits[d] > 0) {
break;
}
}
}

Generate different permutations/combinations in a string
Tag : regex , By : Harry Truman
Date : March 29 2020, 07:55 AM
I hope this helps you . I am given a string (eg "12345678"). I want to generate different combinations using +,,*,/. Like : , this is one way to achieve this: from itertools import product
numbers = "123456"
for operators in product('+*/', repeat=len(numbers)1):
ret = numbers[0]
for op, n in zip(operators, numbers[1:]):
ret += op+n
print(ret)
from itertools import product, zip_longest, chain
numbers = "123456"
operators = '+*/'
for ops in product(operators, repeat=len(numbers)1):
print(''.join(chain(*zip_longest(numbers, ops, fillvalue=''))))

How to generate unique string from number which lies in range of quantity of characters ' permutations in this string?
Date : March 29 2020, 07:55 AM
I wish this helpful for you You could treat the number as a base 62 number, and fill in the string "digits" (base62 bits) accordingly. Let's see how we do this with the decimal number 1234 in different bases. note that division below is always integer division (fractional parts are chopped off). 1234 / 10^3 = 1, 1234 mod 10^3 = 234
234 / 10^2 = 2, 234 mod 10^2 = 34
34 / 10^1 = 3, 34 mod 10^1 = 4
4 / 10^0 = 4, 4 mod 10^0 = 0
Thus we represent this number in base10 as "1234"
1234 / 16^2 = 4, 1234 mod 16^2 = 210
210 / 16^1 = d, 210 mod 16^1 = 2
2 / 16^0 = 2, 2 mod 16^0 = 0
Thus we represent this number in base16 as "4d2"
1234 / 62^1 = j, 1234 mod 62^1 = 56
56 / 62^0 = U, 56 mod 62^0 = 0
Thus we represent this number in base62 as "jU"

Generate all possible well ordered string permutations
Tag : python , By : Adrian Codrington
Date : March 29 2020, 07:55 AM
around this issue Recursion works great here. Pick a starting letter and only iterate from remaining letters, recursing on both upper and lower case and bumping the start letter up along the way. The base case is when the length of the string we're building is the same as the target length. Exponential time complexity. def all_alphabetical_pw(length, start=65, pw=""):
if len(pw) == length:
yield pw
else:
for i in range(start, 91):
yield from all_alphabetical_pw(length, i + 1, pw + chr(i))
yield from all_alphabetical_pw(length, i + 1, pw + chr(i).lower())
if __name__ == "__main__":
pws = list(all_alphabetical_pw(4))
print(len(pws), "\n")
for pw in pws[:10]:
print(pw)
print("...")
for pw in pws[10:]:
print(pw)
239200
ABCD
ABCd
ABCE
ABCe
ABCF
ABCf
ABCG
ABCg
ABCH
ABCh
...
WxyZ
Wxyz
wXYZ
wXYz
wXyZ
wXyz
wxYZ
wxYz
wxyZ
wxyz

Generate all permutations of a given String in D
Date : March 29 2020, 07:55 AM

