From 3f0c25ac7a8089ff3d921c6e4926ff88ebd806cd Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Tue, 12 Aug 2025 13:31:48 +0100 Subject: - Added solutions by Andrew Shitov. - Added solutions by Simon Proctor. - Added solutions by Eric Cheung. - Added solutions by Feng Chang. - Added solutions by Mark Anderson. - Added solutions by PokGoPun. - Added solutions by David Ferrone. - Added solutions by Peter Campbell Smith. - Added solutions by Conor Hoekstra. - Added solutions by Peter Meszaros. - Added solutions by Ali Moradi. - Added solutions by W. Luis Mochan. - Added solutions by Roger Bell_West. --- challenge-334/eric-cheung/python/ch-1.py | 27 +++++++++++++++++++++++ challenge-334/eric-cheung/python/ch-2.py | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100755 challenge-334/eric-cheung/python/ch-1.py create mode 100755 challenge-334/eric-cheung/python/ch-2.py (limited to 'challenge-334/eric-cheung/python') diff --git a/challenge-334/eric-cheung/python/ch-1.py b/challenge-334/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..8f721b34a1 --- /dev/null +++ b/challenge-334/eric-cheung/python/ch-1.py @@ -0,0 +1,27 @@ + +## Example 1 +## arrInts = [-2, 0, 3, -5, 2, -1] +## nX = 0 +## nY = 2 + +## Example 2 +## arrInts = [1, -2, 3, -4, 5] +## nX = 1 +## nY = 3 + +## Example 3 +## arrInts = [1, 0, 2, -1, 3] +## nX = 3 +## nY = 4 + +## Example 4 +## arrInts = [-5, 4, -3, 2, -1, 0] +## nX = 0 +## nY = 3 + +## Example 5 +arrInts = [-1, 0, 2, -3, -2, 1] +nX = 0 +nY = 2 + +print (sum(arrInts[nX:nY + 1])) diff --git a/challenge-334/eric-cheung/python/ch-2.py b/challenge-334/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..4f61f989ba --- /dev/null +++ b/challenge-334/eric-cheung/python/ch-2.py @@ -0,0 +1,38 @@ + +import numpy as np + +def GetManDist(arrValidInputPnt, arrCurPnt): + return abs(arrValidInputPnt[0] - arrCurPnt[0]) + abs(arrValidInputPnt[1] - arrCurPnt[1]) + +## Example 1 +## nX = 3 +## nY = 4 +## arrPnts = [[1, 2], [3, 1], [2, 4], [2, 3]] + +## Example 2 +## nX = 2 +## nY = 5 +## arrPnts = [[3, 4], [2, 3], [1, 5], [2, 5]] + +## Example 3 +## nX = 1 +## nY = 1 +## arrPnts = [[2, 2], [3, 3], [4, 4]] + +## Example 4 +## nX = 0 +## nY = 0 +## arrPnts = [[0, 1], [1, 0], [0, 2], [2, 0]] + +## Example 5 +nX = 5 +nY = 5 +arrPnts = [[5, 6], [6, 5], [5, 4], [4, 5]] + +objValidPnts = {nIndx : arrPntLoop for nIndx, arrPntLoop in enumerate(arrPnts) if arrPntLoop[0] == nX or arrPntLoop[1] == nY} + +if len(objValidPnts) > 0: + nMinIndx = np.argmin([GetManDist(objValidPnts[nIndxKey], [nX, nY]) for nIndxKey in objValidPnts]) + print ([nIndxKey for nIndx, nIndxKey in enumerate(objValidPnts) if nIndx == nMinIndx][0]) +else: + print (-1) -- cgit