From a188ca88722c2e8b88abc34ae2963c0f493072f1 Mon Sep 17 00:00:00 2001
From: Patrick Spek
Date: Thu, 13 Sep 2018 19:23:02 +0200
Subject: Apply fixes from comments to "Hackerrank solutions: Python 3 and Perl
6 (part 1)"
---
...hackerrank-solutions-python3-and-perl6-part-1.adoc | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
(limited to '_posts')
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
+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");
--
cgit v1.1