Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	out := make([][]string, 100)
	for i := range out {
		out[i] = make([]string, 100)
	}
	dx := []int{0, 1, 0, -1}
	dy := []int{-1, 0, 1, 0}
	scanner.Scan()
	a, _ := strconv.Atoi(scanner.Text())
	for a > 0 {
		a--
		scanner.Scan()
		b, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < b; i++ {
			for j := 0; j < b; j++ {
				out[i][j] = " "
			}
			out[i][b] = "0"
		}
		if b == 1 {
			fmt.Println("#")
			if a != 0 {
				fmt.Println()
			}
			continue
		}
		if b == 2 {
			fmt.Println("##")
			if a != 0 {
				fmt.Println()
				continue
			}
		}
		row := b -1
		col := 0
		dir := 0
		l := 0
		out[row][col] = "#"
		for {
			nrow := row+dy[dir%4]
			ncol := col+dx[dir%4]
			if dir%4 == 0 && nrow == 0 || dir%4==3&&ncol==0 || dir%4==2&&nrow==b-1 || dir%4==1&&ncol==b-1 {
				row=nrow
				col=ncol
				out[row][col]="#"
				dir++
				l = 1
			} else if out[nrow+dy[dir%4]][ncol+dx[dir%4]]=="#" {
				if l < 3 {
					break
				}
				dir++
				l = 1
			} else {
				row=nrow
				col=ncol
				out[row][col]="#"
				l++
			}
		}
		for i := 0; i < b; i++ {
			for j := 0; j < b; j++ {
				fmt.Printf("%s", out[i][j])
			}
			fmt.Println()
		}
		if a != 0 {
			fmt.Println()
		}
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int m;
bool isIn(int x, int y){
    return 0 <= x && x < m && 0 <= y && y < m;
}

int main(){
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    bool field[110][110];
    int n;
    cin >> n;
    for(int p=0; p < n; p++){
        if(p != 0) cout << endl;
        cin >> m;
        if(m == 1){cout << "#" << endl; continue;}
        else if(m == 2){cout << "##" << endl; cout << "# " << endl; continue;}
        rep(i, 110)rep(j, 110)field[i][j] = false;
        int x = 0, y = 0, d = 0;
        field[0][0] = true;
        while(true){
            bool change = false;
            while(isIn(x+dx[d], y+dy[d])){
                if(field[x+dx[d]][y+dy[d]]){
                    field[x][y] = false;
                    x -= dx[d]; y -= dy[d];
                    break;
                }
                change = true;
                x += dx[d]; y += dy[d];
                field[x][y] = true;
            }
            if(!change) break;
            d = (d+1)%4;
        }
        if(m%2 == 1){
            x += dx[d]; y += dy[d];
            field[x][y] = true;
        }

        for(int i=m-1; 0 <= i; i--){
            for(int j=0; j < m; j++){
                cout << (field[i][j] ? "#" : " ");
            }
            cout << endl;
        }
    }
}

C++: 
int n;
char G[100][100]; // grid
static int di[4] = {-1, 0, 1, 0};
static int dj[4] = {0, 1, 0, -1};

int main(){
    int dir, width, i, j, a, w;
    int t; scanf("%d", &t);
    for ( int i = 0; i < t; i++ ){
      if ( i ) printf("\n");
      scanf("%d", &n);
      
      for ( i = 0; i < n; i++ )
        for ( j = 0; j < n; j++ ) G[i][j] = ' ';
      
      width = n - 1;
      i = width; j = dir = 0;
      
      for ( a = 1; a <= (n + n % 2); a++, dir = (dir + 1) % 4 ){
        for ( w = 0; w <= width; w++ ) G[i+di[dir]*w][j+dj[dir]*w] = '#';
        i += di[dir] * width;
        j += dj[dir] * width;
        if ( a % 2 == 1 && a >= 3 ) width -= 2;
      }
      
      for ( i = 0; i < n; i++ ){
        for ( j = 0; j < n; j++ ) printf("%c", G[i][j]);
        printf("\n");
      }
    }
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n,dy[]={-1,0,1,0},dx[]={0,1,0,-1};
char c[100][100];

int main(){
	cin>>n;
	int f=0;
	while(cin>>n){
		if(f)cout<<endl;
		if(n==1){cout<<"#"<<endl;continue;}
		for(int i=0;i<n*n;i++)c[i/n][i%n]=' ';
		int y=n-1,x=0,u=0,d=n-1,l=0,r=n-1;
		c[y][x]='#';
		for(int i=0;i<n;i++){
			while(1){
				y+=dy[i%4];x+=dx[i%4];
				c[y][x]='#';
				if(i%4==0&&y==u||i%4==1&&x==r||i%4==2&&y==d||i%4==3&&x==l)break;
			}
			if(i%4==0)l+=2;
			if(i%4==1)u+=2;
			if(i%4==2)r-=2;
			if(i%4==3)d-=2;
		}
		for(int i=0;i<n*n;i++){
			cout<<c[i/n][i%n];
			if(i%n==n-1)cout<<endl;
		}
		f=1;
	}
}

C++: #include <cstdio>
using namespace std;

bool g[100][100];

void clear(int n) {
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      g[i][j] = false;
    }
  }
}

void draw(int n) {
  int i = 0, j = 0, k = n-1;
  bool b = true;
  for (int l=0; l<n; l++) g[l][0] = true;
  while (k > 0) {
    if (b) {
      for (int l=0; l<k; l++) g[i][++j] = true;
      if (k>1) {
        for (int l=0; l<k; l++) g[++i][j] = true;
      }
    } else {
      for (int l=0; l<k; l++) g[i][--j] = true;
      if (k>1) {
        for (int l=0; l<k; l++) g[--i][j] = true;
      }
    }
    k -= 2;
    b = !b;
  }
}

void print(int n) {
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      putchar(g[i][j] ? '#' : ' ');
    }
    putchar('\n');
  }
}

int main() {
  int d, n;
  scanf("%d", &d);
  for (int i=0; i<d; i++) {
    scanf("%d", &n);
    if (i) putchar('\n');
    clear(n);
    draw(n);
    print(n);
  }
  return 0;
}

C++: #include <iostream>
#include <vector>

using namespace std;

const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};

inline int next(int d)
{
    return (d + 1) % 4;
}

int main()
{
    int dataset, n;

    cin >> dataset;
    for (int cnt = 0; cnt < dataset; ++cnt) {
        if (cnt != 0)
            cout << "\n";
        cin >> n;

        if (n == 1) {
            cout << "#\n";
            continue;
        }
        else if (n == 2) {
            cout << "##\n# \n";
            continue;
        }
        else if (n == 3) {
            cout << "###\n# #\n# #\n";
            continue;
        }

        vector<vector<bool> > map(n, vector<bool>(n, false));
        int d = 0, x = 0, y = n - 1;
        bool flag = true;

        while (flag) {
            map[y][x] = true;

            int nx = x + dx[d];
            int ny = y + dy[d];

            if (nx < 0 || nx >= n || ny < 0 || ny >= n) {
                d = next(d);
                x += dx[d];
                y += dy[d];
                continue;
            }

            for (int i = 0; i < 4; ++i) {
                if ((i + 2) % 4 == d)
                    continue;
                int nnx = nx + dx[i];
                int nny = ny + dy[i];

                if (nnx < 0 || nnx >= n || nny < 0 || nny >= n)
                    continue;
                if (map[nny][nnx]) {
                   d =  next(d);
                   break;
                }
            }
            x += dx[d];
            y += dy[d];

            for (int i = 0; i < 4; ++i) {
                if ((i + 2) % 4 == d)
                    continue;
                nx = x + dx[i];
                ny = y + dy[i];

                if (nx < 0 || nx >= n || ny < 0 || ny >= n)
                    continue;
                if (map[ny][nx]) {
                    flag = false;
                    break;
                }
            }
        }

        // Output
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (map[i][j])
                    cout << "#";
                else
                    cout << " ";
            }
            cout << "\n";
        }
    }

    return 0;
}