From 6d10cc601ccd2de4c006258fc4be7e62da3a5b20 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 18 Jul 2023 00:36:10 +0100 Subject: - Added solutions by Robert DiCicco. - Added solutions by Ulrich Rieke. - Added solutions by Laurent Rosenfeld. - Added solutions by Mark Anderson. - Added solutions by W. Luis Mochan. - Added solutions by Packy Anderson. - Added solutions by PokGoPun. - Added solutions by David Ferrone. - Added solutions by Niels van Dijke. - Added solutions by Luca Ferrari. - Added solutions by Bob Lied. - Added solutions by Steven Wilson. - Added solutions by Jaldhar H. Vyas. - Added solutions by Arne Sommer. --- challenge-226/eric-cheung/python/ch-1.py | 12 ++++++++++++ challenge-226/eric-cheung/python/ch-2.py | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100755 challenge-226/eric-cheung/python/ch-1.py create mode 100755 challenge-226/eric-cheung/python/ch-2.py (limited to 'challenge-226/eric-cheung/python') diff --git a/challenge-226/eric-cheung/python/ch-1.py b/challenge-226/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..bd083aa7f7 --- /dev/null +++ b/challenge-226/eric-cheung/python/ch-1.py @@ -0,0 +1,12 @@ + +## Example 1 +## strInput = "lacelengh" +## arrIndices = [3, 2, 0, 5, 4, 8, 6, 7, 1] + +## Example 2 +strInput = "rulepark" +arrIndices = [4, 7, 3, 1, 0, 5, 2, 6] + +strOutput = "".join([strInput[arrIndices.index(nLoop)] for nLoop in range(len(strInput))]) + +print (strOutput) diff --git a/challenge-226/eric-cheung/python/ch-2.py b/challenge-226/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..2550e435d0 --- /dev/null +++ b/challenge-226/eric-cheung/python/ch-2.py @@ -0,0 +1,15 @@ + +import numpy as np + +## arrInput = np.array([1, 5, 0, 3, 5]) ## Example 1 +## arrInput = np.array([0]) ## Example 2 +arrInput = np.array([2, 1, 4, 0, 3]) ## Example 3 + +nCount = 0 + +while np.count_nonzero(arrInput) > 0: + nSubstract = min([nLoop for nLoop in arrInput if nLoop > 0]) + arrInput = [nLoop - nSubstract if nLoop > 0 else 0 for nLoop in arrInput] + nCount = nCount + 1 + +print (nCount) -- cgit