3
\$\begingroup\$

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"]
\$\endgroup\$
7
  • 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
    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
    Feb 17, 2020 at 14:33
  • \$\begingroup\$ This needs an objective winning criterion, such as "smallest number of bytes wins" \$\endgroup\$
    – wastl
    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
    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\$ Feb 17, 2020 at 22:22

7 Answers 7

3
\$\begingroup\$

05AB1E, 6 bytes

.¡{}éθ

Try it online!

.¡ }      # 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
\$\endgroup\$
2
\$\begingroup\$

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)

Try it online

\$\endgroup\$
1
  • 1
    \$\begingroup\$ What the fuck I'm actually intimidated now \$\endgroup\$ Feb 18, 2020 at 15:36
1
\$\begingroup\$

Japt -h, 6 5 bytes

üñ ñl

Try it

üñ ñl     :Implicit input of array
ü         :Sort & group by
 ñ        :  Sorted strings
   ñ      :Sort by
    l     :  Length
          :Implicit output of last element
\$\endgroup\$
1
\$\begingroup\$

Perl 6, 36 bytes

{max .classify(~*.comb.sort){*}||''}

Try it online!

Output an empty string for an empty input. If we could output something else, for example -Inf, then this could be:

Perl 6, 31 bytes

*.classify(~*.comb.sort){*}.max

Try it online!

\$\endgroup\$
1
\$\begingroup\$

J, 19 bytes

0({>\:#&>)/:~&></.]

Try it online!

-2 bytes thanks to FrownyFrog

Similar approach to Grimmy's answer.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Bring { into the () and you don't need [: \$\endgroup\$
    – FrownyFrog
    Feb 18, 2020 at 18:33
  • \$\begingroup\$ Very nice, thank you @FrownyFrog \$\endgroup\$
    – Jonah
    Feb 18, 2020 at 18:37
1
\$\begingroup\$

Python 2, 79 77 bytes

lambda A,S=sorted:A and max([[y for y in A if S(x)==S(y)]for x in A],key=len)

Try it online!

2 bytes thx to wilkben.

The A and... is only required to deal with the empty input.

\$\endgroup\$
1
  • \$\begingroup\$ 77 bytes \$\endgroup\$
    – wilkben
    Feb 18, 2020 at 20:50
0
\$\begingroup\$

Clojure, 54 bytes

#(some val(sort-by(comp count val)>(group-by sort %)))

Returns nil for empty input.

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.