{"id":6782,"date":"2021-04-30T10:46:22","date_gmt":"2021-04-30T10:46:22","guid":{"rendered":"https:\/\/www.dyalog.com\/blog\/?p=6782"},"modified":"2021-12-07T14:33:14","modified_gmt":"2021-12-07T14:33:14","slug":"2020-problem-solving-competition-phase-ii-highlights","status":"publish","type":"post","link":"https:\/\/www.dyalog.com\/blog\/2021\/04\/2020-problem-solving-competition-phase-ii-highlights\/","title":{"rendered":"Highlights of the 2020 Problem Solving Competition \u2013 Phase II"},"content":{"rendered":"<p>With Dyalog\u2019s APL <a href=\"https:\/\/www.dyalogaplcompetition.com\/\">Problem Solving Competition 2021<\/a> in full swing, it\u2019s time to highlight some of the excellent solutions that were submitted to last year\u2019s edition.<\/p>\n<p><a href=\"https:\/\/aplwiki.com\/wiki\/User:Xpqz\">Stefan Kruger<\/a> works for IBM making databases. While he tries to learn at least one new programming language a year, he got hooked on APL and participated in the competition. This is his perspective on some solutions that the judges picked out &ndash; call it the \u201cJudges\u2019 Pick\u201d, if you like; smart, novel, or otherwise noteworthy solutions that can serve as an inspiration.<\/p>\n<p>This blog post is also available as an interactive <a href=\"https:\/\/github.com\/Dyalog\/dyalog-jupyter-notebooks\/blob\/master\/2020%20Problem%20Solving%20Competition%20%E2%80%93%20Phase%20II%20Highlights.ipynb\">Jupyter Notebook document<\/a>.<\/p>\n<hr \/>\n<address style=\"font-style:italic\">By Stefan Kruger<\/address>\n<p>I\u2019ll show a cool solution or two to each Phase II problem and dive into the details of a couple. If you need to refresh your memory with what the problems looked like, there&#8217;s a <a href=\"https:\/\/www.dyalog.com\/uploads\/files\/student_competition\/2020_problems_phase2.pdf\">PDF of the Phase II problems<\/a>.<\/p>\n<p>Oh, and note that at the time of writing there is still plenty time to take part in the current edition of the competition (and really, who <em>knew<\/em> bowling was so complicated?) &ndash; there are some juicy cash prices to be won.<\/p>\n<h2>Problem 1: Take a Dive (1 task)<\/h2>\n<p><em>Level of Difficulty: Low<\/em><\/p>\n<p>So let&#8217;s kick off with problem 1. The task was to calculate the score of an Olympic dive, consisting of a technical difficulty rating and a vector containing either 3, 5 or 7 judges&#8217; scores. Only the central three ordered judges&#8217; scores should be considered, which should be summed and multiplied by the technical difficulty rating.<\/p>\n<p>Here is a cunning trick that wasn&#8217;t at all obvious:<\/p>\n<pre><code class=\"language-apl\">\u2207 score\u2190dd DiveScore scores;sorted;cenzored;rotator\r\n  \u235d 2020 APL Problem Solving Competition Phase II\r\n  \u235d Problem 1, Task 1 - DiveScore\r\n   \r\n  sorted\u2190{\u2375[\u234b\u2375]}scores\r\n   \r\n  \u235d  0 1 2 rotates score indexes to 123, 23451 or 3456712\r\n  \u235d  So three center values always goes first\r\n  \u235d  51 = (0 1 2\u2227.= 3 5 7 \u2218.|\u2373100) \u2373 1\r\n  rotator\u219051\r\n \r\n  cenzored\u21903\u2191rotator\u233dsorted\r\n  score\u2190\u234e2\u2355dd+.\u00d7cenzored\r\n\u2207\r\n<\/code><\/pre>\n<pre><code class=\"language-apl\">      2.9 2.6 2.7 DiveScore\u00a8(7 7.5 6.5 8 8 7.5 7)(9.5 8 8.5)(7.5 7 7 8.5 8)<\/code><code>\r\n63.8 67.6 60.75\r\n<\/code><\/pre>\n<p>This contestant figured out that if a vector of length 3, 5 or 7 is rotated 51 steps, then the original central three items will always end up at the beginning. No, really. It turns out that 51 is the first number <code class=\"language-apl\">X<\/code> such that <code class=\"language-apl\">0 1 2\u22613 5 7|X<\/code>. They tabulated the options and picked the first solution, guessing that it&#8217;d be less than 100:<\/p>\n<pre><code class=\"language-apl\">      \u23780 1 2\u2227.=3 5 7\u2218.|\u2373100\r\n51\r\n<\/code><\/pre>\n<p>But there is another way &ndash; this is one of those situations where the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Chinese_remainder_theorem\">Chinese Remainder Theorem<\/a> comes in handy, especially since it&#8217;s available on <a href=\"https:\/\/aplcart.info\/?q=chinese#\">APLcart<\/a>:<\/p>\n<pre><code class=\"language-apl\">      3 5 7 {m|\u2375+.\u00d7\u237a(\u22a3\u00d7\u22a2|\u2218\u2283{0=\u2375:1 0 \u22c4 (\u2375\u2207\u2375|\u237a)+.\u00d70 1,\u236a1,-\u230a\u237a\u00f7\u2375})\u00a8\u2368\u237a\u00f7\u2368m\u2190\u00d7\/\u237a} 0 1 2 \u235d https:\/\/aplcart.info?q=chinese<\/code><code>\r\n51\r\n<\/code><\/pre>\n<p>If you figured <em>that<\/em> out, award yourself a well-deserved pat on the back. For us mortals, we probably all did something rather more pedestrian:<\/p>\n<pre><code class=\"language-apl\">DiveScore \u2190 {\r\n    d \u2190 2-2\u00f7\u23687-\u2262\u2375       \u235d How many items should we drop each side?\r\n    \u237a+.\u00d7(-d)\u2193d\u2193\u2375[\u234b\u2375]\r\n}\r\n<\/code><\/pre>\n<h2>Problem 2 \u2013 Another Step in the Proper Direction (1 task)<\/h2>\n<p><em>Level of Difficulty: Medium<\/em><\/p>\n<p>Problem 2 builds upon Problem 5 from Phase I. In short, we are asked to write a function <code class=\"language-apl\">Steps<\/code> that takes a two-element vector to the right, defining a start and end value, and an optional left integer argument that tweaks how we generate values from <code class=\"language-apl\">start<\/code> to <code class=\"language-apl\">end<\/code>. The complexity here comes from the many combinations of behaviours from what exactly is given as the left argument: integer or float? positive or negative? Also, the range must be inclusive, even if a floating-point step size means that the end point is overshot. I took this on thinking it would be trivial &ndash; it wasn&#8217;t.<\/p>\n<p>Here&#8217;s a great solution that manages to combine this functionality with a call to a single dfn:<\/p>\n<pre><code class=\"language-apl\">\u2207 steps\u2190{p}Steps fromTo;segments;width\r\n  width \u2190 |-\/fromTo\r\n  :If 0=\u2395NC'p' \u235d No left argument: same as Problem 5 of Phase I\r\n      segments \u2190 0,\u2373width\r\n  :ElseIf p0 \u235d p is the step size\r\n      segments \u2190 p {\u2375\u230a\u237a\u00d70,\u2373\u2308\u2375\u00f7\u237a} width\r\n  :ElseIf p=0 \u235d As if we took zero step\r\n      segments \u2190 0\r\n  :EndIf\r\n  \u235d Take into account the start point and the direction.\r\n  steps \u2190 fromTo {(\u2283\u237a)+(-\u00d7-\/\u237a)\u00d7\u2375} segments\r\n\u2207\r\n<\/code><\/pre>\n<p>I ended up with something more convoluted, with a few ugly special cases, and shamelessly borrowing from <a href=\"https:\/\/dfns.dyalog.com\/c_iotag.htm\">dfns.iotag<\/a>:<\/p>\n<pre><code class=\"language-apl\">Steps \u2190 {\r\n    range \u2190 {\r\n        r \u2190 \u237a-s\u00d7\u2395IO-\u2373\u230a1-(\u237a-\u2283\u2375)\u00f7s\u2190\u00d7\/1\u2193\u2375,(\u237a&gt;\u2283\u2375)\/\u00af1 \u235d \"inspired\" by dfns.iotag\r\n        (\u2283\u2375)\u2260\u2283\u2296r: r,\u2283\u2375 \u22c4 r   \u235d Ensure endpoint is included &ndash; yeuch :(\r\n    }\r\n    \u237a \u2190 \u236c\r\n    (b e) \u2190 \u2375\r\n    \u237a\u2261\u236c: b range e        \u235d No \u237a\r\n    \u237a=0: b                \u235d Zero step; return start point\r\n    \u237a&gt;0: b range e \u237a      \u235d Positive \u237a\r\n    len \u2190 (e-b)\u00f7count\u2190\u230a-\u237a \u235d Negative \u237a\r\n    len=0: b\/\u23681+count     \r\n    b range e len\r\n}\r\n<\/code><\/pre>\n<h2>Problem 3 \u2013 Past Tasks Blast (1 task)<\/h2>\n<p><em>Level of Difficulty: Medium<\/em><\/p>\n<p>The task here was to scrape the Dyalog APL Problem Solving Competition webpage to extract all links to PDF files. We get the suggestion to use either Dyalog&#8217;s <code class=\"language-apl\">HttpCommand<\/code> or shell out to a system mechanism for fetching a web page.<\/p>\n<p>To use <code class=\"language-apl\">HttpCommand<\/code>, we first need to load it:<\/p>\n<pre><code class=\"language-apl\">      ]load HttpCommand<\/code><code>\r\n#.HttpCommand\r\n<\/code><\/pre>\n<p>Here&#8217;s a slightly tweaked competition submission, showing great flair in how to process XML:<\/p>\n<pre><code class=\"language-apl\">PastTasks \u2190 {\r\n    url \u2190 \u2375\r\n    r \u2190 (HttpCommand.Get url).Data  \u235d get page contents\r\n    (d n c a t) \u2190 \u2193\u2349\u2395XML r          \u235d depth; name; content; attributes; type\r\n    (k v) \u2190 \u2193\u2349 \u2283\u236a\/ ((,'a')\u2218\u2261\u00a8n)\/a   \u235d extract key-value pairs of &lt;a&gt; elements\r\n    urls \u2190 ('href'\u2218\u2261\u00a8k)\/v           \u235d get URLs\r\n    pdfs \u2190 ('.pdf'\u2218\u2261\u00a8\u00af4\u2191\u00a8urls)\/urls \u235d filter .pdfs\r\n    base \u2190 \u2283\u233d\u2283('base'\u2218\u2261\u00a8n)\/a        \u235d base URL\r\n    base\u2218,\u00a8pdfs\r\n}\r\n<\/code><\/pre>\n<p>The problem statement suggests that a regex-based solution might be tolerable. Here&#8217;s a stab at that approach:<\/p>\n<pre><code class=\"language-apl\">PastTasks \u2190 {\r\n    body \u2190 (HttpCommand.Get \u2375).Data\r\n    pdfs \u2190 '&lt;a href=\"(.+?\\.pdf)\"'\u2395S'\\1'\u22a2body\r\n    base \u2190 '&lt;base href=\"(.+?)\"'\u2395S'\\1'\u22a2body\r\n    base,\u00a8pdfs\r\n}\r\n<\/code><\/pre>\n<p>So which is the &#8220;better&#8221; solution? Well, the first approach has a number of advantages: firstly, is much more robust (provided that the web page is valid XHTML, which we are told is a given), meaning that we can abdicate responsibility for dealing with markup quirks (single vs double quotes, whitespace etc) to the built-in <code class=\"language-apl\">\u2395XML<\/code> system function, and secondly, there is <a href=\"http:\/\/regex.info\/blog\/2006-09-15\/247\">that (in)famous quote<\/a> from Jamie Zawinski:<\/p>\n<div style=\"border:1px solid #ccc;padding:1em;margin:.5em 0\">Some people, when confronted with a problem, think \u201cI know, I&#8217;ll use regular expressions.\u201d Now they have two problems. &ndash; <em>jwz<\/em><\/div>\n<p>Mixing in a liberal helping of regular expressions in with APL is perhaps not helping APL&#8217;s unfair reputation for being write-only.<\/p>\n<p>However, when dealing with patterns in textual data, as we unquestionably are here, regular expressions &ndash; even in a powerful language like APL &ndash; are sharp tools that are hard to beat, and any programmer worth their salt owes it to themselves to master them. In the case above, had the data not neatly been parseable as XML, it would have been more awkward to solve a problem like this relying only on APL primitives.<\/p>\n<h2>Problem 4 \u2013 Bioinformatics (2 tasks)<\/h2>\n<p><em>Level of Difficulty: Medium<\/em><\/p>\n<p>The two tasks making up Problem 4 are borrowed from Project Rosalind, which is a Bioinformatics problem collection that often has great APL affinity:<\/p>\n<ul>\n<li><a href=\"http:\/\/rosalind.info\/problems\/revp\/\">Locating Restriction Sites<\/a><\/li>\n<li><a href=\"http:\/\/rosalind.info\/problems\/sset\/\">Counting Subsets<\/a><\/li>\n<\/ul>\n<p>and a hint that one benefits from understanding <em>modular multiplication<\/em>, as this isn&#8217;t built into Dyalog APL.<\/p>\n<p>Here is a great example:<\/p>\n<pre><code class=\"language-apl\">revp \u2190 {                    \u235d r \u2190 revp dna\r\n   dnaNum \u2190 'ACGT'\u2373\u2375        \u235d Convert to 1..4 so that A+T = C+G = 5\r\n   FindRevp \u2190 {             \u235d Given chunk size, extract positions and build the output format\r\n       chunks \u2190 \u2375,\/dnaNum\r\n       isRevp \u2190 (\u22a2\u22615-\u233d)\u00a8chunks\r\n       \u2375,\u2368\u236a\u2378isRevp\r\n   }\r\n   \u2283\u236a\/FindRevp\u00a84 6 8 10 12  \u235d Test against all chunk sizes and collect results\r\n}\r\n<\/code><\/pre>\n<pre><code class=\"language-apl\">sset \u2190 {          \u235d r\u2190sset n\r\n   bin \u2190 2\u22a5\u2363\u00af1\u22a2\u2375  \u235d Binary digits\r\n   arr \u2190 \u233d2*bin   \u235d Repeated squaring: Starting from MSB and 1, square \u2375, multiply \u237a, modulo m\r\n   mod \u2190 1000000\r\n   {mod|\u237a\u00d7\u2375*2}\/arr,1\r\n}\r\n<\/code><\/pre>\n<p>This contestant also saw fit to include their test suite; a nice touch! <a href=\"https:\/\/www.jsoftware.com\/papers\/APLDesignExercises1.htm#47\">Roger Hui&#8217;s version of assert<\/a> has become the de facto standard, and the contestant puts it to good use:<\/p>\n<pre><code class=\"language-apl\">Assert \u2190 {\u237a\u2190'assertion failure' \u22c4 0\u220a\u2375:\u237a \u2395SIGNAL 8 \u22c4 shy\u21900} \u235d Roger Hui's Assert\r\n<\/code><\/pre>\n<pre><code class=\"language-apl\">RevpTest \u2190 {\r\n   s \u2190 'TCAATGCATGCGGGTCTATATGCAT'\r\n   ans \u2190 revp s\r\n   Assert 8 2\u2261\u2374ans:\r\n   Assert 5 4 7 4 17 4 18 4 21 4 4 6 6 6 20 6\u2261\u220aans:\r\n  \r\n   header \u2190 'Contest2020\/Data\/'  \u235d Change as needed\r\n   data1 \u2190 \u220a1\u2193\u2283\u2395NGET (header,'rosalind_revp_1_dataset.txt') 1\r\n   ans1 \u2190 \u2191\u234e\u00a8\u2283\u2395NGET (header,'rosalind_revp_1_output.txt') 1\r\n   data2 \u2190 \u220a1\u2193\u2283\u2395NGET (header,'rosalind_revp_2_dataset.txt') 1\r\n   ans2 \u2190 \u2191\u234e\u00a8\u2283\u2395NGET (header,'rosalind_revp_2_output.txt') 1\r\n   Assert ans1 \u2261 revp data1:\r\n   Assert ans2 \u2261 revp data2:\r\n   'Test passed'\r\n}\r\n<\/code><\/pre>\n<pre><code class=\"language-apl\">SsetTest \u2190 {\r\n   Assert 8 = sset 3:\r\n   Assert 551872 = sset 857:\r\n   Assert 935424 = sset 870:\r\n   'Test passed'\r\n}\r\n<\/code><\/pre>\n<h2>Problem 5 \u2013 Future and Present Value (2 tasks)<\/h2>\n<p><em>Level of Difficulty: Medium<\/em><\/p>\n<p>Problem 5 is some hedge fund maths, or something where my eyes glazed over before I fully understood the ask. What is this, K\u203d<\/p>\n<p>This solution is impressively compact &ndash; I removed the comments to highlight the APL artistry on display: no less than three scans, count &#8217;em!<\/p>\n<pre><code class=\"language-apl\">rr \u2190 {AR\u00d7+\\\u237a\u00f7AR\u2190\u00d7\\1+\u2375} \r\npv \u2190 {+\/\u237a\u00f7\u00d7\\1+\u2375}\r\n<\/code><\/pre>\n<p>Here&#8217;s how the competitor outlined how their solution works:<\/p>\n<div style=\"border:1px solid #ccc;padding:1em;margin:.5em 0\">\n<p>This can be calculated elegantly with the following operations:<\/p>\n<ol type=\"1\">\n<li>Find the accumulated interest rate (<code class=\"language-apl\">AR<\/code>) for each term (<code class=\"language-apl\">AR\u2190\u00d7\\1+\u2375<\/code>).<\/li>\n<li>Deprecate the cashflow amounts by dividing them by <code class=\"language-apl\">AR<\/code>. This finds the present value of all the amounts.<\/li>\n<li>Accumulate all the present values of the amounts to find the total present value at each term.<\/li>\n<li>Multiply by <code class=\"language-apl\">AR<\/code> to find future values at each term.<\/li>\n<\/ol>\n<p>This way the money that was invested or withdrawn in a term is not changed for that term, but the money that came from the previous terms is multiplied by the current interest rate for each term arriving to the correct recurrent relation:<\/p>\n<table>\n<tr>\n<td>Step 2)<\/td>\n<td style=\"text-align:left\"><code class=\"language-apl\">amounts[i]\/AR[i]                     \u235d \u2261 PV[i]<\/code><\/td>\n<\/tr>\n<tr>\n<td>Step 3)<\/td>\n<td style=\"text-align:left\"><code class=\"language-apl\">amounts[i]\/AR[i] + APV[i-1]<\/code><\/td>\n<tr>\n<td>Step 4)<\/td>\n<td style=\"text-align:left\"><code class=\"language-apl\">amounts[i] + APV[i-1]\u00d7AR[i]<\/code><br \/>\n                        <code class=\"language-apl\">amounts[i] + APV[i-1]\u00d7AR[i-1]\u00d7(1+rate[i])<\/code><br \/>\n                        <code class=\"language-apl\">amounts[i] + r[i-1]\u00d7(1+rate[i])      \u235d \u2261 r[i]<\/code><\/td>\n<\/table>\n<\/div>\n<h2>Problem 6 \u2013 Merge (1 task)<\/h2>\n<p><em>Level of Difficulty: Medium<\/em><\/p>\n<p>Mail merge &ndash; gotta love it. Your spam folder is full of bad examples of this: &#8220;Dear $FIRSTNAME, do you want to purchase a bridge?&#8221; We&#8217;re given a template file with patterns such as <code class=\"language-apl\">@firstname@<\/code> which are to be replaced with values stored in a JSON file. Here&#8217;s a smart approach from a competitor who knows their way around the <code class=\"language-apl\">@<\/code> operator:<\/p>\n<pre><code class=\"language-apl\">Merge \u2190 {\r\n   templateFile \u2190 \u237a\r\n   jsonFile \u2190 \u2375\r\n   template \u2190 \u2283\u2395NGET templateFile\r\n   ns \u2190 \u2395JSON\u2283\u2395NGET jsonFile\r\n\r\n   getValue \u2190 {\r\n       0=\u2374\u2375:,'@'   \u235d '@@'         \u2192 ,'@'\r\n       6::'???'    \u235d ~\u2375\u220ans.\u2395NL \u00af2 \u2192 '???'\r\n       \u2355ns\u234e\u2375       \u235d  \u2375\u220ans.\u2395NL \u00af2 \u2192 \u2355ns.\u2375\r\n   }\r\n   \u220agetValue\u00a8@(\u2374\u23741 0\u2368)'@'(1\u2193\u00a8=\u2282\u22a2)template\r\n}\r\n<\/code><\/pre>\n<p>The key insight here is that since each template starts and ends with the same marker, we can partition the data on sections beginning with <code class=\"language-apl\">@<\/code> and then we&#8217;ll have a vector where every other element is a template to be substituted. Here&#8217;s an example of this:<\/p>\n<pre><code class=\"language-apl\">      \u2191('@'(1\u2193\u00a8=\u2282\u22a2) '@title@ @firstname@ @lastname@, would you be interested in the Brooklyn Bridge?') (1 0 1 0 1 0)<\/code><code>\r\n\u250c\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\r\n\u2502title\u2502 \u2502firstname\u2502 \u2502lastname\u2502, would you be interested in the Brooklyn Bridge?\u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u25021    \u25020\u25021        \u25020\u25021       \u25020                                                \u2502\r\n\u2514\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\r\n<\/code><\/pre>\n<p>I added the second row for clarity to show the alternating templates. Cool, huh? However, this only works correctly if the data leads with a template. Consider:<\/p>\n<pre><code class=\"language-apl\">      '@'(1\u2193\u00a8=\u2282\u22a2) 'Dear @firstname@ @lastname@, or maybe the Golden Gate?'<\/code><code>\r\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\r\n\u2502firstname\u2502 \u2502lastname\u2502, or maybe the Golden Gate?\u2502\r\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\r\n<\/code><\/pre>\n<p>We still have the alternating templates, but the prefix (<code>Dear <\/code>) is lost. We can tweak the <code class=\"language-apl\">Merge<\/code> function a bit to cater for this if we need to:<\/p>\n<pre><code class=\"language-apl\">Merge \u2190 {\r\n    templateFile \u2190 \u237a\r\n    jsonFile \u2190 \u2375\r\n    template \u2190 \u2283\u2395NGET templateFile\r\n    ns \u2190 \u2395JSON\u2283\u2395NGET jsonFile\r\n    first \u2190 templ\u2373'@'\r\n    first&gt;\u2262templ: templ    \u235d No templates at all\r\n    prefix \u2190 first\u2191templ   \u235d Anything preceding the first '@'?\r\n\r\n    getValue \u2190 {\r\n        0=\u2374\u2375:,'@'   \u235d '@@'         \u2192 ,'@'\r\n        6::'???'    \u235d ~\u2375\u220ans.\u2395NL \u00af2 \u2192 '???'\r\n        \u2355ns\u234e\u2375       \u235d  \u2375\u220ans.\u2395NL \u00af2 \u2192 \u2355ns.\u2375\r\n    }\r\n    \u220aprefix,getValue\u00a8@(\u2374\u23741 0\u2368)'@'(1\u2193\u00a8=\u2282\u22a2)template\r\n}\r\n<\/code><\/pre>\n<p>Now, the competition is pitched such that &#8220;proper array solutions&#8221; are preferred &ndash; and for good reasons, most of the time. However, it&#8217;s hard to overlook some industrial regex action in this case. Strictly for Perl-fans:<\/p>\n<pre><code class=\"language-apl\">Merge \u2190 {\r\n    mrg \u2190 \u2395JSON\u2283\u2395NGET \u2375\r\n    keys \u2190 mrg.\u2395NL\u00af2\r\n    vals \u2190 mrg.\u234e\u00a8keys\r\n\r\n    ('@',\u00a8(keys,'' '[^@]+'),\u00a8'@')\u2395R((\u2355\u00a8vals),'@' '???')\u2283\u2395NGET \u237a\r\n}\r\n<\/code><\/pre>\n<h2>Problem 7 \u2013 UPC (3 tasks)<\/h2>\n<p><em>Level of Difficulty: Medium<\/em><\/p>\n<p>Problem 7 had us learning more about bar codes than we ever thought necessary. Read them, write them, verify them, scan them &ndash; forwards and backwards no less. Good scope for stretching your array muscles on this one. The eagle-eyed amongst you may have spotted that the verification aspect is a simplified version of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Luhn_algorithm\">Luhn&#8217;s algorithm<\/a>, which a certain Morten Kromberg used to illustrate APL&#8217;s array capabilities at <a href=\"https:\/\/jiotalks.com\/watch\/204\/home\/Morten_Kromberg_&amp;_Aaron_Hsu\/Pragmatic_Array_Oriented_Functional_Programming\">JIO<\/a> a while back.<\/p>\n<p>Here&#8217;s a good solution:<\/p>\n<pre><code class=\"language-apl\">CheckDigit \u2190 (10|\u2218-+.\u00d7\u2218(11\u23743 1))          \u235d Computes the check digit for a UPC-A barcode.\r\n\r\nUPCRD \u2190 114 102 108 66 92 78 80 68 72 116 \u235d Right digits of a UPC-A barcode, base 10.\r\nbUPCRD \u2190 \u23492\u2218\u22a5\u2363\u00af1\u22a2UPCRD                    \u235d Bit matrix with one right digit per row.\r\n<\/code><\/pre>\n<pre><code class=\"language-apl\">WriteUPC \u2190 {\r\n   \u235d Writes the bits of a UPC-A barcode.  \r\n   ~((11\u2218=\u2262)\u2227(\u2227\/0\u2218\u2264\u2227\u2264\u22189))\u2375: \u00af1            \u235d Check for simple errors\r\n   b \u2190 bUPCRD[\u2375,CheckDigit \u2375;]  \r\n   1 0 1, (,~6\u2191b), 0 1 0 1 0, (,6\u2193b), 1 0 1 \r\n}\r\n<\/code><\/pre>\n<pre><code class=\"language-apl\">ReadUPC \u2190 {\r\n   \u235d Reads a UPC-A barcode into its digits.\r\n   ~(\u2227\/0\u2218\u2264\u2227\u2264\u22181)\u2375: \u00af1                 \u235d Input isn't a bit vector\r\n   95\u2260\u2262\u2375: \u00af1                         \u235d Number of bits must be 95\r\n   (b l m r e) \u2190 \u2375 \u2282\u2368 (\u220a\u00af1\u2218\u2193,\u233d) (3\u21911)(42\u21911)(5\u21911)\r\n   \r\n   b \u2228\u2365(\u2262\u22181 0 1) e: \u00af1               \u235d Wrong patterns for the guards\r\n   m\u22620 1 0 1 0: \u00af1\r\n   bits \u2190 \u219312 7\u2374 l,r\r\n   C \u2190 (\u2193bUPCRD)\u2218\u2373 ~@(\u23736)            \u235d Convert bits to digits\r\n   tf \u2190 ~\u2227\/10 &gt; nums \u2190 C bits        \u235d Should we try flipping the bits?\r\n   nums \u2190 (nums\u00d71-tf) + tf\u00d7C\u233d\u2193\u233d\u2191bits\r\n   \u2228\/10=nums: \u00af1                     \u235d Bits simply aren't right\r\n   (\u00af1\u2191nums)\u2260CheckDigit 11\u2191nums: \u00af1  \u235d Bad check digit\r\n   nums\r\n}\r\n<\/code><\/pre>\n<h2>Problem 8 \u2013 Balancing the Scales (1 task)<\/h2>\n<p><em>Level of Difficulty: Hard<\/em><\/p>\n<p>Our task is to partition a set of numbers into two groups of equal sum if this is possible, or return <code class=\"language-apl\">\u236c<\/code> if not. This is a well-known NP-complete problem called <a href=\"https:\/\/en.wikipedia.org\/wiki\/Partition_problem\">The Partition Problem<\/a> and, as such, has no polynomial time exact solutions. The problem statement indicates that we only need to consider a set of 20 numbers or fewer, which is a bit of a hint on what kind of solution is expected.<\/p>\n<p>This problem, in common with many other NP problems, also has a plethora of interesting heuristic solutions: polynomial algorithms that whilst not guaranteed to always find the optimal solution will either get close, or be correct for a significant subset of the problem domain in a fraction of the time the exact algorithms would take.<\/p>\n<p>However, it&#8217;s clear that Dyalog expects us to give an exact solution, and has given us an upper bound on the input data length. Finally, we&#8217;re offered the cryptic advice that<\/p>\n<div style=\"border:1px solid #ccc;padding:1em;margin:.5em 0\">Understanding the nuances of the problem is the key to developing a good algorithm.<\/div>\n<p>Yes, thank you, master Yoda.<\/p>\n<p>Here&#8217;s a great, efficient solution:<\/p>\n<pre><code class=\"language-apl\">Balance\u2190{\r\n   sum\u21901\u22a5\u2375\r\n   2|sum: \u236c   \u235d Lists with an odd sum cannot be split into equal parts.\r\n   halfsum\u2190sum\u00f72\r\n  \r\n   \u235d A partitioning method based on the algorithm by Horowitz and Sahni.\r\n   \u235d The basic idea of the algorithm is to split the input into two parts,\r\n   \u235d and then generate all subset sums for these parts. Then the problem\r\n   \u235d becomes finding a sum of two subset sums from different parts\r\n   \u235d equal to the desired value. Instead of sorting the sums and comparing\r\n   \u235d them like in the original algorithm, standard APL searching primitives\r\n   \u235d \u220a and \u2373 are used. Another key idea is to generate the subset sums\r\n   \u235d in a specific order, so that the nth subset sum in the vectors a and b\r\n   \u235d is the sum of the elements chosen by the binary representation of n.\r\n   \u235d This means that we can get the elements of the solution sum\r\n   \u235d without having to generate anything but the sums.\r\n   horowitzsahni\u2190{\r\n       s\u2190\u2375(\u2191{\u237a\u2375}\u2193)\u2368\u230a2\u00f7\u2368\u2262\u2375                          \u235d Split the input.\r\n       a b\u2190\u2283\u00a8(\u22a2,+)\/\u00a8s,\u00a80                           \u235d Generate the subset sums.\r\n       indexes\u2190a {(\u22a2,\u2375\u2373\u237a\u2337\u2368(\u2262\u237a)\u230a\u22a2)1\u2373\u2368\u237a\u220a\u2375} halfsum-b \u235d Search for solution indexes.\r\n       indexes[2]&gt;\u2262b: \u236c\r\n       \u2375 {(\u237a\/\u2368~\u2375)(\u2375\/\u237a)} \u220a(2\u2374\u00a8\u2368\u2262\u00a8s)\u22a4\u00a8indexes-1      \u235d Get the solution from the indexes.\r\n   }\r\n  \r\n   \u235d A simple exhaustive search. It uses the same binary representation\r\n   \u235d idea as the horowitzsahni function.\r\n   exhaustive\u2190{\r\n       i\u2190halfsum\u2373\u2368\u2283(\u22a2,+)\/\u2375,0\r\n       i&gt;2*\u2262\u2375: \u236c\r\n       \u2375 {(\u237a\/\u2368~\u2375)(\u2375\/\u237a)} (2\u2374\u2368\u2262\u2375)\u22a4i-1\r\n   }\r\n\r\n   \u235d The exhaustive method performs better than the Horowitz-Sahni method\r\n   \u235d for small input sizes. 14 seems to be a reasonable cutoff point.\r\n   14&gt;\u2262\u2375: exhaustive \u2375\r\n   horowitzsahni \u2375\r\n}\r\n<\/code><\/pre>\n<p>There are a number of clever touches here &ndash; there are actually two different solutions, an exhaustive search and an implementation of the algorithm due to Horowitz and Sahni, which, although still exponential, is known to be one of the fastest for certain subsets and input sizes. A switch based on input size checks for the crossover point and chooses the fastest option. And this is <em>fast<\/em> &ndash; five times faster than that of the Grand Prize winner, and four orders of magnitude faster than the slowest solution.<\/p>\n<p>Such a performance spread is intriguing, so there are clearly lessons to be learned here. When I tried this problem, I ended up with a pretty straight-forward (a.k.a. naive) brute force search:<\/p>\n<pre><code class=\"language-apl\">Balance \u2190 {\u2395IO\u21900\r\n    total \u2190 +\/\u2375\r\n    2|total: \u236c             \u235d Sum must be divisible by 2\r\n    psum \u2190 total\u00f72         \u235d Our target partition sum\r\n    bitp \u2190 \u23492\u2218\u22a5\u2363\u00af1\u23732*\u2262\u2375    \u235d All possible bit patterns up to \u2262\u2375\r\n    idx \u2190 \u2378&lt;\\psum=bitp+.\u00d7\u2375 \u235d First index of partition sum = target\r\n    \u236c\u2261idx: \u236c               \u235d If we have no 1s, there is no solution\r\n    part \u2190 idx\u2337bitp        \u235d Partition corresponding to solution index\r\n    (part\/\u2375)(\u2375\/\u2368~part)     \u235d Compress input by solution pattern and inverse\r\n}\r\n<\/code><\/pre>\n<p>If you come to APL from a scalar language, that approach must seem incredibly wasteful: make <em>all<\/em> bit patterns. Try <em>all<\/em> sums. Search for the right one, if it exists. But as it turns out, this is APL home turf advantage. Let&#8217;s try to demonstrate this point. If you did this &#8220;loop and branch&#8221;, you&#8217;d iterate over the bit patterns and stop once you find the first solution &ndash; in fact, for the test data in the problem specification, the first solution appears at around the 1500<sup>th<\/sup> bit pattern if you generate them as I do above. The vector version would need to consider the whole space of around<\/p>\n<pre><code class=\"language-apl\">      \u00af1+2*20<\/code><code>\r\n1048575\r\n<\/code><\/pre>\n<p>a million or so, so quite a difference. Surely, in this case the scalar approach should be way faster? Only one way to find out. We can make a scalar version in several ways &ndash; here&#8217;s the &#8220;Scheme&#8221; version:<\/p>\n<pre><code class=\"language-apl\">BalanceScalar \u2190 {\u2395IO\u21900     \u235d Warning: this is not the APL Way, as we shall see.\r\n    total \u2190 +\/\u2375\r\n    2|total: \u236c             \u235d Sum must be divisible by 2\r\n    psum \u2190 total\u00f72         \u235d Our target partition sum\r\n    data \u2190 \u2375\r\n    bitp \u2190 \u2193\u23492\u2218\u22a5\u2363\u00af1\u23732*\u2262\u2375   \u235d Pre-compute the bit patterns\r\n    {                      \u235d Try one sum after the other, halt on first solution\r\n        0=\u2375: \u236c\r\n        patt \u2190 \u2375\u2283bitp\r\n        psum=patt+.\u00d7data: (patt\/data)(data\/\u2368~patt) \u235d Exit on first solution found\r\n        \u2207\u00af1+\u2375\r\n    } \u00af1+\u2262bitp\r\n}\r\n<\/code><\/pre>\n<p>Dyalog&#8217;s got game when it comes to tail call optimisation, right? OK, let&#8217;s race:<\/p>\n<pre><code class=\"language-apl\">      'cmpx'\u2395CY'dfns'\r\n      d \u2190 10 81 98 27 28 5 1 46 63 99 25 39 84 87 76 85 78 64 41 93\r\n      cmpx 'Balance d' 'BalanceScalar d'<\/code><code>\r\n  Balance d       \u2192 2.7E\u00af2 |   0% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395            \r\n* BalanceScalar d \u2192 3.9E\u00af2 | +43% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\r\n<\/code><\/pre>\n<p>Vectorisation, Boolean vectors and primitive functions wins the day. We didn&#8217;t go <em>completely<\/em> scalar, to be fair, as we still pre-computed all the binary patterns.<\/p>\n<p>But back to the task at hand &ndash; let&#8217;s pit ourselves against the intellectual might of Horowitz and Sahni:<\/p>\n<pre><code class=\"language-apl\">horowitzsahni\u2190{\r\n    sum\u21901\u22a5\u2375\r\n    2|sum: \u236c   \u235d Lists with an odd sum cannot be split into equal parts.\r\n    halfsum\u2190sum\u00f72\r\n    s\u2190\u2375(\u2191{\u237a\u2375}\u2193)\u2368\u230a2\u00f7\u2368\u2262\u2375                          \u235d Split the input.\r\n    a b\u2190\u2283\u00a8(\u22a2,+)\/\u00a8s,\u00a80                           \u235d Generate the subset sums.\r\n    indexes\u2190a {(\u22a2,\u2375\u2373\u237a\u2337\u2368(\u2262\u237a)\u230a\u22a2)1\u2373\u2368\u237a\u220a\u2375} halfsum-b \u235d Search for solution indexes.\r\n    indexes[2]&gt;\u2262b: \u236c\r\n    \u2375 {(\u237a\/\u2368~\u2375)(\u2375\/\u237a)} \u220a(2\u2374\u00a8\u2368\u2262\u00a8s)\u22a4\u00a8indexes-1      \u235d Get the solution from the indexes.\r\n}\r\n<\/code><\/pre>\n<pre><code class=\"language-apl\">      cmpx 'horowitzsahni d' 'Balance d' 'BalanceScalar d'<\/code><code>\r\n  horowitzsahni d \u2192 4.7E\u00af5 |      0%                                         \r\n* Balance d       \u2192 2.8E\u00af2 | +59266% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395            \r\n  BalanceScalar d \u2192 4.0E\u00af2 | +84466% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\r\n<\/code><\/pre>\n<p>Ouch! Well, told you my exhaustive search was naive. An impressive performance from the competitor &ndash; but also an impressive performance from Dyalog APL &ndash; even my knocked up exhaustive search runs in a pretty decent 25&ndash;30ms or so, about half the time of <a href=\"https:\/\/gist.github.com\/xpqz\/20c1248347a8014e0a4b1cdabc730ddb\">my shoddy Python attempt<\/a> (although out-speeding Python is a low bar). I&#8217;m keeping the above implementation of Horowitz\/Sahni handy for next edition of <a href=\"https:\/\/aplwiki.com\/wiki\/Advent_of_Code\">Advent of Code<\/a>, where this problem always seems to crop up in some shape or form.<\/p>\n<h2>Problem 9 \u2013 Upwardly Mobile (1 task)<\/h2>\n<p><em>Level of Difficulty: Hard<\/em><\/p>\n<p>And so for the final question. We were offered strong hints that a neat array-oriented solution might not be possible, but that the judges were prepared to be proven wrong.<\/p>\n<p>Here&#8217;s a nicely compact, recursive solution:<\/p>\n<pre><code class=\"language-apl\">\u2207 weights \u2190 Weights filename;diag;FindWeights;start\r\n    diag \u2190 \u2191(\u2260\u2218(\u2395UCS 10)\u2286\u22a2)\u2283\u2395NGET filename\r\n    FindWeights \u2190 {\r\n        '\u250c\u2510\u2502'\u220a\u2368\u2283\u2375: \u22071\u2193\u2375                    \u235d if on any of these, go down        \r\n        \u2395A\u220a\u2368\u2283\u2375: \u2395A=\u2283\u2375                      \u235d if on a letter, give weights\r\n        r_disp \u2190 '\u2510'\u2373\u23680\u2337\u2375                  \u235d otherwise, (i.e. on '\u2534'), find the displacement of right branch,\r\n        l_disp \u2190 -1+'\u250c'\u2373\u2368\u233d0\u2337\u2375              \u235d ...and the left branch\r\n        wts \u2190 \u2191(\u2207r_disp\u233d\u2375)(\u2207l_disp\u233d\u2375)      \u235d recurse,\r\n        +\u233fwts\u00d7[0]\u233d(+\/wts)\u00d7r_disp (-l_disp) \u235d ...and calculate new weights\r\n    }\r\n    start \u2190 diag\u233d\u2368\u2378'\u2534\u2502'\u220a\u23680\u2337diag            \u235d starting position attained by \u233d'ing to '\u2534' or '\u2502'\r\n    weights \u2190 (~\u22180\u00f7\u2228\/)FindWeights start    \u235d remove 0s and get lowest weights\r\n\u2207\r\n<\/code><\/pre>\n<p>Finally, someone took the suggestion that an array-based solution might not be possible as a personal challenge and produced the following:<\/p>\n<pre><code class=\"language-apl\">Weights \u2190 {\r\n    m  \u2190 \u2191(\u2395UCS 10)(\u2260\u2286\u22a2)\u2283\u2395NGET \u2375 \u235d no empty lines midway through so this is fine\r\n    fm \u2190 m='\u2534'               \u235d fulcrum mask\r\n    ER \u2190 {+\\1-\u2375\\\u00af2-\u233f0\u236a\u2378\u2375}    \u235d distance to closest 1 to the left\r\n      \r\n    wa \u2190 +\/,m\u220a\u2395A             \u235d weight amount\r\n    wi \u2190 (\u2373wa)@{\u2375} m\u220a\u2395A      \u235d weight indexes\r\n    fa \u2190 +\/,fm               \u235d fulcrum amount\r\n    fir\u2190 wa + \u2373fa            \u235d fulcrum indexes (reduced)\r\n    fi \u2190 fir@{\u2375} fm          \u235d fulcrum indexes\r\n    ai \u2190 fi+wi               \u235d all indexes\r\n    ai+\u2190 \u2349(m\u220a'\u250c\u2510') {\u237a\\\u2375\/\u2368\u2375\u22600}\u23641\u2365\u2349 0@1\u22a2ai \u235d extend indexes upwards to the \u250c\u2510s that need them (exclude top \u2534 as it isn't matched)\r\n      \r\n    ld \u2190  ER\u23641\u22a2 m='\u250c'        \u235d distance to left\r\n    rd \u2190 \u233dER\u23641\u233d m='\u2510'        \u235d distance to right\r\n    xp \u2190 (\u2374m)\u2374\u23732\u2283\u2374m          \u235d x position\r\n    fml\u2190 \u2193fm                 \u235d fulcrum mask &amp; its lines\r\n    ail\u2190 \u2193ai                 \u235d all index lines\r\n    GET\u2190 {\u2283,\/ail\u2337\u2368\u2218\u2282\u00a8fml\/\u00a8\u2375} \u235d get an item of ai for each fulcrum at x position \u2375\r\n    lir\u2190 GET \u2193xp-ld          \u235d left indexes (reduced)\r\n    rir\u2190 GET \u2193xp+rd          \u235d right indexes (reduced)\r\n    ldr\u2190 fm \/\u2365, ld           \u235d left distance (reduced)\r\n    rdr\u2190 fm \/\u2365, rd           \u235d right distance (reduced)\r\n      \r\n    in \u2190 \u2191\u2283{(+\/\u2375[\u237a])@(\u2283\u237a)\u22a2 \u2375}\/ (\u2193\u2349\u2191fir lir rir) , \u2282\u2193(\u2373fa+wa)\u2218.=\u2373wa \u235d included weights for each index\r\n    cf \u2190 (ldr \u00d7\u2364\u00af1\u22a2 in[lir;]) - rdr \u00d7\u2364\u00af1\u22a2 in[rir;] \u235d coefficients\r\n    ws \u2190 (1,(\u2262cf)\u23740) \u2339 ((2\u2283\u2374cf)\u21911)\u236acf              \u235d unscaled weights\r\n    (\u22a2\u00f7\u2228\/) ws                                      \u235d scale weights to integers\r\n}\r\n<\/code><\/pre>\n<p>I take my hat off in admiration of the audacity: &#8220;An array solution might not be possible, eh? Hold my beer.&#8221;<\/p>\n<p>So there we have it, a sm\u00f6rg\u00e5sbord of clever solutions to serve as an inspiration for us all. The 2020 edition of the competition sported a slightly simplified format where you were expected to tackle every problem instead of the approach in previous years where you had to make a subset selection from themed groups &ndash; this new approach remains for the current (2021) edition.<\/p>\n<p>You <em>are<\/em> taking part, aren&#8217;t you?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With Dyalog\u2019s APL Problem Solving Competition 2021 in full swing, it\u2019s time to highlight some of the excellent solutions that were submitted to last year\u2019s edition. Stefan Kruger works for IBM making databases. While he tries to learn at least &hellip; <a href=\"https:\/\/www.dyalog.com\/blog\/2021\/04\/2020-problem-solving-competition-phase-ii-highlights\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"class_list":["post-6782","post","type-post","status-publish","format-standard","hentry","category-student-competition"],"_links":{"self":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/6782","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/comments?post=6782"}],"version-history":[{"count":57,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/6782\/revisions"}],"predecessor-version":[{"id":7024,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/6782\/revisions\/7024"}],"wp:attachment":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/media?parent=6782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/categories?post=6782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/tags?post=6782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}