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 <queue>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define POF pop_front
#define POB pop_back
#define MA make_pair
#define ll long long
#define VE vector<int>
#define VP vector<pair<int,int> >
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
int main(){
  int N;
  int A[1000];
  while(1){
    cin>>N;
    if(N==0){
      break;
    }
    FOR(i,0,N){
      cin>>A[i];
    }
    sort(A,A+N);
    int mi=INF;
    FOR(i,1,N){
      mi=min(mi,abs(A[i]-A[i-1]));
    }
    cout<<mi<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<numeric>
#include<map>
using namespace std;

#define R(i,s,n) for(int i=s;i<n;i++)
#define D(i,n,s) for(int i=n-1;i>=s;i--)
typedef pair<int,int> P;

int main() {
  int n;
  while (cin >> n && n) {
    int a[n];
    R(i,0,n) {
      cin >> a[i];
    }
    int ans = 1e+6;
    R(i,0,n-1) {
      R(j,i+1,n) {
        int tmp = abs(a[i]-a[j]);
        ans = min(tmp, ans);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
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 = 1 << 20;
        for (int i = 0; i + 1 < n; i++) {
            ans = min(ans, a[i + 1] - a[i]);
        }
        cout << ans << endl;
    }
}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long

int main(){
  int n;
  while(cin>>n , n){
    vector<int> vec(n);
    rep(i,n) cin>>vec[i];
    sort(all(vec));
    int res=INF;
    rep(i,n-1) res = min(res, vec[i+1]-vec[i]);
    cout << res<<endl;
  }
  return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


int main(){
  cin.sync_with_stdio(false);

  while(true) {
  int n;
  cin >> n;
  if (n == 0) break;
  int a[n] = {};
  rep(i, n) {
    cin >> a[i];
  }

  sort(a, a + n);

  int minimum = INF;
  rep(i, n - 1) {
    minch(minimum, a[i + 1] - a[i]);
  }

  print(minimum);
}

  return 0;
}

C++: #include<iostream>
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];
  }

  int min = 1000000;
  for(int j=0; j<n-1; j++){
   for(int i=j+1; i<n; i++){
    if(a[j]>=a[i] && a[j]-a[i]<min){
     min = a[j]-a[i];
    }else if(a[j]<a[i] && a[i]-a[j]<min){
     min = a[i]-a[j];
    }
   }
  }

  cout << min <<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;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<iostream>
#include<algorithm>
#include<vector>
#define SEISEKI 1000001

using namespace std;

int main() {
	while (1) {
		int n,data;
		int ans=SEISEKI;
		vector<int> a;

		cin >> n;
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> data;
			a.push_back(data);
		}

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

		for (int i = 0; i< a.size(); i++) {
			ans = min(ans,a[i]-a[i - 1]);
		}
		cout << ans<<endl;
	}
	return 0;
}

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

int main(void){
  int n;
  int a[1000]={};
  int min=1000000;
  cin>>n;
  while(n!=0){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(i!=j){
	  int sa;
	  if(0>(a[i]-a[j])){
	    sa=a[j]-a[i];
	  }else{
	    sa=a[i]-a[j];
	  }
	  if(sa<min)sa=min;
	}
      }
    }
    cout<<min;
    cin>>n;
  }
}

C++: #include<stdio.h>
 
int main(void){
 int n,a[1001],i,j,b,c,min;
 
 while(1){
  scanf("%d",&n);
 
  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;
    }
   }
  }
  min=a[0];
  for(i=0;i<n;i++){
   c=a[i]-a[i+1];
   if(min>c){
    min=c;
   }
  }
  printf("%d\n",min);
 }
}

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


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

	sort(a, a+n);
	int res=100000000000;
	for (int i = 0; i < n-1; i++) {
		if (res > a[i + 1] - a[i]) {
			res = a[i + 1] - a[i];
		}
	}
	cout << res;
}

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

using namespace std;

int n;
int minn = 200;
int a[1002];
int i;int j;int dif;

int main(){
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++) scanf("%d",&a[i]);
		minn = 1000002;
		for(i=0;i<n;i++){
			for(j=i+1;j<n;j++){
				dif = a[i]-a[j];
				if(dif<0) dif*=(-1);
				if(minn>dif) minn = dif;
			}
		}
		printf("%d\n",minn);
	}	
	return 0;
}

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

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