-
-
Save RameshAditya/522ab1e283a636dcc7f746187498ce75 to your computer and use it in GitHub Desktop.
My Google Hash Code submission
This file contains 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
files = ['a_example.txt', 'b_lovely_landscapes.txt', 'c_memorable_moments.txt','d_pet_pictures.txt', 'e_shiny_selfies.txt'] | |
ct = 0 | |
for file in files: | |
ct += 1 | |
f = open(file, 'r') | |
from collections import defaultdict as dd | |
adj = dd(list) | |
words = dd(list) | |
data = f.readlines() | |
for i in range(len(data)): | |
data[i] = data[i][:-1] | |
layouts = [] | |
avg = 0 | |
al = [] | |
for i in range(int(data[0])): | |
A = data[1+i].split() | |
layout = A[0] | |
layouts.append(layout) | |
m = int(A[1]) | |
tags = A[2:] | |
for ii in tags: | |
al.append(ii) | |
adj[i] = sorted(tags[:]) | |
avg += len(adj[i]) | |
n = int(data[0]) | |
avg = avg/n | |
slides = [] | |
curh = [] | |
curv = [] | |
img = [[adj[i], i, layouts[i]] for i in range(int(data[0]))] | |
img.sort() | |
order = [img[i][1] for i in range(n)] | |
vdone = dd(int) | |
horizontals = [img[i][1] for i in range(n) if img[i][2] == 'H'] | |
verticals = [img[i][1] for i in range(n) if img[i][2]=='V'] | |
x = 0 | |
future = [] | |
for i in range(len(order)): | |
if vdone[i]!=0: | |
continue | |
if layouts[order[i]] == 'H': | |
curh.append(order[i]) | |
#slides.append(curh) | |
future.append(curh) | |
curh = [] | |
elif x<len(verticals)//2: | |
curv.append(verticals[x]) | |
curv.append(verticals[-x-1]) | |
x+=1 | |
if len(curv)==2: | |
slides.append(curv) | |
curv = [] | |
for i in slides: | |
future.append(i) | |
slides = future[:] | |
op = open('output' + str(ct) +'.txt', 'w') | |
op.write(str(len(slides)) + '\n') | |
for i in slides: | |
for j in i: | |
op.write(str(j)+' ') | |
op.write('\n') | |
op.close() | |
f.close() | |
#print(len(slides)) | |
#for i in slides: | |
# print(*i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment