Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

An uninteresting number (which I totally didn't make up only for this challenge) is created like this:

  1. Take a positive integer N
  2. Create a new number O by adding the digits of N at the end of N
  3. The final uninteresting number is O*N

For example for N=12:

  1. O = 1212
  2. O*N = 1212 * 12
  3. Final number is 14544

Input

A positive integer N (N > 0) or your language's equivalent. You don't have to catch incorrect input.

Output

The corresponding uninteresting number.

Test cases

  1 -> 11
  2 -> 44
  3 -> 99
 10 -> 10100
174 -> 30306276

Scoring

Shortest Code in Bytes wins.

share|improve this question
    
Does this mean that floats more than zero are also valid inputs? Or are only integers valid? – R. Kap Jul 7 at 10:42
1  
There must be a relevant OEIS entry... – MKII Jul 7 at 10:52
3  
@MKII my bad, i don't speak joke – Seims Jul 7 at 11:13
1  
Is taking the number as a string argument bending the rules a bit too much? – Dom Hastings Jul 7 at 11:39
1  
Go ahead, bend the rules! :P – Seims Jul 7 at 11:44

53 Answers 53

up vote 29 down vote accepted

05AB1E, 3 bytes

Ы*

Explained

Ð    # triplicate input
 «   # conactenate
  *  # multiply

Try it online

share|improve this answer
2  
Ahh, nice! Ninja'd me by seconds :p. – Adnan Jul 7 at 10:44
2  
@Adnan Hehe. Revenge for that time you did it to me :P – Emigna Jul 7 at 10:46
1  
3 operations, 3 bytes, I don't think you could make it any shorter than that. – youtubefreak Jul 7 at 11:20
1  
@busukxuan Yep. Concatenate automatically converts the number to str and * interprets the string as a number. Very useful :) – Emigna Jul 7 at 11:50
2  
@busukxuan Yeah, a combination of Pyth and 05AB1E could have done it in 2 bytes :) – Emigna Jul 7 at 12:01

JavaScript (ES6), 10 bytes

_=>(_+_)*_

Needs to be called with the argument as a String, not a Number.

Usage:

(_=>(_+_)*_)('3')
99

-3 bytes thanks to @Quill's suggestion.

share|improve this answer
    
If you can pass the parameter as a string you can cut two bytes off this solution: _=>(_+_)*+_ – Quill Jul 7 at 11:34
    
@Quill Done! Thank you! – Dom Hastings Jul 7 at 11:46
3  
How exactly does this work? If I understand correctly, are you using _ as an arbitrary character for a variable? (PS - (_+_) totally looks like a butt) – charredgrass Jul 7 at 13:11
8  
type casting abuse eleven – Downgoat 2 days ago
3  
Out of interest, the best I could do purely mathematically was 30 bytes in ES7 n=>(1+10**-~Math.log10(n))*n*n (sadly -~ have higher precedence than **) or 31 in ES6 n=>-~`1e${-~Math.log10(n)}`*n*n. Even recursion took me 32 bytes: f=(n,m=1)=>n<m?-~m*n*n:f(n,m*10) – Neil 2 days ago

Java 8, 29 26 Bytes

God bless lambda

c->Long.decode(c+""+c)*c;
share|improve this answer
18  
You gotta love Java; even with lambdas of Java 8 and one of the shortest Java answers ever here on codegolf, it's still outgolfed by all other current answers. xD – Kevin Cruijssen Jul 7 at 11:15
3  
java is bae, lambda is bae – Seims Jul 7 at 11:31
1  
@KevinCruijssen i still have a hope, one day java will win codegolf contest – user902383 Jul 7 at 11:51
1  
After your edit you outgolfed @MartinEnder with his Retina answer by 1 byte! o.Ô – Kevin Cruijssen Jul 7 at 12:39
    
@KevinCruijssen but still not enough to win or at least beat python:( – user902383 Jul 7 at 13:08

vim, 11

C<C-r>=<C-r>"<C-r>"*<C-r>"<cr>

crcrcrcrcr...

C       change (delete and enter insert mode) until the end of the line
<C-r>=  insert an expression via the special "expression register"
<C-r>"  insert the contents of the default register (what we just C'd)
<C-r>"  ... again
*       multiplied by
<C-r>"  the input (again)
<cr>    insert the result of this expression
share|improve this answer
    
11 what? bytes? – Insane 2 days ago
2  
@Insane Bytes if you call it from the command line, keystrokes if you do it directly from vim. I usually omit the unit from my vim answers because it can be either one. – Doorknob 2 days ago
    

C#, 19 23 bytes

n=>int.Parse(""+n+n)*n;

Without strings, 47 bytes

n=>{int i=1;while(i<=n)i*=10;return(i+1)*n*n;};
share|improve this answer
2  
This is a snippet, not a full program or function. It would be valid with e.g. (n)=>{int.Parse(""+n+n)*n}2 – cat Jul 7 at 13:12
    
@cat OK, thanks, new to code-golf, will change – weston Jul 7 at 13:19
    
@cat better? do I need the trailing ;? – weston Jul 7 at 13:22
    
I don't know. See also Defaults for Code Golf and Tips for golfing in C# – cat 2 days ago

Python 2.7, 21 bytes:

lambda f:int(`f`*2)*f

Well, this has to be the shortest Python answer I have ever written in the shortest amount of time ever. It's an anonymous lambda function that can be executed by naming it anything you want and then calling it like a normal function wrapped in print(). For instance, if your input is 12, and the function was named H, this this would be called like print(H(12)).

Try It Online! (Ideone)

Note that this only works for values up and equal to 9223372036854775807 since any higher value and repr() puts a L at the end of the integer. Therefore, for values greater than 9223372036854775807, this 24 byte version would be the one that works:

lambda f:int(str(f)*2)*f

Try This Online! (Ideone)

share|improve this answer
    
I still find Phytons String operations magical... – Seims Jul 7 at 10:34
    
@Seims in what way? – busukxuan Jul 7 at 11:36
    
String multiplication and addition. Haven't seen that often. – Seims Jul 7 at 11:37
    
@Seims I guess you mostly deal with static languages then? – busukxuan Jul 7 at 11:42
    
@busukxuan Call me a noob if you want :^) – Seims Jul 7 at 11:44

Pyth, 5 4 bytes

*s+`

Explanation:

    Q    input
   `     representation, basically str(Q)
  +  Q   add Q to its own string form
 s       parse int
*     Q  multiply by input
         print

Test it here.

share|improve this answer

C, 70 68 54 53 52 44

f(n){return(pow(10,(int)log10(n)+1)*n+n)*n;}

Previous version (48 bytes, no math functions), saved 16 bytes thanks to @LeakyNun, 1 byte thanks to @FryAmTheEggman, 4 bytes thanks to @TobySpeight:

f(n,d,i){for(i=d=n;d;d/=10)i*=10;return(i+n)*n;}

Call f() with one argument, the number, and it returns the corresponding uninteresting number.

Test program

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    while (*++argv) {
        int n = atoi(*argv);
        printf("%d -> %d\n", n, f(n));
    }
    return 0;
}

Test results:

$ ./84712 1 2 3 4 10 174
1 -> 11
2 -> 44
3 -> 99
4 -> 176
10 -> 10100
174 -> 30306276
share|improve this answer
    
f(n){int b=1;while(a)b*=10,a/=10;return(n+n*b)*n;} – Leaky Nun Jul 7 at 13:08
    
This shouldn't work properly without including math.h, but you get away with it in GCC, where log10() and pow() are built-in, and the compiler merely warns about "incompatible implicit declaration of built-in function" rather than assuming (as it should) that they both return int. – Toby Speight Jul 7 at 14:16
    
@Leaky - you didn't put anything into a... – Toby Speight Jul 7 at 14:16
1  
It's nice to see another answer that stays entirely within the arithmetic world (not doing string concatenation). :-) – Toby Speight Jul 7 at 14:31
1  
@Toby - String concatenation in C is incompatible with golfing. ;-) – owacoder Jul 7 at 14:32

Emacs, 17 bytes

(*SPACEC-SPACEC-EM-YSPACEC-YC-Y)C-J

Explanation

  • (*SPACE adds (* at point (before the number);
  • C-SPACEC-EM-Y Select and copy the number;
  • SPACE adds a space character at point (after the number);
  • C-YC-Y pastes two times the number at point;
  • ) adds ) at the end;
  • C-J interprets the line as a LISP expression and prints its result.

Exemple

Cursor represented by a pipe (|)

  • |174
  • (*SPACE (* |174
  • C-SPACEC-EM-Y (* 174|
  • SPACE (* 174 |
  • C-YC-Y (* 174 174174|
  • ) (* 174 174174)|
  • C-J

Result

(* 174 174174)
30306276|
share|improve this answer
3  
Hi, and welcome to PPCG! Nice first post! – Eᴀsᴛᴇʀʟʏ Iʀᴋ Jul 7 at 14:54
    
Hey, thank you :) – YSC 2 days ago

Jelly, 4 Bytes

;DḌ×

Try it online

Explanation

;DḌ×    Main link. argument : N

 D      Decimal; Yield the digits of N
;       Concatenate N and its digits
  Ḍ     Convert to integer; We get O
   ×    Multiply O and N
share|improve this answer
    
It's a really happy winking face with a goatee! ;DDx – cat 2 days ago
    
In which encoding does take only 1 byte? Usually we use UTF-8, in which it takes 3 (and the × takes 2, but it is 1 byte in e.g. ISO8859-1). – o11c yesterday

Dyalog APL, 7 bytes

⊢×#⍎⍕,⍕

string representation

⍕, prepend string representation

#⍎ make into number (in root namespace)

⊢× multiply by original number

share|improve this answer
1  
Those wrecked TIE fighters are funny! – Luis Mendo Jul 7 at 11:13
2  
@LuisMendo dyalog.com/blog/2015/12/apl-puns – Adám Jul 7 at 12:09
1  
The fork awakens :-D – Luis Mendo Jul 7 at 12:28
    
I'm pretty sure those aren't bytes in any encoding, since they're not letterlike or very common. – o11c yesterday
    
@o11c Did you check out the preemptive link for the word "bytes", viz. meta.codegolf.stackexchange.com/a/9429/43319. – Adám 13 hours ago

Retina, 27 20 bytes

^
$_$*: $_
:
$_$*:
:

Gets a bit slow for large inputs, because before the last the stage the result is represented in unary.

Try it online! (The first line enables a linefeed-separated test suite.)

Explanation

I'll use 2 as an example input (because the unary representations get a bit unwieldy for larger inputs).

Stage 1: Substitution

^
$_$*: $_

By matching the beginning of the string with ^ we simply prepend some stuff. $_ refers to the input string itself and $*: means we insert that many colons. So we get:

:: 22

Stage 2: Substitution

:
$_$*:

Now we match every : and again replace it with $_$*:. Of course, this time $_ doesn't evaluate to an integer (but to :: 22 in our example), but $* just looks for the first decimal in the string, so this evaluates to the input concatenated to itself (O in the challenge specification). We'll end up with N*O colons, followed by O:

:::::::::::::::::::::::::::::::::::::::::::: 22

Stage 3: Match

:

All that's left is counting the :s to convert from unary back to decimal, which is exactly what this stage does.

share|improve this answer
    
Ooh, so close to being as long as Java. Outgolfed it by just 2 bytes. +1 – R. Kap Jul 7 at 11:21
    
@R.Kap Actually, Java 8 outgolfed it after removing 3 bytes! o.Ô – Kevin Cruijssen Jul 7 at 12:36
3  
Sorry, Java.... – Martin Ender Jul 7 at 13:16

CJam, 8 bytes

ri_`_+i*

Try it online!

r     e# Read input
i     e# Convert to integer
_     e# Duplicate
`     e# Convert to string
_     e# Duplicate
+     e# Concatenate
i     e# Convert to integer
*     e# Multiply. Implicitly display
share|improve this answer
2  
I was about to suggest not converting to in then immediately back to string but the naive approach (i.e. having never used CJam before) is r__+i\i*, which is the same length. – QPaysTaxes Jul 7 at 11:34
    
@QPaysTaxes Ah nice. I noticed the same thing as you: why first convert it to int and then back to string again. I also never used CJam and didn't really look close enough at all the possible operators, so I was unable to find a solution on first glance. Thanks for sharing your approach without converting it back to string, even though it's the same byte-length. – Kevin Cruijssen Jul 7 at 11:40
    
If there was a way to apply an operation to the whole stack in two bytes, it would be a byte shorter (something like r__+si*, where s is "apply this operation over the stack"), but I don't see anything like that – QPaysTaxes Jul 7 at 11:43

Python, 42 bytes

Pure arithmetic approach, without strings!

f=lambda n,m=1:m<=n and f(n,m*10)or-~m*n*n

Ideone it!

share|improve this answer

Awk, 13 bytes

$0=($0$0)*$0

Set the line to 2 of itself multiplied by itself

share|improve this answer

Lua, 20 Bytes

Takes in a command-line argument, and outputs via STDIN

a=...print((a..a)*a)
share|improve this answer

Jelly, 8 6 bytes

ŒṘẋ2v×

Try it online!

Explanation

ŒṘẋ2v× - Main link. Left argument: the number to convert

     × - Multiply
    v  - an evaluation of the left argument
ŒṘ     - converted to string
  ẋ    - multiplied by
   2   - two and the left argument
share|improve this answer
1  
I don't think you need either of those ³s. – Martin Ender Jul 7 at 11:41

Matlab / Octave, 20 bytes

@(x)eval([x x 42 x])

This is an anonymous function that takes the input as a string.

Example use:

>> f = @(x)eval([x x 42 x])
f = 
    @(x)eval([x,x,42,x])
>> f('12')
ans =
       14544

Or try it online with ideone.

Explanation

The code builds a string by concatenating the input string twice, then the character * (that has ASCII code 42), then the string again. The concatenated string is then evaluated.

share|improve this answer
    
What does 42 mean? – Leaky Nun Jul 7 at 14:45
1  
@LeakyNun It's the Answer to the Ultimate Question of Life, the Universe, and Everything". Also, it happens to be the ASCII code for * – Luis Mendo Jul 7 at 14:51
    
Ah. I was searching for something like the 42th function. – Leaky Nun Jul 7 at 14:54
    
The code simply builds a string by concatenating the input string twice, then *, then the string again. The concatenated string is then evaluated. I'll edit that into the answer – Luis Mendo 2 days ago

Perl, 11 bytes

$_*=$_ x2

+ the p and l flags.

(run with perl -ple '$_*=$_ x2')

-2 bytes thanks to pipe.

share|improve this answer
    
Save two bytes: $_*=$_ x2 – pipe 2 days ago
    
Thanks @pipe , I shoud've seen it ealier.. – Dada 2 days ago
    
I don't think you need -l – Brad Gilbert b2gills 2 days ago
    
@BradGilbertb2gills Yes I need it because without it, $_ x2 will produce ...\n...\n which when converted as a number by perl ends at the first \n – Dada 2 days ago
    
I was testing it with both Perl 5 and 6, and didn't notice that I forgot to remove the 6. – Brad Gilbert b2gills 2 days ago

Excel VBA, 35 Bytes

Sub called with number, msgbox returns answer

Sub B(a)
MsgBox (a & a) * a
End Sub

Alternative Excel VBA, 42 Bytes

Number given in formula, returns answer.

Function B(a)
B = (a & a) * a
End Function
share|improve this answer
    
Think about a MsgBox and a Sub. It will save you 13 Byte, if I count correctly – GER_Moki 2 days ago
    
I would need some form of input box to get the value, no? – tjb1 2 days ago
    
Try Sub B(a) MsgBox (a & a) * a End Sub – GER_Moki 2 days ago
    
That requires another sub to pass the value, I'm not sure that's allowed in golf. – tjb1 2 days ago
    
The Function must be called too ;) – GER_Moki 2 days ago

MATL, 6 bytes

tVthU*

Try it online!

tV     % Input number implicitly. Duplicate and convert to string
th     % Duplicate and concatenate the two equal strings
U      % Convert to number
*      % Multiply
share|improve this answer

zsh, 13 bytes

<<<$[$1$1*$1]

Takes input as a command line argument, outputs to STDOUT.

This only works in zsh, but here's 15 bytes in Bash using echo instead of <<<:

echo $[$1$1*$1]
share|improve this answer

J, 7 bytes

*,~&.":

Explanation

*,~&.":  Input: n
     ":  Format n as a string
 ,~&.    Reflect and join the string to make "nn"
         and parse the string to get a number
*        Multiply that number by n
share|improve this answer

Brachylog, 7 bytes

:?c:?*.

Explanation

:?c      Concatenate Input to itself
   :?*.  Output is that concatenation times Input
share|improve this answer

PHP, 25 24 bytes

Short opening tags are useful for surprisingly few golfing challenges, luckily this is one of them. Unfortunately operator precedence is the opposite of the order you need to do them in so lots of brackets are needed.

<?=($a=$argv[1])*"$a$a";

edit: I realised that seeing as how I'm using brackets anyway I can effectively skip the concatenation operator by changing the written order of the operations around.

share|improve this answer

dc, 11 10 bytes

ddZAr^1+**

I knew that eventually I would find a use for the Z command!

Operation is fairly simple - count the digits, take 10 raised to that power and add one. This gives a multiplier that concatenates the number with itself. Then just multiply.

I/O uses the stack, as usual for dc.

Full program

This is what I used for the tests:

#!/usr/bin/dc
?
ddZAr^1+**
p

The two extra commands give us pipeline I/O.

Tests

$ for i in 1 2 3 10 174; do printf '%d -> ' $i; ./84712.dc <<<$i; done
1 -> 11
2 -> 44
3 -> 99
10 -> 10100
174 -> 30306276

Thanks are due to Sir Biden XVII (1 byte).

share|improve this answer
    
You can substitute A for 10 to save a byte. Well done! – Sir Biden XVII 2 days ago

Clojure, 22 bytes

#(*(bigint(str % %))%)

Anonymous function which concatenates string representation of its argument covnerts it to BigInteger and multiplies by the argument. The output is in format 11N (N signifies its a bigint), if there should be no N at the end then we can use

#(*(read-string(str % %))%)

for 27 bytes.

See it online: https://ideone.com/QqYfpo

share|improve this answer

Pyke, 5 4 bytes

`+b*

Try it here!

`    -    str(input)
 +   -   ^+input  (convert to string implicitly)
  b  -  int(^)
   * - ^*input

Also 5 bytes with string inputs

+bRb*
+]mbB
share|improve this answer

SpecBAS - 30 bytes

1 INPUT n$: ?VAL(n$+n$)*VAL n$

My shortest SpecBAS answer yet :-)

share|improve this answer

Python, 51 Bytes

from math import*
g=lambda x:x*(x+x*10**(1+int(log10(x))))

Here's the mathematical way to do it (friend of mine found the formula). I guess using it wouldn't produce an answer shorter than 3 bytes. :)

share|improve this answer
    
I was a bout to post an answer using a similar approach... by the way it is python not phyton. – Leaky Nun Jul 7 at 12:52
    
@LeakyNun Code doesn't work either. Will look into it. – Seims Jul 7 at 12:53
1  
Add from math import* to the beginning of your submission, and you can remove g= from the byte count. – Leaky Nun Jul 7 at 12:55
1  
Changing from 10**(1+int(log10(x))) to 10**-~int(log10(x)) saves you bytes on parentheses. Changing from x*(x+x*10**... to x*x*-~10**... also saves bytes on parentheses. – Sherlock9 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.