text:
Output all strings
Given a set of letters, output all strings made of those letters. (This is Kleene star of the set.) For example, for {'a','b'}, the strings are:
'', 'a', 'b', 'aa', 'ab', 'ba', 'bb', 'aaa', 'aab', ...

Input: A non-empty collection of distinct letters a..z. These may be characters or single-character strings.
Output: All strings in those letters, in any order, without repeats. You may use lists of chars as strings.
This is an infinite list, so you can output it by:

Running forever writing more and more strings. These strings can be written in any flat separated format, meaning that they you can tell where each string ends, but the strings aren't subdivided into groups.
Taking a number n as input and outputting the first n strings in any flat separated format
Yielding each string in turn from a generator object
Producing an infinite object

Be sure that your method eventually produces every string in the output, since it's possible to produce infinitely many strings from the set while never getting to some strings.
You may not output it by

Producing the nth string given n
Providing a membership oracle that decides if a given string belongs to the set

Built-ins are allowed, but I ask voters to give attention to answers that implement the operation themselves over ones that mostly rely on a built-in.

var QUESTION_ID=74273,OVERRIDE_USER=20260;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/74273/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

@Cyoce Not sure what you mean. I clarified that the strings must be separated, so you can tell the empty string from nothing.

Please explain why "producing the Nth string given N" is not allowed.

@CatsAreFluffy It was a judgment call. I think producing the Nth string would be too easy compared to the alternatives and make the challenge less interesting, especially because some languages have built-in arbitrary-base conversion. Also, I didn't think it captured the idea of generating an infinite set rather than querying it.

Can you explain "producing an infinite object"? Does that mean we can for example push each string onto the stack (for stack languages) and let it run "forever", even if no output will ever be produced because the program won't finish?

@DonMuesli Is output to the stack an accepted output method for such languages? And, will the stack contain only these strings at any point in time?

@xnor The stack will only contain those strings at the end of each iteration. Each iteration k does intermediate computations to generate all k-length strings, but the intermediate objects are consumed. I think output to the stack is acceptable, because it's like a function output, and most stack languages display the stack at the end anyway. The problem is, this program has no end...

@DonMuesli It's not OK that the stack holds other things while running, since then it cannot be taken as an output of all strings. If your language has a separate output stack onto which only output strings are pushed, that would be fine.

@xnor Ok. Anyway my current version produces the strings dynamically to stdout, so it fulfills the challenge requirements. Another thing: MATL "displays" the empty string by producing no output. So it's not seen at stdout. Is that acceptable?

@DonMuesli Unfortunately, also no. The empty string needs to be apparent.

@xnor Ok. I'll add it explicitly as an empty line

How about a language like JavaScript working in theory, but being limited due to, say, browser freezing?

Python 2, 53 56
-3 after realizing that yield x can be used as an expression.
def f(s):yield'';[(yield w+c)for w in f(s)for c in s]

One byte shorter, but starts at 'aa' rather than at '': S=lambda s:(c+w for f in[str,S]for w in f(s)for c in s). Also doesn't work for the empty input.

Haskell, 24 bytes
f s=[]:[b:a|a<-f s,b<-s]

Produces an infinite list.
*Main> f "abc"
["","a","b","c","aa","ba","ca","ab","bb","cb","ac","bc","cc","aaa","baa","caa","aba","bba","cba",…

Too bad (:)<$>s<*>f s would give the wrong order. There's f s="":(flip(:)<$>f s<*>s) but it's longer.

Yeah. I had found the 23-byte f s=[]:(f s<**>map(:)s) except that <**> isn’t in Prelude.

Mathematica, 32 31 Bytes
Do[Echo/@#~Tuples~n,{n,0,∞}]&

Edit:
CatsAreFluffy scraped off one byte.

JavaScript (ES6), 61 bytes
function*g(s){yield'';for(let r of g(s))for(c of s)yield c+r}

Port of @feersum's Python generator. The let is necessary. Save 2 bytes by using an array comprehension (failed ES7 proposal, but works in Firefox 30-57):
function*g(s){yield'';[for(r of g(s))for(c of s)yield c+r]}

Alternative version for 73 bytes that returns the first n elements yielded by the above generator:
(s,n)=>Array(n).fill('').map(g=(r,i)=>i--?g(r+s[i%l],i/l|0):r,l=s.length)

JS has generators? :0000000

Perl, 39 37 35 bytes
(First describes an older version. The new shorter program is at the end)
Includes +3 for -alp
Run with the set of characters on STDIN, e.g. perl -alp kleene.pl <<< "a b c"
kleene.pl (this version is 34+3 bytes):
$#a=$"=","}for(@a){push@a,<{@F}$_>

Add +2 for -F (drop implicit -a if no spaces between input characters, or -6 (only @a="" before }) if we already put commas between the characters on STDIN
Explanation:
The -alp options make the code effectively:
BEGIN { $/ = "\n"; $\ = "\n"; }
LINE: while (defined($_ = <ARGV>)) {
    chomp $_;
    our @F = split(' ', $_, 0);
    $#a = $" = ',';
}
foreach $_ (@a) {
    use File::Glob ();
    push @a, glob('{' . join($", @F) . '}' . $_);
}

As you can see <> in perl is not only used for readline, but can also do shell style globbing (in fact in ancient perls it was implemented by calling the shell).
For example <{a,b}{1,2}> will expand to "a1","a2","b1","b2"
So if we have the elements in @F we just need to add commas inbetween. The default inbetween character for interpolation is space, which is stored in special variable $". So setting $" to , will turn "{@F}" into {a,b} if @F=qw(a b) (globs expand as strings)
In fact I would really have liked to loop with something like glob"{@F}"x$n++, but I kept running into the problem that the first empty line doesn't get generated and all workarounds I found made the code too long.
So another essential part of this code is that if you use a for to loop over an array you can actually push extra elements on it during the loop and the loop will also pick up these new elements. So if in the loop we are e.g. at element "ab", then <{@F}$_> will expand to <{a,b}ab> which in list context becomes ("aab", "bab"). So if I push these on @a then the strings extended one to the left become available too
All I still need to do is prime the loop with an empty string. That is done using$#a = 0 (, in numeric context becomes 0) which causes the first and only element of @a to become undef which will behave like "" when I use it
Improvement
In fact by doing tests for this explanation I found a short way to use a growing glob that properly handles the first empty entry. Run as perl -ap kleene0.pl <<< "a b" (so add 2 bytes for -ap)
kleene0.pl (this version is 33+2 bytes):
$"=",";print<$z,>;$z.="{@F}";redo

All these solutions will keep more and more of the output in memory and that will cause the program to fail after some time. You can also use perl globs for lazy generation by using them in scalar context, but that makes the programs longer....

Can you please explain what is going on around:<{@F}$_>? Thanks!

Jelly, 8 6 bytes
⁷³p$Ȯ¿

Try it online!
How it works
⁷³p$Ȯ¿    Monadic link. Argument: A (alphabet)

⁷         Set the return value to '\n'.
     ¿    While loop.
            Condition:
    Ȯ         Print the current return value and return it (always truthy).
            Body:
   $          Combine the two links to the left into a single, monadic link.
 ³              Yield A.
  p             Perform the Cartesian product of A and the current return value,
                updating the return value in the process.

Alternate version, 6 bytes
R’ḃL}ị

This is a dyadic link that accepts an alphabet and the desired number of strings as left and right arguments, respectively.
Try it online!
How it works
R’ḃL}ị    Dyadic link. Arguments: n (integer), A (alphabet)

R         Range; yield [1, ..., n].
 ’        Decrement; yield [0, ..., n-1].
   L}     Yield l, the length of A.
  ḃ       Convert every i in [0, ..., n-1] to bijective base l.
     ị    For each array of digits, retrieve the corresponding characters of A.

Pyth, 7
<s^LzQQ

Try it here
This computes the cartesian product of the input with each number from 0..n-1, joins them, and then only keeps the first n. This will time out online for numbers or strings that are much bigger than 3-4.
Alternatively, to get infinite output look at Jakube's answer.

CJam, 16 10 bytes
Thanks to jimmy23013 for saving 6 bytes.
N{eam*_o}h

Input is one command-line argument per character. Output is one string on each line.
Try it online! (But kill it immediately...)
Explanation
N      e# Push [\n]. At each step this array will contain all strings of length N,
       e# each followed by a linefeed.
{      e# Infinite loop...
  ea   e#   Read command-line arguments.
  m*   e#   Cartesian product: pairs each letter with each string in the list.
  _o   e#   Output all the strings of the current length.
}h

Python 2, 89 84 83 bytes
x,n=input()
l=len(x)
for i in range(n):
 s=''
 while i:i-=1;s+=x[i%l];i/=l
 print s

Wow. Shorter and without builtins.

Nekomata, 2 bytes
Ňŧ

Attempt This Online!
Ňŧ
Ň       Nondeterministically choose an natural number, say n
 ŧ      Nondeterministically choose a tuple of n elements from the input list

In the default mode, Nekomata prints all possible outputs.

Pyth, 7 bytes
.V0j^zb

Alternative to @fry.
This program reads a string and keeps on printing strings until infinity.
Explanation:
.V0      for b in (0 to infinity):
    ^zb     compute all strings of length b consisting of the input alphabet
   j        print each one on a separate line

Alternatively the following will also work. A little bit more hacky though.
u
M^zH7

MATL, 10 bytes
0cD`G@Z^DT

Try it online! But don't leave it running for long, to avoid large computational load on the server.
The program displays the strings dynamically, each string on a different line.
0cD             % force display of a newline to represent the empty string
   `      T     % infinite do-while loop
    G           % push input, or nothing if no input has been taken yet
     @          % push iteration. Gives 1, 2,... in each iteration
      Z^        % Cartesian power. In the first iteration takes input implicitly
       D        % display

Haskell, 33 bytes
k u=do s<-[0..];mapM(\_->u)[1..s]

For exampe, k "xyz" is the infinite list ["","x","y","z","xx","xy","xz","yx","yy","yz","zx","zy","zz","xxx",...]

Husk, 6 7 5 bytes
Θṁπ⁰N

Try it online!
Explanation
 ṁ  N map natural numbers to:
  π⁰  cartesian power of input
 ṁ    and join
Θ     prepend empty string

Nice answer, but you need the strings to have a consistent separator between them like all in one line or all in separate lines, due to the rule 'These strings can be written in any flat separated format, meaning that they you can tell where each string ends, but the strings aren't subdivided into groups."

I don't think it outputs the empty string, since it starts with length-1 strings.

@Bubbler added..

Ruby, 65 60 bytes
->a{n=-1;loop{puts a.repeated_permutation(n+=1).map &:join}}

Such long builtin names...

AFAIK You don't need the space before & and you can use p instead of puts.

@QPaysTaxes The space cannot be dropped, and p calls inspect on its arguments which would produce output like [] ["a","b"] ["aa", "ab", ...

I misunderstood your answer. I thought it was generating an infinite array and printing it. However, I'm fairly sure that on Array, to_s is aliased to inspect, so puts and p have the same output. http://ruby-doc.org/core-2.2.0/Array.html#method-i-to_s WRT the space: Did you check? Admittedly I'm not certain, but I'm fairly sure about it.

Python 3, 95
from itertools import*
def f(x,l=0):
 while 1:print(*combinations_with_replacement(x*l,l));l+=1

Why must itertools functions have such long names.

combinations_with_replacement is never worth it. I'm pretty sure it's shorter to use loops. Always.

Scala, 69
def f[A](s:Set[A]):Stream[List[A]]=Nil#::f(s).flatMap(x=>s.map(_::x))

Lazy streams are quite nice for this kind of thing.

C (gcc), 99 97 95 93 bytes
-2 bytes thanks to @ceilingcat (replaced putchar(v[~s[i++]]) by printf(v+~s[i++])).
-2 more bytes thanks to @ceilingcat (made i a pointer rather than an index).
-2 bytes once more, again thanks to ceilingcat (replaced (*i)--+l by --*i==~l, reversing the last two arguments of the ternary conditional operator, making it possible to remove the parentheses around *i++=-1).
s[999];*i;f(v,l)int*v;{for(i=s;printf(v+~*i++););for(i=s,puts("");;)--*i==~l?*i++=-1:f(v,l);}

Try it online!

Japt, 50 40 34 28 bytes
V²o ®s1+Ul)£UgXnH)¯X¦0}Ãâ ¯V

Input is "string", number of items. Output is sorted by length, then reverse alphabet order. Test it online!
How it works
V²  o ®   s1+Ul)£  UgXnH)¯  X¦ 0}Ã â ¯  V
Vp2 o mZ{Zs1+Ul)mX{UgXnH)s0,X!=0}} â s0,V

Vp2 o      // Create the range [0..V²).
mZ{     }  // Map each item Z in this range to:
Zs1+Ul)    //  Take the base-(1+U.length) representation of Z.
mX{     }  //  Map each char X in this to:
XnH        //   Parse X as a base-32 number.
Ug   )     //   Take the char at index -^ in U.
s0,X!=0    //   If X is 0, slice it to an empty string.
â          // Uniquify the result.
s0,V       // Slice to the first V items.

This version takes a while if you want to do any more than 100 items. If you want a faster version, try this 32-byte one:
V*2 o ms1+Ul)f@!Xf'0Ã®£UgXnH}Ã¯V

Pyke (commit 31), 10 9 bytes
=blR.fbtp

Explanation:
=b         -    set characters for base conversion to eval_or_not(input())
  l        -   len(^)
   R      -  [^, eval_or_not(input()]
    .f    - first_n(^)
      b   -    conv_base(^)
       t  -   ^[-1]
        p -  print(^)

Cinnamon Gum, 6 bytes
0000000: 6801 301c e74b                           h.0..K

Non-competing because Cinnamon Gum was made after this challenge.
Try it online (TIO limits output).
Explanation
The h puts Cinnamon Gum in format and generate mode. The rest of the string decompresses to [%s]*. The %s is then replaced with the input, and a generator is created that outputs all possible strings matching the regex.

05AB1E, 9 bytes
g<∞*εÅв¦J

Try it online!
g             # length of the input
 <            # - 1
  ∞           # infinite list [1, 2, 3, …]
   *          # multiply each by the length-1
    ε         # for each:
     Åв       #  custom base conversion, using the input as the list of digits
       ¦      #  chop off the first digit
        J     #  join the rest to a string

R, 53 50 bytes
-3 bytes thanks to Dominic van Essen
r=scan(,s<-"");repeat cat("",s<-outer(s,r,paste0))

Try it online!
Prints the infinite list, separated by spaces.

50 bytes by putting s into scan and losing the repeat parentheses...

@DominicvanEssen Thanks! I always forget that repeat is not a regular function.

05AB1E, 6 bytes
∞€ã˜õš

Try it online!
∞        # push a list of all positive integers
 €ã      # take the input to each cartesian power
   ˜     # flatten the resulting list of lists
    õ    # push the empty string
     š   # prepend it to the infinite list of strings

Taking a string the 0th cartesian cartesian yields [[]], which would get completely lost when flattening (˜), this is why the empty string is prepended manually.
∞<€ã€` is an alternative 6-byter which uses [] to represent the empty string.

Curry (KiCS2), 18 bytes
f s=""?anyOf s:f s

Attempt This Online!

Vyxal, 4 bytes
ƛ⁰τḢ

Try it Online! Takes the number of strings and the string.
ƛ    # For each number in 1...n
 ⁰τ  # Convert to base <string>
   Ḣ # Remove the first character

Alternatively, a version that prints infinitely (and is probably more efficient)
Vyxal, 6 bytes
{:⁋,ẊṠ

Try it Online!
{      # Forever
 :⁋,   # Print the current string joined by newlines
    ẊṠ # Take the cartesian product with the input

Python, 55 bytes
s=input();l=['']
for x in l:print x;l+=[x+c for c in s]

This is longer than feersum's 53-byte solution, but it illustrates a different method with printed output. The list l is updated while it is iterated over, by appending every one-character suffix of each string that is read.
It's equally long to use map:
s=input();l=['']
for x in l:print x;l+=map(x.__add__,s)

The same length can be done in Python 3, losing a char for print(), and saving one by input unpacking.
s,*l=input(),''
for x in l:print(x);l+=[x+c for c in s]

Zsh, 31 bytes
f(){<<<${(F)a};a=($^a$^@);f $@}

Try it online!
Print the array, then zip on the arguments before recursing. Despite including the function name, this is one byte shorter than the iterative version:
for ((;;))<<<${(F)a}&&a=($^a$^@)

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Descending digit sequences
Introduction
As an example, let's take the number 7. We then duplicate this and place 7 spaces in between. We get this:
7_______7

After that, we are going to decrease the number, until there are no spaces left. We get the following for the number 7:
7_______7
 6543210

Then, we just merge the two of them, so:
7_______7
 6543210  becomes

765432107

This will be out output for N = 7.
Looks easy, right? Now let's take N = 12. We again insert 12 spaces between the two numbers, which gives us:
12____________12

Then we start the decrement:
12____________12
  111098765432

And this finally gives us:
1211109876543212

As you can see, the descending part ends at 2, not at 0.
Task
Given an integer, greater than 1, output the descending sequence as shown above.
Test cases
Input   Output

2       2102
3       32103
4       432104
5       5432105
6       65432106
7       765432107
8       8765432108
9       98765432109
10      10987654321010
11      111098765432111
12      1211109876543212
13      13121110987654313
14      141312111098765414
15      1514131211109876515
20      201918171615141312111020
99      9998979695949392919089888786858483828180797877767574737271706968676665646362616059585756555453525150499
100     1009998979695949392919089888786858483828180797877767574737271706968676665646362616059585756555453525150100

This is code-golf, so the submission with the fewest number of bytes wins!

The inner space must be filled with whole numbers or we should chop numbers if needed? There is not a test case about that (for instance 99)

@edc65 You should chop the numbers if needed. I have added 99 as a test case.

CJam, 11 10 bytes
q4*~,W%s<\

Try it online. Assumes there is a trailing newline in the input. (Thanks to @jimmy23013 for saving a byte.)
Explanation
At the end of each line is what the stack looks like at that point (using 4 as an example).
q4*  e# Push input x 4 times, separated by newlines. ["4\n4\n4\n4\n"]
~    e# Evaluate, separating the 4's and converting them to numbers. [4 4 4 4]
,W%  e# Take the range of x and reverse it. [4 4 4 [3 2 1 0]]
s<   e# Cast to string and take the first x characters. [4 4 "3210"]
\    e# Swap the top two to get the final result. [4 "3210" 4]

Julia, 30 bytes
n->"$n"join(n-1:-1:0)[1:n]"$n"

This is an anonymous function that accepts an integer and returns a string. To call it, assign it to a variable.
We construct and join the descending sequence from n-1 to 0, and take the first n characters from the resulting string. We prepend and append this with the input as a string.
Verify all test cases online

JavaScript (ES6), 55 52 bytes
n=>n+[...Array(m=n)].map(_=>--m).join``.slice(0,n)+n

Edit: Saved 3 bytes thanks to @WashingtonGuedes.

@WashingtonGuedes Bah, I never seem to get to use .keys().

.keys() is like .reduce. The right tool for the job, but you always find something that can do better in that particular case

Haskell, 44 bytes
s=show
f n=s n++take n(s=<<[n-1,n-2..])++s n

Usage example: f 14 -> "141312111098765414".

Python 2, 82 72 58 53 bytes
lambda x:`x`+''.join(map(str,range(x)[::-1]))[:x]+`x`

Try it here!
Thanks to @Alex for teaching me that repr(x) = `x` saving me a bunch of bytes!

Pyth, 11 bytes
++Q<jk_UQQQ

Two alternative versions, which are all also 11 bytes (sigh):
s[Q<jk_UQQQ
pQp<jk_UQQQ

  Q           the input
       UQ     [0, 1, ..., input-2, input-1]
      _       reverse
    jk        join on empty string
   <     Q    first (input) characters
          Q   the input again
++            concatenate everything so it prints on one line

Try it here.

Jelly, 10 bytes
Ȯ’r0DFḣ³Ḍ³

Try it online!
How it works
Ȯ’r0DFḣ³Ḍ³  Main link. Input: n

Ȯ           Print n.
 ’          Decrement to yield n - 1.
  r0        Create a range from n - 1 to 0.
    D       Convert each integer to base 10 (array of decimal digits).
     F      Flatten the resulting array.
      ḣ³    Keep the first n elements.
        Ḍ   Convert from base 10 to integer.
         ³  Print the integer and set the return value to n.
            (implicit) Print the return value.

Japt, 13 bytes
U+Uo w ¬¯U +U

Test it online!
How it works
               // Implicit: U = input integer
  Uo           // Create the range [0..U).
     w         // Reverse.
       ¬       // Join.
        ¯U     // Slice to the first U chars.
U+         +U  // Append U on either end.

Retina, 98 110
Longest answer so far :-/
.+
$&;$&$*:
+`:(:+)$
$& $1
 (:)*
$#1
\d+$
$&0 $&0
T`d`,`\d+$
+`:(.*),
$1
+`. ,

(.+);(.*)
$1$2$1

Try it online.

You can beat Java!

MATL, 15 bytes
VG:qPVXvG:)GVhh

EDIT (May 20, 2016) The code in the link uses Xz instead of Xv, owing to recent changes in the language.
Try it online!
V                 % input n. Convert to string
 G:               % range [1,2,...,n]
   qP             % convert into [n-1,n-2,...,0]
     VXv          % convert to string, no spaces
        G:)       % take first n characters only
           GV     % push input as a string, again
             hh   % concat horizontally twice

Pure Bash, 49
eval printf -va %s {$[$1-1]..0}
echo $1${a::$1}$1

Or:
Bash + coreutils, 48
echo $1$(seq $[$1-1] -1 0|tr -d \\n|head -c$1)$1

I'm not certain these are evaluating the range properly. Upon testing both print only half of the range. ie for $1=90, the range is only down to 45.
My effort was "
for i in $(eval echo {$1..0});do echo -n $i;done;echo $1"

@rcjohnson I think that is the required behaviour.  What do you expect the output to be for N=90?

@rcjohnson e.g. for N=12, the output should be 12, then the first 12 chars of 11..0 (or 111098765432), and then finally 12

Well upon re-reading the description I see that you are correct. The problem states "spaces" not integers.

@rcjohnson Yes, I think the "spaces" part only applies to intermediate steps.  The final output should be just a string of digits.

Vitsy, 35 bytes
Since Vitsy isn't aware of how to make strings out of numbers, I implemented finding the length of the number in decimal places in the second line.
V0VVNHVv[XDN1mv$-DvD);]VN
1a/+aL_1+
Explanation:
V0VVNHVv[XDN1mv$-DvD);]VN
V                          Save the input as a global final variable.
 0V                        Push 0, push input.
   VN                      Output the input.
     H                     Push the range 0...intput.
      Vv                   Push the input, then save it as a temp variable.
        [             ]    Do the stuff in brackets infinitely or until exited.
         X                 Remove the top item of the stack.
          DN               Duplicate, then pop as output.
            1m             Calls the first line index, retrieving length.
              v            Pop the temp var and push it to the stack.
               $           Switch the top two items of the stack.
                -          Subtract them.
                 Dv        Duplicate, then pop one as a temp var.
                   D);     If it's zero, exit the loop.
                       VN  Output the global var.

1a/+aL_1+
1a/+       Add .1. This makes sure we don't throw errors on input 0.
    a      Push ten.
     L     Pop the top item as n, push the log base n of second to top.
      _    Make it an int.
       1+  Add 1.
Try it Online!
Verbose mode for lols:
save top as permanent variable;
push 0;
save top as permanent variable;
save top as permanent variable;
output top as number;
push all ints between second to top and top;
save top as permanent variable;
save top as temporary variable;
begin recursive area;
remove top;
duplicate top item;
output top as number;
push 1;
goto top method;
save top as temporary variable;
switch the top two items;
subtract top two;
duplicate top item;
save top as temporary variable;
duplicate top item;
if (int) top is not 0;
generic exit;
end recursive area;
save top as permanent variable;
output top as number;
:push 1;
push 10;
divide top two;
add top two;
push 10;
push ln(top);
replace top with int(top);
push 1;
add top two;

Looks like verbose mode is wrong in its definition of L, fixing that now (won't update the question though).

Just curious, how do you prevent the method from being executed at the end of the program? Is the newline character a signal to return/exit the program?

@LegionMammal978 Imagine that the first line of every Vitsy program is the "main" method, and all other lines are public static void methods. The main ends the program when it is finished. As for how it does this, the instructions are held in a type ArrayList<ArrayList<String[]>>, where each line is a String[]. Every method is split at the newline by how the file is loaded, causing the main method to be separated from all other methods.

That explains why three levels are needed. So Strings are instructions, String[]s are methods (first one is main method), and ArrayList<String[]>s are classes (first one is main class), correct?

@LegionMammal978 That's all correct. :)

Retina, 63 bytes
.+
$0,y$0$*y$0$*x
x
$'_
(x)*_
$#1
+`(y+)y(.)
$2$1
,(\d+).*
$1$`

There is still quite some room for golfing...
Try it online!

Hm, I'm considering to make the $0 in $0$* optional as well, when the preceding token is a literal which is not a number (as your ys are)... seeing this I might actually implement that.

@MartinBüttner I thought that was the new feature but turned out not really. :)

No, currently that only works at the beginning of the substitution. That said, maybe you can switch the roles of the first and last number to make use of that?

Java, 93 bytes
String x(int v){String o=""+v;for(int i=v-1,c=o.length();o.length()-c<v;i--)o+=i;return o+v;}

Ruby, 41 bytes
->n{[n]*2*(r=0...n).to_a.reverse.join[r]}

Milky Way 1.6.5, 27 25 bytes
I'::%{K£BCH=}<ΩHG<+<;+!

Explanation
I                        ` empty the stack
 '::                     ` push 3 copies of the input
    %{K£BCH=}            ` dump digits of reversed range(n) as strings [n-1...0]
             <ΩHG<+<;+   ` select the first nth digits and pad them with n
                      !  ` output

Usage
$ ./mw <path-to-code> -i <input-integer>

What encoding does Milky Way use?

Uhhh.. UTF-8, I think haha. @AandN

I got this error (yes, I'm a Windows scumbag :p) while trying to run this. I pasted this: I'::%{K£BCH=}<OHG<+<;+! into an UTF-8 encoded file, but it doesn't work.

Here's a link to the file I'm using. @AandN

Perl 6, 31 bytes
{$_~([R~] ^$_).substr(0,$_)~$_}

{
  $_ # input
  ~  # string concatenated with
  ([R~] ^$_)    # all numbers up to and excluding the input concatenated in reverse
  .substr(0,$_) # but use only up to the input number of characters
  ~
  $_
}

Usage:
for 2,3,7,12,100 {
  say {$_~([R~] ^$_).substr(0,$_)~$_}( $_ )
}

2102
32103
765432107
1211109876543212
1009998979695949392919089888786858483828180797877767574737271706968676665646362616059585756555453525150100

Perl, 43 + 2 = 45 bytes
I'm happy that I didn't used reverse and neither substr:
"@{[1-$_..0]}"=~s.\D..gr=~/.{$_}/;$_.=$&.$_

Requires the -pl flags.
$ perl -ple'"@{[1-$_..0]}"=~s.\D..gr=~/.{$_}/;$_.=$&.$_' <<< 12
1211109876543212

How it works:
                                            # '-p' read first line into `$_` and
                                            # auto print at the end
"@{[1-$_..0]}"                              # Create a list from -1-n..0 and
                                            # join it on space. This becomes:
                                            #   "-11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0"
              =~s.\D..gr                    # Remove all but digits:
                                            #   "11109876543210"
                        =~/.{$_}/;          # Match the n first characters from
                                            # the generated string
                                  $_.=$&.$_ # Append the match and the input

C, 130 125 bytes
#define p(x) printf("%i",x);
i,y,h;f(x){for(i=y=x;(i-=h)>=0;){p(y--)h=floor(log10(y))+1;}if(i+=h)p(h=floor(y/pow(10,i)))p(x)}

Ungolfed version (with explanation):
#define p(x) printf("%i",x);     // alias to print an integer
i,y,h;                           // helper variables
f(x){                            // function takes an integer x as arg
    for(i=y=x;(i-=h)>=0;){       // i -> the remaining space
                                 // y -> the current descending number
        p(y--)                   // print y (at first y==x)
        h=floor(log10(y))+1;     // h -> the number of digits in y-1
    }                            // do it until there is no more empty space
    if(i+=h)                     // if needs to chop the last number
        p(h=floor(y/pow(10,i)))  // chop and print (implicitly cast of double to int)
    p(x)                         // print x at the end
}                                // end function

The implicitly cast from double to int in h=floor(...) allowed the use of #define p(x) saving 5 bytes.
Test on ideone.

R, 67 bytes (as function)
# usage example : f(7)
f=function(i)cat(i,substr(paste((i-1):0,collapse=''),1,i),i,sep='')

R, 63 bytes (input from STDIN)
i=scan();cat(i,substr(paste((i-1):0,collapse=''),1,i),i,sep='')

Brainfuck, 265 Bytes
This is only going to work with numbers < 10
Try the golfed version here:
>,------------------------------------------------[->+>+<<]>>[-<<+>>]<[[->+>+<<]>>[-<<+>>]<-]<[<]>[>[>]>+<<[<]>-]>[++++++++++++++++++++++++++++++++++++++++++++++++.>]++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++.

Ungolfed. Try it here:
>
,
---------- Convert to base 10
----------
----------
----------
--------

[->+>+<<]>>[-<<+>>]<

Fill up the grid
[
[->+>+<<]>>[-<<+>>] //duplicate number like [5][0] -> [5][5]
<-
]

<[<]> Go to cell 1
[

>[>] Scan for zero
> Move one more
+ Add one
<< Move two back
[<] Scan for zero
> Move one forward
- Subtract One
]

> Move one forward into actual numbers
[
++++++++++ Convert to ascii
++++++++++
++++++++++
++++++++++
++++++++
.
>
]
++++++++++ Convert to ascii
++++++++++
++++++++++
++++++++++
++++++++
.
>
++++++++++ Convert to ascii
++++++++++
++++++++++
++++++++++
++++++++
.

,>>++++++[<++++++++>-]<[-<->]< This can subtract 48 with shorter code length

This is way shorter.

This is even shorter.

PowerShell Core, 45 bytes
param($a)"$a$(($a-1)..0-join''|% su* 0 $a)$a"

Try it online!
Explanation
($a-1)..0-join''|% su* 0 $a     # builds an array from a-1 to 0, joins them with no separators
                                  # and takes the `a` first chars

"$a ... $a"                       # surrounds the result with the parameter `a`

Jelly, 11 bytes
ḶUDFṁ;D;@DḌ

Try it online!
There is also this kinda cheaty 9 byter, which only works due to how the Y command in the Footer works, so I'm not counting that.
Jelly's dislike of strings really hurts it here, and CJam's stack is just helpful enough to beat Jelly.
How it works
ḶUDFṁ;D;@DḌ - Main link. Takes n on the left
Ḷ           - [0, 1, 2, ..., n-1]
 U          - [n-1, n-2, ..., 1, 0]
  D         - Convert each to digits
   F        - Flatten
    ṁ       - Take the first n
     ;D     - Append the digits of n
       ;@D  - Prepend the digits of n
          Ḍ - Convert from a list of digits to a number

05AB1E, 10 bytes
Î<ŸRJ¹£¹.ø

Try it online!
Î<ŸRJ¹£¹.ø  # full program
        .ø  # surround...
      £     # first...
     ¹      # input...
      £     # chars of...
    J       # joined elements of...
  Ÿ         # [...
Î           # 0 ... input...
 <          # minus 1
  Ÿ         # ]...
   R        # reversed...
        .ø  # with...
     ¹      # input
            # implicit output

Stax, 9 8 7 bytes
îσQçφ╠♦

Run and debug it
-1 byte from recursive.
Explanation (Unpacked)
rr$x%sy|S
r         range 0..n-1
 r        reversed
  $       converted to string
   x(     take n characters
     y    push n as string from register y
      |S  prepend and append it to the range
           implicit output

Perl 5 -p, 40 bytes
print$_,("@{[1-$_..0]}"=~/\d/g)[0..$_-1]

Try it online!

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/