Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys,re
- def part_1():
- with open(sys.argv[1]) as f:
- x1,x2,y1,y2=map(int,re.findall('-?\d+',f.read()))
- ymax=-y1-1
- print((ymax*(ymax+1))//2)
- def part_2():
- with open(sys.argv[1]) as f:
- x1,x2,y1,y2=map(int,re.findall('-?\d+',f.read()))
- cnt=0
- for vy in range(y1,1-y1):
- y,i,vx=0,0,set()
- while y1<=y:
- x,j=0,0
- if y<=y2:
- while x<=x2:
- if x1<=x: vx.add(j)
- j,x=j+1,x+min(j, i)
- i,y,vy=i+1,y+vy,vy-1
- cnt+=len(vx)
- print(cnt)
- if __name__=="__main__":
- from time import time
- t1=time()
- part_1()
- part_2()
- print(time()-t1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement