diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2023-12-03 19:48:30 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-03 19:48:30 +0000 |
| commit | 88be5a7741222795a76ac5faa9034d842f61eb09 (patch) | |
| tree | 178abd3b548eabc84345dc988d555829192f7b89 | |
| parent | 3c3048e0c5fe1c1ce6f7ca3fb4e8bf3ad52a33c4 (diff) | |
| parent | dce313eec716227d397059696995b362199e2b70 (diff) | |
| download | perlweeklychallenge-club-88be5a7741222795a76ac5faa9034d842f61eb09.tar.gz perlweeklychallenge-club-88be5a7741222795a76ac5faa9034d842f61eb09.tar.bz2 perlweeklychallenge-club-88be5a7741222795a76ac5faa9034d842f61eb09.zip | |
Merge pull request #9180 from arnesom/branch-for-challenge-245
Arne Sommer
| -rw-r--r-- | arne-sommer/blog.txt | 1 | ||||
| -rwxr-xr-x | arne-sommer/raku/ch-1.raku | 21 | ||||
| -rwxr-xr-x | arne-sommer/raku/ch-2.raku | 28 | ||||
| -rwxr-xr-x | arne-sommer/raku/largest-of-three | 28 | ||||
| -rwxr-xr-x | arne-sommer/raku/sort-language | 21 |
5 files changed, 99 insertions, 0 deletions
diff --git a/arne-sommer/blog.txt b/arne-sommer/blog.txt new file mode 100644 index 0000000000..db708e1c13 --- /dev/null +++ b/arne-sommer/blog.txt @@ -0,0 +1 @@ +https://raku-musings.com/lala-three.html diff --git a/arne-sommer/raku/ch-1.raku b/arne-sommer/raku/ch-1.raku new file mode 100755 index 0000000000..c456e58bc4 --- /dev/null +++ b/arne-sommer/raku/ch-1.raku @@ -0,0 +1,21 @@ +#! /usr/bin/env raku + +unit sub MAIN ($popularity, + *@lang where @lang.elems == $popularity.words.elems > 0 + && $popularity.words.repeated.elems == 0 + && $popularity.words.min == 1 + && $popularity.words.max == $popularity.words.elems, + :v(:$verbose)); + +my @popularity = $popularity.words>>.Int; +my %popularity; + +for ^@popularity -> $index +{ + %popularity{@lang[$index]} = @popularity[$index]; + say ": Language '{ @lang[$index] } with popularity { @popularity[$index] }" if $verbose; +} + +my @output = @lang.sort({ %popularity{$^a} <=> %popularity{$^b} }); + +say "(" ~ @output.map({ "'$_'" }).join(", ") ~ ")"; diff --git a/arne-sommer/raku/ch-2.raku b/arne-sommer/raku/ch-2.raku new file mode 100755 index 0000000000..ad2ae157ee --- /dev/null +++ b/arne-sommer/raku/ch-2.raku @@ -0,0 +1,28 @@ +#! /usr/bin/env raku + +unit sub MAIN (*@ints where @ints.elems >= 1 && all(@ints) ~~ UInt, :v(:$verbose)); + +my $largest = -1; + +for @ints.combinations(1..Inf) -> @combination +{ + say ":Combination: @combination[]" if $verbose; + + for @combination.permutations.unique(:with(&[eqv])) -> @permutation + { + my $candidate = @permutation.join; + my $is-three = $candidate %% 3; + + if $is-three + { + $largest = max($largest, $candidate); + say ": - Permutation: @permutation[] -> $candidate %% 3" if $verbose; + } + else + { + say ": - Permutation: @permutation[] -> $candidate" if $verbose; + } + } +} + +say $largest;
\ No newline at end of file diff --git a/arne-sommer/raku/largest-of-three b/arne-sommer/raku/largest-of-three new file mode 100755 index 0000000000..ad2ae157ee --- /dev/null +++ b/arne-sommer/raku/largest-of-three @@ -0,0 +1,28 @@ +#! /usr/bin/env raku + +unit sub MAIN (*@ints where @ints.elems >= 1 && all(@ints) ~~ UInt, :v(:$verbose)); + +my $largest = -1; + +for @ints.combinations(1..Inf) -> @combination +{ + say ":Combination: @combination[]" if $verbose; + + for @combination.permutations.unique(:with(&[eqv])) -> @permutation + { + my $candidate = @permutation.join; + my $is-three = $candidate %% 3; + + if $is-three + { + $largest = max($largest, $candidate); + say ": - Permutation: @permutation[] -> $candidate %% 3" if $verbose; + } + else + { + say ": - Permutation: @permutation[] -> $candidate" if $verbose; + } + } +} + +say $largest;
\ No newline at end of file diff --git a/arne-sommer/raku/sort-language b/arne-sommer/raku/sort-language new file mode 100755 index 0000000000..c456e58bc4 --- /dev/null +++ b/arne-sommer/raku/sort-language @@ -0,0 +1,21 @@ +#! /usr/bin/env raku + +unit sub MAIN ($popularity, + *@lang where @lang.elems == $popularity.words.elems > 0 + && $popularity.words.repeated.elems == 0 + && $popularity.words.min == 1 + && $popularity.words.max == $popularity.words.elems, + :v(:$verbose)); + +my @popularity = $popularity.words>>.Int; +my %popularity; + +for ^@popularity -> $index +{ + %popularity{@lang[$index]} = @popularity[$index]; + say ": Language '{ @lang[$index] } with popularity { @popularity[$index] }" if $verbose; +} + +my @output = @lang.sort({ %popularity{$^a} <=> %popularity{$^b} }); + +say "(" ~ @output.map({ "'$_'" }).join(", ") ~ ")"; |
