diff options
| -rw-r--r-- | challenge-329/deadmarshal/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-329/deadmarshal/java/Ch1.java | 27 | ||||
| -rw-r--r-- | challenge-329/deadmarshal/java/Ch2.java | 34 | ||||
| -rw-r--r-- | challenge-329/deadmarshal/perl/ch-1.pl | 14 | ||||
| -rw-r--r-- | challenge-329/deadmarshal/perl/ch-2.pl | 19 |
5 files changed, 95 insertions, 0 deletions
diff --git a/challenge-329/deadmarshal/blog.txt b/challenge-329/deadmarshal/blog.txt new file mode 100644 index 0000000000..2373c60766 --- /dev/null +++ b/challenge-329/deadmarshal/blog.txt @@ -0,0 +1 @@ +https://deadmarshal.blogspot.com/2025/07/twc329.html diff --git a/challenge-329/deadmarshal/java/Ch1.java b/challenge-329/deadmarshal/java/Ch1.java new file mode 100644 index 0000000000..b2302f5c4a --- /dev/null +++ b/challenge-329/deadmarshal/java/Ch1.java @@ -0,0 +1,27 @@ +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class Ch1 { + public static void main(String[] args) { + System.out.println(counter_integers("the1weekly2challenge2")); + System.out.println(counter_integers("go21od1lu5c7k")); + System.out.println(counter_integers("4p3e2r1l")); + } + + private static List<String> counter_integers(String word) { + Set<String> s = new HashSet<>(); + int n = word.length(); + for (int i = 0; i < n; ++i) { + if (Character.isDigit(word.charAt(i))) { + while ((i < n) && (word.charAt(i) == '0')) ++i; + int j = i; + while ((j < n) && (Character.isDigit(word.charAt(j)))) ++j; + s.add(word.substring(i, j)); + i = j; + } + } + return s.stream().toList(); + } +} + diff --git a/challenge-329/deadmarshal/java/Ch2.java b/challenge-329/deadmarshal/java/Ch2.java new file mode 100644 index 0000000000..c90d343ea6 --- /dev/null +++ b/challenge-329/deadmarshal/java/Ch2.java @@ -0,0 +1,34 @@ +import java.util.HashSet; +import java.util.Set; + +public class Ch2 { + public static void main(String[] args) { + System.out.println(nice_string("YaaAho")); + System.out.println(nice_string("cC")); + System.out.println(nice_string("A")); + } + + private static String nice_string(String s) { + int n = s.length(), k = -1, max = 0; + for (int i = 0; i < n; ++i) { + Set<Character> sc = new HashSet<>(); + for (int j = i; j < n; ++j) { + sc.add(s.charAt(j)); + boolean ok = true; + for (char a : sc) { + char b = (char) (a ^ 32); + if (!(sc.contains(a) && sc.contains(b))) { + ok = false; + break; + } + } + if (ok && (max < j - i + 1)) { + max = j - i + 1; + k = i; + } + } + } + return k == -1 ? "" : s.substring(k, k + max); + } +} + diff --git a/challenge-329/deadmarshal/perl/ch-1.pl b/challenge-329/deadmarshal/perl/ch-1.pl new file mode 100644 index 0000000000..17e998a89d --- /dev/null +++ b/challenge-329/deadmarshal/perl/ch-1.pl @@ -0,0 +1,14 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Data::Show; +use List::Util qw(uniq); + +sub counter_integers{ + uniq $_[0] =~ /(\d+)/g +} + +print show counter_integers('the1weekly2challenge2'); +print show counter_integers('go21od1lu5c7k'); +print show counter_integers('4p3e2r1l'); + diff --git a/challenge-329/deadmarshal/perl/ch-2.pl b/challenge-329/deadmarshal/perl/ch-2.pl new file mode 100644 index 0000000000..e7155cb0e9 --- /dev/null +++ b/challenge-329/deadmarshal/perl/ch-2.pl @@ -0,0 +1,19 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +sub nice_string{ + my ($str) = @_; + my %h; + $h{lc $_} |= 1 + /[a-z]/ foreach split '',$str; + foreach my $c(keys %h){ + next if $h{$c} == 3; + $str =~ s/$c//gi; + } + $str +} + +printf "%s\n",nice_string('YaaAho'); +printf "%s\n",nice_string('cC'); +printf "%s\n",nice_string('A'); + |
