CJam, 77 71 70 69 63 62 bytes
r_,5*_Sa*a*\{~"÷Ðëúܾ¿ðÿþ"=i2bS"\/"4*W<+.*3/..e>2fm>2m>}/Wf%N*
All characters are printable, so copy and paste should work just fine.
Try it online in the CJam interpreter.
Idea
We start by examining the number of digits n in the input and pushing a square of spaces big enough to cover the output. In the implementation, this square will be encoded as a two-dimensional array of one-character strings.
A square of length 2n+1 would be just right (i.e., no surrounding whitespace) for a straightforward implementation, but we'll use one of length 5n to save a couple of bytes. Thankfully, surrounding whitespace is allowed.
If we reverse the lines of the seven slash representation of 8, we obtain the following:
\/
\/\
/\
The representation of all digits can be encoded as an 8-bit integer, where the ith bit is 0 iff the ith character should get replaced with a space. For the digits 0 to 9, the resulting integers are
247 208 235 250 220 190 191 240 255 254
which correspond to the following ISO-8559-1 characters:
÷Ðëúܾ¿ðÿþ
For each digit in the input, after selecting the corresponding 8-bit integer, we repeat the ith character of the representation of 8 exactly ai times, where ai is the ith bit of the integer. This pushes an array of strings of either one or zero characters. By dividing this array into chunks of length 3, we obtain an array where each element corresponds to a line of the representation.
Now, we compute the vectorized maximum of the strings that represent the square and the strings that represent the digit. The strings /
and \
are bigger than the string
, so they will replace the spaces in the square. The empty string, however, is smaller than the string
, so empty strings in the digit representation will preserve the spaces in the square.
We now rotate the rows and columns by two units to place the following digit representation in the proper part of the square and repeat the process for the remaining digits in the input.
Finally, we reverse each row and insert a linefeed between the individual rows.
Code
r_, e# Read a token from STDIN and push the length of a copy.
5*_ e# Multiply the length by 5 and push a copy.
Sa* e# Repeat the array [" "] that many times.
a* e# Repeat the array [[" " ... " "]] that many times.
\{ e# For each character C in the input:
~ e# Push eval(C), i.e., the digit the character represents.
"÷Ðëúܾ¿ðÿþ"
e# Push the encodings of all 10 seven slash representations.
= e# Select the proper one.
i2b e# Push the resulting characters code point in base 2, i.e., its bits.
S e# Push " ".
"\/"4* e# Push "\/\/\/\/".
+W< e# Concatenate and eliminate the last character.
.* e# Vectorized repetition.
e# For the digit 5, e.g., we have [1 0 1 1 1 1 1 0] and " \/\/\/\" on
e# the stack, so .* yields [" " "" "/" "\" "/" "\" "/" ""].
3/ e# Divide the representation into chunks of length 3, i.e., its lines.
..e> e# Compute the twofold vectorized maximum, as explained above.
2fm> e# Rotate each line to characters to the right.
2m> e# Rotate the lines two units down.
}/
Wf% e# Reverse each line.
N* e# Place linefeeds between them.
The last rotations would mess up the output if the square's side length was smaller than 2n+3. Since 5n ≥ 2n+3 for all positive integers n, the square is big enough to prevent this.