><>, 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.
Does this mean that floats more than zero are also valid inputs? Or are only integers valid? – R. Kap – 2016-07-07T10:42:08.690
R.Kap: No, only whole numbers. Everything else would need a lot of specification. :) – Seims – 2016-07-07T10:43:53.943
Both positive and negative? Or only positive? – R. Kap – 2016-07-07T10:44:57.423
No, only positive. – Seims – 2016-07-07T10:45:25.023
@R.Kap can be anything as long as it's > 0 :p – weston – 2016-07-07T10:46:06.170
10There must be a relevant OEIS entry... – MKII – 2016-07-07T10:52:04.767
@MKII Can be described as 11n^2 for 1-digit-numbers. Otherwise no. – Seims – 2016-07-07T10:53:25.863
@MKII Sadly, no there is not.
– R. Kap – 2016-07-07T10:53:36.3831@Seims It was a joke, based on the "uninsteresting" name – MKII – 2016-07-07T11:10:34.450
10@MKII my bad, i don't speak joke – Seims – 2016-07-07T11:13:01.690
1Is taking the number as a string argument bending the rules a bit too much? – Dom Hastings – 2016-07-07T11:39:51.533
^^ I was just about to ask the same – Luis Mendo – 2016-07-07T11:43:49.410
1Go ahead, bend the rules! :P – Seims – 2016-07-07T11:44:34.640
For those who didn't understand my post: https://en.wikipedia.org/wiki/Interesting_number_paradox
– thepiercingarrow – 2016-07-07T13:44:02.227@MKII I checked there isn't :( – thepiercingarrow – 2016-07-07T15:19:30.517
This reminds me of the proof that there are no non-interesting natural numbers. By counterexample, suppose there are some non-interesting natural numbers. Let n be the least of those. Then n is the smallest non-interesting natural number, which is interesting. Thus n is not non-interesting, which is a contradiction. Thus, there are no non-interesting natural numbers. – Joshua Taylor – 2016-07-07T21:09:00.567
Could we take input as a unit type which coerces to an integer? – MayorMonty – 2016-07-10T18:20:54.490
Never mind, someone already posted exactly what I had in mind, good job @DomHastings – MayorMonty – 2016-07-10T18:22:24.857
@JoshuaTaylor only if non-interesting is defined that specific way. you could just define it so it doesn't lead to a paradox :P – ASCII-only – 2018-04-17T11:47:20.187