Login
You're viewing the assemblag.es public feed.
  • Oct 1, 2026, 1:16 PM

    As usual when I see maths posts with some fun calculation, I implement a solution for it in Kap.

    Now, why am I posting this? Well, the Kap engine has primitives for modular exponentiation since they are needed for the prime calculation stuff, but they are not exposed to the language. It would be trivial to expose separate functions for it, but my plan is to make the straightforward code below "just work" by having the compiler automatically determine that the the entire expression is performed mod s*2 (the * means exponentiation in Kap).

    So, for now, this thing will run slowly. It takes 1 second to compute the results up to 10000 (that's in the JVM version. It's much, much slower in the javascript version), but then it gets exponentially slower due to the large bigint calculations.

    1+⍸ { s←(10*⌈10⍟⍵) ⋄ ((s*2)|⍵*⍵) = ⍵+⍵×s } 1+⍳1000

    Run the example

    mathstodon.xyz/@aperiodical/11

    Thanks to @christianp for the fun blog post.

    💬 0🔄 0⭐ 0