Created
February 28, 2018 23:06
-
-
Save erssebaggala/65850966f5d46e9dfef172949750976a to your computer and use it in GitHub Desktop.
Hash_Code_Pizza_Practice_2018_Try_02.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
input_file = sys.argv[1] | |
def get_all_factors(n): | |
factors = [] | |
for i in range(1,n+1): | |
if n%i == 0: | |
factors.append(i) | |
return factors | |
R = 0 | |
C = 0 | |
L = 0 | |
H = 0 | |
(r,c) = (0,0) | |
pizza = [] | |
slices = [] | |
areas = range(2,7,1) | |
masks = [] | |
with open(input_file, "r") as f: | |
data = f.readlines() | |
line_count = 0 | |
for line in data: | |
line_count += 1 | |
words = line.split() | |
if line_count == 1: | |
(R,C,L,H) = map( lambda x: int(x), words) | |
continue | |
pizza.append( list(line.rstrip()) ) | |
# print pizza | |
# print( "R:{} C:{} L:{} H:{}".format(R,C,L,H) ) | |
# print pizza[ len(pizza)-1 ] | |
continue_checking = True | |
# for area in range(H,2*L-1,-1): | |
for area in [H]: | |
factors_of_area = [H] | |
for f in factors_of_area: | |
rows = f | |
cols = area / f | |
rr = cc = 0 | |
for r in range(0,R,rows): | |
for c in range(0,C,cols): | |
# print("r: {} c:{} ".format(r, c)) | |
num_of_tomatoes = 0 | |
num_of_mushrooms = 0 | |
# Go over the mask | |
for r_i in range(r, r + rows, 1): | |
for c_i in range(c, c + cols, 1): | |
if r_i >= R or c_i >= C : break | |
(rr, cc) = (r_i, c_i) | |
# print("r_i: {} c_i:{} ".format(r_i, c_i)) | |
if pizza[r_i][c_i] == 'T': | |
num_of_tomatoes += 1 | |
else: | |
num_of_mushrooms += 1 | |
if num_of_tomatoes >= L and num_of_mushrooms >= L: | |
# print("r:{} c:{} rr:{} cc:{} R:{} C:{}".format(r,c,rr,cc,R,C)) | |
slices.append((r, c, rr, cc)) | |
# for p in pizza: print p | |
print ("{}".format(len(slices))) | |
for s in slices: | |
print("{} {} {} {}".format(s[0],s[1],s[2], s[3])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment