RosettaCodeData/Task/Anagrams/Jq/anagrams-1.jq
2017-09-25 22:28:19 +02:00

11 lines
323 B
Text

def anagrams:
(reduce .[] as $word (
{table: {}, max: 0}; # state
($word | explode | sort | implode) as $hash
| .table[$hash] += [ $word ]
| .max = ([ .max, ( .table[$hash] | length) ] | max ) ))
| .max as $max
| .table | .[] | select(length == $max) ;
# The task:
split("\n") | anagrams