Walter Vos
waltervos.bsky.social
Walter Vos
@waltervos.bsky.social
Here to learn about TDD, software architecture, and agile software development methods.
November 14, 2025 at 6:29 PM
After a weekend of YouTube, @stackoverflow.com.web.brid.gy and documentation...
March 2, 2025 at 9:15 AM
An off by one error?! In my house?! @kevlin.bsky.social
February 2, 2025 at 11:08 AM
My logs after running for 10 minutes:
December 10, 2024 at 12:36 PM
I did get a solution for part 1 now, but I think I've gone about it in a ridiculous way :D. Now for some coffee.
December 5, 2024 at 9:25 AM
Day 3 of my #fsharp #adventofcode went a lot better. If you're interested, I've published my solutions on github: github.com/waltervos/ad...
December 3, 2024 at 8:51 AM
Finally cracked day 2 of #adventofcode in #fsharp. Once solved, it's quite easy, I'm finding out I'm not a programmer for puzzles.
December 2, 2024 at 9:37 PM
That's day 1 of #adventofcode in #fsharp. I thought it was a bit more complicated that it actually was, so I wasted some time. Oh well, lessons were learned.
December 1, 2024 at 4:11 PM
... and then it becomes easy to remove the duplication (and the branching!) in two steps:
November 27, 2024 at 5:21 PM
This is when I realised my `times` argument should be called `desiredLength`. And I realised that I could make the if and else branch indentical:
November 27, 2024 at 5:21 PM
In the else branch, we can create a 'tail' to append to the output that was created earlier (replacing `input` with `output` in the concat as well):
November 27, 2024 at 5:21 PM
Another test is required to implement the else branch (uneven desired length). I first took the `remainder` calculation out of the else branch.
November 27, 2024 at 5:21 PM
Now for some refactoring: Use repeatFor to determine even length; Create the output list outside the if/else; Determine the remainder in the else branch:
November 27, 2024 at 5:21 PM
We can now use modulo to handle lists of an even length, by dividing the desired length by the current list length. For readability, I extracted the repeatFor variable:
November 27, 2024 at 5:21 PM
We're not quite there yet. `List.replicate` "multiplies" the list. This works when repeating a list of 1 items to a length of 2, but not for larger lists. So, I'm adding another test case to further lock down the behaviour:
November 27, 2024 at 5:21 PM
Seeing that I'm just repeating the input list in my function, I now refactor the function to be slightly more generic, using the input to construct the result. I then found `List.replicate` in the #fsharp docs and used that for the `times = 2` case (it creates a list of lists, which we can concat):
November 27, 2024 at 5:21 PM
We can now replace the identical lambdas by a call to a function. Initially I had the function return the lambda (copy + paste), and then refactored it into a regular ol' function
November 27, 2024 at 5:21 PM
Realising that the `times` argument (wrong name, should be `desiredLength`) plays a role in deciding which output to give, I now make the duplication in these two tests obvious by putting an if expression in the lambda:
November 27, 2024 at 5:21 PM
Let's add another test, which is about truncating the route if repeating it by "multiplication" would overflow the desired length. After expressing the input and expected result, I write the lambda to return the hard coded result:
November 27, 2024 at 5:21 PM
At this point I realised that I need to tell the function the desired length of the output, so I pass another parameter to the lambda:
November 27, 2024 at 5:21 PM
Let's use a lambda function to "transform" the input to the expected result, by returning a hard coded value (the simplest thing that could possibly work):
November 27, 2024 at 5:21 PM
Bus drivers driver their route (a list of stop numbers) for 480 minutes, driving one stop per minute. Not every route has the same length. So the first challenge was to repeat the stops in a route to a certain length. First, let's establish the input and desired output (obviously fails):
November 27, 2024 at 5:21 PM