diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2024-02-20 15:39:29 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2024-02-20 15:39:29 +0000 |
| commit | 43ba87df5e3aaa950fcf8ef55152105fe311276f (patch) | |
| tree | d9f91c84e0945c530c10aa28ca71c14cba3cd9ff /challenge-257 | |
| parent | 1cdfd5aafd6e3b8e6411dc9373e415996ced3c91 (diff) | |
| download | perlweeklychallenge-club-43ba87df5e3aaa950fcf8ef55152105fe311276f.tar.gz perlweeklychallenge-club-43ba87df5e3aaa950fcf8ef55152105fe311276f.tar.bz2 perlweeklychallenge-club-43ba87df5e3aaa950fcf8ef55152105fe311276f.zip | |
- Added solutions by Dave Jacoby.
- Added solutions by Eric Cheung.
- Added solutions by Mohammad Meraj Zia.
- Added solutions by Mark Anderson.
- Added solutions by Luca Ferrari.
- Added solutions by Bob Lied.
- Added solutions by Jaldhar H. Vyas.
- Added solutions by David Ferrone.
- Added solutions by Thomas Kohler.
- Added solutions by Mariano Spadaccini.
- Added solutions by PokGoPun.
- Added solutions by Roger Bell_West.
Diffstat (limited to 'challenge-257')
| -rwxr-xr-x | challenge-257/eric-cheung/python/ch-1.py | 9 | ||||
| -rwxr-xr-x | challenge-257/eric-cheung/python/ch-2.py | 35 | ||||
| -rw-r--r-- | challenge-257/ziameraj16/java/SmallerThanCurrent.java | 24 |
3 files changed, 68 insertions, 0 deletions
diff --git a/challenge-257/eric-cheung/python/ch-1.py b/challenge-257/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..5b438b92e1 --- /dev/null +++ b/challenge-257/eric-cheung/python/ch-1.py @@ -0,0 +1,9 @@ +
+## arrInt = [5, 2, 1, 6] ## Example 1
+## arrInt = [1, 2, 0, 3] ## Example 2
+## arrInt = [0, 1] ## Example 3
+arrInt = [9, 4, 9, 2] ## Example 4
+
+arrOutput = [len([arrInt[nColLoop] for nColLoop in range(len(arrInt)) if nColLoop != nRowLoop and arrInt[nColLoop] < arrInt[nRowLoop]]) for nRowLoop in range(len(arrInt))]
+
+print (arrOutput)
diff --git a/challenge-257/eric-cheung/python/ch-2.py b/challenge-257/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..3b13af9e91 --- /dev/null +++ b/challenge-257/eric-cheung/python/ch-2.py @@ -0,0 +1,35 @@ +
+## arrMatrix = [[1, 0, 0, 1], [0, 1, 0, 2], [0, 0, 1, 3]]
+## arrMatrix = [[1, 1, 0], [0, 1, 0], [0, 0, 0]] ## Example 1
+## arrMatrix = [[0, 1, -2, 0, 1], [0, 0, 0, 1, 3], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] ## Example 2
+## arrMatrix = [[1, 0, 0, 4], [0, 1, 0, 7], [0, 0, 1, -1]] ## Example 3
+## arrMatrix = [[0, 1, -2, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 1, 3], [0, 0, 0, 0, 0]] ## Example 4
+## arrMatrix = [[0, 1, 0], [1, 0, 0], [0, 0, 0]] ## Example 5
+arrMatrix = [[4, 0, 0, 0], [0, 1, 0, 7], [0, 0, 1, -1]] ## Example 6
+
+t_arrMatrix = [arrLoop for arrLoop in zip(*arrMatrix)]
+
+## print (t_arrMatrix)
+
+arrLead_1_Pos = [-1 if len([1 for arrColLoop in arrRowLoop if arrColLoop == 1]) == 0 else min([nIndx for nIndx, arrColLoop in enumerate(arrRowLoop) if arrColLoop == 1]) for arrRowLoop in arrMatrix]
+
+## print (arrLead_1_Pos)
+
+arrLead_1_Positive = [nLoop for nLoop in arrLead_1_Pos if nLoop >= 0]
+arrLead_1_Pos_Positive = [nIndx for nIndx, nLoop in enumerate(arrLead_1_Pos) if nLoop >= 0]
+arrLead_1_Pos_Negative = [nIndx for nIndx, nLoop in enumerate(arrLead_1_Pos) if nLoop < 0]
+
+## print (arrLead_1_Positive)
+## print (arrLead_1_Pos_Positive)
+## print (arrLead_1_Pos_Negative)
+
+bResult = (sorted(arrLead_1_Positive) == arrLead_1_Positive)
+if bResult and len(arrLead_1_Pos_Negative) > 0:
+ bResult = (arrLead_1_Pos_Positive[-1] < arrLead_1_Pos_Negative[0])
+if bResult:
+ for arrLoop in t_arrMatrix[:-1]:
+ if sum([0 if rLoop == 0 else 1 for rLoop in arrLoop]) > 1:
+ bResult = False
+ break
+
+print (1 if bResult else 0)
diff --git a/challenge-257/ziameraj16/java/SmallerThanCurrent.java b/challenge-257/ziameraj16/java/SmallerThanCurrent.java new file mode 100644 index 0000000000..28c1047c0a --- /dev/null +++ b/challenge-257/ziameraj16/java/SmallerThanCurrent.java @@ -0,0 +1,24 @@ +import java.util.*; +import java.util.stream.Collectors; + +public class SmallerThanCurrent { + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("Enter comma separate numbers"); + final List<Integer> original = Arrays.stream(scanner.nextLine().split(",")).map(Integer::new).collect(Collectors.toList()); + List<Integer> sorted = new ArrayList<>(original); + Collections.sort(sorted); + Map<Integer, Integer> map = new HashMap<>(); + for (int i = 0; i < sorted.size(); i++) { + if (!map.containsKey(sorted.get(i))) { + map.put(sorted.get(i), i); + } + } + List<Integer> output = new ArrayList<>(); + for (int i : original) { + output.add(map.get(i)); + } + System.out.println(output); + } +} |
