summaryrefslogtreecommitdiff
path: root/content/posts/2018/2018-09-13-hackerrank-solutions-python3-and-perl6-part-1.md
diff options
context:
space:
mode:
Diffstat (limited to 'content/posts/2018/2018-09-13-hackerrank-solutions-python3-and-perl6-part-1.md')
-rw-r--r--content/posts/2018/2018-09-13-hackerrank-solutions-python3-and-perl6-part-1.md48
1 files changed, 24 insertions, 24 deletions
diff --git a/content/posts/2018/2018-09-13-hackerrank-solutions-python3-and-perl6-part-1.md b/content/posts/2018/2018-09-13-hackerrank-solutions-python3-and-perl6-part-1.md
index c3f2aee..3ca0497 100644
--- a/content/posts/2018/2018-09-13-hackerrank-solutions-python3-and-perl6-part-1.md
+++ b/content/posts/2018/2018-09-13-hackerrank-solutions-python3-and-perl6-part-1.md
@@ -14,7 +14,7 @@ tags:
I recently started at a new company, for which I will have to write Python 3
code. To make sure I still know how to do basic stuff in Python, I started to
-work on some [https://www.hackerrank.com/](Hackerrank challenges). In this post,
+work on some [Hackerrank challenges](https://www.hackerrank.com/). In this post,
I will show solutions to some challenges to show the differences. I hope that I
can show that Perl doesn't have to be the "write only" language that many
people make it out to be.
@@ -29,12 +29,12 @@ solutions!
## Challenges
-The challenges covered in this post are the
-[https://www.hackerrank.com/domains/algorithms?filters%5Bsubdomains%5D%5B%5D=warmup](warmup
-challenges) you are recommended to solve when you make a new account. The code
-around the function I'm expected to solve won't be included, as this should be
-irrelevant (for now). Additionally, I may rename the sub to conform to
-[https://en.wikipedia.org/wiki/Letter_case#Special_case_styles](kebab-case), as
+The challenges covered in this post are the [warmup
+challenges](https://www.hackerrank.com/domains/algorithms?filters%5Bsubdomains%5D%5B%5D=warmup)
+you are recommended to solve when you make a new account. The code around the
+function I'm expected to solve won't be included, as this should be irrelevant
+(for now). Additionally, I may rename the sub to conform to
+[kebab-case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles), as
this is more readable (in my opinion), and allowed in Perl 6.
### Solve Me First
@@ -56,7 +56,7 @@ sub solve-me-first ($a, $b) {
```
For those not familiar with Perl 6, the `$` in front of the variable names is
-called a [https://docs.perl6.org/language/glossary#index-entry-Sigil](Sigil),
+called a [Sigil](https://docs.perl6.org/language/glossary#index-entry-Sigil),
and it signals that the variable contains only a single value.
You may have noticed that there's also no `return` in the Perl 6 variant of
@@ -91,10 +91,10 @@ sub simple-array-sum (@ar) {
Here you can see a different sigil for `@ar`. The `@` sigil denotes a list of
scalars in Perl 6. In most other languages this would simply be an array.
-This code can be written even shorter, however. Perl 6 has
-[https://docs.perl6.org/language/operators#index-entry-%5B%2B%5D_%28reduction_metaoperators%29](reduction
-meta-operators). This allows you to put an operator between brackets, like
-`[+]`, to apply a certain operator as a reduce function.
+This code can be written even shorter, however. Perl 6 has [reduction
+meta-operators](https://docs.perl6.org/language/operators#index-entry-%5B%2B%5D_%28reduction_metaoperators%29).
+This allows you to put an operator between brackets, like `[+]`, to apply a
+certain operator as a reduce function.
```raku
sub simple-array-sum (@ar) {
@@ -234,11 +234,11 @@ In Perl 6, this is not needed if it's the last statement in a block (any code
surrounded by a `{` and `}`.
The `given/when` construct is similar to a `switch/case` found in other
-languages (but not Python, sadly), but uses the
-[https://docs.perl6.org/language/operators#index-entry-smartmatch_operator](smartmatch
-operator) implicitly to check if the statements given to `when` are `True`. The
-`*` is the [https://docs.perl6.org/type/Whatever](Whatever operator), which in
-this case will get the value of `$i`.
+languages (but not Python, sadly), but uses the [Smartmatch
+operator](https://docs.perl6.org/language/operators#index-entry-smartmatch_operator)
+implicitly to check if the statements given to `when` are `True`. The `*` is the
+[Whatever operator](https://docs.perl6.org/type/Whatever), which in this case
+will get the value of `$i`.
Lastly, he `$_` in the `map` function is similar to inside a `for` loop,
it's the current element. Since the code given to `map` is inside a block,
@@ -408,7 +408,7 @@ of the logic it's using to get the result. The biggest difference is that in
Perl 6, strings can't be accessed as lists, so I use the `substr` method to
extract the parts that I want. The first one starts at `*-2`, which means 2
places before the end. The others get a
-[https://docs.perl6.org/type/Range](`Range`) as argument, and will get the
+[`Range`](https://docs.perl6.org/type/Range) as argument, and will get the
characters that exist in that range.
```raku
@@ -425,11 +425,11 @@ sub time-conversion ($s) {
```
The `.Int` method converts the `Str` object into an `Int` object, so we can
-perform calculations on it. The `eq` operator checks specifically for
-[https://docs.perl6.org/routine/eq](_string equality_). Since Perl 6 is a
-[https://en.wikipedia.org/wiki/Gradual_typing](gradually typed programming
-language), there's a dedicated operator to ensure that you're checking string
-equality correctly.
+perform calculations on it. The `eq` operator checks specifically for [_string
+equality_](https://docs.perl6.org/routine/eq). Since Perl 6 is a [gradually
+typed programming language](https://en.wikipedia.org/wiki/Gradual_typing),
+there's a dedicated operator to ensure that you're checking string equality
+correctly.
## Wrap-up
@@ -442,4 +442,4 @@ This is also the first post in which I have tried this format to show off two
languages side-by-side, and to highlight differences in how you can accomplish
certain (relatively simple) tasks with them. If you have suggestions to improve
this format, do not hesitate to contact me. I am always open for feedback,
-preferably via email. You can find my contact details on the [/](homepage).
+preferably via email. You can find my contact details on the [homepage](/).