Skip to main content
added 404 characters in body
Source Link
lynn
  • 69.2k
  • 11
  • 133
  • 283

Jelly, 9 bytes, slow

DUḌ⁵%
’Ç¿

Try it online!

’Ç¿     Decrement input while…

DUḌ     The number with digits reversed (12300 → 321)
   ⁵%   is not a divisor of 10 (10 % n is truthy).

Jelly, 11 bytes, fast

This uses the fact that mapping \$[1 \dots 9]\$ to \$[1,2,2,2,2,5,5,5,5,5]\$ is achieved by $$ n \mapsto \max_{1 \leq k \leq n} \gcd(k, 10). $$

DḢRg⁵ṀṁDŻIḌ

Try it online!

DḢR           range [1..first digit]
   g⁵         gcd each with 10
     Ṁ        maximum
      ṁD      reshape like original digits (e.g. [2,2,2,2,2])
        ŻI    prepend 0, get increments (e.g. [2,0,0,0,0])
          Ḍ   digits to number

This uses the fact that mapping \$[1 \dots 9]\$ to \$[1,2,2,2,5,5,5,5,5]\$ is achieved by $$ n \mapsto \max_{1 \leq k \leq n} \gcd(k, 10). $$

Porting xnor's 5>>5/-~n formula is six bytes ‘5:5æ», but the above is only four Rg⁵Ṁ.

Jelly, 9 bytes, slow

DUḌ⁵%
’Ç¿

Try it online!

’Ç¿     Decrement input while…

DUḌ     The number with digits reversed (12300 → 321)
   ⁵%   is not a divisor of 10 (10 % n is truthy).

Jelly, 11 bytes, fast

This uses the fact that mapping \$[1 \dots 9]\$ to \$[1,2,2,2,2,5,5,5,5,5]\$ is achieved by $$ n \mapsto \max_{1 \leq k \leq n} \gcd(k, 10). $$

DḢRg⁵ṀṁDŻIḌ

Try it online!

DḢR           range [1..first digit]
   g⁵         gcd each with 10
     Ṁ        maximum
      ṁD      reshape like original digits (e.g. [2,2,2,2,2])
        ŻI    prepend 0, get increments (e.g. [2,0,0,0,0])
          Ḍ   digits to number

Jelly, 9 bytes, slow

DUḌ⁵%
’Ç¿

Try it online!

’Ç¿     Decrement input while…

DUḌ     The number with digits reversed (12300 → 321)
   ⁵%   is not a divisor of 10 (10 % n is truthy).

Jelly, 11 bytes, fast

DḢRg⁵ṀṁDŻIḌ

Try it online!

DḢR           range [1..first digit]
   g⁵         gcd each with 10
     Ṁ        maximum
      ṁD      reshape like original digits (e.g. [2,2,2,2,2])
        ŻI    prepend 0, get increments (e.g. [2,0,0,0,0])
          Ḍ   digits to number

This uses the fact that mapping \$[1 \dots 9]\$ to \$[1,2,2,2,5,5,5,5,5]\$ is achieved by $$ n \mapsto \max_{1 \leq k \leq n} \gcd(k, 10). $$

Porting xnor's 5>>5/-~n formula is six bytes ‘5:5æ», but the above is only four Rg⁵Ṁ.

added 404 characters in body
Source Link
lynn
  • 69.2k
  • 11
  • 133
  • 283

Jelly, 9 bytes, slow

DUḌ⁵%
’Ç¿

Try it online!

’Ç¿     Decrement input while…

DUḌ     The number with digits reversed (12300 → 321)
   ⁵%   is not a divisor of 10 (10 % n is truthy).

Jelly, 11 bytes, fast

This uses the fact that mapping \$[1 \dots 9]\$ to \$[1,2,2,2,2,5,5,5,5,5]\$ is achieved by $$ n \mapsto \max_{1 \leq k \leq n} \gcd(k, 10). $$

DḢRg⁵ṀṁDŻIḌ

Try it online!

DḢR           range [1..first digit]
   g⁵         gcd each with 10
     Ṁ        maximum
      ṁD      reshape like original digits (e.g. [2,2,2,2,2])
        ŻI    prepend 0, get increments (e.g. [2,0,0,0,0])
          Ḍ   digits to number

Jelly, 11 bytes

DḢRg⁵ṀṁDŻIḌ

Try it online!

DḢR           range [1..first digit]
   g⁵         gcd each with 10
     Ṁ        maximum
      ṁD      reshape like original digits (e.g. [2,2,2,2,2])
        ŻI    prepend 0, get increments (e.g. [2,0,0,0,0])
          Ḍ   digits to number

Jelly, 9 bytes, slow

DUḌ⁵%
’Ç¿

Try it online!

’Ç¿     Decrement input while…

DUḌ     The number with digits reversed (12300 → 321)
   ⁵%   is not a divisor of 10 (10 % n is truthy).

Jelly, 11 bytes, fast

This uses the fact that mapping \$[1 \dots 9]\$ to \$[1,2,2,2,2,5,5,5,5,5]\$ is achieved by $$ n \mapsto \max_{1 \leq k \leq n} \gcd(k, 10). $$

DḢRg⁵ṀṁDŻIḌ

Try it online!

DḢR           range [1..first digit]
   g⁵         gcd each with 10
     Ṁ        maximum
      ṁD      reshape like original digits (e.g. [2,2,2,2,2])
        ŻI    prepend 0, get increments (e.g. [2,0,0,0,0])
          Ḍ   digits to number
Source Link
lynn
  • 69.2k
  • 11
  • 133
  • 283

Jelly, 11 bytes

DḢRg⁵ṀṁDŻIḌ

Try it online!

DḢR           range [1..first digit]
   g⁵         gcd each with 10
     Ṁ        maximum
      ṁD      reshape like original digits (e.g. [2,2,2,2,2])
        ŻI    prepend 0, get increments (e.g. [2,0,0,0,0])
          Ḍ   digits to number