From f296a22e81b1ac8b8426d4271d61fe2ee5b4c02d Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Sun, 16 Oct 2022 12:22:34 -0400 Subject: initial commit --- challenge-186/adam-russell/blog.txt | 1 + challenge-186/adam-russell/blog1.txt | 1 + challenge-186/adam-russell/perl/ch-1.pl | 15 +++++++++++++ challenge-186/adam-russell/perl/ch-2.pl | 38 ++++++++++++++++++++++++++++++++ challenge-186/adam-russell/prolog/ch-1.p | 3 +++ 5 files changed, 58 insertions(+) create mode 100644 challenge-186/adam-russell/blog.txt create mode 100644 challenge-186/adam-russell/blog1.txt create mode 100644 challenge-186/adam-russell/perl/ch-1.pl create mode 100644 challenge-186/adam-russell/perl/ch-2.pl create mode 100644 challenge-186/adam-russell/prolog/ch-1.p diff --git a/challenge-186/adam-russell/blog.txt b/challenge-186/adam-russell/blog.txt new file mode 100644 index 0000000000..770a721c1b --- /dev/null +++ b/challenge-186/adam-russell/blog.txt @@ -0,0 +1 @@ +http://www.rabbitfarm.com/cgi-bin/blosxom/perl/2022/10/16 \ No newline at end of file diff --git a/challenge-186/adam-russell/blog1.txt b/challenge-186/adam-russell/blog1.txt new file mode 100644 index 0000000000..6893e8e5cd --- /dev/null +++ b/challenge-186/adam-russell/blog1.txt @@ -0,0 +1 @@ +http://www.rabbitfarm.com/cgi-bin/blosxom/prolog/2022/10/16 \ No newline at end of file diff --git a/challenge-186/adam-russell/perl/ch-1.pl b/challenge-186/adam-russell/perl/ch-1.pl new file mode 100644 index 0000000000..5564c6cf31 --- /dev/null +++ b/challenge-186/adam-russell/perl/ch-1.pl @@ -0,0 +1,15 @@ +use v5.36; +use strict; +use warnings; +## +# You are given two lists of the same size. +# Create a subroutine sub zip() that merges the two lists. +## +sub zip($a, $b){ + return map { $a->[$_], $b->[$_] } 0 .. @$a - 1; +} + +MAIN:{ + print join(", ", zip([qw/1 2 3/], [qw/a b c/])) . "\n"; + print join(", ", zip([qw/a b c/], [qw/1 2 3/])) . "\n"; +} \ No newline at end of file diff --git a/challenge-186/adam-russell/perl/ch-2.pl b/challenge-186/adam-russell/perl/ch-2.pl new file mode 100644 index 0000000000..e3b75a756a --- /dev/null +++ b/challenge-186/adam-russell/perl/ch-2.pl @@ -0,0 +1,38 @@ +use utf8; +use v5.36; +use strict; +use warnings; +## +# You are given a string with possible unicode characters. Create a subroutine +# sub makeover($str) that replace the unicode characters with their ascii equivalent. +# For this task, let us assume the string only contains letters. +## +use Imager; +use File::Temp q/tempfile/; +use Image::OCR::Tesseract q/get_ocr/; + +use constant TEXT_SIZE => 30; +use constant FONT => q#/usr/pkg/share/fonts/X11/TTF/Symbola.ttf#; + +sub makeover($s){ + my $image = Imager->new(xsize => 100, ysize => 100); + my $temp = File::Temp->new(SUFFIX => q/.tiff/); + my $font = Imager::Font->new(file => FONT) or die "Cannot load " . FONT . " ", Imager->errstr; + $font->align(string => $s, + size => TEXT_SIZE, + color => q/white/, + x => $image->getwidth/2, + y => $image->getheight/2, + halign => q/center/, + valign => q/center/, + image => $image + ); + $image->write(file => $temp) or die "Cannot save $temp", $image->errstr; + my $text = get_ocr($temp); + return $text; +} + + +MAIN:{ + say makeover(q/ Ã Ê Í Ò Ù /); +} \ No newline at end of file diff --git a/challenge-186/adam-russell/prolog/ch-1.p b/challenge-186/adam-russell/prolog/ch-1.p new file mode 100644 index 0000000000..28429c87a3 --- /dev/null +++ b/challenge-186/adam-russell/prolog/ch-1.p @@ -0,0 +1,3 @@ +zip([], [], []). +zip([Ha|Ta], [Hb|Tb], [Ha, Hb|Tc]):- + zip(Ta, Tb, Tc). \ No newline at end of file -- cgit