March 8, 2024

Bashing my head against a wall: Week 6 of 48 in 24

This week’s1 challenge was List Ops: create methods for manipulating lists like map, filter and reduce (well, foldr and foldl). I found this exercise frustrating in different languages in different ways. I used bash, elixir and haskell. In elixir and haskell, the frustration was that the exercise required me to return the standard list objects. I think it would have been more fun and more interesting to actually create a new list type and implement the methods there. For example, do these list operations look significantly different if you have a dynamic array compared to if you have a linked list? (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). Read more

February 23, 2024

Haskellbrain Harder: Week 5 of 48 in 24

Week 5 of 48 in 24! This time around we’re doing Protein Translation. Basically, take a sequence of amino acids and translate that into a list of proteins. Each triple of amino acids – a codon – gets mapped to a protein. Or rather, some codons are valid proteins, some represent a “stop” signal, and others are garbage and should throw an error. Bash The first language I thought I’d try this week is bash. I use bash shell most days, but I very rarely do anything beyond simple commands. (Maybe a little grep, some modest piping…) It would, however, be kind of useful to know a little more about how to write simple scripts. Often if I need to do something like that, I’d reach for python which I know better than I do bash, but sometimes that seems like overkill. And I did run into a situation at work recently where a little bash script was useful. The container I was troubleshooting didn’t have python installed, indeed, it didn’t have lsof installed, but I needed a way to get an overview of what was eating all the file descriptors. I cobbled together something where I looped over ls /proc/[0-9]* and pulled out all the cmdlines. It sort of worked but it was painful and it made me realise a better handle on bash (and unix tools more generally) would be a good investment. So here is my prosaic, straightforward solution to the exercise in bash. Read more

February 15, 2024

Javascript crimes: Week 4 of 48 in 24

I’m now well over a week behind with these challenges, so it’s Thursday of week 5, but we’re just finishing up week 4. Part of the issue is I’m quite bust, but part of the issue is that I am trying to use this as an opportunity to learn elixir, and I’m doing the elixir learning track. This means that the exercises are locked until I do the relevant learning exercises that teach the concepts. Elixir has quite an extensive learning track, and this exercise is quite far down the tree, so I actually had to do quite a few learning exercises to unlock it. Read more

February 2, 2024

Haskellbrain: Week 3 of 48 in 24

Well, I’m quite late with this week’s challenges. Again, I was only going for the silver medal of doing any three languages, but I didn’t have a lot of time to spare for the challenges last week, and I also spent more time than I should have tweaking my haskell solution in particular. This week’s exercise is fizzbuzz, but slightly different. JavaScript First up, here’s my javascript solution. export const convert = (num) => { let s = [[3, "Pling"], [5,"Plang"], [7,"Plong"]] .map(([x,y]) => num % x === 0 ? y : "") .join(""); return s === "" ? num.toString() : s; }; The basic idea is to take a list of pairs (a divisor and a string) and map that pair to the string if $n$ is divisible by the divisor, or map to the empty string otherwise. We then join those strings together. The final wrinkle is to check if the string we have left over is is still empty, and if it is, return the number as a string, rather than the resultant string. Read more

January 27, 2024

Indiana Jonesing: Week 2 of 48 in 24

This week’s challenge was to reverse a string. And I took the “Indiana Jones when that guy waves the sword around and Indy just shoots him” approach this week and got the silver medal using three languages that make this exercise a one-liner. Clojure First up, Clojure: (ns reverse-string) (defn reverse-string [s] ;; <- arglist goes here (clojure.string/reverse s) ) Haskell Next Haskell: module ReverseString (reverseString) where reverseString :: String -> String reverseString str = reverse str JavaScript And finally, Javascript. Read more

© Seamus Bradley 2021–6

Powered by Hugo & Kiss.