Liste des Groupes | Revenir à cl c |
On 22/03/2025 08:07, Peter 'Shaggy' Haywood wrote:
<snip>
Here's my solution, for what it's worth:
#include <stdio.h>
unsigned long weird(unsigned long n)
{
printf("%lu", n);
if(n & 1)
{
/* Odd - multiply by 3 & add 1. */
n = n * 3 + 1;
Or you can save yourself a multiplication
n = (n << 2) - (n - 1);
potentially shaving entire picoseconds off the runtime.
}
else
{
/* Even - divide by 2. */
n /= 2;
do
{
n >>= 1;
} while(~(n & 1));
...and there goes another attosecond.
Les messages affichés proviennent d'usenet.