From 3a0d3971fee4f0e88baa2cf83e7a4a33b24ca8ec Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 23 Jan 2023 01:51:15 +0000 Subject: - Added solutions by Roger Bell_West. - Added solutions by Dave Jacoby. - Added solutions by David Ferrone. - Added solutions by Luca Ferrari. - Added solutions by Mark Anderson. - Added solutions by W. Luis Mochan. - Added solutions by Peter Campbell Smith. - Added solutions by Mariano Spadaccini. - Added solutions by Thomas Kohler. - Added solutions by Bob Lied. - Added solutions by Jorg Sommrey. - Added solutions by Flavio Poletti. - Added solutions by Pip Stuart. - Added solutions by E. Choroba. - Added solutions by Stephen G. Lynn. - Added solutions by Matthew Neleigh. - Added solutions by Robert Ransbottom. - Added solutions by Athanasius. - Added solutions by Simon Green. - Added solutions by Cheok-Yin Fung. - Added solutions by Tyler Wardhaugh. - Added solutions by Jan Krnavek. - Added solutions by Bruce Gray. - Added solutions by James Smith. - Added solutions by Robbie Hatley. - Added solutions by Solathian. - Added solutions by Arne Sommer. - Added solutions by Carlos Oliveira. - Added solutions by Marton Polgar. - Added solutions by Adam Russell. - Added solutions by Duncan C. White. - Added solutions by Lars Balker. - Added solutions by Colin Crain. - Added solutions by Laurent Rosenfeld. - Added solutions by Robert DiCicco. - Added solutions by Ulrich Rieke. --- challenge-199/eric-cheung/python/ch-2.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 challenge-199/eric-cheung/python/ch-2.py (limited to 'challenge-199/eric-cheung/python/ch-2.py') diff --git a/challenge-199/eric-cheung/python/ch-2.py b/challenge-199/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..2ed1c89d29 --- /dev/null +++ b/challenge-199/eric-cheung/python/ch-2.py @@ -0,0 +1,25 @@ + +from itertools import combinations + +def get_GoodTriplets_List(arrInput, arrInputInt): + + arrGoodPairsList = [] + + nIndxTuple = combinations(range(0, len(arrInput)), 3) + + for nIndxLoop_01, nIndxLoop_02, nIndxLoop_03 in list(nIndxTuple): + if abs(arrInput[nIndxLoop_01] - arrInput[nIndxLoop_02]) <= arrInputInt[0] and abs(arrInput[nIndxLoop_02] - arrInput[nIndxLoop_03]) <= arrInputInt[1] and abs(arrInput[nIndxLoop_01] - arrInput[nIndxLoop_03]) <= arrInputInt[2]: + arrGoodPairsList.append([nIndxLoop_01, nIndxLoop_02, nIndxLoop_03]) + + return arrGoodPairsList + + +## Example 1 +## arrInputList = [3, 0, 1, 1, 9, 7] +## arrInputList_Int = [7, 2, 3] + +## Example 2 +arrInputList = [1, 1, 2, 2, 3] +arrInputList_Int = [0, 0, 1] + +print (len(get_GoodTriplets_List(arrInputList, arrInputList_Int))) -- cgit