Skip to main content
deleted 42 characters in body
Source Link
Noodle9
  • 20.3k
  • 3
  • 21
  • 46

C (gcc), 40 39 32 bytes

Saved 7 bytes using formula from xnor's Python answer!!!

f(n){n=n>9?10*f(n/10):5>>5/-~n;}

Try it online!

Recursively calls itself, multiplying the returned value by \$10\$ and chopping the last digit off \$n\$ until \$n\$ is \$9\$ or less. Then returns one of \$\{1,2,5\}\$, whichever lays just below or equal to \$n\$ using xnor's formula.

C (gcc), 40 39 32 bytes

Saved 7 bytes using formula from xnor's Python answer!!!

f(n){n=n>9?10*f(n/10):5>>5/-~n;}

Try it online!

Recursively calls itself, multiplying the returned value by \$10\$ and chopping the last digit off \$n\$ until \$n\$ is \$9\$ or less. Then returns one of \$\{1,2,5\}\$, whichever lays just below or equal to \$n\$.

C (gcc), 40 39 32 bytes

f(n){n=n>9?10*f(n/10):5>>5/-~n;}

Try it online!

Recursively calls itself, multiplying the returned value by \$10\$ and chopping the last digit off \$n\$ until \$n\$ is \$9\$ or less. Then returns one of \$\{1,2,5\}\$, whichever lays just below or equal to \$n\$ using xnor's formula.

added 10 characters in body
Source Link
Noodle9
  • 20.3k
  • 3
  • 21
  • 46

C (gcc), 40 39 32 bytes

Saved 7 bytes using formula from xnor's Python answer!!!

f(n){n=n>9?10*f(n/10):5>>5/-~n;}

Try it online!

Recursively calls itself, multiplying the returned value by \$10\$ and chopping the last digit off n\$n\$ until n\$n\$ is \$9\$ or less. Then returns either \$1\$,one of \$2\$\$\{1,2,5\}\$, or \$5\$ whichever lays just below or equal to n\$n\$.

C (gcc), 40 39 32 bytes

Saved 7 bytes using formula from xnor's Python answer!!!

f(n){n=n>9?10*f(n/10):5>>5/-~n;}

Try it online!

Recursively calls itself, multiplying the returned value by \$10\$ and chopping the last digit off n until n is \$9\$ or less. Then returns either \$1\$, \$2\$, or \$5\$ whichever lays just below n.

C (gcc), 40 39 32 bytes

Saved 7 bytes using formula from xnor's Python answer!!!

f(n){n=n>9?10*f(n/10):5>>5/-~n;}

Try it online!

Recursively calls itself, multiplying the returned value by \$10\$ and chopping the last digit off \$n\$ until \$n\$ is \$9\$ or less. Then returns one of \$\{1,2,5\}\$, whichever lays just below or equal to \$n\$.

added 214 characters in body
Source Link
Noodle9
  • 20.3k
  • 3
  • 21
  • 46

C (gcc), 40 39 32 bytes

Saved 7 bytes using formula from xnor's Python answer!!!

f(n){n=n>9?10*f(n/10):5>>5/-~n;}

Try it online!

Recursively calls itself, multiplying the returned value by \$10\$ and chopping the last digit off n until n is \$9\$ or less. Then returns either \$1\$, \$2\$, or \$5\$ whichever lays just below n.

C (gcc), 40 39 32 bytes

Saved 7 bytes using formula from xnor's Python answer!!!

f(n){n=n>9?10*f(n/10):5>>5/-~n;}

Try it online!

C (gcc), 40 39 32 bytes

Saved 7 bytes using formula from xnor's Python answer!!!

f(n){n=n>9?10*f(n/10):5>>5/-~n;}

Try it online!

Recursively calls itself, multiplying the returned value by \$10\$ and chopping the last digit off n until n is \$9\$ or less. Then returns either \$1\$, \$2\$, or \$5\$ whichever lays just below n.

added 7 characters in body
Source Link
Noodle9
  • 20.3k
  • 3
  • 21
  • 46
Loading
Source Link
Noodle9
  • 20.3k
  • 3
  • 21
  • 46
Loading