[Question]
  [
## Challenge
Given a size s, print a cube net of that size made of hash symbols (`#`) and spaces ().
Examples:
```
1:
  #
# # #    
  #
  #
2:
    # #
    # #
# # # # # #
# # # # # #
    # #
    # #
    # #
    # #
3:
      # # #
      # # #
      # # #
# # # # # # # # #
# # # # # # # # #
# # # # # # # # #
      # # #
      # # #
      # # #
      # # #
      # # #
      # # #
```
The net can actually be any valid cube net that can fold into a cube, for example these:
```
    # #
    # #
# # # # # # # #
# # # # # # # #
    # #
    # #
    # # # #
    # # # #
    # #
    # #
    # #
    # #
# # # #
# # # #
```
## Rules
* The resulting net must be geometrically valid (foldable into a cube)
* Standard loopholes forbidden
* Read the rules carefully
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), shortest answer wins, but will not be selected
  
[Answer]
## Python 2, 47 bytes
```
n=input()
for c in 1,4,1:exec"print'# '*c*n;"*n
```
[Try it online!](https://tio.run/nexus/python2#@59nm5lXUFqiocmVll@kkKyQmadgqGOiY2iVWpGarFRQlJlXoq6soK6VrJVnraSV9/@/MQA)
Prints this net, chosen for being left-justified:
```
# # 
# # 
# # # # # # # # 
# # # # # # # # 
# # 
# # 
```
The lines have `n` or `4*n` copies of `'# '`. For each of `1,4,1`, we print `n` times that many copies, done `n` times for `n` lines. Having an `exec` loop inside a `for` loop seems wasteful, but I didn't see better.
Alternatives I tested:
```
lambda n:('# '*n*3+'\n')*n+('  '*n+'# '*n+'\n')*3*n
lambda n:('# '*n*3+'\n')*n+(' '*4*n+'# '*n*3+'\n')*n
def f(n):
 for c in[3]*n+[1]*3*n:print('# '*c*n).center(6*n)
def f(n):
 for c in[4]*n+[0]*n:print' '*c*n+'# '*n*3
def f(n):
 for c in[1]*n+[4]*n+[1]*n:print'# '*c*n
def f(n):
 c=1;exec("print'# '*c*n;"*n+"c^=5;"*n)*3
def f(n):
 for i in range(3*n):print'# '*[1,4,1][i/n]*n
def f(n):
 for c in 1,4,1:print('# '*c*n+'\n')*n,
def f(n):
 for c in 1,4,1:exec"print'# '*c*n;"*n
```
(The `def` functions can all be one shorter as a program.)
[Answer]
# Octave, ~~58~~ ~~44~~ ~~42~~ 32 bytes
```
@(n)[z=repmat('# ',n);z,z,z,z;z]
```
partly inspired by @xnor 's python answer.
```
z=repmat('# ',n);
```
creates a squre pattern of '# ' for input 2 results the following pattern:
```
# #             
# # 
y=[z,z,z,z];
```
four `z` s are concatenated horizontally:
```
# # # # # # # # 
# # # # # # # # 
[z;y;z]
```
`z` and `y` and `z` are concatenated vertically
[Try It Online!](https://tio.run/#RbANN)
```
# #             
# #             
# # # # # # # # 
# # # # # # # # 
# #             
# #             
```
Previous answer:
```
@(n){h(1:n,1:2:n*6)=1;h(1:n*4,n*2+1:2:4*n)=1;' #'(h+1)}{3}
```
[Try It Online!](https://tio.run/#imwsv)
Generates a T shaped one
```
# # # # # # # # #
# # # # # # # # #
# # # # # # # # #
      # # #      
      # # #      
      # # #      
      # # #      
      # # #      
      # # #      
      # # #      
      # # #      
      # # #      
```
[Answer]
# Mathematica, ~~77~~ ~~60~~ 52 bytes
*Thanks to Martin Ender for golfing 8 bytes away!*
```
{±s_:=s~Table~#;b=±{a=±"# ","
"},±{a,a,a,a,"
"}}<>b&
```
Unnamed function taking a positive integer argument `#` and returning a string with newlines (including a trailing newline); each line has a trailing space as well. First we define `±` to be a function that repeats its input `#` times; then `a` is defined as `±"# "` (this `#` is a character, not the input!), and from that `b` is defined to be the set of `#` short lines, while `±{a,a,a,a}<>n` is the set of `#` long lines. (In both cases, there is a literal linefeed between matching quotes.) The final `<>b` concatenates the resulting list of strings with second copy of the set of short lines. Example output when `#=2` ([xnor's answer](https://codegolf.stackexchange.com/a/106824/56178) taught me that this orientation is golfier):
```
# #     
# #     
# # # # # # # # 
# # # # # # # # 
# #     
# #     
```
Previous version of this implementation:
```
""<>(±s_:=s&~Array~#;{b=±{a=±"# ",n="\n"},±{a,a,a,a}<>n,b})&
```
Original submission:
```
""<>If[(m=n~Mod~t)==0,"\n",If[n<t#||#<m<=2#,"# ","  "]]~Table~{n,4(t=3#+1)#}&
```
Builds a string out of `4*(3#+1)` pieces, each of which is either `"# "`, `" "`, or `"\n"`; simply calculates which pieces to use based on the index `n`. Example output when `#=2`:
```
# # # # # # 
# # # # # # 
    # #     
    # #     
    # #     
    # #     
    # #     
    # #     
```
[Answer]
## JavaScript (ES6), 59 bytes
```
f=
n=>`141`.replace(/./g,m=>`${`# `.repeat(n*m)}\n`.repeat(n))
```
```
<input type=number oninput=o.textContent=f(this.value)><pre id=o>
```
Output includes a trailing space at the end of each line and a trailing newline.
[Answer]
# Ruby, 36 bytes
```
f=->n{puts (t=[s="# "*n]*n)+[s*4]*n+t}
```
Usage:
```
f=->n{puts (t=[s="# "*n]*n)+[s*4]*n+t}
f[3]
# # #
# # #
# # #
# # # # # # # # # # # #
# # # # # # # # # # # #
# # # # # # # # # # # #
# # #
# # #
# # #
```
# Ruby, 38 bytes
This shape is longer in Ruby but I expect there are some languages where it is shorter.
```
->n{puts [s="# "*n*3]*n+[" "*n*4+s]*n}
```
Usage:
```
g=->n{puts [s="# "*n*3]*n+[" "*n*4+s]*n}
g[3]
# # # # # # # # #
# # # # # # # # #
# # # # # # # # #
            # # # # # # # # #
            # # # # # # # # #
            # # # # # # # # #
```
Both answers can be shorter if it is permitted to return (preferably) an array of strings or (less preferably) a single string instead of printing.
[Answer]
# Scala, 56 bytes
```
(n:Int)=>Seq(1,4,1)map("# "*_*n+"\n")map(_*n)mkString ""
```
[Answer]
# JavaScript (ES6), 71
```
n=>((z='# '[R='repeat'](n))[R](3)+`
`)[R](n)+('  '[R](n)+z+`
`)[R](n*3)
```
**Test**
```
f=
n=>((z='# '[R='repeat'](n))[R](3)+`
`)[R](n)+('  '[R](n)+z+`
`)[R](n*3)
function update() {
  O.textContent=f(I.value)
}
update()
```
```
<input id=I type=number value=3 oninput='update()'><pre id=O></pre>
```
[Answer]
# Java 8, 99 bytes
```
l->{for(int i=-1,j;++i<3*l;)for(j=-1,k=(i/l==2)?4*l:l;++j<k;)System.out.print("# "+j>k-2?"\n":"");}
```
[Answer]
# [V](https://github.com/DJMcMayhem/V), ~~24~~ ~~23~~ ~~20~~ ~~18~~ 20 bytes
```
Ài# ddÀpLyGïp3PGïp
```
With all the hidden characters shown
```
Ài# ^[ddÀp^VLyGïp3PGoïp
```
`^[` is `0x1b` (escape character literal) and `^V` is `0x16` (`C-v`)
[Try it online!](https://tio.run/nexus/v#@3@4IVNZQTol5XBDgZhPpfvh9QXGASDy////RgA)
I had to increase bytecount because the `Ä` command was being buggy in this new V pull
Outputs in this format:
```
# 
# # # # 
# 
```
with a leading newline
Hexdump:
```
00000000: c069 2320 1b64 64c0 7016 4c79 47ef 7033  .i# .dd.p.LyG.p3
00000010: 5047 ef70                                PG.p
```
## Explanation
```
Ài# ^[              " Argument times insert "# "
ddÀp                " Argument times duplicate line
```
Now that one face of the net has been completed, we have to create the net
```
^VLy                " Copy the face
Gïp                 " Paste it at the end of buffer
3P                  " Paste 3 times (these form the line)
Gïp                 " Paste at end of buffer again
```
---
Alternate solution if we don't output the spaces:
### ~~21~~ ~~20~~ ~~18~~ ~~16~~ 18 bytes
```
Àé#ddÀpLyGïp3pGïp
```
(for the same reason as the top solution, this TIO link is modified)
[Try it online!](https://tio.run/nexus/v#@3@44fBK5ZSUww0FYj6V7ofXFxgHgMj///8bAgA)
[Answer]
# [V](https://github.com/DJMcMayhem/V), 14 bytes (non-competing)
```
Ài# 5Ù4JjòÀÄk
```
[Try it online!](https://tio.run/nexus/v#@3@4IVNZQdr08EwTr6zDmw43HG7J/v//vwkA "V – TIO Nexus")
```
00000000: c069 2320 1b35 d934 4a6a f2c0 c46b       .i# .5.4Jj...k
```
For whatever reason, this challenge uncovered numerous bugs. Now that they're all fixed, this version is unfortunately non-competing, but it's nice to see what a V answer to this challenge should look like when it doesn't have to add tons of bytes to keep up with my sloppy coding.
Explanation:
```
À                   " Arg 1 times:
 i# <esc>           "   Insert the string "# "
         5Ù         " Make 5 copies of this line, and put the cursor on the second copy
           4J       " Join four of these lines together
             j      " Move down to the last line
              ò     " Recursively:
               ÀÄ   "   Make Arg 1 copies of this line
                 k  "   And move up a line
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~20~~ 19 bytes
```
”#xẋ³Wẋ³K€Y
141DÇ€Y
```
[Try it online!](https://tio.run/nexus/jelly#@/@oYa5yxcNd3Yc2h4NJ70dNayK5DE0MXQ63g5j///83NAAA "Jelly – TIO Nexus")
*-1 thanks to 44874 (steenbergh).*
I CAN'T OUTGOLF MUDDYFISH HELP!
Is this golfable??? ~~20~~ 19 bytes just seems like **too much**, seeing Link 1.
Explanation:
```
”#xẋ³Wẋ³K€Y Helper link. Arguments: z
”#          Character #.
            y (implicit)
  x         Repeat each element of y x times.
    ³       1st command-line argument.
   ẋ        Repeat x y times.
     W      Wrap z.
       ³    1st command-line argument.
      ẋ     Repeat x y times.
        K   Join z on spaces.
         €  Map this link on x.
          Y Join z on newlines.
141DÇ€Y Main link. Arguments: 0
141     Integer 141.
   D    Convert z to base 10.
    Ç   The above link as a monad.
     €  Map this link on x.
      Y Join z on newlines.
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 20 bytes
```
ＮλＧ↑λ←×⁶λ↓λ# ＤＭ×⁴λ← 
```
The code ends with a space. [Try it online!](https://tio.run/nexus/charcoal#@/9@z7pzu9/vWf6obeK53Y/aJhye/qhxG4g1@dxuZYX3e5a837MWJLYFLKvw/78xAA "Charcoal – TIO Nexus")
### Explanation
Charcoal is a language specializing in ASCII art. It is also incomplete, buggy, and under-documented. Suffice it to say, this took a fair amount of trial and error before it did what it was supposed to.
* `Ｎλ` inputs a number into `λ`.
* `Ｇ` is the polygon command, which we'll use here to draw a rectangle. `↑λ←×⁶λ↓λ` specifies the border of the polygon: upward `λ` steps, leftward 6 times `λ` steps, and downward `λ` steps. (That's three `λ` by `λ` blocks side-by-side.) The bottom edge of the rectangle is inferred. The polygon is then filled with the string `#` .
* `Ｄ` dumps the current canvas to stdout, resulting in something like this:
```
 # # # # # # # # #
 # # # # # # # # #
 # # # # # # # # #
```
* After the `Ｇ` command, the cursor is at the bottom left corner of the canvas. `Ｍ×⁴λ←` moves it leftward by 4 times `λ` steps (equivalent to two `λ` by `λ` blocks).
* outputs a space there, extending the canvas leftward by the correct amount.
* At the end of the program, the canvas is (again) sent to stdout:
```
             # # # # # # # # #
             # # # # # # # # #
             # # # # # # # # #
```
Put 'em together and you've got a cube net.
[Answer]
# [Bash](https://www.gnu.org/software/bash/) / Unix utilities, ~~72~~ ~~69~~ ~~68~~ 66 bytes
```
b()(yes `dc<<<2o4d$n^$1^3/p`|tr 01 ' #'|head -$n);n=$1;b 1;b 4;b 1
```
[Try it online!](https://tio.run/nexus/bash#@5@koalRmVqskJCSbGNjY5RvkqKSF6diGGesX5BQU1KkYGCooK6grF6TkZqYoqCrkqdpnWerYmidpADCJiD6////xgA "Bash – TIO Nexus")
This works by using the fact that [4^k / 3], when written in base 2, is 10101010...01, with k 1's. (The square brackets here denote the floor function.)
[Answer]
# Pyke, 16 bytes
```
uAD,sXF**"# 
```
[Try it here!](http://pyke.catbus.co.uk/?code=u%03%01%04%01AD%2CsXF%2a%2a%22%23+&input=2&warnings=0)
Equivalent to
```
1 4 1]3AD,sXF**"# 
```
Because of unprintables
This uses a couple of tricks to lower the byte-count:
* It uses some unprintables to represent the list `[1, 4, 1]`
* `XF` automatically dumps the output to the stack
* The string `"#`  at the end gets swapped with the last `*`, meaning that the closing `"` is not required. This happens implicitly when the last token is a string.
  
```
u                -      [1, 4, 1]
     AD          -     apply(*, ^, input)
       ,         -    zip(^)
        s        -   sum(^)
          F**"#  -  for i in ^:
           *     -    ^ * input
            *    -   ^ * v
             "#  -    "# "
         X       - splat(^)
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~68~~ ~~71~~ 65 bytes
-6 with thanks to @sagiksp
```
def f(i,c=1):
 print(' '*i*4,'')[c>i]+'# '*i*3
 if i*2>c:f(i,c+1)
```
[Try it online!](https://tio.run/nexus/python2#@5@SmqaQppGpk2xrqGnFpVBQlJlXoqGuoK6VqWWio66uGZ1slxmrra4MFjHmUshMU8jUMrJLtgJr0jbU/J@mYar5HwA "Python 2 – TIO Nexus")
In the absence of finding a way to beat @xnor I'll post my recursive function simply as an alternative approach. For f(5) prints
```
                    # # # # # # # # # # # # # # # 
                    # # # # # # # # # # # # # # # 
                    # # # # # # # # # # # # # # # 
                    # # # # # # # # # # # # # # # 
                    # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # 
```
This pattern was chosen simply because it can be split into two parts unlike all of the others.
[Answer]
## PHP, 64 62 bytes
Saved 2 bytes thanks to [Christoph](https://codegolf.stackexchange.com/users/29637/christoph).
```
while($a="282"[$i++/$s=$argv[1]]*$s)echo str_pad("
",$a,"# ");
```
Prints a net like this:
```
# #
# #
# # # # # # # #
# # # # # # # #
# #
# #
```
(with a leading newline)
[Answer]
## Batch, 111 bytes
```
@set s=
@set i=@for /l %%i in (1,1,%1)do @
%i%call set s=%%s%% #
%i%echo%s%
%i%echo%s%%s%%s%%s%
%i%echo%s%
```
[Answer]
# [Pushy](https://github.com/FTcode/Pushy), ~~32~~ ~~29~~ 28 bytes
Prints the cube net left-justified. This was hard to golf...
```
&V:`# `;{:";N^:4:";T'.;TD^:"
```
[**Try it online!**](https://tio.run/nexus/pushy#@68WZpWgrJBgXW2lZO0XZ2UCpELU9axDXOKslP7//28CAA)
[Answer]
# [Retina](https://github.com/m-ender/retina), 39 37 bytes
This is my first time using Retina, I'm still trying to understand how to do things.
```
.+
$*#
#
# 
\`# 
$_¶
G`.
)*%`^
$_$_$_
  
```
(with two trailing spaces after the 4th and 5th lines)
Thanks to Martin Ender for golfing 2 bytes!
[Try it online!](https://tio.run/nexus/retina#@6@nzaWipcwFhApcMQlAQiX@0DYu9wQ9Lk0t1YQ4IBcE//83AgA)
[Answer]
## [QBIC](https://drive.google.com/drive/folders/0B0R1Jgqp8Gg4cVJCZkRkdEthZDQ), ~~52~~ ~~67~~ 40 bytes
Complete re-write:
```
:[a*3|G=G+@#`][a*2|G=G+@ `][a|?G][a|?_fG
```
This now uses this pattern:
```
###--
--###
```
Where the `-`are filled with spaces.
```
:        Read 'a' from the command line        > Assume 3
[a*3|    Create 3 segments times 'a' filling   > 3*3 = 9
G=G+@#`] Define A$ to be '#' and add this to G > G = "#########" 
[a*2|    Create 2 segments times 'a' spacer
G=G+@ `] Define B$ to be ' ' and add this to G > G = "#########       " 
[a|      FOR d == 1; d <= a; d++
?G]      Display G$:
            "#########       " 
            "#########       " 
            "#########       " 
[a|      FOR e == 1; e <= a; e++
?_fG     Display G$ in reverse (_f...|):
            "      #########" 
            "      #########" 
            "      #########" 
         (For loop and function call to Flip impicitly closed by QBIC)
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), ~~28~~ ~~17~~ 16 bytes
15 bytes of code, +1 for `-n` flag.
```
"# "Xa*_RLaM141
```
Takes the size as a command-line argument. [Try it online!](https://tio.run/nexus/pip#@6@krKAUkagVH@ST6GtoYvj//3/dvP/GAA "Pip – TIO Nexus")
### Explanation
```
                 a is 1st cmdline arg
       _         Build a lambda function
     a*          (a) times argument
"# "X            Repeat string "# " that many times
        RLa      Wrap in a list and repeat list (a) times
           M141  Map that function to the characters of 141
                 Autoprint (-n flag separating list items with newlines)
```
The following isn't exactly how the data gets modified, but it gives the basic idea (for `a=2`):
```
141
[1;4;1]
[2;8;2]
["# # ";"# # # # # # # # ";"# # "]
[["# # ";"# # "];["# # # # # # # # ";"# # # # # # # # "];["# # ";"# # "]]
# # 
# # 
# # # # # # # # 
# # # # # # # # 
# # 
# # 
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 13 bytes
```
D141S×S*„# ×»
```
[Try it online!](https://tio.run/nexus/05ab1e#@@9iaGIYfHh6sNajhnnKCoenH9r9/78xAA "05AB1E – TIO Nexus")
**Explanation**
Example input `n=2`
```
D              # duplicate input
               # STACK: 2, 2
 141S          # push the list [1,4,1]
               # STACK: 2, 2, [1,4,1]
     ×         # repeat each item in the list input_no times
               # STACK: 2, [11, 44, 11]
      S        # split into list of digits
               # STACK: 2, [1, 1, 4, 4, 1, 1]
       *       # multiply each digit with input
               # STACK: [2, 2, 8, 8, 2, 2]
        „# ×   # repeat the string "# " for each item in the list
               # STACK: ['# # ','# # ','# # # # # # # # ','# # # # # # # # ','# # ','# # ']
            »  # join by newlines
               # OUTPUT: # # 
                         # # 
                         # # # # # # # # 
                         # # # # # # # # 
                         # # 
                         # # 
```
[Answer]
## C#, 152 bytes
```
n=>{var m="";foreach(int c in new[]{1,4,1})for(int i=0,j;i++<n;){for(j=0;j++<c;)m+=new System.Text.StringBuilder().Insert(0,"# ",n);m+="\n";}return m;};
```
[Answer]
# SmileBASIC, ~~57~~ 50 bytes
```
INPUT S
E$=("#"*S*3+CHR$(10))*S?E$SCROLL-S*2,-1?E$
```
Explained:
```
INPUT SIZE
PART$=("#"*SIZE*3+CHR$(10))*S 'generate half of the pattern
PRINT PART$ 'print half the pattern
SCROLL SIZE*-2,-1 'scroll the text 2 squares right (and 1 character down)
PRINT PART$ 'print half the pattern again
```
After the first PRINT (size=2, @ is the cursor position):
```
######
######
@ 
```
After the SCROLL:
```
    ######
    ######
@
```
After the second PRINT:
```
    ######
    ######
######
######
@
```
[Answer]
# Common Lisp, ~~83~~ ~~81~~ 79 bytes
```
(lambda(x)(format t"~v@{~v@{# ~}~:*~%~}~v@{~vt~0@*~v{# ~}~%~}"x(* x 3)(* x 2)))
```
Usage:
`(funcall #'(lambda(x)(format t"~v@{~v@{# ~}~:*~%~}~v@{~vt~0@*~v{# ~}~%~}"x(* x 3)(* x 2)))2)`
Output:
```
# # # # # #
# # # # # #
    # # 
    # # 
    # # 
    # #       
    # # 
    # #           
```
### How does it work?
```
in format there is control string (inside "") and arguments after it
certain commands in string can use arguments (for example ~a displays argument)
~v{~} - takes argument and does commends inside {~} number of times 
                                      (number is given by argument)
       we can write text in loop body - it'll get displayed. Even if
       in loop body there are none commends to use arguments loop itself                 
       will consume one argument (it doesn't matter what it'll be -
       it doesn't seem to affect output)
~% - newline
~n* - jump n arguments forward (relative)
~n:* - jump n arguments backwards (relative)
~n@* - jump to argument n (global, counting from 0)
~v@{~v{# ~}~%~1@*~} <--- we make x rowns, 3x columns of string "# ". 
                         ~1@* is used during looping, it also means we end on argument 1. 
                         (second argument: (* x 3))
~v@{~vt~0@*~v{# ~}~%~} <--- we now make 3x rows, x columns of "(spaces)# "
                         ~vt - is used to move to accurate column. 
                         Here it takes argument (* x 2) - this is 
                         minimal number of columns to display. It uses
                         space as default character for missing characters
                         (when string inside <~> is shorter than min 
                         number of columns). I use it to make (* x 2) spaces, 
                         by giving it no text.
      ~0@* <--- after making spaces we have no new arguments, we go back to
                argument number zero - it is used to determine number of columns in our block
```
Ideas for improvement are welcomed.
]