Code golf: find all anagrams

后端 未结 8 2137
再見小時候
再見小時候 2021-02-04 06:00

A word is an anagram if the letters in that word can be re-arranged to form a different word.

Task:

  • The shortest source code by character count to find

8条回答
  •  再見小時候
    2021-02-04 06:15

    AWK - 119

    {split(toupper($1),a,"");asort(a);s="";for(i=1;a[i];)s=a[i++]s;x[s]=x[s]$1" "}
    END{for(i in x)if(x[i]~/ .* /)print x[i]}
    

    AWK does not have a join function like Python, or it could have been shorter...

    It assumes uppercase and lowercase as different.

提交回复
热议问题