diff options
| author | brtastic <brtastic.dev@gmail.com> | 2020-08-23 00:14:40 +0200 |
|---|---|---|
| committer | brtastic <brtastic.dev@gmail.com> | 2020-08-23 00:14:40 +0200 |
| commit | fae3dea833fcea717e5cc24f0983b0784501e7cf (patch) | |
| tree | ede9c4757b77114b9c7ea1bbb648784c847590c0 /challenge-074/brtastic | |
| parent | b69afeae6bfcdbf44e4c0dbb5ff3d2442223b770 (diff) | |
| download | perlweeklychallenge-club-fae3dea833fcea717e5cc24f0983b0784501e7cf.tar.gz perlweeklychallenge-club-fae3dea833fcea717e5cc24f0983b0784501e7cf.tar.bz2 perlweeklychallenge-club-fae3dea833fcea717e5cc24f0983b0784501e7cf.zip | |
Challenge 74 refactoring and blog post link
Diffstat (limited to 'challenge-074/brtastic')
| -rw-r--r-- | challenge-074/brtastic/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-074/brtastic/perl/ch-1.pl | 9 | ||||
| -rw-r--r-- | challenge-074/brtastic/perl/ch-2.pl | 2 |
3 files changed, 5 insertions, 7 deletions
diff --git a/challenge-074/brtastic/blog.txt b/challenge-074/brtastic/blog.txt new file mode 100644 index 0000000000..786fe5c2a5 --- /dev/null +++ b/challenge-074/brtastic/blog.txt @@ -0,0 +1 @@ +https://brtastic.xyz/blog/article/perl-weekly-74 diff --git a/challenge-074/brtastic/perl/ch-1.pl b/challenge-074/brtastic/perl/ch-1.pl index 015c803bc6..0bc8072171 100644 --- a/challenge-074/brtastic/perl/ch-1.pl +++ b/challenge-074/brtastic/perl/ch-1.pl @@ -10,13 +10,10 @@ sub get_majority my $list = superpos(@_); # superpositions have a built in statistics module - my $majority = $list->stats->most_probable; + # the result of most_probable is actually a new superposition, it can have multiple states + my ($state) = $list->stats->most_probable->states->@*; - # majority is actually a new superposition, it can have multiple states - return -1 if $majority->states->@* != 1; - - # we now know that this element is certainly a majority, but does it have a proper weight? - my $state = $majority->states->[0]; + # we now know that this element is certainly most frequent, but does it have proper weight? return $state->weight > 0.5 ? $state->value : -1; } diff --git a/challenge-074/brtastic/perl/ch-2.pl b/challenge-074/brtastic/perl/ch-2.pl index 9464f0b80e..d1a93a1ffd 100644 --- a/challenge-074/brtastic/perl/ch-2.pl +++ b/challenge-074/brtastic/perl/ch-2.pl @@ -22,7 +22,7 @@ sub first_non_repeating # since we have a couple of non-repeating characters, we get the first one # (the superposition here helps so that we solve this by a simple eq) - my $alternatives = superpos(map { $_->value } @non_repeating); + my $alternatives = superpos(@non_repeating); return first { $_ eq $alternatives } @split; } |
