daily pastebin goal
27%
SHARE
TWEET

Untitled

a guest Dec 14th, 2018 130 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from collections import Counter
  2.  
  3. def CoordSplit(c):
  4.     c = c.split(",")
  5.     return c
  6.  
  7. def AreaSplit(a):
  8.     a = a.split("x")
  9.     return a
  10.        
  11.  
  12. def cleanInput(li):
  13.     i = 0
  14.     for item in li:
  15.         temparr = item.split()
  16.         li[i] = ''.join(temparr[2:4]).split(':')
  17.         i+=1
  18.  
  19.     return li
  20.  
  21. allCoords = []
  22. overlappedCoords = []
  23. templist = []
  24.  
  25. currCoord = []
  26. currArea = []
  27.  
  28. start = []
  29. inp = []
  30.  
  31. f = open('input.txt', 'r')
  32.  
  33. for line in f:
  34.     inp.append(line.rstrip("\n"))
  35.  
  36. f.close()
  37.  
  38. #inp = ["#1 @ 1,3: 4x4", "#2 @ 3,1: 4x4", "#3 @ 5,5: 2x2"]
  39.  
  40. inp = cleanInput(inp)
  41.  
  42. i = 0
  43. j = 0
  44.  
  45. for inputs in inp:
  46.    
  47.     currCoord = CoordSplit(inputs[0])
  48.     currArea = AreaSplit(inputs[1])
  49.  
  50.     currCoord[0] = int(currCoord[0])
  51.     currCoord[1] = int(currCoord[1])
  52.  
  53.     currArea[0] = int(currArea[0])
  54.     currArea[1] = int(currArea[1])
  55.  
  56.     start.append(currCoord[0])
  57.     start.append(currCoord[1])
  58.  
  59.  
  60.     while i < (currArea[1]):
  61.         if i != 0:
  62.             currCoord[0] += 1
  63.  
  64.         while j < currArea[0]:
  65.             if j != 0:
  66.                 currCoord[1] += 1
  67.  
  68.             templist.append(currCoord[0])
  69.             templist.append(currCoord[1])
  70.  
  71.             allCoords.append(templist)
  72.             templist = []
  73.             j+=1
  74.  
  75.         currCoord[1] = start[1]
  76.         j = 0
  77.         i+=1
  78.  
  79.     currCoord[0] = start[0]
  80.     i = 0
  81.     start = []
  82.  
  83.  
  84. tupledAllCoords = map(tuple, allCoords)
  85.  
  86. final_count = Counter(tupledAllCoords)
  87.  
  88. curr = (0,0)
  89.  
  90. for key, value in final_count.items():
  91.  
  92.     if value > 1:
  93.         overlappedCoords.append(key)
  94.  
  95. print(len(overlappedCoords))
  96.  
  97. #99314 is the wrong answer. it's too low.
  98. #467210 is wrong. it's too high.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand