9
votes
What programming/technical projects have you been working on?
This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's interesting about it? Are you having trouble with anything?
TL;DR: I cheat at a choose-your-own-adventure book using a computer.
In an attempt to get back into reading, I looked through my shelves for something I haven't read in a while.
What I settled on was Das Mandala der Donnerdrachen, a choose-your-own-adventure book published before the turn of the century. I don't think it was ever translated into English, but the name of the book is a reference to the native name of Bhutan -- the plot has you travel to the himalaya region in order to bring about a new era of peace on earth. It's a wonderful book.
The idea is that you have to make a choice at the end of many of the ~250 chapters on how to proceed. "If you want to do X, go to chapter Y".
In addition, there are sometimes pre-conditions of the form "if you have/haven't read chapter X, then go to chapter Y".
I used Graphviz
dot
to make a map of the book fifteen years ago, but at the time I didn't include the pre-conditions in said map, so it was a mere curiosity to see the structure of the chapters.This time I wanted to leverage my now more-developed programming skills to answer a few questions:
My plan was to just generate all possible paths through the book using a breadth-first search. Can't be that many, right? Right??
After going through the book twice to extract and proof-read the chapter transitions, I started the program and waited. And waited. And waited.
I expected a few thousand to ten thousands of paths through the book, but unfortunately, due to combinatorial explosion, there are at least hundreds of millions (that's when I aborted the program...).
Hm. Should have done some back-of-the-envelope math first. If only every 4th chapter has a binary choice, that makes for 2^62 distinct paths... 🤦.
Now what?
Well, looks like I can't answer the first question, but maybe the others will yield to a Monte Carlo approach: just play the game randomly for one hundred million times and then extract the wanted statistics from that.
Results
There were about 1 million distinct games after filtering out duplicates.
What is the shortest path that loses?
Huh. The shortest path is
1->3
, the one where you immediately reject the call to action in your hero's journey. Never did that in a read-through.Among the sampled games, what is the longest path that loses?
The longest path that still loses has 144 chapters.
Among the sampled games, what is the shortest path that wins?
The shortest path that still wins was 99 chapters long.
Among the sampled games, what is the longest path that wins?
The longest winning path has 148 chapters.
(Fun fact: finding the longest path in a graph is, in general, NP-hard)
This is the order I want to use when I re-read the book. :)
Not something I've been working on for real yet, but I kinda want to make an automated watering system to keep some little plants I have alive when I'm gone. I figure it can probably be done with a moisture sensor, some servos, a microcontroller of some sort, and a battery, but one thing I thought of was safety with using a lithium battery for it since I haven't really done that before.
I'm sure this is simpler than I think and a solved problem, but anyone have any experience/resources for sourcing/integrating batteries in DIY/maker stuff like that?
I've been looking to do pretty much exact thing. A comment on ES32 thread on HN ignited my curioisuty and I've been researching since.
I think I'm going to abandon low-power dreams for now and go for path of least resistance with ESP32 for wireless and 24V brass valve from amazon (plastic ones are shite and degrade quickly in subtropical summars. Then a few lines of ESPHome, maybe integrate with HomeAssistant on existing RPi.
I'll actually be able to test once I get back home, but can start building in a week or so after parts arrive. Haven't done embedded programming in years, so should be interesting.
My only worry is water proofing because I probably won't etch a PCB and just chuck everything on a breadboard. Will see how it goes.
Yeah, I should probably do the same. Get something working first and then see if it's worth improving...
Same I get antsy with the idea of doing homebrew electronics and then leaving them unattended near water haha.
Now that SerialViz is done, I did an experiment using optical sensors to measure the rotation of a wheel and wrote it up: A Sine-Cosine encoder experiment. The Observable Plot library is a nice way to draw charts, once you get used to it.
Now I’m going to spin the wheel with an old Lego Mindstorms stepper motor I have to hopefully get a more consistent spin than doing it by hand. I didn’t want to install Lego’s ancient desktop software (it’s the NXT which Lego doesn’t make anymore), so I’m writing a little web app to control the motor.
The NXT supports both USB and Bluetooth. If you use Bluetooth, it appears as a serial port, and the protocol is slightly different. There are a couple of Word documents where they documented the protocol, and also other NXT software that people wrote in various languages that I can use as example code.
So far I can press a button to spin a motor or stop it, but I’m going to make it slightly fancier and show power usage and rotation on the screen.
(Believe it or not, this is still related to my accordion synthesizer project.)
I'm trying to make a static site generator that will turn my collection of markdown files that I update into html, Gemini text, and an rss feed without too much fuss. I did it in python and threw in Jinja templates because I wanted that looping capability for listing pages/indexes, but it's honestly seeming like overkill. I kind of want to go the route of shell scripts with utilities, and if I find the right combination of tools in my coffee break browsing I might just commit to it