From 3fa86e7eb1946c9a51fc70c2a5585f8bf9e449bb Mon Sep 17 00:00:00 2001 From: Alexander Pankoff Date: Mon, 1 Feb 2021 17:33:34 +0100 Subject: add perl solution for wk-098 ch-1.pl --- challenge-098/alexander-pankoff/perl/ch-1.pl | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 challenge-098/alexander-pankoff/perl/ch-1.pl diff --git a/challenge-098/alexander-pankoff/perl/ch-1.pl b/challenge-098/alexander-pankoff/perl/ch-1.pl new file mode 100755 index 0000000000..19294205aa --- /dev/null +++ b/challenge-098/alexander-pankoff/perl/ch-1.pl @@ -0,0 +1,33 @@ +#!/usr/bin/env perl +use v5.20; +use utf8; +use strict; +use warnings; +use feature qw(say signatures); +no warnings 'experimental::signatures'; + +{ + my ( $FILE, @numbers ) = @ARGV; + say readN( $FILE, $_ ) for @numbers; +} + +sub readN ( $file, $chars ) { + state $filehandles = {}; + + my $fh; + if ( $filehandles->{$file} ) { + $fh = $filehandles->{$file}; + } + else { + open( $fh, '<', $file ); + $fh->binmode( ':utf8' ); + $filehandles->{$file} = $fh; + } + + my $out; + while ( $chars-- && !$fh->eof ) { + $out .= $fh->getc; + } + + return $out; +} -- cgit From 725689b7a528f30d1923cbd49c11a440d19576cd Mon Sep 17 00:00:00 2001 From: Alexander Pankoff Date: Mon, 1 Feb 2021 18:05:23 +0100 Subject: add perl solution for wk-098 ch-2.pl --- challenge-098/alexander-pankoff/perl/ch-2.pl | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 challenge-098/alexander-pankoff/perl/ch-2.pl diff --git a/challenge-098/alexander-pankoff/perl/ch-2.pl b/challenge-098/alexander-pankoff/perl/ch-2.pl new file mode 100755 index 0000000000..6031dfaebf --- /dev/null +++ b/challenge-098/alexander-pankoff/perl/ch-2.pl @@ -0,0 +1,42 @@ +#!/usr/bin/env perl +use v5.20; +use utf8; +use strict; +use warnings; +use feature qw(say signatures); +no warnings 'experimental::signatures'; + +use List::Util qw(first); + +{ + my @N = @ARGV; + my $N = pop @N; + + say join( " ", '@N:', @N ); + say join( " ", '$N:', $N ); + my ( $index, @new_N ) = search_insert_position( $N, @N ); + + my $human_index = $index + 1; + + say @new_N == @N + ? "$human_index since the target $N is in the array at the index $human_index." + : "$human_index since the target $N is missing and should be placed at the index $human_index." +} + +sub search_insert_position ( $target, @xs ) { + my $index = first_index( sub($x) { $x >= $target }, @xs ); + + if ( !$index ) { + return ( $#xs + 1, @xs, $target ); + } + elsif ( $xs[$index] && $xs[$index] == $target ) { + return ( $index, @xs ); + } + else { + return ( $index, @xs[ 0 .. $index - 1 ], $target, @xs[ $index .. $#xs ] ); + } +} + +sub first_index ( $cond, @xs ) { + first { $cond->( $xs[$_] ) } 0 .. $#xs; +} -- cgit From a14e8a2d21fb0d242c3bea7bf62a1d9467f55726 Mon Sep 17 00:00:00 2001 From: boblied Date: Tue, 2 Feb 2021 13:04:33 -0600 Subject: Update for 98 --- challenge-098/bob-lied/README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/challenge-098/bob-lied/README b/challenge-098/bob-lied/README index be9398e9a3..07a4221a5d 100644 --- a/challenge-098/bob-lied/README +++ b/challenge-098/bob-lied/README @@ -1,3 +1,3 @@ -Solutions to weekly challenge 83 by Bob Lied. +Solutions to weekly challenge 98 by Bob Lied. -https://perlweeklychallenge.org/blog/perl-weekly-challenge-083/ +https://perlweeklychallenge.org/blog/perl-weekly-challenge-098/ -- cgit From f0d39197a36ffbebc63565199f9227f440524291 Mon Sep 17 00:00:00 2001 From: chirvasitua Date: Mon, 8 Feb 2021 02:09:59 -0500 Subject: 1st commit on 099_raku --- challenge-099/stuart-little/raku/ch-1.p6 | 11 +++++++++++ challenge-099/stuart-little/raku/ch-2.p6 | 12 ++++++++++++ 2 files changed, 23 insertions(+) create mode 100755 challenge-099/stuart-little/raku/ch-1.p6 create mode 100755 challenge-099/stuart-little/raku/ch-2.p6 diff --git a/challenge-099/stuart-little/raku/ch-1.p6 b/challenge-099/stuart-little/raku/ch-1.p6 new file mode 100755 index 0000000000..65b1cbe7d2 --- /dev/null +++ b/challenge-099/stuart-little/raku/ch-1.p6 @@ -0,0 +1,11 @@ +#!/usr/bin/env perl6 +use v6; + +# run