Some slides from a short talk at Recurse Center on Dijkstra's 1974 essay "On the role of scientific thought"
Monday, October 12, 2020
Sunday, October 11, 2020
Game of Risk Elm Visualization
Building on the previous post... an interactive(ish) Elm visualization of the game's probability trees:
https://tarokuriyama.com/projects/risk.php
Thursday, September 17, 2020
Game of Risk
The last assignment in the CIS194 Haskell class is to simulate dice-throwing battles in the game of Risk. The combat rules, taken from assignment specs, are:
- There is an attacking army (containing some number of units) and a defending army (containing some number of units).
- The attacking player may attack with up to three units at a time. However, they must always leave at least one unit behind. That is, if they only have three total units in their army they may only attack with two, and so on.
- The defending player may defend with up to two units (or only one if that is all they have).
- To determine the outcome of a single battle, the attacking and defending players each roll one six-sided die for every unit they have attacking or defending. So the attacking player rolls one, two, or three dice, and the defending player rolls one or two dice.
- The attacking player sorts their dice rolls in descending order. The defending player does the same.
- The dice are then matched up in pairs, starting with the highest roll of each player, then the second-highest.
- For each pair, if the attacking player’s roll is higher, then one of the defending player’s units die. If there is a tie, or the defending player’s roll is higher, then one of the attacking player’s units die.

Friday, September 11, 2020
Trying TCR
A fellow at the Recurse Center hosted a workshop on TCR (see Kent Beck's post for an introduction to the idea), using these templates.
The short of it is: a watcher will automatically run tests upon file save; if any tests fail, it will revert to the prior commit; else, it will make a new commit.
Despite some initial mental (and practical workflow) resistance, I've warmed very rapidly to the idea.
By far the biggest change is the revert part of test && commit || revert. Some initial complaints:
- I made a typo, and it revert to the last commit
- I just lost a whole block of code
- I can't just try this simple thing because it keeps failing a test and getting deleted
- slow down
- write fragments that you understand
- write smaller fragments if necessary
- Instead of inotifywait, on macOS fswatch can be installed from Homebrew (brew install fswatch)
- fswatch should be called with the --one-event flag, since it's already called in an infinite loop (otherwise it blocks the next line)
- By default, TCR will auto-commit with the same message; as one possible alternative, call AppleScript and ask for a commit message via a prompt

- The default example has some assertions in the main Python file; modify this to call a testing framework instead (in my case, py.test)
Friday, August 28, 2020
Sudoku Visualization
The Sudoku solver visualization in Elm is done!
https://tarokuriyama.com/projects/sudoku.php
Writing Elm feels similar to writing Haskell, with a bit of syntax that's more like F# (e.g. the pipeline operators <| and |>). Between the familiar format of Learn You and Elm and the examples in Beginning Elm, it's relatively easy to pick up given a bit of functional programming background.
All of the code for the solver and visualization is on GitHub.
Wednesday, August 26, 2020
Elm JSON Decoder
In the vein of functional programming, I've been learning Elm to visualize the progress of a Sudoku solver.
The JSON decoding tutorials are clear, and the JSON.Decode library is well-documented once you know how to read it (in general, the library documentation in Elm seems to be on the terse side).
- https://elmprogramming.com/decoding-json-part-1.html
- https://elmprogramming.com/decoding-json-part-2.html
Two things were not very clear from initial read of the docs: how to parse lists to tuples, and how to parse strings to custom types.
Leaning on SO for the below example, tuples apparently used to be supported as first-class decoders, but in the current version of Json.Decoder, index seems to be the official way to construct decoders for tuples.
arrayAsTuple2 a b c =
Decode.index 0 a
|> Decode.andThen (\ aVal -> Decode.index 1 b
|> Decode.andThen (\ bVal -> Decode.succeed (aVal, bVal)))
boardDecoder : Decoder Board
boardDecoder = Decode.list <| arrayAsTuple2 Decode.int Decode.int
Elm 0.19 only supports up to three-value tuples (somewhat surprising coming from Haskell, though with records and custom data types, the decision to limit unnamed tuples has a certain logic...). So the helper construction isn't too bad.
Saturday, August 22, 2020
Recurse Center
I've wanted to attend the Recurse Center (formerly known as Hacker School) or a while, and have finally found the time to do so. It's very consistent with the free education path (it's free!), and so far has been a great source of exposure to new topics and ideas, as well as of inspiration to work on different classes of problems. They've put a lot of effort into fostering a healthy, supportive community, and the nature of the program is such that self-motivated, inquisitive learners more or less self-select themeselves into attendance. Some topics I was exposed to or participated in so far -- audio programming, gaming, lower-level / systems programming languages (eg Zig), functional programming (eg Haskell, Elm), procedural generetion, Web Assembly compilation... There are folks of all walks of life, skills, and interests in the community, making it something that I expect will continue to yield rich experiences for the remainder of the three-month batch.
