diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2024-09-24 10:19:34 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2024-09-24 10:19:34 +0100 |
| commit | a79f66715f311ce9acdc9a78bde1720c07087edc (patch) | |
| tree | 4c0acefce1a4778d591adbf0d90f1993746c5478 | |
| parent | 8b345b1cf29bd9c2095ca29a7efcf38f7f2729ed (diff) | |
| download | perlweeklychallenge-club-a79f66715f311ce9acdc9a78bde1720c07087edc.tar.gz perlweeklychallenge-club-a79f66715f311ce9acdc9a78bde1720c07087edc.tar.bz2 perlweeklychallenge-club-a79f66715f311ce9acdc9a78bde1720c07087edc.zip | |
- Added solutions by Reinier Maliepaard.
- Added solutions by Eric Cheung.
- Added solutions by Paulo Custodio.
- Added solutions by Roger Bell_West.
26 files changed, 2462 insertions, 2228 deletions
diff --git a/challenge-288/eric-cheung/python/ch-1.py b/challenge-288/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..5a13c5991a --- /dev/null +++ b/challenge-288/eric-cheung/python/ch-1.py @@ -0,0 +1,43 @@ +
+## Ref.
+## https://www.geeksforgeeks.org/closest-palindrome-number-whose-absolute-difference-min/
+
+def IsPalindrome(strInput):
+
+ nMiddleCharPos = int((len(strInput) + (0 if len(strInput) % 2 == 0 else -1)) / 2)
+ nSecondStrStart = nMiddleCharPos + (0 if len(strInput) % 2 == 0 else 1)
+
+ ## If len(strInput) == 3 --> nMiddleCharPos = 1
+ ## If len(strInput) == 4 --> nMiddleCharPos = 2
+
+ ## print (nMiddleCharPos)
+ ## print (nSecondStrStart)
+ ## print (strInput[:nMiddleCharPos])
+ ## print (strInput[nSecondStrStart::][::-1])
+
+ return (strInput[:nMiddleCharPos] == strInput[nSecondStrStart::][::-1])
+
+def GetClosestPalindrome(strInput):
+
+ nOrigNum = int(strInput)
+
+ ## Case 1 : Largest Palindrome Number Smaller than Given Number
+ nSmallStart = nOrigNum - 1
+ while not IsPalindrome(str(nSmallStart)):
+ nSmallStart = nSmallStart - 1
+
+ ## Case 2 : Smallest Palindrome Number Larger than Given Number
+ nLargeStart = nOrigNum + 1
+ while not IsPalindrome(str(nLargeStart)):
+ nLargeStart = nLargeStart + 1
+
+ return (nSmallStart if abs(nSmallStart - nOrigNum) <= abs(nLargeStart - nOrigNum) else nLargeStart)
+
+## strNum = "123" ## Example 1
+## strNum = "2" ## Example 2
+## strNum = "1400" ## Example 3
+strNum = "1001" ## Example 4
+
+## print (IsPalindrome(strNum))
+print (GetClosestPalindrome(strNum))
+
diff --git a/challenge-288/eric-cheung/python/ch-2.py b/challenge-288/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..bd7ef93a22 --- /dev/null +++ b/challenge-288/eric-cheung/python/ch-2.py @@ -0,0 +1,89 @@ +
+def GetDivQuot (nNum, nDiv):
+ return int(nNum / nDiv)
+
+## arrMatrix = [["x", "x", "x", "x", "o"], ["x", "o", "o", "o", "o"], ["x", "o", "o", "o", "o"], ["x", "x", "x", "o", "o"]] ## Example 1
+
+## arrMatrix = [["x", "x", "x", "x", "x"], ["x", "o", "o", "o", "o"], ["x", "x", "x", "x", "o"], ["x", "o", "o", "o", "o"]] ## Example 2
+
+arrMatrix = [["x", "x", "x", "o", "o"], ["o", "o", "o", "x", "x"], ["o", "x", "x", "o", "o"], ["o", "o", "o", "x", "x"]] ## Example 3
+
+arrPosMatrix_X = []
+arrPosMatrix_O = []
+
+nNumRow = len(arrMatrix)
+nNumCol = len(arrMatrix[0])
+
+for nRowLoop in range(nNumRow):
+ for nColLoop in range(nNumCol):
+ nIndx = nRowLoop * nNumCol + nColLoop
+ if arrMatrix[nRowLoop][nColLoop] == "x":
+ arrPosMatrix_X.append(nIndx)
+ else:
+ arrPosMatrix_O.append(nIndx)
+
+## print (arrPosMatrix_X)
+## print (arrPosMatrix_O)
+
+arrBlock_X = []
+arrBlock_Sub_X = []
+for nLoop in arrPosMatrix_X:
+ if len(arrBlock_Sub_X) > 0 and not (int((nLoop - 1) / nNumCol) == int(nLoop / nNumCol) and nLoop - 1 in arrBlock_Sub_X) and nLoop - nNumCol not in arrBlock_Sub_X:
+ arrBlock_X.append(arrBlock_Sub_X)
+ arrBlock_Sub_X = []
+
+ arrBlock_Sub_X.append(nLoop)
+
+if len(arrBlock_Sub_X) > 0:
+ arrBlock_X.append(arrBlock_Sub_X)
+
+for nIndxLoop in range(len(arrBlock_X) - 1, 0, -1):
+ for nElem in arrBlock_X[nIndxLoop]:
+ bIsFound = False
+ for nIndxSubLoop in range(nIndxLoop):
+ if nElem - nNumCol in arrBlock_X[nIndxSubLoop]:
+ bIsFound = True
+ arrBlock_X[nIndxSubLoop] = arrBlock_X[nIndxSubLoop] + arrBlock_X[nIndxLoop]
+ break
+
+ if bIsFound:
+ del arrBlock_X[nIndxLoop]
+ break
+
+## print (arrBlock_X)
+
+arrBlock_O = []
+arrBlock_Sub_O = []
+for nLoop in arrPosMatrix_O:
+ if len(arrBlock_Sub_O) > 0 and not (GetDivQuot(nLoop - 1, nNumCol) == GetDivQuot(nLoop, nNumCol) and nLoop - 1 in arrBlock_Sub_O) and nLoop - nNumCol not in arrBlock_Sub_O:
+ arrBlock_O.append(arrBlock_Sub_O)
+ arrBlock_Sub_O = []
+
+ arrBlock_Sub_O.append(nLoop)
+
+if len(arrBlock_Sub_O) > 0:
+ arrBlock_O.append(arrBlock_Sub_O)
+
+for nIndxLoop in range(len(arrBlock_O) - 1, 0, -1):
+ for nElem in arrBlock_O[nIndxLoop]:
+ bIsFound = False
+ for nIndxSubLoop in range(nIndxLoop):
+ if nElem - nNumCol in arrBlock_O[nIndxSubLoop]:
+ bIsFound = True
+ arrBlock_O[nIndxSubLoop] = arrBlock_O[nIndxSubLoop] + arrBlock_O[nIndxLoop]
+ break
+
+ if bIsFound:
+ del arrBlock_O[nIndxLoop]
+ break
+
+## print (arrBlock_O)
+
+arrOutput = []
+for arrLoop in arrBlock_X:
+ arrOutput.append(len(arrLoop))
+
+for arrLoop in arrBlock_O:
+ arrOutput.append(len(arrLoop))
+
+print (max(arrOutput))
diff --git a/challenge-288/reinier-maliepaard/blog.txt b/challenge-288/reinier-maliepaard/blog.txt new file mode 100644 index 0000000000..340390568e --- /dev/null +++ b/challenge-288/reinier-maliepaard/blog.txt @@ -0,0 +1 @@ +https://reiniermaliepaard.nl/perl/pwc/index.php?id=pwc288 diff --git a/challenge-288/reinier-maliepaard/perl/ch-1.pl b/challenge-288/reinier-maliepaard/perl/ch-1.pl new file mode 100644 index 0000000000..3d9b0ec0fb --- /dev/null +++ b/challenge-288/reinier-maliepaard/perl/ch-1.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl +use strict; +use warnings; + +sub is_palindrome { + return ($_[0] eq reverse($_[0])); +} + +sub find_closest_palindrome { + my $input_num = shift; + + # both numbers are equally distant from the given input number + my $decrement_num = $input_num - 1; + my $increment_num = $input_num + 1; + + while (1) { + # if there are more than one closest palindrome + # then return the smallest + if (is_palindrome($decrement_num)) { + return $decrement_num; + } + if (is_palindrome($increment_num)) { + return $increment_num; + } + $decrement_num--; + $increment_num++; + } +} + +# Tests + +my $str; + +# Example 1 +$str = "123"; +print(find_closest_palindrome($str), "\n"); # Output: "121" + +# Example 2 +$str = "2"; +print(find_closest_palindrome($str), "\n"); # Output: "1" + +# Example 3 +$str = "1400"; +print(find_closest_palindrome($str), "\n"); # Output: "1441" + +# Example 4 +$str = "1001"; +print(find_closest_palindrome($str), "\n"); # Output: "999" diff --git a/stats/pwc-current.json b/stats/pwc-current.json index fd94622131..4b5768da22 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,81 +1,71 @@ { - "tooltip" : { - "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", - "followPointer" : 1, - "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>" - }, - "xAxis" : { - "type" : "category" - }, - "subtitle" : { - "text" : "[Champions: 7] Last updated at 2024-09-23 16:55:08 GMT" - }, - "plotOptions" : { - "series" : { - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - }, - "borderWidth" : 0 - } + "legend" : { + "enabled" : 0 }, "series" : [ { - "name" : "The Weekly Challenge - 288", - "colorByPoint" : 1, "data" : [ { - "y" : 2, + "name" : "David Ferrone", "drilldown" : "David Ferrone", - "name" : "David Ferrone" + "y" : 2 }, { - "name" : "E. Choroba", "drilldown" : "E. Choroba", - "y" : 2 + "y" : 2, + "name" : "E. Choroba" }, { - "name" : "Feng Chang", + "y" : 2, "drilldown" : "Feng Chang", - "y" : 2 + "name" : "Feng Chang" }, { - "y" : 3, + "name" : "Laurent Rosenfeld", "drilldown" : "Laurent Rosenfeld", - "name" : "Laurent Rosenfeld" + "y" : 3 }, { "y" : 2, - "name" : "Lubos Kolouch", - "drilldown" : "Lubos Kolouch" + "drilldown" : "Lubos Kolouch", + "name" : "Lubos Kolouch" }, { - "drilldown" : "Luca Ferrari", "name" : "Luca Ferrari", - "y" : 5 + "y" : 5, + "drilldown" : "Luca Ferrari" + }, + { + "name" : "Paulo Custodio", + "drilldown" : "Paulo Custodio", + "y" : 2 }, { "name" : "Peter Campbell Smith", "drilldown" : "Peter Campbell Smith", "y" : 3 + }, + { + "drilldown" : "Reinier Maliepaard", + "y" : 2, + "name" : "Reinier Maliepaard" + }, + { + "name" : "Roger Bell_West", + "y" : 4, + "drilldown" : "Roger Bell_West" } - ] + ], + "colorByPoint" : 1, + "name" : "The Weekly Challenge - 288" } ], - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } + "xAxis" : { + "type" : "category" }, "chart" : { "type" : "column" }, - "legend" : { - "enabled" : 0 - }, - "title" : { - "text" : "The Weekly Challenge - 288" - }, "drilldown" : { "series" : [ { @@ -89,14 +79,14 @@ "name" : "David Ferrone" }, { - "name" : "E. Choroba", - "id" : "E. Choroba", "data" : [ [ "Perl", 2 ] - ] + ], + "id" : "E. Choroba", + "name" : "E. Choroba" }, { "id" : "Feng Chang", @@ -109,8 +99,6 @@ "name" : "Feng Chang" }, { - "name" : "Laurent Rosenfeld", - "id" : "Laurent Rosenfeld", "data" : [ [ "Perl", @@ -124,7 +112,9 @@ "Blog", 1 ] - ] + ], + "id" : "Laurent Rosenfeld", + "name" : "Laurent Rosenfeld" }, { "id" : "Lubos Kolouch", @@ -137,7 +127,7 @@ "name" : "Lubos Kolouch" }, { - "name" : "Luca Ferrari", + "id" : "Luca Ferrari", "data" : [ [ "Raku", @@ -148,9 +138,20 @@ 3 ] ], - "id" : "Luca Ferrari" + "name" : "Luca Ferrari" }, { + "name" : "Paulo Custodio", + "id" : "Paulo Custodio", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "id" : "Peter Campbell Smith", "data" : [ [ "Perl", @@ -161,9 +162,61 @@ 1 ] ], - "id" : "Peter Campbell Smith", "name" : "Peter Campbell Smith" + }, + { + "name" : "Reinier Maliepaard", + "data" : [ + [ + "Perl", + 1 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Reinier Maliepaard" + }, + { + "name" : "Roger Bell_West", + "id" : "Roger Bell_West", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ] } ] + }, + "title" : { + "text" : "The Weekly Challenge - 288" + }, + "tooltip" : { + "followPointer" : 1, + "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + } + } + }, + "subtitle" : { + "text" : "[Champions: 10] Last updated at 2024-09-24 09:19:08 GMT" } } diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index 5e702fff64..03ac51edcd 100644 --- a/stats/pwc-language-breakdown-2019.json +++ b/stats/pwc-language-breakdown-2019.json @@ -1,14 +1,7 @@ { - "title" : { - "text" : "The Weekly Challenge Language" - }, - "legend" : { - "enabled" : "false" - }, "drilldown" : { "series" : [ { - "name" : "041", "data" : [ [ "Perl", @@ -23,11 +16,11 @@ 9 ] ], - "id" : "041" + "id" : "041", + "name" : "041" }, { "name" : "040", - "id" : "040", "data" : [ [ "Perl", @@ -41,10 +34,10 @@ "Blog", 10 ] - ] + ], + "id" : "040" }, { - "name" : "039", "id" : "039", "data" : [ [ @@ -59,7 +52,8 @@ "Blog", 12 ] - ] + ], + "name" : "039" }, { "id" : "038", @@ -98,7 +92,7 @@ ] }, { - "id" : "036", + "name" : "036", "data" : [ [ "Perl", @@ -113,10 +107,10 @@ 11 ] ], - "name" : "036" + "id" : "036" }, { - "name" : "035", + "id" : "035", "data" : [ [ "Perl", @@ -131,10 +125,9 @@ 9 ] ], - "id" : "035" + "name" : "035" }, { - "name" : "034", "id" : "034", "data" : [ [ @@ -149,10 +142,11 @@ "Blog", 11 ] - ] + ], + "name" : "034" }, { - "id" : "033", + "name" : "033", "data" : [ [ "Perl", @@ -167,7 +161,7 @@ 10 ] ], - "name" : "033" + "id" : "033" }, { "data" : [ @@ -188,7 +182,6 @@ "name" : "032" }, { - "name" : "031", "data" : [ [ "Perl", @@ -203,7 +196,8 @@ 9 ] ], - "id" : "031" + "id" : "031", + "name" : "031" }, { "name" : "030", @@ -278,7 +272,7 @@ "name" : "027" }, { - "id" : "026", + "name" : "026", "data" : [ [ "Perl", @@ -293,11 +287,9 @@ 10 ] ], - "name" : "026" + "id" : "026" }, { - "name" : "025", - "id" : "025", "data" : [ [ "Perl", @@ -311,11 +303,11 @@ "Blog", 12 ] - ] + ], + "id" : "025", + "name" : "025" }, { - "name" : "024", - "id" : "024", "data" : [ [ "Perl", @@ -329,11 +321,12 @@ "Blog", 11 ] - ] + ], + "id" : "024", + "name" : "024" }, { "name" : "023", - "id" : "023", "data" : [ [ "Perl", @@ -347,10 +340,11 @@ "Blog", 12 ] - ] + ], + "id" : "023" }, { - "id" : "022", + "name" : "022", "data" : [ [ "Perl", @@ -365,9 +359,10 @@ 10 ] ], - "name" : "022" + "id" : "022" }, { + "name" : "021", "id" : "021", "data" : [ [ @@ -382,8 +377,7 @@ "Blog", 10 ] - ], - "name" : "021" + ] }, { "name" : "020", @@ -422,7 +416,7 @@ "id" : "019" }, { - "name" : "018", + "id" : "018", "data" : [ [ "Perl", @@ -437,10 +431,10 @@ 14 ] ], - "id" : "018" + "name" : "018" }, { - "name" : "017", + "id" : "017", "data" : [ [ "Perl", @@ -455,7 +449,7 @@ 12 ] ], - "id" : "017" + "name" : "017" }, { "name" : "016", @@ -494,6 +488,8 @@ "id" : "015" }, { + "name" : "014", + "id" : "014", "data" : [ [ "Perl", @@ -507,13 +503,9 @@ "Blog", 15 ] - ], - "id" : "014", - "name" : "014" + ] }, { - "name" : "013", - "id" : "013", "data" : [ [ "Perl", @@ -527,7 +519,9 @@ "Blog", 13 ] - ] + ], + "id" : "013", + "name" : "013" }, { "id" : "012", @@ -548,6 +542,7 @@ "name" : "012" }, { + "name" : "011", "data" : [ [ "Perl", @@ -562,11 +557,11 @@ 10 ] ], - "id" : "011", - "name" : "011" + "id" : "011" }, { "name" : "010", + "id" : "010", "data" : [ [ "Perl", @@ -580,11 +575,10 @@ "Blog", 11 ] - ], - "id" : "010" + ] }, { - "name" : "009", + "id" : "009", "data" : [ [ "Perl", @@ -599,7 +593,7 @@ 13 ] ], - "id" : "009" + "name" : "009" }, { "data" : [ @@ -638,6 +632,8 @@ ] }, { + "name" : "006", + "id" : "006", "data" : [ [ "Perl", @@ -651,11 +647,10 @@ "Blog", 7 ] - ], - "id" : "006", - "name" : "006" + ] }, { + "name" : "005", "id" : "005", "data" : [ [ @@ -670,11 +665,9 @@ "Blog", 12 ] - ], - "name" : "005" + ] }, { - "name" : "004", "data" : [ [ "Perl", @@ -689,10 +682,10 @@ 10 ] ], - "id" : "004" + "id" : "004", + "name" : "004" }, { - "id" : "003", "data" : [ [ "Perl", @@ -707,10 +700,11 @@ 9 ] ], + "id" : "003", "name" : "003" }, { - "name" : "002", + "id" : "002", "data" : [ [ "Perl", @@ -725,7 +719,7 @@ 10 ] ], - "id" : "002" + "name" : "002" }, { "id" : "001", @@ -747,48 +741,24 @@ } ] }, - "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2024-09-23 16:55:08 GMT" - }, - "plotOptions" : { - "series" : { - "borderWidth" : 0, - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - } - } + "legend" : { + "enabled" : "false" }, "xAxis" : { "type" : "category" }, - "tooltip" : { - "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>", - "headerFormat" : "<span style=\"font-size:11px\"></span>", - "followPointer" : "true" - }, - "chart" : { - "type" : "column" - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, "series" : [ { - "name" : "The Weekly Challenge Languages", - "colorByPoint" : "true", "data" : [ { + "name" : "041", "y" : 80, - "drilldown" : "041", - "name" : "041" + "drilldown" : "041" }, { "y" : 77, - "name" : "040", - "drilldown" : "040" + "drilldown" : "040", + "name" : "040" }, { "y" : 68, @@ -797,48 +767,48 @@ }, { "y" : 74, - "name" : "038", - "drilldown" : "038" + "drilldown" : "038", + "name" : "038" }, { - "y" : 70, "drilldown" : "037", + "y" : 70, "name" : "037" }, { - "y" : 70, "name" : "036", + "y" : 70, "drilldown" : "036" }, { - "y" : 68, "name" : "035", + "y" : 68, "drilldown" : "035" }, { "y" : 70, - "name" : "034", - "drilldown" : "034" + "drilldown" : "034", + "name" : "034" }, { - "y" : 113, + "name" : "033", "drilldown" : "033", - "name" : "033" + "y" : 113 }, { - "drilldown" : "032", "name" : "032", - "y" : 97 + "y" : 97, + "drilldown" : "032" }, { - "y" : 93, + "name" : "031", "drilldown" : "031", - "name" : "031" + "y" : 93 }, { + "y" : 120, "drilldown" : "030", - "name" : "030", - "y" : 120 + "name" : "030" }, { "name" : "029", @@ -846,119 +816,119 @@ "y" : 83 }, { - "y" : 82, "name" : " |
