diff options
| author | rir <rirans@comcast.net> | 2025-02-09 23:21:34 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-09 23:21:34 +0000 |
| commit | 6f080fc3c36c5dd16f6ffb1b6e643fac6babc84b (patch) | |
| tree | 5b7d8fa04b96268238b7b6ce520a76649b4d8be2 /challenge-307 | |
| parent | 9380fe143cc5ce16d97cd6fcc2f2f8d18151e4d3 (diff) | |
| parent | 20203255d0f29f170a3c0cd55a737c0b2981597f (diff) | |
| download | perlweeklychallenge-club-6f080fc3c36c5dd16f6ffb1b6e643fac6babc84b.tar.gz perlweeklychallenge-club-6f080fc3c36c5dd16f6ffb1b6e643fac6babc84b.tar.bz2 perlweeklychallenge-club-6f080fc3c36c5dd16f6ffb1b6e643fac6babc84b.zip | |
Merge branch 'manwar:master' into work
Diffstat (limited to 'challenge-307')
102 files changed, 4440 insertions, 15 deletions
diff --git a/challenge-307/arne-sommer/blog.txt b/challenge-307/arne-sommer/blog.txt new file mode 100644 index 0000000000..9e4f58421f --- /dev/null +++ b/challenge-307/arne-sommer/blog.txt @@ -0,0 +1 @@ +https://raku-musings.com/find-check.html diff --git a/challenge-307/arne-sommer/raku/ch-1.raku b/challenge-307/arne-sommer/raku/ch-1.raku new file mode 100755 index 0000000000..7cdcfc635f --- /dev/null +++ b/challenge-307/arne-sommer/raku/ch-1.raku @@ -0,0 +1,23 @@ +#! /usr/bin/env raku + +unit sub MAIN (*@ints where @ints.elems >= 2 && all(@ints) ~~ Int, + :v(:$verbose)); + +my @ordered = @ints.sort; + +my @indices; + +for ^@ints.elems -> $index +{ + if @ints[$index] == @ordered[$index] + { + say ": Index $index: @ints[$index] == @ordered[$index] *" if $verbose; + } + else + { + @indices.push: $index; + say ": Index $index: @ints[$index] != @ordered[$index]" if $verbose; + } +} + +say "({ @indices.join(", ") })"; diff --git a/challenge-307/arne-sommer/raku/ch-2.raku b/challenge-307/arne-sommer/raku/ch-2.raku new file mode 100755 index 0000000000..7e36e25b6e --- /dev/null +++ b/challenge-307/arne-sommer/raku/ch-2.raku @@ -0,0 +1,30 @@ +#! /usr/bin/env raku + +unit sub MAIN (*@words where @words.elems > 0, :v(:$verbose)); + +my %canonical; + +@words.map({ %canonical{$_} = $_.lc.comb.sort.join }); + +@words.map({ say ": Canonical of: $_ -> %canonical{$_}" }) if $verbose; + +my $index = 0; + +loop +{ + last if @words.elems == 0; + last if @words.end == $index; + + if %canonical{@words[$index + 0]} eq %canonical{@words[$index + 1]} + { + print ": Dropping @words[$index + 0] (index $index)" if $verbose; + @words.splice($index,1); + say " -> ({ @words.join(",") })" if $verbose; + } + else + { + $index++; + } +} + +say @words.elems; diff --git a/challenge-307/arne-sommer/raku/check-order b/challenge-307/arne-sommer/raku/check-order new file mode 100755 index 0000000000..7cdcfc635f --- /dev/null +++ b/challenge-307/arne-sommer/raku/check-order @@ -0,0 +1,23 @@ +#! /usr/bin/env raku + +unit sub MAIN (*@ints where @ints.elems >= 2 && all(@ints) ~~ Int, + :v(:$verbose)); + +my @ordered = @ints.sort; + +my @indices; + +for ^@ints.elems -> $index +{ + if @ints[$index] == @ordered[$index] + { + say ": Index $index: @ints[$index] == @ordered[$index] *" if $verbose; + } + else + { + @indices.push: $index; + say ": Index $index: @ints[$index] != @ordered[$index]" if $verbose; + } +} + +say "({ @indices.join(", ") })"; diff --git a/challenge-307/arne-sommer/raku/find-anagrams b/challenge-307/arne-sommer/raku/find-anagrams new file mode 100755 index 0000000000..7e36e25b6e --- /dev/null +++ b/challenge-307/arne-sommer/raku/find-anagrams @@ -0,0 +1,30 @@ +#! /usr/bin/env raku + +unit sub MAIN (*@words where @words.elems > 0, :v(:$verbose)); + +my %canonical; + +@words.map({ %canonical{$_} = $_.lc.comb.sort.join }); + +@words.map({ say ": Canonical of: $_ -> %canonical{$_}" }) if $verbose; + +my $index = 0; + +loop +{ + last if @words.elems == 0; + last if @words.end == $index; + + if %canonical{@words[$index + 0]} eq %canonical{@words[$index + 1]} + { + print ": Dropping @words[$index + 0] (index $index)" if $verbose; + @words.splice($index,1); + say " -> ({ @words.join(",") })" if $verbose; + } + else + { + $index++; + } +} + +say @words.elems; diff --git a/challenge-307/athanasius/perl/ch-1.pl b/challenge-307/athanasius/perl/ch-1.pl new file mode 100644 index 0000000000..0f1659fa96 --- /dev/null +++ b/challenge-307/athanasius/perl/ch-1.pl @@ -0,0 +1,172 @@ +#!perl + +################################################################################ +=comment + +Perl Weekly Challenge 307 +========================= + +TASK #1 +------- +*Check Order* + +Submitted by: Mohammad Sajid Anwar + +You are given an array of integers, @ints. + +Write a script to re-arrange the given array in an increasing order and return +the indices where it differs from the original array. + +Example 1 + + Input: @ints = (5, 2, 4, 3, 1) + Output: (0, 2, 3, 4) + + Before: (5, 2, 4, 3, 1) + After : (1, 2, 3, 4, 5) + + Difference at indices: (0, 2, 3, 4) + +Example 2 + + Input: @ints = (1, 2, 1, 1, 3) + Output: (1, 3) + + Before: (1, 2, 1, 1, 3) + After : (1, 1, 1, 2, 3) + + Difference at indices: (1, 3) + +Example 3 + + Input: @ints = (3, 1, 3, 2, 3) + Output: (0, 1, 3) + + Before: (3, 1, 3, 2, 3) + After : (1, 2, 3, 3, 3) + + Difference at indices: (0, 1, 3) + +=cut +################################################################################ + +#--------------------------------------# +# Copyright © 2025 PerlMonk Athanasius # +#--------------------------------------# + +#=============================================================================== +=comment + +Interface +--------- +1. If no command-line arguments are given, the test suite is run. Otherwise: +2. A non-empty list of integers is entered on the command-line. + +=cut +#=============================================================================== + +use v5.32; # Enables strictures +use warnings; +use Const::Fast; +use Regexp::Common qw( number ); +use Test::More; + +const my $USAGE => <<END; +Usage: |
