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"]
xnor
149k26 gold badges286 silver badges673 bronze badges
asked Feb 17, 2020 at 14:19
\$\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\$ Commented 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\$ Commented Feb 17, 2020 at 14:33
  • \$\begingroup\$ This needs an objective winning criterion, such as "smallest number of bytes wins" \$\endgroup\$ Commented 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\$ Commented 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\$ Commented 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
answered Feb 17, 2020 at 14:32
\$\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

answered Feb 18, 2020 at 14:37
\$\endgroup\$
1
  • 1
    \$\begingroup\$ What the fuck I'm actually intimidated now \$\endgroup\$ Commented 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
answered Feb 17, 2020 at 18:54
\$\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!

answered Feb 17, 2020 at 23:58
\$\endgroup\$
1
\$\begingroup\$

J, 19 bytes

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

Try it online!

-2 bytes thanks to FrownyFrog

Similar approach to Grimmy's answer.

answered Feb 18, 2020 at 6:41
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Bring { into the () and you don't need [: \$\endgroup\$ Commented Feb 18, 2020 at 18:33
  • \$\begingroup\$ Very nice, thank you @FrownyFrog \$\endgroup\$ Commented 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.

answered Feb 18, 2020 at 3:10
\$\endgroup\$
1
  • \$\begingroup\$ 77 bytes \$\endgroup\$ Commented 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!

answered Feb 18, 2020 at 14:09
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.