Algorithms, Blockchain and Cloud

Codeforces: A. Is your horseshoe on the other hoof?


The problem is from codeforces: http://www.codeforces.com/problemset/problem/228/A

The answer is to count the unique number of integers and substract from four. The SQL to the answer is:

select 4 - count(distinct `numbers`) from input

Using Python set (that automatically removes duplicated elements), the answer can be easily obtained.

#!/usr/bin/env python
print 4 - len(set(raw_input().split()))

Python supports union, disjoin, intersection operations on sets. For example,

>>> a=set([1,2,3,4])
>>> b=set([2,3,4,5])
>>> a&b
set([2, 3, 4])
>>> a-b
set([1])
>>> b-a
set([5])
>>> a|b
set([1, 2, 3, 4, 5])

–EOF (The Ultimate Computing & Technology Blog) —

182 words
Last Post: Disable Buggy Compiler Warnings Undefined Function Return for Delphi 2007
Next Post: Codeforces: A. Where do I Turn?

The Permanent URL is: Codeforces: A. Is your horseshoe on the other hoof? (AMP Version)

Exit mobile version