New answers tagged

2

Perl 5, 170 168 bytes sub f{($a,$b,$e)=map[uniq(/./g)],@_;%n=map{($_,0)}@$b;%s=map{$c=$$b[rand@$b];$e+=/$c/;$n{$c}++;($_,$c)}@$a;@v=values%n;max(@v)-min(@v)>1||$e?f(@_):$_[0]=~s,.,$s{$&},gr} Try it online! With spaces, newlines, my's, comments and a small test script added: sub f{ my($a,$b,$e)=map[uniq(/./g)],@_; #$a and $b are now arrayrefs to ...


6

JavaScript (Node.js),  160  159 bytes I/O format: matrix of 24-bit integers. Takes input as (a)(b). a=>F=b=>(g=a=>[...new Set(a.flat())].sort(_=>Math.random()-.5))(a).every((c,i)=>c^=F[c]=B[i%B.length],B=g(b).slice(-g(a).length))?a.map(r=>r.map(c=>F[c])):F(b) Try it online! Commented Helper function The helper function \$...


11

Mathematica, 116 chars, 118 bytes Mathematica's ColorReplacep[] function paired with DominantColors[] is really good at this sort of problem. n=DominantColors;ColorReplace[#1,#1->#2&@@@({##})&[n@#1,Flatten[RandomSample@Permutations@n@#2][[;;Length@n@#1]]]]& Also, mathematica has built in bitmaps for all countries if you install the ...


Top 50 recent answers are included