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++: //#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;
  vector<int> a;

  while (cin >> n, n) {
    a.resize(n);
    rep (i, n) cin >> a[i];

    sort(a.begin(), a.end());
    int ans = 1001001001;

    rep (i, n-1) {
      ans = min(ans, a[i+1] - a[i]);
    }

    cout << ans << endl;
  }

  return 0;
}

C++: #include<stdio.h>

int main(void){
 int n,a[1001],i,j,b,c,min;

 while(1){
  scanf("%d",&n);
  min=1000000;

  if(n==0){
   break;
  }
  for(i=0;i<n;i++){
   scanf("%d",&a[i]);
  }
  for(i=0;i<n-1;i++){
   for(j=n-1;j>i;j--){
    if(a[j-1]<a[j]){
     b=a[j-1];a[j-1]=a[j];a[j]=b;
    }
   }
  }
  for(i=0;i<n;i++){
   c=a[i]-a[i+1];
   if(min>c){
    min=c;
   }
  }
  printf("%d\n",min);
 }
}

C++: #include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1e+10
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0; i<n; i++)

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vii;
typedef pair<int,ll> pii;

int main() {
  int n;
  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    vi data(n);
    rep(i, n) {
      cin >> data[i];
    }
    sort(data.begin(), data.end());
    ll closest = INF;
    rep(i, n-1) {
      closest = min(closest, data[i+1] - data[i]);
    }
    cout << closest << endl;
  }
}

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

int main()
{

	int n = 1;
	
	while (cin >> n) {
		int ans = 100000;
		if (n == 0)
			break;
		int a[1000];
		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 (ans > abs(a[i] - a[j]))
					ans = abs(a[i] - a[j]);
			}
		}
			cout << ans << endl;

	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;

void merge (int *first1, int *last1, int *first2, int *last2){
    int size1 = last1 - first1;
    int size2 = last2 - first2;
    int *result = new int[size1+size2];
    int i = 0;
    int j = 0;
    int index = 0;
    while (true){
        if (i < size1 && (first1[i] <= first2[j] || j >= size2)){
            result[index] = first1[i];
            ++i; ++index;
        }
        if (j < size2 && (first1[i] > first2[j] || i >= size1)){
            result[index] = first2[j];
            ++j; ++index;
        }
        if (i==size1 && j==size2){
            for (i=0; i<size1; ++i) first1[i] = result[i];
            for (j=0; j<size2; ++j) first2[j] = result[j+size1];
            delete[] result;
            return;
        }
    }
}
void MergeSort (int *first, int *last){
    int size = last - first;
    if(size <= 1) return;
    MergeSort(first, first+size/2);
    MergeSort(first+size/2, last);
    merge(first, first+size/2, first+size/2, last);
}

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

  int n;
  while(1){
    cin >> n;
    if(n == 0) break;

    int score[n];
    REP(i, n) cin >> score[i];
    stable_sort(score, score+n);

    int min = 1000001;
    REP(i, n-1) if(min > abs(score[i]-score[i+1])) min = abs(score[i]-score[i+1]);

    cout << min << endl;
  }

  return 0;
}

C++: using namespace std;
using ll=long long;
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#define out(S) cout<<(S)<<endl;
#define mod(i) ((i)%(ll)(1000000000 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define For(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFor(i,a,b) for(size_t i=(a)-1;i>=(b);i--)
#define Rep(i,a) for(size_t i=0;i<(a);i++)
#define rRep(i,a) for(size_t i=(a)-1;i>=0;i--)
#define Foreach(item,collection) for(auto item:collection)
 
int main(){
    int N;
    cin >> N;
    vector<ll> ans;
    while (N!=0)
    {
        vector<ll> a;
        a.resize(N);
        Rep(i, N) cin >> a[i];
        ll thismin = 1e10;
        Rep(i, N) {
            Rep(n, N) {
                if (n == i) continue;
                thismin = min(thismin, abs(a[i] - a[n]));
            }
        }
        ans.push_back(thismin);
        cin >> N;
    }
    Foreach(i, ans) out(i);
    return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

const int MAX=1000;

#define hoge(i,n) for(int i=0;i<n;i++)
int main(){
    int n,a[MAX],gap[MAX-1];
    while(cin>>n && n){
        hoge(i,n){
            scanf("%d", &a[i]);
        }
        sort(a,a+n);
        int mingap=20000000;
        hoge(i,n-1){
            gap[i]=a[i+1]-a[i];
            mingap=min(mingap,gap[i]);
        }
        cout << mingap <<endl;
    }
}

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

int main (){
    int n;
	while(cin>>n && n){
		vector<int> v(n);
		int ans=INT_MAX;
		for(int i=0;i<n;i++)cin>>v[i];

		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i!=j)ans=min(ans,abs(v[i]-v[j]));
			}
		}
		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] - point[i+1]);
		}

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
int a[10000];
int main(){
  int n;
  while(cin>>n,n){

  for(int i=0;i<n;i++)cin>>a[i];
  int ans=1000000;
  sort(a,a+n);
  for(int i=1;i<n;i++)ans=min(ans,abs(a[i]-a[i-1]));
  cout<<ans<<endl;
  for(int i=0;i<n;i++)a[i]=0;
  }
  return 0;
}