puts "AABBCC".scan(/\w/).permutation(6).to_a.uniq.map{|x| x.join}.sort
Standard input is empty
AABBCC AABCBC AABCCB AACBBC AACBCB AACCBB ABABCC ABACBC ABACCB ABBACC ABBCAC ABBCCA ABCABC ABCACB ABCBAC ABCBCA ABCCAB ABCCBA ACABBC ACABCB ACACBB ACBABC ACBACB ACBBAC ACBBCA ACBCAB ACBCBA ACCABB ACCBAB ACCBBA BAABCC BAACBC BAACCB BABACC BABCAC BABCCA BACABC BACACB BACBAC BACBCA BACCAB BACCBA BBAACC BBACAC BBACCA BBCAAC BBCACA BBCCAA BCAABC BCAACB BCABAC BCABCA BCACAB BCACBA BCBAAC BCBACA BCBCAA BCCAAB BCCABA BCCBAA CAABBC CAABCB CAACBB CABABC CABACB CABBAC CABBCA CABCAB CABCBA CACABB CACBAB CACBBA CBAABC CBAACB CBABAC CBABCA CBACAB CBACBA CBBAAC CBBACA CBBCAA CBCAAB CBCABA CBCBAA CCAABB CCABAB CCABBA CCBAAB CCBABA CCBBAA