$10K coding deathmatch

Jonathan Ellis jonathan at carnageblender.com
Thu Nov 2 11:13:34 MST 2006


On Thu, 2 Nov 2006 04:57:41 -0500, "Barry Roberts" <blr at robertsr.us>
said:
> I'm still a python novice, but I thouhgt it would be fun to post a
> python solution just for discussion.

Your python reference appears to be about 5 years old. :)

Here's a translation that uses some newer features.  Untested, YMMV.

import sys

for line in sys.stdin:
    nums = [int(item) for item in line.strip().split()]
    numset = set(nums)
    for i, item in enumerate(nums[:-1]):
        diff = abs(item - nums[i + 1])
        if diff in numset:
            print "match"
        else:
            print "not a match"
            break
-- 
C++ is history repeated as tragedy. Java is history repeated as farce.  --Scott McKay




More information about the PLUG mailing list