March 11, 2024

Three Genuinely Different Solutions: Week 7 of 48 in 24

Week 7 sees us take on the challenge of turning a string into an acronym. If we’re being picky, these are mostly initialisms rather than acronyms because they don’t spell a word. And in a break with tradition, I actually took three fairly different approaches to solving this problem in the three languages I tried. 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). 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 very quickly became more effort than I was willing to put in. I like the idea of PowerShell (what if a shell, but with objects) but in practice I find it kind of annoying. Read more

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

© Seamus Bradley 2021–6

Powered by Hugo & Kiss.