diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2023-11-20 15:40:49 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2023-11-20 15:40:49 +0800 |
| commit | 72dc5412e640e26601ffdebc4f0247db4c4bc7fe (patch) | |
| tree | d405aa98925dfed0b745e5ec331e9498005b1de7 /challenge-243/jo-37/Blog.md | |
| parent | 35d79358f3d12607da66ffefefed5e93c469d396 (diff) | |
| parent | fda51162ad0e1e8b4489fd2c73ef7dfdc8f0df5e (diff) | |
| download | perlweeklychallenge-club-72dc5412e640e26601ffdebc4f0247db4c4bc7fe.tar.gz perlweeklychallenge-club-72dc5412e640e26601ffdebc4f0247db4c4bc7fe.tar.bz2 perlweeklychallenge-club-72dc5412e640e26601ffdebc4f0247db4c4bc7fe.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-243/jo-37/Blog.md')
| -rw-r--r-- | challenge-243/jo-37/Blog.md | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/challenge-243/jo-37/Blog.md b/challenge-243/jo-37/Blog.md deleted file mode 100644 index f3ae3e7b96..0000000000 --- a/challenge-243/jo-37/Blog.md +++ /dev/null @@ -1,44 +0,0 @@ -# Missing Reversed Inversions -## Task 1: Missing Members -> You are given two arrays of integers. -> Write a script to find out the missing members in each other arrays. - -In set theory, given two sets A and B, this task asks for the difference sets A \ B and B \ A. - -There are many approches to solve this with Perl. -The most basic way would be to use hashes as representations of sets. -Hash slices come *very* handy when an array shall be convertet to as set: -``` -my @a = (...); -my %ha; -@ha{@a} = (); -``` -Now `%h` is a hash with all members of `@a` as keys. -Taking the set difference A \ B to a second array `@b` is as easy as: -``` -@b = (...); -delete @ha{@b}; -``` -However, I prefer a more functional approach. -Using PDL ndarrays of unique sorted numbers as set representations. -Then we may use PDL set operation in a natural way to solve the task: -``` -$m1 = long(...)->uniq; -``` -makes `$m1` a 1-d ndarray representing a set and -``` -setdiff_sorted($m1, $m2); -``` -gives M1 \ M2. -Same result, but better readable. -## Task 2: Flip Matrix -> You are given `n x n` binary matrix. -> Write a script to flip the given matrix as below. - -Again, with PDL this task is almost trivial. -Using `PDL::NiceSlice` we may reverse a dimension using the notation `(-1:0)`. -Reverting a value is done with the unary negation operator `!`. -Performing the "flip matrix" operation on a 2-d ndarray `$m` thus is as easy as: -``` -!$m->(-1:0) -```
\ No newline at end of file |
