diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-03-18 23:02:50 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-18 23:02:50 +0000 |
| commit | 87e50ae17dae2c587957134a5ec50ecd3a3c6fce (patch) | |
| tree | bea60d0fdce54156cb2d91e52bfe6c9d14d42408 | |
| parent | a5a24c7cbdca2f3ae26c458ac6df7029d0261299 (diff) | |
| parent | ecdfadccfff20790ae184a2b70fe204553f3c719 (diff) | |
| download | perlweeklychallenge-club-87e50ae17dae2c587957134a5ec50ecd3a3c6fce.tar.gz perlweeklychallenge-club-87e50ae17dae2c587957134a5ec50ecd3a3c6fce.tar.bz2 perlweeklychallenge-club-87e50ae17dae2c587957134a5ec50ecd3a3c6fce.zip | |
Merge pull request #7747 from arnesom/branch-for-challenge-208
Arne Sommer
| -rw-r--r-- | challenge-208/arne-sommer/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-208/arne-sommer/raku/ch-1.raku | 39 | ||||
| -rwxr-xr-x | challenge-208/arne-sommer/raku/ch-2.raku | 26 | ||||
| -rwxr-xr-x | challenge-208/arne-sommer/raku/duplicate-and-missing | 26 | ||||
| -rwxr-xr-x | challenge-208/arne-sommer/raku/minimum-index-sum | 39 |
5 files changed, 131 insertions, 0 deletions
diff --git a/challenge-208/arne-sommer/blog.txt b/challenge-208/arne-sommer/blog.txt new file mode 100644 index 0000000000..650295a3fd --- /dev/null +++ b/challenge-208/arne-sommer/blog.txt @@ -0,0 +1 @@ +https://raku-musings.com/mis-ing.html diff --git a/challenge-208/arne-sommer/raku/ch-1.raku b/challenge-208/arne-sommer/raku/ch-1.raku new file mode 100755 index 0000000000..dde51d836c --- /dev/null +++ b/challenge-208/arne-sommer/raku/ch-1.raku @@ -0,0 +1,39 @@ +#! /usr/bin/env raku + +unit sub MAIN ($list1 = "Perl Raku Love", $list2 = "Raku Perl Hate", :v($verbose)); + +my @list1 = $list1.words; +my @list2 = $list2.words; + +die "Repetitions in list1" if @list1.elems != @list1.unique.elems; +die "Repetitions in list2" if @list2.elems != @list2.unique.elems; + +my $mis = Inf; +my @common; + +for ^@list1.elems -> $i +{ + next unless @list1[$i] eq any(@list2); + + for ^@list2.elems -> $j + { + if @list1[$i] eq @list2[$j] + { + my $sum = $i + $j; + say ": Index sum of \"@list1[$i]\": $i + $j = $sum" if $verbose; + + next if $sum > $mis; + + @common = () if $sum < $mis; + $mis = $sum; + + @common.push: @list1[$i]; + + } + } +} + +say @common.elems + ?? "(" ~ @common.map({ "\"$_\"" }).join(", ") ~ ")" + !! "()"; + diff --git a/challenge-208/arne-sommer/raku/ch-2.raku b/challenge-208/arne-sommer/raku/ch-2.raku new file mode 100755 index 0000000000..16daa23449 --- /dev/null +++ b/challenge-208/arne-sommer/raku/ch-2.raku @@ -0,0 +1,26 @@ +#! /usr/bin/env raku + +unit sub MAIN ($nums = "1 2 2 4", :v($verbose)); + +my @nums = $nums.words; + +die "Not increasing values" unless [<=] @nums; + +my $duplicate = @nums.repeated; + +say ": Duplicate: $duplicate" if $verbose; + +my $current = @nums.shift; + +while (@nums.elems) +{ + if @nums[0] != $current + 1 + { + say ": Missing: { $current + 1 }" if $verbose; + say "($duplicate, { $current + 1 })"; + exit; + } + $current = @nums.shift; +} + +say "-1"; diff --git a/challenge-208/arne-sommer/raku/duplicate-and-missing b/challenge-208/arne-sommer/raku/duplicate-and-missing new file mode 100755 index 0000000000..16daa23449 --- /dev/null +++ b/challenge-208/arne-sommer/raku/duplicate-and-missing @@ -0,0 +1,26 @@ +#! /usr/bin/env raku + +unit sub MAIN ($nums = "1 2 2 4", :v($verbose)); + +my @nums = $nums.words; + +die "Not increasing values" unless [<=] @nums; + +my $duplicate = @nums.repeated; + +say ": Duplicate: $duplicate" if $verbose; + +my $current = @nums.shift; + +while (@nums.elems) +{ + if @nums[0] != $current + 1 + { + say ": Missing: { $current + 1 }" if $verbose; + say "($duplicate, { $current + 1 })"; + exit; + } + $current = @nums.shift; +} + +say "-1"; diff --git a/challenge-208/arne-sommer/raku/minimum-index-sum b/challenge-208/arne-sommer/raku/minimum-index-sum new file mode 100755 index 0000000000..dde51d836c --- /dev/null +++ b/challenge-208/arne-sommer/raku/minimum-index-sum @@ -0,0 +1,39 @@ +#! /usr/bin/env raku + +unit sub MAIN ($list1 = "Perl Raku Love", $list2 = "Raku Perl Hate", :v($verbose)); + +my @list1 = $list1.words; +my @list2 = $list2.words; + +die "Repetitions in list1" if @list1.elems != @list1.unique.elems; +die "Repetitions in list2" if @list2.elems != @list2.unique.elems; + +my $mis = Inf; +my @common; + +for ^@list1.elems -> $i +{ + next unless @list1[$i] eq any(@list2); + + for ^@list2.elems -> $j + { + if @list1[$i] eq @list2[$j] + { + my $sum = $i + $j; + say ": Index sum of \"@list1[$i]\": $i + $j = $sum" if $verbose; + + next if $sum > $mis; + + @common = () if $sum < $mis; + $mis = $sum; + + @common.push: @list1[$i]; + + } + } +} + +say @common.elems + ?? "(" ~ @common.map({ "\"$_\"" }).join(", ") ~ ")" + !! "()"; + |
