Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This should not be best practice. Abusing global variables to pass information from different closures, i.e. creating side effects, is a big no-no for me.
And of course, the one-liner format makes it extra hard to read.
Your testcase is wrong. The next bigger value of 1111111111111111119 is 1111111111111111191.
But your assumption is right: Searching for the solution iteratively is wasting lots of CPU, so this isn't qualifying as "clever" in the sense of "using an approach that is not brute-forcing it, but identifying the problem as what it truly is, and applying a very good solution to it".
But it might qualify for "clever" as in "applying a solution that isn't obvious".
It's iteratively searching, wasting huge amounts of useless CPU cycles.
I don't like these single-letter variable names. It makes it really hard to understand the meaning of what content is getting assigned.
It should not have gotten any "best practices" labels just for that reason alone.
There is a big red warning box on the PHP page for foreach:
https://www.php.net/manual/en/control-structures.foreach.php
The rule is simple: Do not expand the scope if no one asks about it.
Care to elaborate how it might mess up stuff?
This will win some code golf competition.
This comment is hidden because it contains spoiler information about the solution
I'd rather not use foreach with reference variables (like $word), this will mess up stuff unexpectedly if you don't clean up afterwards.
What about unicode chars? The Kata only supports PHP 7.0, so some string functions would have to be backported manually. :(