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++: import java.util.*;                                                              
  public class Main{
  public static void main(String args[]) throws Exception{
  Scanner sc = new Scanner(System.in);
  int N = sc.nextInt();sc.nextLine();
  while(N!=0){
   int[] array = new int[N];
   String s = sc.nextLine();
   String[] a = s.split(" ");
   for(int i=0;i<N;i++){
    array[i]=Integer.parseInt(a[i]);
   }
   Arrays.sort(array);
   int abs= 1000;
   for(int k=0;k<N-1;k++){
    if(abs>array[k+1]-array[k]){
    abs=array[k+1]-array[k];
    }
   }
 System.out.println(abs);
 N = sc.nextInt();sc.nextLine();
 }
}
}

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

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

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n;
    while(cin >> n) {
        if(!n) break;
        vector<int> v(n);
        rep(i,0,n) cin >> v[i];
        sort(v.begin(), v.end());

        int mi = INF;
        rep(i,1,n) {
            int temp = v[i] - v[i-1];
            mi = min(mi, temp);
        }
        cout << mi << endl;
    }
    return 0;
}

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

int main() {
	int n;
	while (cin >> n, n) {
		vector<int> a(n);
		for (int& i : a) cin >> i;
		sort(a.begin(), a.end());
		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 <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    while(1){
        int n; cin>>n;
        if(n == 0) return 0;
        vector<int> a(n);
        for(int i=0; i<n; i++) cin>>a[i];
        sort(a.begin(), a.end());

        int ans=1e9;
        for(int i=0; i<n-1; i++){
            chmin(ans, a[i+1] - a[i]);
        }

        cout << ans << endl;
    }
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;

template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}
//-----------------------------------------------------------------------

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

    int n;
    while(cin>>n,n)
    {
        vector<int> v(n);
        REP(i,n) cin>>v[i];
        sort(ALL(v));

        int diff=1e9;
        REP(i,v.size()-1){
            diff=min(diff,v[i+1]-v[i]);
        }
        cout<<diff<<endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
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.at(i);
    
    sort(a.begin(),a.end());
    
    int min, d;
    min = 1000000;
    
    for(int i=0; i<n-1; i++){
        d = (a.at(i) - a.at(i+1) > 0 ? a.at(i)-a.at(i+1):a.at(i+1)-a.at(i));
        if(min > d) min = d;
    }
    
    cout << min << endl;
    }
}

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

int main(){
	while(1){
		int n;
		cin>>n;
		if(n == 0)
			break;
		
		char  c[100];
		for(int i=0; i<n; i++){
		  cin>>c[i];
		}

		int cnt[26] = {0};
		for(int i=0; i<n; i++){
		  cnt[(int)(c[i]-'A')]++;

		  int max1=-1;
		  int max2 = -1;
		  for(int j=0; j<26; j++){
		    if(cnt[j]>max1){
		      max2 = max1; 
		      max1=cnt[j];
		    }
		    else if(cnt[j]>max2){
		      max2 = cnt[j];
		    }
		  }

		  if(max1-max2>n-(i+1)){
		    for(int j=0; j<26; j++){
		      if(cnt[j]==max1){
			cout<<(char)(j+'A')<<' ';
			break;
		      }
		    }
		    cout<<(i+1)<<endl;
		    break;
		  }

		  if(i==n-1){
		    cout<<"TIE"<<endl;
		    break;
		  }
		}
	}
	
	return 0;
}

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

using namespace std;

int solve(vector<int>& v) {
  sort(v.begin(), v.end());
  auto mn = INT_MAX;
  for (auto i = 1; i < v.size(); ++i) mn = min(v[i] - v[i - 1], mn);
  return mn;
}

int main() {
  int n;
  while(cin >> n, n) {
    vector<int> v(n);
    REP(i, n) cin >> v[i];
    cout << solve(v) << endl;
  }
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	int n;
	while (cin >> n) {
		if (n == 0)break;
		int a[1000] = {};
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(a, a + n);
		int mi = (int)MOD;
		for (int i = 0; i < n-1; i++) {
			mi = min(mi, a[i + 1] - a[i]);
		}
		cout << mi << endl;
	}
	return 0;
}