Advertisement
Guest User

Untitled

a guest
Dec 17th, 2021
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. import sys,re
  2.  
  3. def part_1():
  4.     with open(sys.argv[1]) as f:
  5.         x1,x2,y1,y2=map(int,re.findall('-?\d+',f.read()))
  6.     ymax=-y1-1
  7.     print((ymax*(ymax+1))//2)
  8.  
  9.  
  10. def part_2():
  11.     with open(sys.argv[1]) as f:
  12.         x1,x2,y1,y2=map(int,re.findall('-?\d+',f.read()))
  13.     cnt=0
  14.     for vy in range(y1,1-y1):
  15.         y,i,vx=0,0,set()
  16.         while y1<=y:
  17.             x,j=0,0
  18.             if y<=y2:
  19.                 while x<=x2:
  20.                     if x1<=x: vx.add(j)
  21.                     j,x=j+1,x+min(j, i)
  22.             i,y,vy=i+1,y+vy,vy-1
  23.         cnt+=len(vx)
  24.     print(cnt)
  25.  
  26.  
  27. if __name__=="__main__":
  28.     from time import time
  29.     t1=time()
  30.     part_1()
  31.     part_2()
  32.     print(time()-t1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement