Print the biggest-size subset of strings in the input that are all permutations of each other. If there are ties, any one will do. If no strings are permutations of each other (for example, only one string was given or the strings contain distinct characters), this is just one of the strings. If no strings were passed in , do not output anything or output an empty list.
Test cases:
Input => Output
["ABCDE", "EDBCA", "XYZ", "ZYX", "ZXY"] => ["XYZ", "ZYX", "ZXY"]
["A"] => ["A"]
-
1\$\begingroup\$ Is that an example of just input or are the outputs also in that same line? Can you include clear examples of expected output, with at least two test cases? \$\endgroup\$640KB– 640KB2020年02月17日 14:30:02 +00:00Commented Feb 17, 2020 at 14:30
-
\$\begingroup\$ To make this a challenge suitable for CGCC is not enough to just translate the old Russian SO question. \$\endgroup\$manatwork– manatwork2020年02月17日 14:33:40 +00:00Commented Feb 17, 2020 at 14:33
-
\$\begingroup\$ This needs an objective winning criterion, such as "smallest number of bytes wins" \$\endgroup\$wastl– wastl2020年02月17日 17:23:19 +00:00Commented Feb 17, 2020 at 17:23
-
3\$\begingroup\$ @close voters: please don’t close code-golf questions for not having an objective primary winning criterion. If it’s code-golf, the winning criterion is "fewest bytes of source code wins". \$\endgroup\$Grimmy– Grimmy2020年02月17日 21:27:28 +00:00Commented Feb 17, 2020 at 21:27
-
\$\begingroup\$ I've voted to reopen, presuming that the only problem was that the winning criterion was inadvertently omitted -- although it's clear because of the code-golf tag. (If there's some other issue, please post it, of course.) \$\endgroup\$Mitchell Spector– Mitchell Spector2020年02月17日 22:22:40 +00:00Commented Feb 17, 2020 at 22:22
7 Answers 7
05AB1E, 6 bytes
.¡{}éθ
.¡ } # group the input strings by:
{ # sort (all permutations of each other will be identical when sorted)
é # sort the groups by length
θ # output the last (longest) group
T-SQL, 267 bytes
SQL queries was totally made to solve this type of question
SELECT top 1WITH TIES x FROM(SELECT(SELECT a FROM(SELECT
top 999substring(x,number+1,1)a,*FROM
@,spt_values WHERE type='P'and number<len(x)ORDER BY a)c
WHERE x=t.x for xml path(''),type).value('.','char(9)')v,x FROM @ t)z
ORDER BY-count(*)over(PARTITION BY v),-len(x)
-
1\$\begingroup\$ What the fuck I'm actually intimidated now \$\endgroup\$Realitätsverlust– Realitätsverlust2020年02月18日 15:36:29 +00:00Commented Feb 18, 2020 at 15:36
-
1\$\begingroup\$ Bring
{
into the () and you don't need [: \$\endgroup\$FrownyFrog– FrownyFrog2020年02月18日 18:33:54 +00:00Commented Feb 18, 2020 at 18:33 -
\$\begingroup\$ Very nice, thank you @FrownyFrog \$\endgroup\$Jonah– Jonah2020年02月18日 18:37:37 +00:00Commented Feb 18, 2020 at 18:37
Clojure, 54 bytes
#(some val(sort-by(comp count val)>(group-by sort %)))
Returns nil
for empty input.