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<algorithm>
#include<vector>
#include<climits>

using namespace std;

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

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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1L<<62)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N;
  while (cin >> N, N) {
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    int min_abs = INF;
    rep(i, N) rep(j, N) {
      if (i == j) continue;
      min_abs = min(abs(A[i] - A[j]), min_abs);
    }

    cout << min_abs << endl;
  }
  return 0; 
}

C++: #include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    int n;
    while(cin >> n){
        if(n == 0)return 0;
        vector<int> vec;
        for(int i = 0;i < n;i++){
            int b;cin >> b;
            vec.push_back(b);
        }
        sort(vec.begin(), vec.end());
        int ans = 1e9;
        for(int i = 0;i < n-1;i++){
            ans = min(ans, vec.at(i+1)-vec.at(i));
        }
        cout<<ans<<endl;
    }
}

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

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

C++: #include <cstdio>
#include <algorithm>

using namespace std;

int a[1001];

int main() {
  int n;
  while (true) {
    scanf("%d", &n);
    if (n == 0) break;
    for (int i=0;i<n;i++) scanf("%d", &a[i]);
    sort(a, a+n);
    int mind = a[n-1];
    for (int i=0;i<n-1;i++) mind = min(mind, a[i+1]-a[i]);
    printf("%d\n", mind);
  }
  return 0;
}

C++: #include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
 
const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
 
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;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

////////////////////////////////////////////////////////////

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

    vector<unsigned int> a(n);
  
    rep(i,0,n)
      cin >> a[i];
  
    unsigned int min_sa = abs(a[0] - a[1]);
  
    sort( a.begin() , a.end());

    //cout << "UNKO" << endl;

    rep(i,0,n-1){
      if(min_sa > abs(a[i + 1] - a[i])){
        min_sa = abs(a[i+1] - a[i]);
        //cout << i << endl;
      }
    }   
    
    cout << min_sa << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#define SEISEKI 1000001

using namespace std;

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

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

		sort(a.begin(), a.end());	//昇順

		for (int i = 0; i< n; i++) {
			ans = min(ans,a[i]-a[i - 1]);
		}
		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 s=1000001;
		for(int i=0;i<n;i++){
			for(int j=0;j<n-1;j++){
				if(s>abs(a[i]-a[j])){
					s=abs(a[i]-a[j]);
				}
			}
		}
		cout<<s<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int a[1010];
void solve(int n){
  REP(i,n)cin>>a[i];
  sort(a,a+n);
  int result=1e+7;
  REP(i,n-1)
    if(result>a[i+1]-a[i])
      result=a[i+1]-a[i];
  cout<<result<<endl;
}


int main(){ _;
  int n;
  while(cin>>n,n!=0){
    solve(n);
  }
}

C++: #include <stdio.h>
#include <stdlib.h>
int min(int a, int b ){
  if (a > b) {
    return b;
  } else {
    return a;
  }
}
int main(void) {
  int n,a[1000],ans;
  scanf("%d",&n );
  while(n){
    ans = 1000000;
    for (int i = 0; i < n; i++) {
      scanf("%d",&a[i] );
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i != j) {
          ans = min(ans, abs(a[j] - a[i]));
        }
      }
    }
    printf("%d\n",ans );
    scanf("%d",&n );
  }
  return 0;
}

C++: //
//  main.cpp
//  Selection of Participants of an Experiment
//
//  Created by x15071xx on 2017/06/13.
//  Copyright ?? 2017??´ AIT. All rights reserved.
//

#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char * argv[]) {
    
   
    while (1) {
        
        int n,i,min=10000000,tmp;
        vector<int> s;
        
        
        cin >> n;
        
        if (n == 0) {
            break;
        }
        
        for (i = 0; i < n; i++) {
            cin >> tmp;
            s.push_back(tmp);
        }
        
        sort(s.begin(), s.end());
        
        for (i = 0; i < s.size()-1; i++) {
            int ans = abs(s[i] - s[i+1]);
            
            if (ans < min) {
                min = ans;
            }
        }
        
        cout << min << endl;
        
    }
    return 0;
}