Charcoal, 6970 bytes
WS⟦ι⟧FKAF¬Noυι⊞υι≔υθ≔⟦⟧ηWSFιF¬Noηκ⊞ηκW⊙υ=κ§θλ«≔⟦⟧θFη⊞θ‽Φη¬Noθλ»UMKA§θ⌕υιWS⟦ι⟧WΦKA¬Noυκ⊞υ‽ι≔υθ≔⟦⟧ηWSFιF¬Noηκ⊞ηκW⊙υ=κ§θλ«≔⟦⟧θWΦη¬Noθλ⊞θ‽κ»UMKA§θ⌕υι
Try it online! Try it online! Link is to verbose version of code. Takes input as character arrays, where different characters represent different colours. For the link I've rendered two flags in ASCII art. Explanation:
WS⟦ι⟧
Input and print the first character array.
FKAF¬Noυι⊞υιWΦKA¬Noυκ⊞υ‽ι
ExtractRandomly extract the distinct characters into a list.
≔υθ
Make a temporary copy of the list. This copy will be replaced by a shuffle of the transliteration characters.
≔⟦⟧η
Create a second list. (The first list was automatically predefined by Charcoal.)
WSFιF¬Noηκ⊞ηκ
Input the second character array and extract the unique characters to the second list.
W⊙υ=κ§θλ«
Repeat while at least one character in the first list maps to a character in the second list. The mapping is cyclic, so that once all of the colours run out, they are reused again in the same order, thus ensuring that no colour is used an unbalanced number of times.
≔⟦⟧θFη⊞θ‽Φη¬Noθλ≔⟦⟧θWΦη¬Noθλ⊞θ‽κ
Shuffle the unique characters from the second list.
»UMKA§θ⌕υι
Once a distinct shuffle has been found, transliterate the whole canvas from the first to the second list.
Charcoal, 69 bytes
WS⟦ι⟧FKAF¬Noυι⊞υι≔υθ≔⟦⟧ηWSFιF¬Noηκ⊞ηκW⊙υ=κ§θλ«≔⟦⟧θFη⊞θ‽Φη¬Noθλ»UMKA§θ⌕υι
Try it online! Link is to verbose version of code. Takes input as character arrays, where different characters represent different colours. For the link I've rendered two flags in ASCII art. Explanation:
WS⟦ι⟧
Input and print the first character array.
FKAF¬Noυι⊞υι
Extract the distinct characters into a list.
≔υθ
Make a temporary copy of the list. This copy will be replaced by the transliteration characters.
≔⟦⟧η
Create a second list. (The first list was automatically predefined by Charcoal.)
WSFιF¬Noηκ⊞ηκ
Input the second character array and extract the unique characters to the second list.
W⊙υ=κ§θλ«
Repeat while at least one character in the first list maps to a character in the second list. The mapping is cyclic, so that once all of the colours run out, they are reused again in the same order, thus ensuring that no colour is used an unbalanced number of times.
≔⟦⟧θFη⊞θ‽Φη¬Noθλ
Shuffle the unique characters from the second list.
»UMKA§θ⌕υι
Once a distinct shuffle has been found, transliterate the whole canvas from the first to the second list.
Charcoal, 70 bytes
WS⟦ι⟧WΦKA¬Noυκ⊞υ‽ι≔υθ≔⟦⟧ηWSFιF¬Noηκ⊞ηκW⊙υ=κ§θλ«≔⟦⟧θWΦη¬Noθλ⊞θ‽κ»UMKA§θ⌕υι
Try it online! Link is to verbose version of code. Takes input as character arrays, where different characters represent different colours. For the link I've rendered two flags in ASCII art. Explanation:
WS⟦ι⟧
Input and print the first character array.
WΦKA¬Noυκ⊞υ‽ι
Randomly extract the distinct characters into a list.
≔υθ
Make a temporary copy of the list. This copy will be replaced by a shuffle of the transliteration characters.
≔⟦⟧η
Create a second list. (The first list was automatically predefined by Charcoal.)
WSFιF¬Noηκ⊞ηκ
Input the second character array and extract the unique characters to the second list.
W⊙υ=κ§θλ«
Repeat while at least one character in the first list maps to a character in the second list. The mapping is cyclic, so that once all of the colours run out, they are reused again in the same order, thus ensuring that no colour is used an unbalanced number of times.
≔⟦⟧θWΦη¬Noθλ⊞θ‽κ
Shuffle the unique characters from the second list.
»UMKA§θ⌕υι
Once a distinct shuffle has been found, transliterate the whole canvas from the first to the second list.
Charcoal, 69 bytes
WS⟦ι⟧FKAF¬Noυι⊞υι≔υθ≔⟦⟧ηWSFιF¬Noηκ⊞ηκW⊙υ=κ§θλ«≔⟦⟧θFη⊞θ‽Φη¬Noθλ»UMKA§θ⌕υι
Try it online! Link is to verbose version of code. Takes input as character arrays, where different characters represent different colours. For the link I've rendered two flags in ASCII art. Explanation:
WS⟦ι⟧
Input and print the first character array.
FKAF¬Noυι⊞υι
Extract the distinct characters into a list.
≔υθ
Make a temporary copy of the list. This copy will be replaced by the transliteration characters.
≔⟦⟧η
Create a second list. (The first list was automatically predefined by Charcoal.)
WSFιF¬Noηκ⊞ηκ
Input the second character array and extract the unique characters to the second list.
W⊙υ=κ§θλ«
Repeat while at least one character in the first list maps to a character in the second list. The mapping is cyclic, so that once all of the colours run out, they are reused again in the same order, thus ensuring that no colour is used an unbalanced number of times.
≔⟦⟧θFη⊞θ‽Φη¬Noθλ
Shuffle the unique characters from the second list.
»UMKA§θ⌕υι
Once a distinct shuffle has been found, transliterate the whole canvas from the first to the second list.