aboutsummaryrefslogtreecommitdiff
path: root/challenge-243/jo-37
diff options
context:
space:
mode:
authorJörg Sommrey <28217714+jo-37@users.noreply.github.com>2023-11-17 16:21:46 +0100
committerGitHub <noreply@github.com>2023-11-17 16:21:46 +0100
commit479ffe0ca464f86c2334abb2d6f947486742309c (patch)
tree6c131577c602247cc69567bed3550a45832a40e1 /challenge-243/jo-37
parentfa5d9c8163a12f98701b7002ed0bcea12f48a411 (diff)
downloadperlweeklychallenge-club-479ffe0ca464f86c2334abb2d6f947486742309c.tar.gz
perlweeklychallenge-club-479ffe0ca464f86c2334abb2d6f947486742309c.tar.bz2
perlweeklychallenge-club-479ffe0ca464f86c2334abb2d6f947486742309c.zip
Fix markdown
Diffstat (limited to 'challenge-243/jo-37')
-rw-r--r--challenge-243/jo-37/blog/Blog.md21
1 files changed, 11 insertions, 10 deletions
diff --git a/challenge-243/jo-37/blog/Blog.md b/challenge-243/jo-37/blog/Blog.md
index dd75639527..ce6ce1aec2 100644
--- a/challenge-243/jo-37/blog/Blog.md
+++ b/challenge-243/jo-37/blog/Blog.md
@@ -1,5 +1,6 @@
-#Count the Pairs on the Floor
-##Task 1: Reverse Pairs
+# Count the Pairs on the Floor
+
+## Task 1: Reverse Pairs
**Submitted by: Mohammad S Anwar**
---
@@ -12,7 +13,7 @@ A reverse pair is a pair `(i, j)` where:
a) `0 <= i < j < nums.length` and
b) `nums[i] > 2 * nums[j]`.
-###Example 1
+### Example 1
```
Input: @nums = (1, 3, 2, 3, 1)
Output: 2
@@ -20,7 +21,7 @@ Output: 2
(1, 4) => nums[1] = 3, nums[4] = 1, 3 > 2 * 1
(3, 4) => nums[3] = 3, nums[4] = 1, 3 > 2 * 1
```
-###Example 2
+### Example 2
```
Input: @nums = (2, 4, 3, 5, 1)
Output: 3
@@ -30,7 +31,7 @@ Output: 3
(3, 4) => nums[3] = 5, nums[4] = 1, 5 > 2 * 1
```
---
-###Solution
+### Solution
Using the Perl Data Language to solve this task.
First we create a 1-d long ndarray from the given numbers.
@@ -91,14 +92,14 @@ The sum over the and'ed matrices yields the total number of reverse pairs:
((sequence($nums) > sequence(1, $nums->dim(0)))
& ($nums->dummy(0) > 2 * $nums))->sum;
```
-##Task 2: Floor Sum
+## Task 2: Floor Sum
**Submitted by: Mohammad S Anwar**
---
You are given an array of positive integers (`>=1`).
Write a script to return the sum of `floor(nums[i] / nums[j])` where `0 <= i,j < nums.length`. The `floor()` function returns the integer part of the division.
-###Example 1
+### Example 1
```
Input: @nums = (2, 5, 9)
Output: 10
@@ -113,13 +114,13 @@ floor(5 / 2) = 2
floor(9 / 2) = 4
floor(9 / 5) = 1
```
-###Example 2
+### Example 2
```
Input: @nums = (7, 7, 7, 7, 7, 7, 7)
Output: 49
```
---
-###Solution
+### Solution
Again, using PDL.
Creating a 1-d double ndarray from the given numbers:
@@ -139,4 +140,4 @@ Finally, sum over this matrix:
```
floor($nums / $nums->dummy(0))->sum;
```
-This works not only for positive integers but for all non-zero integers. \ No newline at end of file
+This works not only for positive integers but for all non-zero integers.