aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYitzchak Scott-Thoennes <sthoenna@gmail.com>2025-08-01 04:57:23 -0400
committerYitzchak Scott-Thoennes <sthoenna@gmail.com>2025-08-01 16:22:49 -0400
commit94077abe311a690244173e96e77aac27a0c7ccae (patch)
tree3b79b75f7b53b39ed07442823d8d5d0dadf5ab1e
parent6f0d16f05f2773a17829abb2db30dff2c2f73444 (diff)
downloadperlweeklychallenge-club-94077abe311a690244173e96e77aac27a0c7ccae.tar.gz
perlweeklychallenge-club-94077abe311a690244173e96e77aac27a0c7ccae.tar.bz2
perlweeklychallenge-club-94077abe311a690244173e96e77aac27a0c7ccae.zip
challenge 332 python, go, and perl solutions
-rw-r--r--challenge-332/ysth/go/ch-1.go31
-rw-r--r--challenge-332/ysth/go/ch-2.go26
-rw-r--r--challenge-332/ysth/perl/ch-1.pl14
-rw-r--r--challenge-332/ysth/perl/ch-2.pl14
-rw-r--r--challenge-332/ysth/python/ch-1.py13
-rw-r--r--challenge-332/ysth/python/ch-2.py14
6 files changed, 112 insertions, 0 deletions
diff --git a/challenge-332/ysth/go/ch-1.go b/challenge-332/ysth/go/ch-1.go
new file mode 100644
index 0000000000..165c495580
--- /dev/null
+++ b/challenge-332/ysth/go/ch-1.go
@@ -0,0 +1,31 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "slices"
+ "strconv"
+ "strings"
+)
+
+func binary_date(date string) string {
+ return strings.Join(
+ slices.Collect(func(yield func(string) bool) {
+ for _, component := range strings.Split(date, "-") {
+ component_as_int, err := strconv.Atoi(component)
+ if err != nil {
+ panic(err)
+ }
+ var component_in_binary = fmt.Sprintf("%b", component_as_int)
+ if !yield(component_in_binary) {
+ return
+ }
+ }
+ }), "-")
+}
+
+func main() {
+ for _, string := range os.Args[1:] {
+ fmt.Printf("%-30s -> %s\n", string, binary_date(string))
+ }
+}
diff --git a/challenge-332/ysth/go/ch-2.go b/challenge-332/ysth/go/ch-2.go
new file mode 100644
index 0000000000..fb9a8ca334
--- /dev/null
+++ b/challenge-332/ysth/go/ch-2.go
@@ -0,0 +1,26 @@
+package main
+
+import (
+ "fmt"
+ "os"
+)
+
+func odd_letters(s string) bool {
+ rune_odd := map[rune]int{}
+ for _, r := range []rune(s) {
+ rune_odd[r] = 1 - rune_odd[r]
+ }
+ var evens bool
+ for _, odd:= range rune_odd {
+ if odd == 0 {
+ evens = true
+ }
+ }
+ return ! evens
+}
+
+func main() {
+ for _, string := range os.Args[1:] {
+ fmt.Printf("%-30s -> %t\n", string, odd_letters(string))
+ }
+}
diff --git a/challenge-332/ysth/perl/ch-1.pl b/challenge-332/ysth/perl/ch-1.pl
new file mode 100644
index 0000000000..a583eca377
--- /dev/null
+++ b/challenge-332/ysth/perl/ch-1.pl
@@ -0,0 +1,14 @@
+use 5.036;
+
+sub binary_date($date) {
+ $date =~ s/([0-9]+)/sprintf '%b', $1/gre
+}
+
+sub main() {
+ my @inputs = @ARGV;
+ for my $date (@inputs) {
+ printf "%-30s -> %s\n", $date, binary_date $date;
+ }
+}
+
+main() unless caller;
diff --git a/challenge-332/ysth/perl/ch-2.pl b/challenge-332/ysth/perl/ch-2.pl
new file mode 100644
index 0000000000..de8469c5a7
--- /dev/null
+++ b/challenge-332/ysth/perl/ch-2.pl
@@ -0,0 +1,14 @@
+use 5.036;
+
+sub odd_letters($string) {
+ join('', sort split //, $string) !~ /(\pL)(?<!(?=\1\1)..)(?:\1\1)*+(?=\1)/
+}
+
+sub main() {
+ my @inputs = @ARGV;
+ for my $string (@inputs) {
+ printf "%-30s -> %s\n", $string, (odd_letters($string) ? 'true' : 'false');
+ }
+}
+
+main() unless caller;
diff --git a/challenge-332/ysth/python/ch-1.py b/challenge-332/ysth/python/ch-1.py
new file mode 100644
index 0000000000..496418ca02
--- /dev/null
+++ b/challenge-332/ysth/python/ch-1.py
@@ -0,0 +1,13 @@
+import sys
+
+def binary_date(date: str) -> str:
+ return '-'.join(bin(int(i))[2:] for i in date.split('-'))
+
+def main() -> None:
+ inputs: list[str] = sys.argv[1:]
+
+ for string in inputs:
+ print(f'{string:<30} -> {binary_date(string)}')
+
+if __name__ == '__main__':
+ main()
diff --git a/challenge-332/ysth/python/ch-2.py b/challenge-332/ysth/python/ch-2.py
new file mode 100644
index 0000000000..5a497f5f14
--- /dev/null
+++ b/challenge-332/ysth/python/ch-2.py
@@ -0,0 +1,14 @@
+import sys
+import regex
+
+def odd_letters(string: str) -> bool:
+ return not regex.search(r'(\pL)(?<!\1\1)(?:\1\1)*+(?=\1)', ''.join(sorted(string)))
+
+def main() -> None:
+ inputs: list[str] = sys.argv[1:]
+
+ for string in inputs:
+ print(f'{string:<30} -> {odd_letters(string)}')
+
+if __name__ == '__main__':
+ main()