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<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n,a[50000],ans;
    scanf("%d",&n);
    while(n){
        ans=1000000000;
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        sort(a,a+n);
        for(int i=1;i<n;i++){
            ans=min(ans,a[i]-a[i-1]);
        }
        printf("%d\n",ans);
        scanf("%d",&n);
    }
}

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

const int maxn = 1000000 + 5;
int n;
int mem[1000+5];

void Print()
{
    cout << "show" << endl;
    for(int i = 0; i < n; i++)
    {
        printf("%d ", mem[i]);
    }
    printf("\n");
}
int main()
{
    while(1)
    {
        scanf("%d", &n);
        if(!n) break;
        memset(mem, 0, sizeof(mem));
        for(int i = 0; i < n; i++)
        {
            scanf("%d", &mem[i]);
        }

        sort(mem, mem+n); //Print();
        int m = maxn;
        int d;
        for(int i = 0; i < n-1; i++)
        {
            d = mem[i+1]-mem[i];
            if(d < m) m = d;
        }

        cout << m << endl;
    }
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

int main() {
	int n;
	while (cin >> n&& n) {
		vector<int> v;
		
		int a;
		for (int i = 0; i < n; i++) {
			cin >> a;
			v.emplace_back(a);
		}

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

		int minl = INF;
		for (int i = 0; i < n-1; i++) {
			if (v[i + 1] - v[i] < minl){
				minl = v[i + 1] - v[i];
			}
		}
		cout << minl << endl;
	}
}

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

int main() {
	
	int n;
//	int a[1100];
	int point[51000]; //データセットごとの点数
	int count = 0;
	
	while (1)
	{
		
		cin >> n;
		int a[n];
		
		if(n == 0) break; // 0を入力されたら終了
		
		count++;
		
		for (int i = 0; i < n; i++) std::cin >> a[i];
		
		// 配列を大きい順に並べ替える
		sort(a, a+n, greater<int>());
		
		int proa;
		int d;
		//データセットごとの作業
		for (int i = 0; i < n; i++) {
			
			// 隣のデータとの差
			d = abs(proa - a[i]);
			
			// 初期値は最大点
			if(i == 0) point[count - 1] = a[0];
			
			if(d < point[count - 1]) point[count - 1] = d;
			
			proa = a[i];
		}
	}
	
	for (int i = 0; i < count; i++) {
		cout << point[i] << endl;
	}
	
	return 0;
}

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

int n, a[1000];

int main() {

	while (true) {
		cin >> n;

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

		sort(a, a + n);

		int Min = INT32_MAX;
		for (int i = 0; i < n - 1; i++) {
			if (a[i + 1] - a[i] < Min) {
				Min = a[i + 1] - a[i];
			}
		}

		cout << Min << endl;
	}
}

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

using namespace std;

int main(){
    long long int n;

    while(cin>>n){
        if(n==0)break;
        else{
            long long int ans=1000001;
            vector<long long int> v;

            for(int i=0;i<n;i++){
                long long int a;
                cin>>a;
                v.push_back(a);
            }

            sort(v.begin(),v.end());
            
            for(int i=0;i<n-1;i++){
                ans=min(ans,v[i+1]-v[i]);
            } 
            cout<<ans<<endl;
        }
    }

    return 0;
}

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

using namespace std;

int main(){
  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 mini=1000005;
    for(int i=0;i<n-1;++i){
      mini=min(mini,(a[i]<a[i+1])?a[i+1]-a[i]:a[i]-a[i+1]);
    }
    cout << mini <<endl;
  }
  
  return 0;
}

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

int main()
{
    vector<int> ans;
    while (1)
    {
        int n;
        cin >> n;

        if (n == 0)
        {
            break;
        }

        vector<int> scoreList;

        for (int i = 0; i < n; ++i)
        {
            int input;
            cin >> input;
            scoreList.push_back(input);
        }

        int min = INT_MAX;

        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                if (i != j)
                {
                    int dif = abs(scoreList[i] - scoreList[j]);
                    if (dif < min)
                    {
                        min = dif;
                    }
                }
            }
        }

        ans.push_back(min);
    }

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

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e9+7;
const ll N = 1007;





int main(){
	while(1){
		ll n;cin>>n;
		if(n==0)break;
		vector<ll> a;
		a.resize(n);
		FOR(i,0,n)cin>>a[i];
		ll sa=INF;
		FOR(i,0,n){
			FOR(j,0,n){
				if(i==j)continue;
				if(abs(a[i]-a[j])<sa){
					sa = abs(a[i]-a[j]);
				}
			}
		}
		cout<<sa<<endl;
	}
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;

int main() {
  int a;
  while (cin >> a, a) {
    int b[a], c[a - 1];
    rep(i, a) cin >> b[i];
    sort(b, b + a);
    rep(i, a - 1) c[i] = b[i + 1] - b[i];
    cout << *min_element(c, c + a - 1) << endl;
  }
  return 0;
}

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


ll i,h,n,ans;
ll x[10005];


bool solve(){
	cin >> n;
	if(n == 0)return false;
	for(i=0;i<n;i++){
		cin >> x[i];
	}
	ans = 99999999;
	sort(x,x+n);
	for(i=0;i<n-1;i++){
		ans = min(ans,x[i+1]-x[i]);
	}
	cout << ans << endl;
	return true;
}

int main(){
	while(solve()){}
	return 0;
}