From 90611edd156841377442722dd322047901dcd42d Mon Sep 17 00:00:00 2001 From: naifqarni <73849082+naifqarni@users.noreply.github.com> Date: Sun, 12 Jun 2022 01:06:29 +0300 Subject: [PATCH] Create medium.py --- submittions/medium.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 submittions/medium.py diff --git a/submittions/medium.py b/submittions/medium.py new file mode 100644 index 0000000..e2c626f --- /dev/null +++ b/submittions/medium.py @@ -0,0 +1,40 @@ +arr='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +def line_intersection(n,m,start,end): + s = [int(arr.index(start[0]))+1,int(start[1:])] # list of the start postiion with the format [a,b] where a and b are int + e = [int(arr.index(end[0]))+1,int(end[1:])] # .............. end ....... + if start == end: + return [end] + sol1 ,sol2 ='','' # two possible solutions max + + # making two line and finding the intersection between them (positive first) + solpx = (-s[1]+s[0]+e[1]+e[0])/2 + solpy = solpx+s[1]-s[0] + + if not solpx.is_integer(): + return ['no solution'] + + # check if they are on the board + if solpx>0 and solpx0 and solpy0 and solnx0 and solny