aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-07-14 00:26:38 +0100
committerGitHub <noreply@github.com>2025-07-14 00:26:38 +0100
commit348c59e616b0fd19880933ba3cd58ddae57fd772 (patch)
treed1327145b29b39e7070059f0515bf9768f9a9e89
parentd2e3420d1d0d4efaf9abca5e5b1c9a2f70d912d1 (diff)
parent56e7a763084fefdf9fd0c0f5805886747e13b4b7 (diff)
downloadperlweeklychallenge-club-348c59e616b0fd19880933ba3cd58ddae57fd772.tar.gz
perlweeklychallenge-club-348c59e616b0fd19880933ba3cd58ddae57fd772.tar.bz2
perlweeklychallenge-club-348c59e616b0fd19880933ba3cd58ddae57fd772.zip
Merge pull request #12336 from adamcrussell/challenge-329
initial commit
-rw-r--r--challenge-329/adam-russell/blog.txt1
-rw-r--r--challenge-329/adam-russell/perl/ch-1.pl62
-rw-r--r--challenge-329/adam-russell/perl/ch-2.pl45
3 files changed, 108 insertions, 0 deletions
diff --git a/challenge-329/adam-russell/blog.txt b/challenge-329/adam-russell/blog.txt
new file mode 100644
index 0000000000..0e7317ec80
--- /dev/null
+++ b/challenge-329/adam-russell/blog.txt
@@ -0,0 +1 @@
+http://www.rabbitfarm.com/cgi-bin/blosxom/perl/2025/07/13
diff --git a/challenge-329/adam-russell/perl/ch-1.pl b/challenge-329/adam-russell/perl/ch-1.pl
new file mode 100644
index 0000000000..0756e54193
--- /dev/null
+++ b/challenge-329/adam-russell/perl/ch-1.pl
@@ -0,0 +1,62 @@
+
+ use GD;
+ use JSON;
+ use OCR::OcrSpace;
+
+ sub write_image{
+ my($s) = @_;
+ my $width = 500;
+ my $height = 500;
+ my $image_file = q#/tmp/output_image.png#;
+ my $image = GD::Image->new($width, $height);
+ my $white = $image->colorAllocate(255, 255, 255);
+ my $black = $image->colorAllocate(0, 0, 0);
+ $image->filledRectangle(0, 0, $width - 1, $height - 1, $white);
+ my $font_path = q#/System/Library/Fonts/Courier.ttc#;
+ my $font_size = 14;
+ $image->stringFT($black, $font_path, $font_size, 0, 10, 50, $s);
+ open TEMP, q/>/, qq/$image_file/;
+ binmode TEMP;
+ print TEMP $image->png;
+ close TEMP;
+ return $image_file;
+ }
+
+
+ sub counter_integers{
+ my($s) = @_;
+ my @numbers;
+
+ $s =~ tr/a-z/ /;
+
+ my $image = write_image($s);
+ my $ocrspace = OCR::OcrSpace->new();
+ my $ocrspace_parameters = { file => qq/$image/,
+ apikey => q/K89345674088957/,
+ filetype => q/PNG/,
+ scale => q/True/,
+ isOverlayRequired => q/True/,
+ OCREngine => 2};
+ my $result = $ocrspace->get_result($ocrspace_parameters);
+ $result = decode_json($result);
+ my $lines = $result->{ParsedResults}[0]
+ ->{TextOverlay}
+ ->{Lines};
+ for my $line (@{$lines}){
+ for my $word (@{$line->{Words}}){
+ push @numbers, $word->{WordText};
+ }
+ }
+ return join q/, /, @numbers;
+ }
+
+
+MAIN:{
+ print counter_integers q/the1weekly2challenge2/;
+ print qq/\n/;
+ print counter_integers q/go21od1lu5c7k/;
+ print qq/\n/;
+ print counter_integers q/4p3e2r1l/;
+ print qq/\n/;
+}
+
diff --git a/challenge-329/adam-russell/perl/ch-2.pl b/challenge-329/adam-russell/perl/ch-2.pl
new file mode 100644
index 0000000000..a00733e91d
--- /dev/null
+++ b/challenge-329/adam-russell/perl/ch-2.pl
@@ -0,0 +1,45 @@
+
+ use v5.40;
+
+ sub is_nice{
+ my ($s) = @_;
+ my %seen;
+ for my $c (split //, $s){
+ if($c =~ m/[a-z]/) {
+ $seen{$c}{lower} = 1;
+ }
+ elsif($c =~ m/[A-Z]/) {
+ $seen{lc($c)}{upper} = 1;
+ }
+ }
+ for my $c (keys %seen){
+ return 0 unless exists $seen{$c}{lower} &&
+ exists $seen{$c}{upper};
+ }
+ return 1;
+ }
+
+
+ sub nice_substring{
+ my ($s) = @_;
+ my $n = length($s);
+ my $longest = q//;
+ for my $i (0 .. $n - 1) {
+ for my $j ($i + 1 .. $n) {
+ my $substring = substr($s, $i, $j - $i);
+ if (is_nice($substring) &&
+ length($substring) > length($longest)){
+ $longest = $substring;
+ }
+ }
+ }
+ return $longest;
+ }
+
+
+MAIN:{
+ say nice_substring q/YaaAho/;
+ say nice_substring q/cC/;
+ say nice_substring q/A/;
+}
+