g | x | w | all
Bytes Lang Time Link
030AWK250304T172142Zxrs
018BQN250227T143648Zpanadest
003Thunno 2 S230722T164048ZThe Thon
011J221112T001833ZnaffetS
009GolfScript221115T020747ZTwilight
046PowerShell Core221115T010425ZJulian
014K ngn/k221112T055254Zoeuf
025><>221111T214051ZEmigna
040Prolog SWI220902T221634ZnaffetS
036Ruby220825T172406Zsouth
012Knight220801T211017ZnaffetS
029PHP220730T135211ZRam Chan
036Regex 🐇 PCRE2 v10.35+220728T125948ZDeadcode
026Wolfram Language Mathematica220727T133111ZRoman
012perl p220728T171803ZAbigail
073ECMAScript 2016220727T235514ZEric Xue
019Bash220726T203357ZDigital
012Perl 5 Minteger pF220727T141949ZXcali
004Vyxal r220726T144623ZnaffetS
027JavaScript Node.js220726T085436Ztsh
042C++ gcc220727T000642Zc--
013Raku220726T233440ZSean
029Desmos220726T220009ZAiden Ch
015BQN220726T194218ZDLosc
005Brachylog220726T191753ZUnrelate
010dc220726T184611ZDigital
007Pip220726T183413ZDLosc
008Charcoal220726T114331ZNeil
027BQN220726T141521ZDominic
008Burlesque220726T143316ZDeathInc
007APL Dyalog Unicode220726T133505ZAdá
048Nibbles220726T121623ZDominic
00405AB1E220726T082318ZKevin Cr
016Retina220726T113811ZNeil
021PARI/GP220726T081421Zalephalp
033Factor220726T104556Zchunes
035C gcc220726T090241ZNoodle9
003Japt220726T093850ZBubbler
021R220726T091117ZDominic
057Python220726T092538Zsolid.py
003Jelly220726T084214Zalephalp
005MathGolf220726T083734ZKevin Cr
008Vyxal220726T080417Zlyxal
005Jelly220726T080137Zemanresu
023Haskell220726T080026Zxnor
025Python 2220726T075814Zxnor
004Vyxal220726T075653Zemanresu

AWK, 30 bytes

{for(;i++<NF;s=s 0)x+=$0s}$0=x

Attempt This Online!

BQN, 18 bytes

+´10⊸⋆{𝔽↕⌊1+𝔽⁼𝕩}⊸×

BQN online REPL

There is an answer already with a similar idea, but this one doesn't use any system provided value like •Fmt.

Thunno 2 S, 3 bytes

Że×

Try it online!

Explanation

Że×  # Implicit input
Ż    # Push [0..len(input))
 e   # Take 10 ** each
  ×  # Multiply by input
     # Auto-sum and output

J, 12 11 bytes

10#.]#~$@":

Try it online!

-1 byte thanks to rdm

GolfScript, 9 bytes

.,1`*~\~*

Try it online!

There's clearly a better way to do this, only I haven't discovered it.

PowerShell Core, 46 bytes

"$(1..($s="$args").Length|%{"+$s";$s+=0})"|iex

Try it online!

For example for 123:
We generate an array containing: "+123","+1230""+12300"
Then we join them all in a space separated string "+123 +1230 +12300"
Then we execute it as a PowerShell expression, returning 13653

K (ngn/k), 17 14 bytes

{x*10/(#$x)#1}

Try it online!

-3 bytes thanks to ovs!

Explanations:

{x*10/(#$x)#1}  Main function. x is input (123)
            1   The number 1              (1)
           #    Duplicate by the amount of
      ( $x)     x converted to string     ("123")
       #        Length times              (3)
                (This creates an array of integers, which is (1, 1, 1))
   10/          Convert the integers to base 10
 x*             Multiply by x

><>, 25 bytes

::a(?va,{:@a*}!
=?n+0>~l1

Try it online

Explanation

:             !   # save a copy of the input on the stack
 :a(?v            # if the current number is lower than 10 move to next row
      a,          # else divide the current number by 10
        {:@a*}    # and store a copy of the original number * 10 on the stack

     >~           # discard the current number
=?n    l1         # if there is only one item on the stack, print it
   +0             # else add the top 2 numbers, and push a 0 to be discarded

Prolog (SWI), 40 bytes

X+N:-N is(10^(floor(log10(X))+1)-1)*X/9.

Try it online!

Ruby, 40 36 bytes

p [*0...gets.size].sum{eval$_+?0*_1}

Attempt This Online!

-4 bytes thanks to Steffan

Knight, 12 bytes

O*/^10L=xP9x

Try it online!

Ungolfed:

OUTPUT (* (/ (^ 10 (LENGTH (= x PROMPT))) 9) x)

PHP, 29 bytes

fn($n)=>$n*~-10**strlen($n)/9

Try it online!

Regex 🐇 (PCRE2 v10.35+), 36 bytes

^(?*(\1{10}|^x{9})*x(x*$))(?*\2x+)x+

Attempt This Online!
Attempt This Online! - just the test cases (that are small enough to complete in reasonable time)

Takes its input in unary, as the length of a string of xs. Returns its output as the number of ways the regex can match. (The rabbit emoji indicates this output method. It can yield outputs bigger than the input, and is really good at multiplying.)

^                     # Anchor to start; tail = N = input number
(?*                   # Non-atomic lookahead - try all possibilities to find ones
                      # resulting in a later match. This is used to multiply the
                      # number of possible matches outside by the number of
                      # possible matches inside.
    (\1{10}|^x{9})*x  # tail -= {any power of 10}
    (x*$)             # \2 = tail = N - {the power of 10}
)
(?*                   # Another non-atomic lookahead
    \2                # tail = {the power of 10 chosen above}
    x+                # Multiply the number of possible matches by tail. This
                      # applies for each power of 10 found, and those numbers of
                      # matches will add together.
)
x+                   # Add tail possible matches, where tail==N, with the above
                     # multiplier being applied.

Regex 🐇 (Perl / PCRE), 108 76 bytes

^(x?)(?=(x*)\2$).*(?=\2((x+)\4{8}(?=\4$))*x{5}$)()?x+.*(?=\2$)(()?x+|\1+$)|x

Try it online! - Perl v5.28.2 / Attempt This Online! - Perl v5.36+
Try it online! - PCRE1
Try it online! - PCRE2 v10.33 / Attempt This Online! - PCRE2 v10.40+
Try it online! - PCRE2 - just the test cases

Without (?*...) molecular lookahead, it's much harder to do multiplication. So we reserve half of the number to use as a counter for one operand of the multiplication, letting \$a=\lfloor n/2\rfloor\$ and \$b=n\bmod 2\$, such that \$2a+b=n\$, in order to emulate operations on \$n\$.

We don't actually need to construct the number of the form 111...111 to multiply by. We can pretty much directly sum \$n\$ multiplied by each power of \$10\$, that is to say,

$$\large\left({\sum_{k=1}^{\lfloor log_{10}n\rfloor}2{{10^k}\over 2}(2a+b)}\right)+n = \sum_{k=0}^{\lfloor log_{10}n\rfloor}10^k n$$

using emulated arithmetic on \$2a+b=n\$.

    ^                         # Anchor to start; tail = N = input number
    (x?)                      # \1 = N % 2; tail -= \1
    (?=(x*)\2$)               # \2 = floor(N / 2)
    .*                        # Find any value of tail ≤ N satisfying the
                              # following:
    (?=
        # Assert that 2*(tail-\2) is a power of 10
        \2                      # tail -= \2
        (
            (x+)\4{8}(?=\4$)  # Assert tail is divisible by 10; tail /= 10
        )*                    # Iterate the above as many times as possible,
                              # minimum zero.
        x{5}$                 # Assert tail == 5
    )
    ()?                       # possibleMatches *= 2, for the following:
    x+                        # possibleMatches *= tail - \2, for the following:
    .*(?=\2$)                 # tail = \2
    (
        ()?                   # possibleMatches *= 2, for the following:
        x+                    # possibleMatches += tail
    |
        \1+$                  # possibleMatches += \1
    )
|
                              # Unanchored
    x                         # possibleMatches += N

Regex (.NET), 129 117 bytes

^(?=(x)*)(x?)(?=(x*)\3$)(((?=\3((x+)\7{8}(?=\7$))*x{5}$)(?=((?=.*(?=\3)(?<1>x)*){4}(?=.*(?=\2)(?<1>x)?){2}x)*\3))?x)*

Try it online!
Try it online! - just the test cases

Returns its output as the capture count of \1.

This is now a fairly straight port of the Perl/PCRE 🐇 version.

The former 129 byte version actually constructed the number whose digits are all 1 to multiply by – indirectly – by constructing the number \$c\$ whose every digit is a 1 and has one less digit than the input, such that \$10c+1\$ is the actually desired number, then returning \$(10c)(2a+b)+n\$ \$=(10c+1)n\$ as a capture count. That version couldn't return a result for an input of \$0\$, but this version can.

^                               # Anchor to start; tail = N = input number
(?=(x)*)                        # \1.captureCount = tail = N
(x?)                            # \2 = N % 2; tail = tail-\2 == \3 * 2
(?=(x*)\3$)                     # \3 = floor(N / 2)
(
    (
        (?=                       # Lookahead conditional
            # Assert that 2*(tail-\3) is a power of 10
            \3                      # tail -= \3
            (
                (x+)\7{8}(?=\7$)    # Assert tail is divisible by 10; tail /= 10
            )*                      # Iterate the above as many times as possible,
                                    # minimum zero.
            x{5}$                   # Assert tail == 5
        )
        # If the above assertion matches, do the following:
        (?=
            (
                (?=
                    .*(?=\3)    # tail = \3
                    (?<1>x)*    # \1.captureCount += tail
                ){4}            # Iterate the above 4 times
                (?=
                    .*(?=\2)    # tail = \2
                    (?<1>x)?    # \1.captureCount += tail
                ){2}            # Iterate the above 2 times
                x
            )*                  # Iterate the above as many times as possible,
                                # which will be a number of iterations equal to
                                # exactly half the current power of 10.
            \3                  # Assert tail >= \3
        )
    )?
    x
)*                              # Iterate the above as many times as possible,
                                # applying the payload to each power of 10

I think I may have discovered a bug in the .NET regex engine, or at least the version on TIO, while working on this. The following variant of the same length should have worked, but didn't:

^(?=(x)*)(x?)(?=(x*)\3$)((?(?=\3((x+)\6{8}(?=\6$))*x{5}$)(?=((?=.*(?=\3)(?<1>x)*){4}(?=.*(?=\2)(?<1>x)?){2}x)*\3))x)*

Wolfram Language (Mathematica), 27 26 bytes

#(10^IntegerLength@#-1)/9&

Try it online!

perl -p, 12 bytes

$_*=s/./1/gr

Multiplies itself with 1, 11, 111, etc, depending on the length of the input.

Try it online!

ECMAScript 2016, 73 bytes

n=>Array(String(n).length).fill(n).map((a,b)=>a*10**b).reduce((a,b)=>a+b)

Bash, 19 bytes

expr ${1//?/1} * $1

An unusual example of expr being shorter than regular $[] arithmetic expansion.

Try it online!

Perl 5 -Minteger -pF , 12 bytes

$_*=10**@F/9

Try it online!

Vyxal r, 4 bytes

Lẋ₀β

Try it Online!

Another approach.

Vyxal s, 3 bytes

ẏ↵*

Try it Online!

To get even with these 3 byters, lol.

JavaScript (Node.js), 27 bytes

n=>(n+'').replace(/./g,1)*n

Try it online!

It is shorter than

n=>n*(g=i=>i<n?g(i+9):i/9)`` // 28 bytes
n=>~~(.1**~Math.log10(n)/9)*n // 29 bytes
n=>(10**-~Math.log10(n)-1)/9*n // 30 bytes

C++ (gcc), 42 bytes

[](int&n){int i=1;for(;n/i;)i*=10;n*=i/9;}

Try it online!

Raku, 13 bytes

{$_*S:g/./1/}

Try it online!

Desmos, 29 bytes

f(k)=∑_{n=0}^{logk-.5}10^nk

Try It On Desmos!

Using the formula $$n\cdot\frac{10^{length(n)}-1}9$$ is surprisingly 1 byte longer:

f(k)=k(10^{floor(logk)+1}-1)/9

BQN, 15 bytes

10⊸×⊸+˜´⊢⊣¨•Fmt

Try it at BQN online!

Explanation

10⊸×⊸+˜´⊢⊣¨•Fmt
            •Fmt  Convert the argument number to a string (list of characters)
          ⊣¨      Replace each character with
        ⊢         The argument number
       ´          Right fold
      ˜           on this function with reversed arguments:
    ⊸+              Add the right argument to
10⊸×                The left argument times 10

Other versions

Another 15-byte solution that constructs a list of powers of 10:

+´⊢×10⋆↕∘≠∘•Fmt

A 16-byte solution that constructs a list of 10s and multiplication-scans it:

+´÷⟜10×`·10¨•Fmt

Another 16-byte solution that constructs a string of 1s and evaluates it:

⊢×·•BQN·'1'¨•Fmt

Brachylog, 5 bytes

lᵐ×↙?

Try it online!

 ᵐ       For each digit of the input,
l        get its length (i.e. 1),
 ᵐ       and concatenate the lengths back into an integer.
  ×↙?    Multiply by the input.

dc, 10

?dZAr^9/*p

Try it online!

Explanation

?             # Read input
 d            # duplicate input on stack
  Z           # push count digits of input to stack
   Ar         # push 10, reverse top 2 stack elements
     ^        # calculate power of 10
      9/      # divide by 9 to get 111....1
        *     # multiply by original input
         p    # print

Pip, 7 bytes

a*:1X#a

Try it online!

Explanation

Port of Bubbler's string-based Japt answer:

a*:1X#a
     #a  Length (number of digits) of cmdline argument
   1X    String of that many 1s
 *:      (Treat as a number and) Multiply by
a        Cmdline argument

Charcoal, 8 bytes

I×NI×1Lθ

Try it online! Link is to verbose version of code. Works with both integer and string input. Explanation:

     1      Literal string `1`
    ×       Repeated by
       θ    First input
      L     Digit length
   I        Cast to integer
 ×          Multiplied by
  N         Input as an integer
I           Cast to string
            Implicitly print

7 bytes but only accepts numeric input in JSON format:

I↨χEIθθ

Try it online! Link is to verbose version of code. Explanation: Port of @alephalpha's Jelly answer.

     θ  Input
    I   Cast to string
   E    Map over characters
      θ Input
 ↨χ     Convert from "base 10"
I       Cast to string
        Implicitly print

BQN, 27 bytes

{𝕩≤𝕨÷10?(𝕨×𝕩)+𝕨𝕊𝕩×10;𝕨×𝕩}⟜1

Try it at BQN REPL

Recursive function to try to circumvent the lack of simple base-conversion, string-conversion or logarithm functions in BQN.

{𝕩≤𝕨÷10?(𝕨×𝕩)+𝕨𝕊𝕩×10;𝕨×𝕩}⟜1     # recursive function with input 𝕨 
                         ⟜1     #  and second argument 𝕩 initiall set to 1
 𝕩≤𝕨÷10?                        # is 𝕩 less than or equal to 𝕨÷10?
                                # if yes:
        (𝕨×𝕩)                   #  return 𝕨×𝕩
             +                  #  plus
              𝕨𝕊𝕩×10            #  the result of a recursive call
                                #   with 𝕩 multiplied by 10
                    ;           # otherwise:
                     𝕨×𝕩        #  just return 𝕨×𝕩

Burlesque, 8 bytes

Jq./]m|*

Try it online!

Takes input as a string (as from standard in) containing number.

J   # Duplicate input
q./ # Quoted isNumeric (returns 1 for each digit)
]m  # Map and concat to string
|*  # String multiply

APL (Dyalog Unicode), 7 bytes

Anonymous tacit prefix function.

10⊥⊢⊣¨⍕

Try it online!

 stringify

⊣¨ defer each digit in favour of:

 the argument

10⊥ evaluate as (carrying) base-10 digits

Nibbles, 4 bytes (8 nibbles)

`@~.`p$@

Inspired by alephalpha's Jelly answer.

    `p$     # convert input to string
   .        # map function over each element (characters in string):
       @    # second argument (arg1=element, arg2=input)
            # so now we have digits-of-input copies of the input
`@          # interpret as digits in base
  ~         # 10

enter image description here

05AB1E, 5 4 bytes

$g×*

-1 byte porting emanresuA's Jelly answer

Try it online or verify all test cases.

Alternative 4-byter (port of @Bubbler's Japt answer:

gиTβ

Try it online or verify all test cases.

Explanation:

$     # Push 1 and the input
 g    # Pop the input, and push its length
  ×   # Repeat 1 that many times
   *  # Multiply it to the (implicit) input-integer
      # (after which the result is output implicitly)

g     # Push the length of the (implicit) input-integer
 и    # Repeat the (implicit) input-list that many times
  Tβ  # Convert it from a base-10 list to a base-10 integer
      # (after which the result is output implicitly)

Retina, 16 bytes

.+
$.($($.&*1)**

Try it online! Link includes test cases. Explanation: $($.&*1) represents the input with its characters replaced by 1s, which is then implicitly multiplied by the original input. (Retina's multiplication is decimal times unary, so the extra * is required to convert one of the decimal numbers to unary for the multiplication, and the $.( converts the result back to decimal.)

PARI/GP, 21 bytes

n->n*(10^#Str(n)-1)/9

Attempt This Online!


PARI/GP, 29 bytes

f(n,m=n)=if(n,10*f(n\10,m)+m)

Attempt This Online!


PARI/GP, 31 bytes

n->fromdigits([n|i<-digits(n)])

Attempt This Online!

Factor, 33 bytes

[ dup log10 1 /i 1 + 10^ 9 /i * ]

Try it online!

       ! 123
dup    ! 123 123
log10  ! 123 2.089905111439398
1      ! 123 2.089905111439398 1
/i     ! 123 2
1      ! 123 2 1
+      ! 123 3
10^    ! 123 1000
9      ! 123 1000 9
/i     ! 123 111
*      ! 13653

C (gcc), 38 36 35 bytes

m;f(n){n*=m=exp10(m=log10(n)+1)/9;}

Try it online!

Saved 2 3 bytes thanks to tsh!!!

Japt, 3 bytes

ì£U

Try it

Found a 3 that works with numbers.

ì£U
ì      Convert to base-10 array of digits, do ... and convert back:
 £     Map over the array with:
  U    Return the original input

Japt, 4 bytes

*sç1

Try it

*sç1
*       Multiply the input with
 s      Transform the input as a string:
  ç1    Replace each char by 1

If it is allowed to take the number as a string:

Japt, 3 bytes

*ç1

Try it

*ç1
*      Multiply the input with (coercing both sides to number)
 ç1    Replace each char by 1

R, 21 bytes

\(x)x*10^nchar(x)%/%9

Attempt This Online!

Uses an 'x multiplied by 111' approach, where the '111' is constructed as the next power-of-10 greater-or-equal to x, integer-divided by 9.

(now reading the other answers: this is the same approach already used in xnor's Python answer)

Python, 57 bytes

lambda n:sum(n//10for i in range(len(str(n)))if(n:=n*10))

Attempt This Online!

Python, 31 bytes

lambda n:int('1'*len(str(n)))*n

Attempt This Online!

Python, 29 bytes

Port of @xnor's answer.

lambda n:10**len(str(n))//9*n

Attempt This Online!

Jelly, 4 3 bytes

-1 byte thanks to Unrelated String.

ṁDḌ

Try it online!

A port of my PARI/GP answer.

 D     # To digits
ṁ      # Fill with the input
  Ḍ    # From digits

MathGolf, 5 bytes

hª*y*

Try it online.

Explanation:

h      # Push the length of the (implicit) input-integer (without popping)
 ª*    # Push a list of the length amount of 1s:
 ª     #  Push [1]
  *    #  Python-style multiply it to the length
   y   # Join it together and implicitly convert it to an integer
    *  # Multiply it to the input
       # (after which the entire stack is output implicitly as result)

Vyxal, 8 bytes

₌ẏL+↲›⌊∑

Try it Online!

(yes I know there's a 4 byter, but I liked this approach so much I posted it separately)

Kids these days with their "ten to the power of" approaches. Hasn't anyone ever heard of literal spec interpretation? :p

Takes input as a string.

Explained

₌ẏL+↲›⌊∑
₌ẏL      # Push the range [0, len(in)) and len(in)
  +      # add those together
   ↲›    # pad the input left with spaces until length for each item in that list and replace all spaces with 0s
     ⌊∑  # convert each item to int and sum

Jelly, 5 bytes

D1€Ḍ×

Try it online!

I suspect there's a 4-byter but I can't find one.

D  Ḍ  # To digits...
 1€   # Fill with 1
    × # Multiply by original

Haskell, 23 bytes

f n=n*read('1'<$show n)

Try it online!

Multiplies n by the number obtained from replacing each of its digits with a 1. Same length pointfree:

(*)<*>read.('1'<$).show

Try it online!

Python 2, 25 bytes

lambda n:10**len(`n`)/9*n

Try it online!

Vyxal, 4 bytes

ẏ↵*∑

Try it Online!

ẏ    # Exclusive range 0-length
 ↵   # 10 to the power of each of those
  *  # Multiply by the input
   ∑ # Sum