From ecdfadccfff20790ae184a2b70fe204553f3c719 Mon Sep 17 00:00:00 2001 From: arnesom Date: Sat, 18 Mar 2023 19:06:54 +0100 Subject: Arne Sommer --- challenge-208/arne-sommer/blog.txt | 1 + challenge-208/arne-sommer/raku/ch-1.raku | 39 ++++++++++++++++++++++ challenge-208/arne-sommer/raku/ch-2.raku | 26 +++++++++++++++ .../arne-sommer/raku/duplicate-and-missing | 26 +++++++++++++++ challenge-208/arne-sommer/raku/minimum-index-sum | 39 ++++++++++++++++++++++ 5 files changed, 131 insertions(+) create mode 100644 challenge-208/arne-sommer/blog.txt create mode 100755 challenge-208/arne-sommer/raku/ch-1.raku create mode 100755 challenge-208/arne-sommer/raku/ch-2.raku create mode 100755 challenge-208/arne-sommer/raku/duplicate-and-missing create mode 100755 challenge-208/arne-sommer/raku/minimum-index-sum 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(", ") ~ ")" + !! "()"; + -- cgit