News for hackers. Stuff that matters.
Re:Computing the number of digits of an integer even faster by Zamicol on Friday June 04, 2021 @12:19PM (#27395195)
I sometimes have difficulty finding efficient algorithms for specific tasks like this. Any advice on becoming better at finding efficient algorithms?
Re:Computing the number of digits of an integer even faster by legends2k on Friday June 04, 2021 @02:01PM (#27396682)
Here's a gem called _Matters Computational_; a storehouse of many such tricks with proper categorization and index.

https://www.jjj.de/fxt/fxtbook.pdf

Re:Computing the number of digits of an integer even faster by __vim__ on Saturday June 05, 2021 @04:26AM (#27403263)
Thank you for this
Re:Computing the number of digits of an integer even faster by an1sotropy on Friday June 04, 2021 @05:36PM (#27399348)
holy moly this is awesome; thanks!
Re:Computing the number of digits of an integer even faster by klodolph on Friday June 04, 2021 @12:29PM (#27395332)
I don't have any tips. Micro-optimization at this level often requires creative leaps, and proving that they work can be tricky (although for 32-bit integers, you can just iterate over all of them to validate). There are web pages with "bit-twiddling hacks" (https://graphics.stanford.edu/~seander/bithacks.html), and sometimes you can find a solution for your problem with a superoptimizer (if you care enough).
Re:Computing the number of digits of an integer even faster by knuthsat on Friday June 04, 2021 @12:47PM (#27395572)
One other way to prove these algorithms is by writing them in z3 prover. You write a simple one that is 100% correct and then you prove equality for your optimized one or find an example that will show inequality.
Re:Computing the number of digits of an integer even faster by chrisseaton on Friday June 04, 2021 @12:59PM (#27395747)
A great thing about a monadic operation that takes a 32-bit integer, like this one, is that you can also just exhaustively test it in reasonable time!
Re:Computing the number of digits of an integer even faster by Dylan16807 on Friday June 04, 2021 @03:37PM (#27398129)
Today I learned "monadic" has two significantly different meanings in the realm of programming.

I'm only familiar with using "unary" to mean single-parameter.

Re:Computing the number of digits of an integer even faster by Filligree on Friday June 04, 2021 @05:13PM (#27399140)
Nah, they’re pretty much the same meaning.
Re:Computing the number of digits of an integer even faster by Dylan16807 on Friday June 04, 2021 @05:33PM (#27399309)
A monad, derived from monoid, means multiple very specific things completely unrelated to the other definition of "single parameter".

And the etymology is basically a coincidence because "mono" got used in different places, isn't it?

Re:Computing the number of digits of an integer even faster by a1369209993 on Friday June 04, 2021 @07:14PM (#27400178)
> []completely unrelated[] to the other definition of "single parameter".

Actually, all monads are monadic functions/operators on their (usually type) parameter. Eg, 'list' is a monadic operator from element types to types of lists of those elements.

It's completely different (AFAICT), and mostly unrelated, but it's not completely unrelated.

Re:Computing the number of digits of an integer even faster by freeone3000 on Friday June 04, 2021 @12:39PM (#27395461)
Let's assume you've studied the well-known computer science tricks like divide and conquer, greedy algorithms, and the various tree searches, and that's insufficient, even after specializing for your reduced domain. (These will get you 90% of the way there 90% of the time, and usually that's good enough. Sometimes it's not.)

For integer tricks like this, you'll want to look at number theory. Modular equivalence is particularly useful, but lots of things in that space are useful. However, there are a lot of other tricks that rely on geometric sequences, or geometry themselves, and other higher maths -- a lot of advances like this are simply connecting random theorum a to situation b, if you can envision the situation in the correct space.

Re:Computing the number of digits of an integer even faster by kevin_thibedeau on Friday June 04, 2021 @06:22PM (#27399751)
Buy a copy of Hacker's Delight.