Go: package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		an := make([]int, n)
		min := 1000000
		for i := 0; i < n; i++ {
			an[i] = nextInt()
		}
		sort.Ints(an)
		for i := 1; i < n; i++ {
			sub := an[i] - an[i-1]
			if min > sub {
				min = sub
			}
		}
		fmt.Println(min)
	}
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	vector<long long>e;
	int n;
	while (cin >> n) {
		if (n == 0)break;
		vector<long long>l;
		for (int i = 0; i < n; i++) {
			long long a; cin >> a;
			l.push_back(a);
		}
		sort(l.begin(), l.end());
		long long num = l[1] - l[0];
		for (int i = 1; i < n - 1; i++)
			num = min(num, l[i + 1] - l[i]);
		e.push_back(num);
	}
	for (long long l : e) 
		cout << l << endl;
	return 0;
}

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

using namespace std;

int main(void)  {

  int n;
  int temp;
  int divmin;
	vector<int> a;
  
  while (true)  {
    
    scanf("%d", &n);
    
    if (n == 0) { break; }
    
    divmin = 1000000;
    
    for (int i = 0; i <= n-1; i++)  {
      cin >> temp;
    	a.push_back(temp);
    }

  	sort(a.begin(), a.end());

  	for (int i = 1; i <= n-1; i++)	{
  		divmin = min(divmin, a[i] - a[i-1]);
  	}
    
    printf("%d\n", divmin);

  	vector<int>().swap(a);
  }
  
  return 0;
}

C++: #include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(int N) {
    VI a(N);
    for_each(ALL(a), [](int &e){cin >> e;});
    SORT(a);
    int ans = INF;
    REP(i, N - 1) ans = min(ans, a[i + 1] - a[i]);
    cout << ans << endl;
    return;
}

signed main(void) {
    LL n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> n, n) {
        solve(n);
        //return 0;
    }
}

C++: #include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int solve(int n) {
    vector<int>keep(n);
    vector<int>ans(n-1);
    int a;
    for(int i=0;i<n;i++){
        cin>>a;
        keep[i]=a;
    }
    // for(int i:keep)cout<<i<<" ";
    sort(keep.begin(),keep.end());
    for(int i=0;i<n-1;i++){
        ans[i]=abs(keep[i]-keep[i+1]);
    }
    // for(int i:ans)cout<<i<<" ";
    sort(ans.begin(),ans.end());
    // int sa = ans[0];
    return ans[0];
}

int main(int argc, char const *argv[]) {
    int n;
    vector<int>ans;
    while (1) {
        cin >> n;
        if (n == 0) break;
        ans.push_back(solve(n));
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
}

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

using namespace std;

int main()
{
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        vector<int> v;
        for (int i = 0; i < n; ++i) {
            int a;
            cin >> a;
            v.push_back(a);
        }

        int r = 10000000;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (i == j) {
                    continue;
                }
                r = min(abs(v[i] - v[j]), r);
            }
        }
        cout << r << endl;
    }
}

C++: #include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

int n;
int a[1010];

signed main()
{
    while (true) {
        cin >> n;
        if (n == 0) break;

        REP(i,n) cin >> a[i];
        sort(a, a + n);

        int minSa = INT_MAX;
        REP(i,n-1) {
            minSa = min(minSa, a[i+1] - a[i]);
        }

        cout << minSa << endl;
    }
}

C++: 5
10 10 10 10 10
5
1 5 8 9 11
7
11 34 83 47 59 29 70
0

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	int n;

	while (cin >> n, n) {
			vector<int> point(n);
			for (int i = 0; i < n; i++) {
				cin >> point[i];
			}
		
		sort(point.begin(), point.end());

		int ans = 1000000;
		for (int i = 0; i < n; i++) {
			ans = min(ans, abs(point[i] - point[i+1]));
		}

		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n, n)
    {
        vector<int> A(n);
        for(int i = 0; i < n; i++) cin >> A[i];
        sort(A.begin(), A.end());
        int ans = INF;
        for(int i = 0; i < n - 1; i++)
        {
            ans = min(ans, abs(A[i] - A[i + 1]));
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;


int main(){
  int n;
  scanf ("%d",&n);
  while(n){
    int k;
    vector<int> p(n);
    for(int t=0;t<n;t++){
      scanf ("%d",&p[t]);
    }
    sort(p.begin(),p.end());
    k=p[1]-p[0];
    for(int t=1;t<n-1;t++){
      if(k>(p[t+1]-p[t])){
        k=(p[t+1]-p[t]);
      }
    }
    printf("%d\n",k);
    scanf ("%d",&n);
  }
}