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?

6 comments

  1. DataWraith
    Link
    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...

    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:

    • How many paths in total are there?
    • What is the shortest path that loses?
    • What is the longest path that loses?
    • What is the shortest path that wins?
    • What is the longest path that wins?

    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.

    1 13 10 6 2 14 17 20 15 22 59 53 64 23 51 43 61 70 62 45 25 34 41 72 67 27 50 36 38 31 33 44 54 40 73 79 113 109 76 111 100 82 104 95 75 98 78 88 83 112 97 110 103 94 114 116 92 105 84 99 117 130 149 178 123 156 146 165 118 122 170 179 151 163 132 126 137 173 175 147 167 177 154 171 158 164 162 180 190 204 197 198 193 182 187 183 181 199 192 206 189 188 194 191 195 209 216 225 215 212 223 219 220 214 222 227 211 217 211 214 222 227 220 219 216 225 223 212 215 213 218 221 210 217 226 224 228 244 229 247 243 242 237 232

    Among the sampled games, what is the shortest path that wins?

    The shortest path that still wins was 99 chapters long.

    1 13 10 4 15 22 28 64 30 24 26 65 49 69 25 55 34 52 72 67 27 50 36 38 31 33 44 54 40 73 79 113 109 76 111 100 82 95 115 98 106 88 83 102 97 110 107 91 80 116 92 81 117 130 149 138 156 176 174 118 135 147 177 154 171 145 129 180 190 204 197 182 200 206 208 184 188 194 186 209 220 214 222 217 211 217 226 224 228 244 229 247 243 242 236 233 246 235 249

    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)

    1 9 2 5 17 7 11 22 59 35 64 30 68 71 62 45 25 55 34 41 72 67 50 36 58 31 33 44 42 54 40 73 100 113 79 76 90 109 82 104 95 75 98 106 88 83 112 97 110 103 91 80 116 92 105 117 161 178 123 156 176 124 165 120 144 170 179 172 151 148 126 137 173 175 147 139 127 177 143 154 131 142 171 145 169 180 190 185 197 198 193 182 187 183 205 199 192 206 208 184 188 194 186 209 220 219 216 212 223 225 215 213 218 221 210 217 210 221 218 213 215 212 223 225 216 219 220 214 211 227 222 217 226 224 228 244 240 247 243 242 236 238 241 248 233 246 235 249

    This is the order I want to use when I re-read the book. :)

    9 votes
  2. [3]
    sqew
    Link
    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...

    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?

    7 votes
    1. [2]
      helloworld
      Link Parent
      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...

      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.

      5 votes
      1. sqew
        Link Parent
        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...

        I think I'm going to abandon low-power dreams for now and go for path of least resistance

        Yeah, I should probably do the same. Get something working first and then see if it's worth improving...

        My only worry is water proofing

        Same I get antsy with the idea of doing homebrew electronics and then leaving them unattended near water haha.

        4 votes
  3. skybrian
    (edited )
    Link
    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...

    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.)

    4 votes
  4. kyotja
    Link
    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...

    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

    3 votes