Tag: Programming

NCSS Python Golf

Posted by on January 3, 2010

It is time again for me to run a Python Golf challenge… The aim? To write a python program that solves a problem in the least number of bytes (of source code).

The first of a few problems is:

Given a list of words on stdin (one per line), find the words that have the largest number of anagrams in that list.

Print all of the words that have the meet the criteria of having the largest number anagrams (One per line, in alphabetical order).

This competition has now finished. The winner was Nick Cooper at 103 bytes, with the following awesome solution:

import sys
s=sorted
o=s(sys.stdin)
r=map(s,o)
d=map(r.count,r)
for e,t in zip(o,d):print e*(max(d)==t),

Input:
caret
crate
react
trace
ester
reset
steer
terse
organ
groan

Output:
caret
crate
ester
react
reset
steer
terse
trace