Joker_vD a day ago

That's a lot of manual effort to save just a tiny bit of thinking. The first digit is the largest digit among the first N-1 digits. The second digit is the largest digit to the right of the first digit up to and including the Nth digit. That's it.

  • seafoamteal a day ago

    Hi! Yes, I talk about this a little bit at the end and I solve Part 2 the normal way. This is a toy example that I did for fun. The objective was to introduce people to Program Construction and show how you can use formal methods to derive correct programs. Whether the juice is worth the squeeze is a judgement call that you make depending on how critical the software you are writing is.

    • Joker_vD 18 hours ago

      But the resulting algorithm is just... weird. It operates under the assumption that the elements f.i can be arbitrary e.g. negative or greater than 9 — which they can't. And adopting that assumption allows you to dispense with keeping track of the variations of the total sum and merely track the separate digits themselves, which would allow a non-mechanical programmer to see easily that the algorithm is correct.

  • amackera 20 hours ago

    To me it seems more like a lot of _thinking_ just to save a tiny bit of thinking.

    It was a fun read though, and obviously this exercise is not about efficiency so much as exploring an interesting idea.

    • layer8 19 hours ago

      Maybe you missed this part: “That seemed like a lot of thinking, you might object. It probably was if you’re not familiar with Program Construction yet, but once you’ve derived a couple of these theorems, you’ll find that there is no thinking involved. Not in the sense that once you’re good at something, you can do it almost mechanically, but in the sense that there’s only one way this could have gone. Starting from that post-condition, the theorems we proved fall out automatically as we continue expanding our model, and the same can be said for our loop body. Program construction is really easy in that way, because all you’re doing is following the program derivation to its logical end.”

  • layer8 19 hours ago

    The benefit of that effort is that you know the program is provably correct.

anonzzzies 20 hours ago

I was drilled in using the GCL (and variations on it) in Eindhoven TUE and Amsterdam UvA a long time ago, nice to see it here. Not very practical these days but good for brain.

hasanhasan2005 21 hours ago

Wow, this is certainly a new perspective for solving this problem