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;
using ll = long long int;
#define long ll

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);

    ll n;
    while(cin >> n) {
        if(!n) break;
        vector<ll> a(n);
        for(auto &e: a) cin >> e;
        ll r = 1e9;
        sort(a.begin(), a.end());
        for(ll i=0; i<n-1; i++)
            r = min(r, abs(a[i+1] - a[i]));
        cout << r << endl;
    }
}

C++: //#define _GRIBCXX_DEBUG
#include <bits/stdc++.h>
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int n, left, right;
  vector<int> p;

  while (cin >> n >> left >> right, n) {
    p.resize(n);
    rep (i, n) cin >> p[i];

    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());

    int n_passed = 0;
    int max_gap = 0;

    rep (i, n) {
      // cout << "i: " << i << endl;
      if (! (left <= i+1 && i+1 <= right) ) continue;
      // cout << "passed " << i+1 << " students (lowest: " << left << ", highest: " << right << ")" << endl;
      // cout << "current gap: " << p[i] - p[i+1] << endl;

      if (max_gap <= p[i] - p[i+1]) {
        // cout << "new gap: " << p[i] - p[i+1] << endl;
        // cout << left << ", " << i+1 << ", " << right << endl;
        // cout << "update" << endl;
        n_passed = i+1;
        max_gap = p[i] - p[i+1];
      }
    }
    cout << n_passed << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#define SEISEKI 10000000

using namespace std;

int main() {
	while (1) {
		int n;
		int ans=SEISEKI;

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

		sort(a, a+n);	//昇順

		for (int i = n-1; i>=0; i--) {
				ans = min(ans, a[i] - a[i - 1]);
		}
		cout << ans<<endl;
	}
	return 0;
}

C++: //#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#include <climits>

using namespace std;
using ll=long long;

void solve(){
  while(1){
    int num;
    cin >> num;
    if(num==0)return;
    int ar[num];
    for(int i=0;i<num;i++)
      cin >> ar[i];
    int res=10000000;
    for(int i=0;i<num;i++)
      for(int j=i+1;j<num;j++)
        res=min(res,abs(ar[i]-ar[j]));
    cout << res << endl;
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

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

int main()
{
  while (true)
  {
    long long n, tmp = LLONG_MAX;
    cin >> n;

    if (n == 0)
      exit(0);

    vector<long long> v(n, 0);
    for (int i = 0; i < n; i++)
      cin >> v[i];

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

    for (int i = 1; i < n; i++)
    {
      if (v[i] - v[i - 1] < tmp)
        tmp = v[i] - v[i - 1];
    }

    cout << tmp << endl;
  }

}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main( ){
  while(1){
    double D,E,min;
    cin>>D>>E;
    if(D==0&&E==0)break;
    for(int i=0;i<=D;i++){
      double l=fabs(sqrt(pow(D-i,2)+pow(i,2))-E);
      if(i==0)min=l;
      if(l<min)min=l;
    }
    cout<<min<<endl;
  }
  return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(),(a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  while(cin >> N, N){
	VI xs(N);
	REP(i,N) cin >> xs[i];
	SORT(xs);
	
	int ans = 1e9;
	REP(i,N-1) ans = min(ans, xs[i+1]-xs[i]);
	
	cout << ans << endl;
  }

  return 0;
}

C++: #include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 2000000;
using namespace std;

int main() {
  int N;
  while (cin >> N && N) {
    std::vector<int> A(N);
    REP(i, N) { cin >> A[i]; }
    sort(A.begin(), A.end());
    int ans = A[1] - A[0];
    REP(i, N - 1) {
      ans = min(ans, A[i + 1] - A[i]);
    }
    cout << ans << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans,t;
  int a[1000];
  while(1){
  cin >> n;
  if(n==0) break;
  for(int i=0; i<n; i++){
	cin >> a[i];
  }
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
	t = a[i] - a[j];
	if(t<0) t = t*(-1);
	if(i==0 && j==i+1) ans = t;
	ans = min(ans,t);
    }
  }
  cout << ans << endl;
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

int a[1000];
int main() {
    while(1) {
        int n;
        cin >> n;

        if (n == 0) break;

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

        int mindelta = 2000000;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                if (abs(a[i] - a[j]) < mindelta) mindelta = abs(a[i] - a[j]);
            }
        }
        cout << mindelta << endl;
    }
}

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

using namespace std;

int n[1000]={};
long long a[1000][1000]={};
long long ans = 10000000000;

int main(){
    int s=0;
    while(1){
        scanf("%d",&n[s]);
        if(n[s] == 0){
            break;
        }
        for(int i=0;i<n[s];i++){
           scanf("%lld",&a[s][i]); 
        }
        s++;
    }

    int times =s;
    int sub;
    for(int i=0;i<s;i++){
        sort(a[i],a[i]+n[i]);
        for(int j=0;j<n[i]-1;j++){
            sub = abs(a[i][j] - a[i][j+1]);
            if(ans >= sub){
                ans = sub;
            }
        }
        cout << ans << endl;
        ans = 1000000000;
    }
    

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < (n);i++)
typedef long long ll;

int main(){
    while(true){
        int n;
        long ans = 100000000000;
        cin >> n;
        if(n == 0)return 0;
        vector<int > a(n);
        rep(i,n)cin >> a[i];

        rep(i,n){
            for(int j = i+1;j<n;j++){
                int temp = abs(a[i]-a[j]);
                if(ans > temp)ans = temp;
            }
        }
        cout << ans << endl;
    }
}