aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYitzchak Scott-Thoennes <sthoenna@gmail.com>2025-07-18 15:56:53 -0400
committerYitzchak Scott-Thoennes <sthoenna@gmail.com>2025-07-20 18:40:52 -0400
commitc59c514f141986ca1c98e32d44f6ad37bf15b28c (patch)
tree718b574bd8f3fbe0b4a1794468504fcf7e31cfa2
parent9e8884f1448e66646c1e56eb7dfc94339da4acbb (diff)
downloadperlweeklychallenge-club-c59c514f141986ca1c98e32d44f6ad37bf15b28c.tar.gz
perlweeklychallenge-club-c59c514f141986ca1c98e32d44f6ad37bf15b28c.tar.bz2
perlweeklychallenge-club-c59c514f141986ca1c98e32d44f6ad37bf15b28c.zip
challenge 330 python, perl, and go solutions
-rw-r--r--challenge-330/ysth/blog.txt1
-rw-r--r--challenge-330/ysth/go/ch-1.go19
-rw-r--r--challenge-330/ysth/go/ch-2.go38
-rw-r--r--challenge-330/ysth/perl/ch-1.pl14
-rw-r--r--challenge-330/ysth/perl/ch-2.pl11
-rw-r--r--challenge-330/ysth/python/ch-1.py14
-rw-r--r--challenge-330/ysth/python/ch-2.py17
7 files changed, 114 insertions, 0 deletions
diff --git a/challenge-330/ysth/blog.txt b/challenge-330/ysth/blog.txt
new file mode 100644
index 0000000000..8732ff42c0
--- /dev/null
+++ b/challenge-330/ysth/blog.txt
@@ -0,0 +1 @@
+https://blog.ysth.info/specifications-ambiguity-contradiction-weekly-challenge-330/
diff --git a/challenge-330/ysth/go/ch-1.go b/challenge-330/ysth/go/ch-1.go
new file mode 100644
index 0000000000..70b2937fc7
--- /dev/null
+++ b/challenge-330/ysth/go/ch-1.go
@@ -0,0 +1,19 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "github.com/htfy96/go-pcre2/v2"
+)
+var subst = pcre2.MustCompile("[0-9]+|(?<pair>[a-z](?&pair)?[0-9])+", 0)
+
+func clear_digits(in string) string {
+ out := subst.ReplaceAllString(in, "", 0)
+ return out
+}
+
+func main() {
+ for _, string := range os.Args[1:] {
+ fmt.Printf("%-30s -> %s\n", string, clear_digits(string))
+ }
+}
diff --git a/challenge-330/ysth/go/ch-2.go b/challenge-330/ysth/go/ch-2.go
new file mode 100644
index 0000000000..ba1e8a2fcc
--- /dev/null
+++ b/challenge-330/ysth/go/ch-2.go
@@ -0,0 +1,38 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "strings"
+ "slices"
+ "github.com/clipperhouse/uax29/graphemes"
+)
+
+func grapheme_length_more_than_2(word string) bool {
+ var seg = graphemes.NewSegmenter([]byte(word))
+ return seg.Next() && seg.Next() && seg.Next() && true
+}
+
+func title_capital(in string) string {
+ return strings.Join(
+ slices.Collect(func(yield func(string) bool) {
+ for _, word := range strings.Split(in, " ") {
+ var cased_word string
+ if grapheme_length_more_than_2(word) {
+ runes := []rune(word)
+ cased_word = strings.ToTitle(string(runes[0])) + strings.ToLower(string(runes[1:]))
+ } else {
+ cased_word = strings.ToLower(word)
+ }
+ if !yield(cased_word) {
+ return
+ }
+ }
+ }), " ")
+}
+
+func main() {
+ for _, string := range os.Args[1:] {
+ fmt.Printf("%-30s -> %s\n", string, title_capital(string))
+ }
+}
diff --git a/challenge-330/ysth/perl/ch-1.pl b/challenge-330/ysth/perl/ch-1.pl
new file mode 100644
index 0000000000..decf8aca0d
--- /dev/null
+++ b/challenge-330/ysth/perl/ch-1.pl
@@ -0,0 +1,14 @@
+use 5.036;
+
+sub clear_digits($string) {
+ $string =~ s/[0-9]*(?<pair>[a-z](?&pair)?[0-9])*//gr;
+}
+
+sub main() {
+ my @inputs = @ARGV;
+ for my $string (@inputs) {
+ printf "%-30s -> %s\n", $string, clear_digits($string);
+ }
+}
+
+main() unless caller;
diff --git a/challenge-330/ysth/perl/ch-2.pl b/challenge-330/ysth/perl/ch-2.pl
new file mode 100644
index 0000000000..1fae0a3bd8
--- /dev/null
+++ b/challenge-330/ysth/perl/ch-2.pl
@@ -0,0 +1,11 @@
+use 5.036;
+use utf8::all;
+
+sub title_capital($string) {
+ join ' ', map { /^\X{3}/ ? ucfirst lc : lc } split / /, $string
+}
+
+my @inputs = @ARGV;
+for my $string (@inputs) {
+ printf "%-30s -> %s\n", $string, title_capital($string);
+}
diff --git a/challenge-330/ysth/python/ch-1.py b/challenge-330/ysth/python/ch-1.py
new file mode 100644
index 0000000000..13f8df9546
--- /dev/null
+++ b/challenge-330/ysth/python/ch-1.py
@@ -0,0 +1,14 @@
+import sys
+import regex
+
+def clear_digits(string: str) -> str:
+ return regex.sub(r'[0-9]*(?<pair>[a-z](?&pair)?[0-9])*', '', string)
+
+def main() -> None:
+ inputs: list[str] = sys.argv[1:]
+
+ for string in inputs:
+ print(f'{string:<30} -> {clear_digits(string)}')
+
+if __name__ == '__main__':
+ main()
diff --git a/challenge-330/ysth/python/ch-2.py b/challenge-330/ysth/python/ch-2.py
new file mode 100644
index 0000000000..0b3f0ae6fa
--- /dev/null
+++ b/challenge-330/ysth/python/ch-2.py
@@ -0,0 +1,17 @@
+import sys
+import grapheme
+
+def grapheme_length_more_than_2(string: str) -> bool:
+ return grapheme.length(string, 3) > 2
+
+def title_capital(string: str) -> str:
+ return ' '.join( word.capitalize() if grapheme_length_more_than_2(word) else word.lower() for word in string.split(' ') )
+
+def main() -> None:
+ inputs: list[str] = sys.argv[1:]
+
+ for string in inputs:
+ print(f'{string:<30} -> {title_capital(string)}')
+
+if __name__ == '__main__':
+ main()