aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-08-23 09:26:14 +0100
committerGitHub <noreply@github.com>2020-08-23 09:26:14 +0100
commit541152c9ed18a0729883101c183ae6dced26666e (patch)
tree6df9aac1f0209da08957fb92fd5745f61e4309f9
parent7681c1b1dc2d345eb4fe18b895cc9e8516dce5ed (diff)
parentfae3dea833fcea717e5cc24f0983b0784501e7cf (diff)
downloadperlweeklychallenge-club-541152c9ed18a0729883101c183ae6dced26666e.tar.gz
perlweeklychallenge-club-541152c9ed18a0729883101c183ae6dced26666e.tar.bz2
perlweeklychallenge-club-541152c9ed18a0729883101c183ae6dced26666e.zip
Merge pull request #2123 from brtastic/challenge-74
Challenge 74 refactoring and blog post link
-rw-r--r--challenge-074/brtastic/blog.txt1
-rw-r--r--challenge-074/brtastic/perl/ch-1.pl9
-rw-r--r--challenge-074/brtastic/perl/ch-2.pl2
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;
}