><>, 22 Bytes
a:{:@)8$.$a*!
::{*+*n;
Input is expected to be on the stack already. If that's not okay, then I'll probably mark this answer non-competing. Reading numeric inputs in ><> is a real pain. Try it online
On a side note, this is my first post after a long period of inactivity; I'm glad to be able to contribute to this wonderful community again.
Explanation
I'm using the term "padding" to refer to a "variable"* that the input will be multiplied so that its digits may be duplicated.
e.g. if 12 is our input N
and 1212
is the number O
, then the padding used would be 100
since 12*100 + 12 = 1212
.
*><> doesn't exactly have those, aside from the register (&
), but you can effectively have them by manipulating the stack if that makes sense
Line 1
a:{:@)8$.$a*!
a push initial padding value (10)
:{: duplicate padding, bring input to front of stack and duplicate it
@ manipulate stack so that it looks like [padding,input,padding,input]
) pop input and padding from top and push the result of (padding > input)
8$. push 8 and swap with the result, then jump to that location
$ swap top so it looks like [input,padding]
a*! multiply padding by 10, skip pushing 10 at beginning
Line 2
::{*+*n;
:: duplicate input twice -> [padding,input,input,input]
{ bring padding from bottom -> [input,input,input,padding]
* multiply first input copy by padding
+ add it to the second copy
* multiply by the final copy
n print result
; terminate
Here's a hopefully more readable explanation.
Line 1
a:{:@)8$.$a*!
The program initializes the stack so that it contains [input,10]
(10 is the initial padding value). It then checks to see if the padding is greater than the input. The result of this (1 if true, 0 if false) is pushed onto the top of the stack. The pointer then jumps to the location (8,padding>input
), which means that if the padding is greater than the input, the program goes to the second line and if it isn't it continues along on the first line. If it continues on the first line, it'll multiply the padding by 10 and repeat the process.
Line 2
::{*+*n;
On Line 2, the program duplicates the input twice and then evaluates the expression input*((input*padding) + input)
and prints it.