<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Coding on SCMB XYZ</title>
    <link>https://www.scmb.xyz/tags/coding/</link>
    <description>Recent content in Coding on SCMB XYZ</description>
    <generator>Hugo</generator>
    <language>en-gb</language>
    <copyright>&amp;copy; Seamus Bradley 2021–6</copyright>
    <lastBuildDate>Sun, 01 Dec 2024 20:49:23 +0000</lastBuildDate>
    <atom:link href="https://www.scmb.xyz/tags/coding/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>December Adventure 2024</title>
      <link>https://www.scmb.xyz/post/december-adventure-2024/</link>
      <pubDate>Sun, 01 Dec 2024 20:49:23 +0000</pubDate>
      <guid>https://www.scmb.xyz/post/december-adventure-2024/</guid>
      <description>&lt;p&gt;While I have enjoyed doing (the first week or two of) Advent of Code the last few years,&#xA;I think I&amp;rsquo;m going to not do it this year.&#xA;I currently have my one-month old son asleep on me, and this is simply not an environment&#xA;that&amp;rsquo;s conducive to that kind of problem-solving.&#xA;I think, instead, I will participate in &lt;a href=&#34;https://eli.li/december-adventure&#34;&gt;December Adventure&lt;/a&gt;&#xA;which seems like a much gentler way of having some community and bit of a push to do a bit of coding&#xA;this month.&#xA;I have a few plans for what I will work on, but I am deliberately not specifying them up front in case&#xA;I don&amp;rsquo;t actually decide to work on them this month.&#xA;This post will record what I got up to on each day, so I&amp;rsquo;ll be editing it throughout the month.&lt;/p&gt;</description>
    </item>
    <item>
      <title>One efficient solution to Circular Buffer (and two others): Week 8 of 48 in 24</title>
      <link>https://www.scmb.xyz/post/week-8-exercism/</link>
      <pubDate>Mon, 08 Apr 2024 16:08:16 +0100</pubDate>
      <guid>https://www.scmb.xyz/post/week-8-exercism/</guid>
      <description>&lt;p&gt;It&amp;rsquo;s been a while, but we&amp;rsquo;re back for week 8.&#xA;This week&amp;rsquo;s challenge is to write a &lt;a href=&#34;https://exercism.org/exercises/circular-buffer&#34;&gt;Circular Buffer&lt;/a&gt;.&#xA;It&amp;rsquo;s basically a first in, first out data structure with the limitation that there&amp;rsquo;s only $n$ slots for data.&lt;/p&gt;&#xA;&lt;p&gt;It took me a while to get around to this because of having to do a bunch more elixir learning track exercises,&#xA;and also because I&amp;rsquo;ve been on holiday.&#xA;The selection of languages available for this exercise were kind of limited,&#xA;so I&amp;rsquo;ve had to branch out into using web assembly for this one.&#xA;I also did a few easier web assembly exercises to get the hang of it.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Three Genuinely Different Solutions: Week 7 of 48 in 24</title>
      <link>https://www.scmb.xyz/post/week-7-exercism/</link>
      <pubDate>Mon, 11 Mar 2024 08:41:44 +0000</pubDate>
      <guid>https://www.scmb.xyz/post/week-7-exercism/</guid>
      <description>&lt;p&gt;Week 7 sees us take on the challenge of &lt;a href=&#34;https://exercism.org/exercises/acronym&#34;&gt;turning a string into an acronym&lt;/a&gt;.&#xA;If we&amp;rsquo;re being picky, these are mostly initialisms rather than acronyms because they don&amp;rsquo;t spell a word.&#xA;And in a break with tradition, I actually took three fairly different approaches to solving this problem in the&#xA;three languages I tried.&lt;/p&gt;&#xA;&lt;p&gt;In fact, I also tried doing this exercise in PowerShell (because I had ambitions to go for the gold medal of doing Haskell, PowerShell and TCL).&#xA;I gave up because learning bash and elixir pretty much from scratch for this project is already a lot, so trying to wrap my head around PowerShell as well&#xA;very quickly became more effort than I was willing to put in.&#xA;I like the idea of PowerShell (what if a shell, but with objects) but in practice I find it kind of annoying.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Bashing my head against a wall: Week 6 of 48 in 24</title>
      <link>https://www.scmb.xyz/post/week-6-exercism/</link>
      <pubDate>Fri, 08 Mar 2024 08:31:14 +0000</pubDate>
      <guid>https://www.scmb.xyz/post/week-6-exercism/</guid>
      <description>&lt;p&gt;This week&amp;rsquo;s&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; challenge was &lt;a href=&#34;https://exercism.org/exercises/list-ops&#34;&gt;List Ops&lt;/a&gt;:&#xA;create methods for manipulating lists like &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt; and &lt;code&gt;reduce&lt;/code&gt; (well, &lt;code&gt;foldr&lt;/code&gt; and &lt;code&gt;foldl&lt;/code&gt;).&#xA;I found this exercise frustrating in different languages in different ways.&#xA;I used bash, elixir and haskell.&#xA;In elixir and haskell, the frustration was that the exercise required me to return the standard list objects.&#xA;I think it would have been more fun and more interesting to actually create a new list type and implement the methods there.&#xA;For example, do these list operations look significantly different if you have a dynamic array compared to if you have a linked list?&#xA;(For example, reversing a doubly linked list is just swapping the next and previous pointers, whereas reversing an array is going to be quite different).&lt;/p&gt;</description>
    </item>
    <item>
      <title>Haskellbrain Harder: Week 5 of 48 in 24</title>
      <link>https://www.scmb.xyz/post/week-5-exercism/</link>
      <pubDate>Fri, 23 Feb 2024 13:58:05 +0000</pubDate>
      <guid>https://www.scmb.xyz/post/week-5-exercism/</guid>
      <description>&lt;p&gt;Week 5 of 48 in 24!&#xA;This time around we&amp;rsquo;re doing &lt;a href=&#34;https://exercism.org/exercises/protein-translation&#34;&gt;Protein Translation&lt;/a&gt;.&#xA;Basically, take a sequence of amino acids and translate that into a list of proteins.&#xA;Each triple of amino acids &amp;ndash; a codon &amp;ndash; gets mapped to a protein.&#xA;Or rather, some codons are valid proteins, some represent a &amp;ldquo;stop&amp;rdquo; signal,&#xA;and others are garbage and should throw an error.&lt;/p&gt;&#xA;&lt;h1 id=&#34;bash&#34;&gt;Bash&lt;/h1&gt;&#xA;&lt;p&gt;The first language I thought I&amp;rsquo;d try this week is bash.&#xA;I use bash shell most days, but I very rarely do anything beyond simple commands.&#xA;(Maybe a little &lt;code&gt;grep&lt;/code&gt;, some modest piping&amp;hellip;)&#xA;It would, however, be kind of useful to know a little more about how to write simple scripts.&#xA;Often if I need to do something like that, I&amp;rsquo;d reach for python which I know better than I do bash,&#xA;but sometimes that seems like overkill.&#xA;And I did run into a situation at work recently where a little bash script was useful.&#xA;The container I was troubleshooting didn&amp;rsquo;t have python installed, indeed,&#xA;it didn&amp;rsquo;t have &lt;code&gt;lsof&lt;/code&gt; installed, but I needed a way to get an overview of what was eating all the file descriptors.&#xA;I cobbled together something where I looped over &lt;code&gt;ls /proc/[0-9]*&lt;/code&gt; and pulled out all the &lt;code&gt;cmdline&lt;/code&gt;s.&#xA;It sort of worked but it was painful and it made me realise a better handle on bash (and unix tools more generally)&#xA;would be a good investment.&#xA;So here is my prosaic, straightforward solution to the exercise in bash.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Javascript crimes: Week 4 of 48 in 24</title>
      <link>https://www.scmb.xyz/post/week-4-exercism/</link>
      <pubDate>Thu, 15 Feb 2024 09:53:54 +0000</pubDate>
      <guid>https://www.scmb.xyz/post/week-4-exercism/</guid>
      <description>&lt;p&gt;I&amp;rsquo;m now well over a week behind with these challenges, so it&amp;rsquo;s Thursday of week 5,&#xA;but we&amp;rsquo;re just finishing up week 4.&#xA;Part of the issue is I&amp;rsquo;m quite bust, but part of the issue is that I am trying to use&#xA;this as an opportunity to learn elixir, and I&amp;rsquo;m doing the elixir learning track.&#xA;This means that the exercises are locked until I do the relevant learning exercises&#xA;that teach the concepts.&#xA;Elixir has quite an extensive learning track, and this exercise is quite far down&#xA;the tree,&#xA;so I actually had to do quite a few learning exercises to unlock it.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Haskellbrain: Week 3 of 48 in 24</title>
      <link>https://www.scmb.xyz/post/week-3-exercism/</link>
      <pubDate>Fri, 02 Feb 2024 16:34:03 +0000</pubDate>
      <guid>https://www.scmb.xyz/post/week-3-exercism/</guid>
      <description>&lt;p&gt;Well, I&amp;rsquo;m quite late with this week&amp;rsquo;s challenges.&#xA;Again, I was only going for the silver medal of doing any three languages,&#xA;but I didn&amp;rsquo;t have a lot of time to spare for the challenges last week,&#xA;and I also spent more time than I should have tweaking my haskell solution in particular.&lt;/p&gt;&#xA;&lt;p&gt;This week&amp;rsquo;s &lt;a href=&#34;https://exercism.org/exercises/raindrops&#34;&gt;exercise&lt;/a&gt; is fizzbuzz, but slightly different.&lt;/p&gt;&#xA;&lt;h1 id=&#34;javascript&#34;&gt;JavaScript&lt;/h1&gt;&#xA;&lt;p&gt;First up, here&amp;rsquo;s my javascript solution.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;export&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;const&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;convert&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; (&lt;span style=&#34;color:#a6e22e&#34;&gt;num&lt;/span&gt;) =&amp;gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;s&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;  [[&lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Pling&amp;#34;&lt;/span&gt;], [&lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;,&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Plang&amp;#34;&lt;/span&gt;], [&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;,&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Plong&amp;#34;&lt;/span&gt;]]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      .&lt;span style=&#34;color:#a6e22e&#34;&gt;map&lt;/span&gt;(([&lt;span style=&#34;color:#a6e22e&#34;&gt;x&lt;/span&gt;,&lt;span style=&#34;color:#a6e22e&#34;&gt;y&lt;/span&gt;]) =&amp;gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;num&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;%&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;x&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;===&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;?&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;y&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      .&lt;span style=&#34;color:#a6e22e&#34;&gt;join&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;s&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;===&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;?&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;num&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;toString&lt;/span&gt;() &lt;span style=&#34;color:#f92672&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;s&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The basic idea is to take a list of pairs (a divisor and a string)&#xA;and map that pair to the string if $n$ is divisible by the divisor,&#xA;or map to the empty string otherwise.&#xA;We then join those strings together.&#xA;The final wrinkle is to check if the string we have left over is is still empty,&#xA;and if it is, return the number as a string, rather than the resultant string.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Indiana Jonesing: Week 2 of 48 in 24</title>
      <link>https://www.scmb.xyz/post/week-2-exercism/</link>
      <pubDate>Sat, 27 Jan 2024 13:48:11 +0000</pubDate>
      <guid>https://www.scmb.xyz/post/week-2-exercism/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://exercism.org/exercises/reverse-string&#34;&gt;This week&amp;rsquo;s challenge&lt;/a&gt;&#xA;was to reverse a string.&#xA;And I took the &amp;ldquo;Indiana Jones when that guy waves the sword around and Indy just shoots him&amp;rdquo;&#xA;approach this week and got the silver medal using three languages that make this exercise a one-liner.&lt;/p&gt;&#xA;&lt;h1 id=&#34;clojure&#34;&gt;Clojure&lt;/h1&gt;&#xA;&lt;p&gt;First up, Clojure:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-clojure&#34; data-lang=&#34;clojure&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#66d9ef&#34;&gt;ns &lt;/span&gt;reverse-string)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#66d9ef&#34;&gt;defn &lt;/span&gt;reverse-string [s] &lt;span style=&#34;color:#75715e&#34;&gt;;; &amp;lt;- arglist goes here&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#a6e22e&#34;&gt;clojure.string/reverse&lt;/span&gt; s)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h1 id=&#34;haskell&#34;&gt;Haskell&lt;/h1&gt;&#xA;&lt;p&gt;Next Haskell:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-haskell&#34; data-lang=&#34;haskell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;module&lt;/span&gt; ReverseString (&lt;span style=&#34;color:#a6e22e&#34;&gt;reverseString&lt;/span&gt;) &lt;span style=&#34;color:#66d9ef&#34;&gt;where&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;reverseString&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;::&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;String&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;String&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;reverseString&lt;/span&gt; str &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; reverse str&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h1 id=&#34;javascript&#34;&gt;JavaScript&lt;/h1&gt;&#xA;&lt;p&gt;And finally, Javascript.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Starting off easy: Week 1 of 48 in 24</title>
      <link>https://www.scmb.xyz/post/week-1-exercism/</link>
      <pubDate>Tue, 23 Jan 2024 21:19:25 +0000</pubDate>
      <guid>https://www.scmb.xyz/post/week-1-exercism/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://www.exercism.org&#34;&gt;Exercism&lt;/a&gt; &amp;ndash; one of my favourite &amp;ldquo;learn to code&amp;rdquo; websites &amp;ndash;&#xA;is doing a thing where each week (ish?) there is a new challenge to solve a coding exercise in several languages.&#xA;It&amp;rsquo;s called &amp;ldquo;&lt;a href=&#34;https://exercism.org/challenges/48in24&#34;&gt;48 in 24&lt;/a&gt;&amp;rdquo;.&#xA;It looks like you get a bronze medal if you solve the coding exercise in some language,&#xA;a silver medal if you solve it in three specific languages,&#xA;and a gold medal if you solve it in any three languages in 2024.&#xA;We&amp;rsquo;ll see how long this lasts, but I&amp;rsquo;m going to try to blog about my attempts to solve the exercise.&#xA;To be clear, these are my attempts to solve the exercise, likely often in languages I&amp;rsquo;m not that familiar&#xA;with, so the solutions might not be optimal or idiomatic.&#xA;I&amp;rsquo;m also not going to explain every key word and language construct I use,&#xA;I&amp;rsquo;ll only explain those things that I think you might not be able to guess by looking at the code.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
