| Bytes | Lang | Time | Link |
|---|---|---|---|
| 030 | AWK | 250304T172142Z | xrs |
| 018 | BQN | 250227T143648Z | panadest |
| 003 | Thunno 2 S | 230722T164048Z | The Thon |
| 011 | J | 221112T001833Z | naffetS |
| 009 | GolfScript | 221115T020747Z | Twilight |
| 046 | PowerShell Core | 221115T010425Z | Julian |
| 014 | K ngn/k | 221112T055254Z | oeuf |
| 025 | ><> | 221111T214051Z | Emigna |
| 040 | Prolog SWI | 220902T221634Z | naffetS |
| 036 | Ruby | 220825T172406Z | south |
| 012 | Knight | 220801T211017Z | naffetS |
| 029 | PHP | 220730T135211Z | Ram Chan |
| 036 | Regex 🐇 PCRE2 v10.35+ | 220728T125948Z | Deadcode |
| 026 | Wolfram Language Mathematica | 220727T133111Z | Roman |
| 012 | perl p | 220728T171803Z | Abigail |
| 073 | ECMAScript 2016 | 220727T235514Z | Eric Xue |
| 019 | Bash | 220726T203357Z | Digital |
| 012 | Perl 5 Minteger pF | 220727T141949Z | Xcali |
| 004 | Vyxal r | 220726T144623Z | naffetS |
| 027 | JavaScript Node.js | 220726T085436Z | tsh |
| 042 | C++ gcc | 220727T000642Z | c-- |
| 013 | Raku | 220726T233440Z | Sean |
| 029 | Desmos | 220726T220009Z | Aiden Ch |
| 015 | BQN | 220726T194218Z | DLosc |
| 005 | Brachylog | 220726T191753Z | Unrelate |
| 010 | dc | 220726T184611Z | Digital |
| 007 | Pip | 220726T183413Z | DLosc |
| 008 | Charcoal | 220726T114331Z | Neil |
| 027 | BQN | 220726T141521Z | Dominic |
| 008 | Burlesque | 220726T143316Z | DeathInc |
| 007 | APL Dyalog Unicode | 220726T133505Z | Adá |
| 048 | Nibbles | 220726T121623Z | Dominic |
| 004 | 05AB1E | 220726T082318Z | Kevin Cr |
| 016 | Retina | 220726T113811Z | Neil |
| 021 | PARI/GP | 220726T081421Z | alephalp |
| 033 | Factor | 220726T104556Z | chunes |
| 035 | C gcc | 220726T090241Z | Noodle9 |
| 003 | Japt | 220726T093850Z | Bubbler |
| 021 | R | 220726T091117Z | Dominic |
| 057 | Python | 220726T092538Z | solid.py |
| 003 | Jelly | 220726T084214Z | alephalp |
| 005 | MathGolf | 220726T083734Z | Kevin Cr |
| 008 | Vyxal | 220726T080417Z | lyxal |
| 005 | Jelly | 220726T080137Z | emanresu |
| 023 | Haskell | 220726T080026Z | xnor |
| 025 | Python 2 | 220726T075814Z | xnor |
| 004 | Vyxal | 220726T075653Z | emanresu |
BQN, 18 bytes
+´10⊸⋆{𝔽↕⌊1+𝔽⁼𝕩}⊸×
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×
Explanation
Że× # Implicit input
Ż # Push [0..len(input))
e # Take 10 ** each
× # Multiply by input
# Auto-sum and output
GolfScript, 9 bytes
.,1`*~\~*
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
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}
-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
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
Knight, 12 bytes
O*/^10L=xP9x
Ungolfed:
OUTPUT (* (/ (^ 10 (LENGTH (= x PROMPT))) 9) x)
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)*
perl -p, 12 bytes
$_*=s/./1/gr
Multiplies itself with 1, 11, 111, etc, depending on the length of the input.
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.
JavaScript (Node.js), 27 bytes
n=>(n+'').replace(/./g,1)*n
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
Desmos, 29 bytes
f(k)=∑_{n=0}^{logk-.5}10^nk
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
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ᵐ×↙?
ᵐ 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
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
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
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|*
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⊥⊢⊣¨⍕
⍕ 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
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
PARI/GP, 29 bytes
f(n,m=n)=if(n,10*f(n\10,m)+m)
PARI/GP, 31 bytes
n->fromdigits([n|i<-digits(n)])
Factor, 33 bytes
[ dup log10 1 /i 1 + 10^ 9 /i * ]
! 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
Japt, 3 bytes
ì£U
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
*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
*ç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
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))
Python, 31 bytes
lambda n:int('1'*len(str(n)))*n
Python, 29 bytes
Port of @xnor's answer.
lambda n:10**len(str(n))//9*n
Jelly, 4 3 bytes
-1 byte thanks to Unrelated String.
ṁDḌ
A port of my PARI/GP answer.
D # To digits
ṁ # Fill with the input
Ḍ # From digits
MathGolf, 5 bytes
hª*y*
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+↲›⌊∑
(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€Ḍ×
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)
Multiplies n by the number obtained from replacing each of its digits with a 1. Same length pointfree:
(*)<*>read.('1'<$).show
Vyxal, 4 bytes
ẏ↵*∑
ẏ # Exclusive range 0-length
↵ # 10 to the power of each of those
* # Multiply by the input
∑ # Sum
