Skip to content

Instantly share code, notes, and snippets.

@magicleon94
Created May 9, 2017 18:07
Show Gist options
  • Save magicleon94/72d9d6aa902dedb45206f80cdb095288 to your computer and use it in GitHub Desktop.
Save magicleon94/72d9d6aa902dedb45206f80cdb095288 to your computer and use it in GitHub Desktop.
solution to the first quiz of the hacker rank challenge for booking.com job applying
# Enter your code here. Read input from STDIN. Print output to STDOUT
import sys
def isSquare(sides):
if len(sides)!=4:
return False
if sides[0]==sides[1] and sides[2]==sides[3] and sides[1]==sides[2]:
return True
return False
def isRectangle(sides):
if len(sides)!=4:
return False
if sides[0]==sides[2] and sides[1]==sides[3]:
return True
return False
def countPolys(inputs):
squares = 0
rectangles = 0
others = 0
for poly in inputs:
for i in range(len(poly)):
poly[i] = int(poly[i])
if sum(x<0 for x in poly)>0:
others += 1
continue
if isSquare(poly):
squares += 1
continue
if isRectangle(poly):
rectangles += 1
continue
others += 1
return squares,rectangles,others
text_input = sys.stdin.read()
inputs = [ x.split(' ') for x in text_input.split('\n')]
s,r,o = countPolys(inputs)
print s,r,o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment