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 <iostream>
#include <vector>
#include <cmath>
using namespace std;

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

  int min_diff = 1000000;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j)  {
        int diff = abs(scores[i] - scores[j]);
        min_diff = min_diff > diff ? diff : min_diff;
      }
    }
  }
  cout << min_diff << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
int INF = 10000000;
int main(){
  while (1){
    int n;
    cin >> n;
    if (n == 0){
      break;
    }
    vector<int> a(n);
    for (int i = 0; i < n; i++){
      cin >> a[i];
    }
    sort(a.begin(), a.end());
    int ans = INF;
    for (int i = 0; i < n - 1; i++){
      ans = min(ans, a[i + 1] - a[i]);
    }
    cout << ans << endl;
  }
}

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

int a[1010];

void sort(int l, int r) {
    if (l >= r) return;
    int p = l;
    int k = l+1;
    while (k <= r) {
        if (a[k] < a[l]) {
            swap(a[k], a[p+1]);
            p++;
        }
        k++;
    }
    swap(a[l], a[p]);
    sort(l, p);
    sort(p+1, r);
}

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

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

int main(){
	while(1){
		int n;
		vector<int> a;
		
		cin>>n; 
		if(n == 0)
			break;
			
		for(int i=0; i<n; i++){
			int x; 
			cin>>x; 
			a.push_back(x);
		}
		sort(a.begin(),a.end());
		
		int diff=1000000; 
		for(int i=0; i<n-1; i++){
			if(a[i+1] - a[i] < diff){
				diff=a[i+1] - a[i];
			}
			if(diff == 0)
				break;
		}
		cout<<diff<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
constexpr int INF = (1 << 29);
 
int main()
{
    int N;
    while (cin >> N, N) {
        vector<int> a(N);
        for (int i = 0; i < N; i++) {
            cin >> a[i];
        }
        int res = INF;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                res = min(res, abs(a[i] - a[j]));
            }
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

int main(void) {
	int n = 0;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		int A[1000];
		for (int i = 0; i < 1000; i++) {
			A[i] = 0;
		}
		for (int i = 0; i < n; i++) {
			cin >> A[i];
		}
		int min = 1000000;
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (min > abs(A[i] - A[j])) {
					min = abs(A[i] - A[j]);
				}
			}
		}
		cout << min << endl;
	}
	return 0;
}

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

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){
			break;
		}
		int mDistance = 1000000;
		int data[n];
		for(int i = 0; i < n; i++){
			int a = 0;
			cin >> a;
			data[i] = a;
		}
		for(int i = 0; i < n; i++){
			for(int j = i + 1; j < n; j++){
				if(abs(data[i] - data[j]) < mDistance){
					mDistance = abs(data[i] - data[j]);
				}
			}
		}
		cout << mDistance << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
using namespace std;

#define ll long long
#define MP make_pair

int main(void) {

    int n;
    while(1){
        cin>>n;
        if(n==0)break;
        ll a[1000]={},sa=100000000;

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

        for (int i = 1; i < n; i++) {
            sa = min(sa,a[i]-a[i-1]);
        }

        cout<<sa<<"\n";
    }
    
    
    return 0;
}

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

using namespace std;

int main(){
    long long int n;
    long long int ans=1000001;

    while(cin>>n){
        if(n==0)break;
        else{
            ans=1000;
            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 <iostream>
#include "cstdlib"
using namespace std;


int main(){
 while(1){
	 int n;
	 cin>>n;

	 if(n==0) break;

	 int a[1000];

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

	 int dif=1000001;

	 for(int i=0;i<n-1;i++){
		 for(int j=i+1;j<n;j++){
			 int d=abs(a[i]-a[j]);
			 if(dif>d) dif=d;
		 }
	 }

	 cout<<dif<<endl;

 }
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    int n;
    while(cin >>n,n)
    {
        vector<int> a(n);
        rep(i,n) cin >>a[i];

        int ans = 19191919;
        rep(i,n)rep(j,i) ans = min(ans,abs(a[i]-a[j]));
        cout << ans << endl;
    }
    return 0;
}

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

C++: #include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> p;

int main(void){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int tmp=1000001;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(tmp>abs(a[i]-a[j]))tmp=abs(a[i]-a[j]);
    }
  }
  cout << tmp << endl;
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,a[1001]={};
  while(1){
    int min=1000000;
    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++)
	if(a[i]-a[j]>=0){
	  if(min>a[i]-a[j])min=a[i]-a[j];
	}
	else{ 
	  if(min>a[j]-a[i])min=a[j]-a[i];
	}

    cout<<min<<endl;
  }
  return 0;
}