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<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n&&n){
    vector<int> d(n);
    for(int i=0;i<n;++i) cin>>d[i];
    sort(d.begin(),d.end());
    int s=d[1]-d[0];
    for(int i=1;i<n-1;++i)
      if(s>d[i+1]-d[i]) s=d[i+1]-d[i];
    cout<<s<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
	
	while(1){
		int N, a[1000], min = 10000000;
		cin>>N;
		if(N == 0)break;
		for(int i = 0; i < N; i++){
			cin>>a[i];
		}
	
		for(int i = 0; i < N - 1; i++){
			for(int j = i + 1; j < N; j++){
				if(fabs(a[i] - a[j]) < min) min = fabs(a[i] - a[j]);
			}
		}
		cout<<min<<endl;
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int32 N;
	while(cin >> N && N){
		vector<int32> x(N);
		REP(i, N) cin >> x[i];
		int32 res = 0;
		sort(all(x));
		REP(i, N-1) res = min(res, x[i+1]-x[i]);
		cout << res << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
    int a;
    while(true){
        cin >> a;
        if(a==0)break;
        int k[a];
        for(int i=0;i<a;i++)cin >> k[i];
        sort(k,k+a);
        int ans=10000000;
        for(int i=0;i<a-1;i++){
            if(k[i+1]-k[i]<ans)ans=k[i+1]-k[i];
        }
        cout << ans << endl;
    }
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<int>v(N);
		for (int i = 0; i < N; ++i) {
			cin >> v[i];
		}
		sort(v.begin(), v.end());

		int ans = INT_MAX;
		for (int i = 0; i < N - 1; ++i) {
			ans = min(ans, v[i + 1] - v[i]);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 10000000000
#define rep(i,n) for(i=0;i<n;i++)

typedef pair<int,int> pii;
int i,j;


int main() {
    int n;
    cin>>n;
    int a[10000];
    rep(i,n)
    cin>>a[i];
    sort(a,a+n);
    int m=1000;
    rep(i,n-1)
    m=min(m,abs(a[i]-a[i+1]));
    return 0;
}

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

using namespace std;

int main(void)
{
    int N;
    while (1)
    {
        cin >> N;
        if (!N) break;
        vector<int> a(N);
        int d;
        int res = 1000000;
        for (int i = 0; i < N; i++) cin >> a[i];
        sort(a.begin(), a.end());
        for (int i = 1; i < N; i++) { d = a[i] - a[i - 1]; if (res > d) res = d; }
        cout << res << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N;
    while (cin >> N, N) {
        vector<int> A(N);
        rep(i, N) cin >> A[i];

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

        int ans = INF;
        rep(i, N-1) {
            ans = min(ans, A[i+1] - A[i]);
        }
        cout << ans << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    int A[n];
    for (int i = 0; i < n; ++i) cin >> A[i];
    sort(A, A+n);
    int d = abs(A[0] - A[1]);
    for (int i = 1; i < n; ++i) d = min(d, abs(A[i]-A[i-1]));
    cout << d << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;

int main(void){
    while(true){
        int n;
        cin >> n;
        if(n == 0) return 0;
        
        vector<ll> a(n);
        For(i, n) cin >> a[i];
        sort(a.begin(), a.end());
        
        ll ans = 1e18;
        For(i, n-1) ans = min(ans, a[i+1] - a[i]);
        cout << ans << "\n";
    }
}

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


int main() {

	vector<int> result;
	while (true)
	{
		
		int n;
		int a[50000];
		cin >> n;
		if (n == 0) {
			break;
		}
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}

		sort(a, a + n);
		int res = 1000000000;
		for (int i = 0; i < n - 1; i++) {
			if (res > a[i + 1] - a[i]) {
				res = a[i + 1] - a[i];
			}
		}
		result.push_back(res);
		
	}	

	for (int i = 0; i < result.size(); i++)
	{
		cout << result[i] << endl;
	}

}

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

using namespace std;
int main()
{
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        vector<int> s(n);
        for (int i = 0; i < n; i++) {
            cin >> s[i];
        }
        sort(s.begin(), s.end());
        int minv = numeric_limits<int>::max();
        for (int i = 0; i < n - 1; i++) {
            if (minv > s[i + 1] - s[i]) {
                minv = s[i + 1] - s[i];
            }
        }
        cout << minv << endl;
    }
    return 0;
}