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;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int main(void) {
  while (true) {
    int n, a[1010];
    cin >> n;
    if (!n)
      break;
    REP(i, n) cin >> a[i];
    sort(a, a + n);

    int mind = INF;
    FOR(i, 1, n) {
      int diff = a[i] - a[i - 1];
      mind = min(mind, diff);
    }

    cout << mind << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
#define INF 1000001

void quickSort(int* Array,int left,int right){
    if(left < right){
        int i=left,j=right;
        int pivot;

        pivot = Array[(left+right)/2];
        while(1){
            while(Array[i]<pivot)
                i++;
            while(Array[j]>pivot)
                j--;
            if(i>=j)break;
            swap(Array[i],Array[j]);
            i++;j--;
        }
        quickSort(Array,left,i-1);
        quickSort(Array,j+1,right);
    }
}
int absolute(int x){
    if(x>=0)return x;
    else return -1*x;
}
int main(){
    int n;
    while(true){
        cin>>n;
        if(n==0)break;
        int grades[n];
        int minimum = INF;
        for(int i=0;i<n;i++)
            cin>>grades[i];
        quickSort(grades,0,n-1);
        for(int i=0;i<n-1;i++){
            int sub = grades[i+1] - grades[i];
            if(minimum > absolute(sub))minimum = absolute(sub);
        }
        cout<<minimum<<endl;
    }
    return 0;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    cin >> skipws;

    for (;;) {
        int n;
        cin >> n;
        if (!n)
            break;
        vector<int> v(n);
        rep(i, 0, n) cin >> v[i];
        sort(all(v));
        int ans = 0x3f3f3f3f;
        rep(i, 0, n - 1) ans = min(ans, v[i + 1] - v[i]);
        cout << ans << endl;
    }
}

C++: #include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <algorithm>

int testcase_ends() {
  size_t n;
  scanf("%zu", &n);
  if (n == 0) return 1;

  std::vector<int> a(n);
  for (auto& ai: a) scanf("%d", &ai);
  std::sort(a.begin(), a.end());

  int res = 1e7;
  for (size_t i = 1; i < n; ++i)
    res = std::min(res, std::abs(a[i]-a[i-1]));

  printf("%d\n", res);
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}

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

using namespace std;

int main()
{
  int n;
  while(cin >> n, n) {
    int a[1001];
    int dif = 1<<25;
    for(int i = 0; i < n; i++) {
      cin >> a[i];
      for(int j = 0; j < i; j++) dif = min(dif, abs(a[i] - a[j]));
    }
    cout << dif << endl;
  }
  return 0;
}

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

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

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

int main() {
	int n;

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

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

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

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)


int main() {
    int n;
    while (cin >> n && n) {
        int a[n]; rep(i, n) cin >> a[i];
        sort(a, a + n);
        int ans = inf;
        rep3(i, 1, n) {
            chmin(ans, a[i] - a[i - 1]);
        }
        out(ans);
    }
}

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

C++: #include <stdio.h>

int main() {
    // insert code here...
    int n;
    int x[1000];
    int y;
    int h, i, j, k;
    int di, an;
    for(;;){
        scanf("%d", &n);
        if(n == 0) break;
        else{
            for(h = 1; h < n + 1; h++){
                scanf("%d", &x[h]);
            }
            for(i = 2; i < n + 1; i++){
                j = i - 1;
                while(j > 0 && x[j] > x[j+1]){
                    y = x[j+1];
                    x[j+1] = x[j];
                    x[j] = y;
                    j = j - 1;
                }
            }
            an = 1000000;
            for(k = 1; k < n; k++){
                di = x[k+1] - x[k];
                if(an > di) an = di;
            }
            
            printf("%d\n", an);
        }
    }
    return 0;
}