summaryrefslogtreecommitdiff
path: root/_posts
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2018-09-13 19:23:02 +0200
committerPatrick Spek <p.spek@tyil.nl>2018-09-13 19:23:02 +0200
commita188ca88722c2e8b88abc34ae2963c0f493072f1 (patch)
tree51aaac2743ddffbd8b1fe4b2162e538170cc9603 /_posts
parent942867222063c80844837a5564cbcd8a8ef03771 (diff)
Apply fixes from comments to "Hackerrank solutions: Python 3 and Perl 6 (part 1)"
Diffstat (limited to '_posts')
-rw-r--r--_posts/2018-09-13-hackerrank-solutions-python3-and-perl6-part-1.adoc19
1 files changed, 16 insertions, 3 deletions
diff --git a/_posts/2018-09-13-hackerrank-solutions-python3-and-perl6-part-1.adoc b/_posts/2018-09-13-hackerrank-solutions-python3-and-perl6-part-1.adoc
index 2c06ab0..3c6e380 100644
--- a/_posts/2018-09-13-hackerrank-solutions-python3-and-perl6-part-1.adoc
+++ b/_posts/2018-09-13-hackerrank-solutions-python3-and-perl6-part-1.adoc
@@ -104,6 +104,13 @@ sub simple-array-sum (@ar) {
}
----
+[NOTE]
+====
+After publishing this post I have learned that both Python 3 and Perl 6 have a
+`.sum` function that can also be called on the array, simplifying the code in
+both languages.
+====
+
=== Compare the Triplets
This challenge provides you with 2 lists of 3 elements each. The lists should
@@ -134,7 +141,7 @@ had to use `+= 1` instead.
[source,perl6]
----
sub compare-triplets (@a, @b) {
- @scores = [0, 0];
+ my @scores = [0, 0];
for ^3 {
@scores[0]++ if @a[$_] > @b[$_];
@@ -151,6 +158,12 @@ Both of these loops could use a `continue` (or `next` in Perl 6) to skip the
second `if` in case the first `if` was true, but for readability I chose not
to.
+[NOTE]
+====
+After publishing this post I learned that Python 3 also supports the <NAME>
+syntax, just like Perl 6, so I could've used this in Python 3 as well.
+====
+
=== A Very Big Sum
In this challenge, you need to write the function body for `aVeryBigSum`, which
@@ -270,8 +283,8 @@ left-hand side up to the right hand side, inclusive.
[source,perl6]
----
-sub staircaise ($n) {
- for 1..($n+1) -> $i {
+sub staircase ($n) {
+ for 1..$n -> $i {
print(" ") for 0..($n - $i);
print("#") for ^$i;
print("\n");