Hello, tell me what are the methods for enumerating all the combination of characters.
I have such a line.
“ABC1abc”
I want to get this as a result
Abc
ABC
CBA
C1A
BC1
…
Are you looking for:
julia> s = "ABC1abc"
"ABC1abc"
julia> join.(Iterators.product(s,s,s))
7×7×7 Array{String,3}:
[:, :, 1] =
"AAA" "ABA" "ACA" "A1A" "AaA" "AbA" "AcA"
"BAA" "BBA" "BCA" "B1A" "BaA" "BbA" "BcA"
"CAA" "CBA" "CCA" "C1A" "CaA" "CbA" "CcA"
"1AA" "1BA" "1CA" "11A" "1aA" "1bA" "1cA"
"aAA" "aBA" "aCA" "a1A" "aaA" "abA" "acA"
"bAA" "bBA" "bCA" "b1A" "baA" "bbA" "bcA"
"cAA" "cBA" "cCA" "c1A" "caA" "cbA" "ccA"
[:, :, 2] =
"AAB" "ABB" "ACB" "A1B" "AaB" "AbB" "AcB"
"BAB" "BBB" "BCB" "B1B" "BaB" "BbB" "BcB"
"CAB" "CBB" "CCB" "C1B" "CaB" "CbB" "CcB"
"1AB" "1BB" "1CB" "11B" "1aB" "1bB" "1cB"
"aAB" "aBB" "aCB" "a1B" "aaB" "abB" "acB"
"bAB" "bBB" "bCB" "b1B" "baB" "bbB" "bcB"
"cAB" "cBB" "cCB" "c1B" "caB" "cbB" "ccB"
[:, :, 3] =
"AAC" "ABC" "ACC" "A1C" "AaC" "AbC" "AcC"
"BAC" "BBC" "BCC" "B1C" "BaC" "BbC" "BcC"
"CAC" "CBC" "CCC" "C1C" "CaC" "CbC" "CcC"
"1AC" "1BC" "1CC" "11C" "1aC" "1bC" "1cC"
"aAC" "aBC" "aCC" "a1C" "aaC" "abC" "acC"
"bAC" "bBC" "bCC" "b1C" "baC" "bbC" "bcC"
"cAC" "cBC" "cCC" "c1C" "caC" "cbC" "ccC"
[:, :, 4] =
"AA1" "AB1" "AC1" "A11" "Aa1" "Ab1" "Ac1"
"BA1" "BB1" "BC1" "B11" "Ba1" "Bb1" "Bc1"
"CA1" "CB1" "CC1" "C11" "Ca1" "Cb1" "Cc1"
"1A1" "1B1" "1C1" "111" "1a1" "1b1" "1c1"
"aA1" "aB1" "aC1" "a11" "aa1" "ab1" "ac1"
"bA1" "bB1" "bC1" "b11" "ba1" "bb1" "bc1"
"cA1" "cB1" "cC1" "c11" "ca1" "cb1" "cc1"
[:, :, 5] =
"AAa" "ABa" "ACa" "A1a" "Aaa" "Aba" "Aca"
"BAa" "BBa" "BCa" "B1a" "Baa" "Bba" "Bca"
"CAa" "CBa" "CCa" "C1a" "Caa" "Cba" "Cca"
"1Aa" "1Ba" "1Ca" "11a" "1aa" "1ba" "1ca"
"aAa" "aBa" "aCa" "a1a" "aaa" "aba" "aca"
"bAa" "bBa" "bCa" "b1a" "baa" "bba" "bca"
"cAa" "cBa" "cCa" "c1a" "caa" "cba" "cca"
[:, :, 6] =
"AAb" "ABb" "ACb" "A1b" "Aab" "Abb" "Acb"
"BAb" "BBb" "BCb" "B1b" "Bab" "Bbb" "Bcb"
"CAb" "CBb" "CCb" "C1b" "Cab" "Cbb" "Ccb"
"1Ab" "1Bb" "1Cb" "11b" "1ab" "1bb" "1cb"
"aAb" "aBb" "aCb" "a1b" "aab" "abb" "acb"
"bAb" "bBb" "bCb" "b1b" "bab" "bbb" "bcb"
"cAb" "cBb" "cCb" "c1b" "cab" "cbb" "ccb"
[:, :, 7] =
"AAc" "ABc" "ACc" "A1c" "Aac" "Abc" "Acc"
"BAc" "BBc" "BCc" "B1c" "Bac" "Bbc" "Bcc"
"CAc" "CBc" "CCc" "C1c" "Cac" "Cbc" "Ccc"
"1Ac" "1Bc" "1Cc" "11c" "1ac" "1bc" "1cc"
"aAc" "aBc" "aCc" "a1c" "aac" "abc" "acc"
"bAc" "bBc" "bCc" "b1c" "bac" "bbc" "bcc"
"cAc" "cBc" "cCc" "c1c" "cac" "cbc" "ccc"
2 Likes
Please tell me how to combine this array into one one-dimensional? To get this:Array{String,1}
vec
Thank you!
You can also use the GitHub - JuliaMath/Combinatorics.jl: A combinatorics library for Julia package, which has a function combinations
for iterating combinations.
julia> using Combinatorics
julia> [join(x) for x in combinations("ABC1abc", 3)]
35-element Array{String,1}:
"ABC"
"AB1"
"ABa"
"ABb"
"ABc"
"AC1"
⋮
"Cbc"
"1ab"
"1ac"
"1bc"
"abc"
3 Likes
Thanks for the feedback. I think your decision suits me better