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 <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define be(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};

int main()
{
    int n;
    while(cin>>n)
    {
        if(n==0)return 0;
        vector<int>a(n);
        REP(i,n)cin>>a[i];
        sort(a.begin(),a.end());
        vector<int>s(n-1);
        REP(i,n-1)s[i]=abs(a[i]-a[i+1]);
        sort(s.begin(),s.end());
        cout<<s[0]<<endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define popb(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  ll n,a[50001]={},ans=1e9;
  while(1){
    cin>>n;
    if(n==0)return 0;
    rep(i,0,n)cin>>a[i];
    sort(a,a+n);
    rep(i,1,n){
      ans=min(ans,a[i]-a[i-1]);
    }
    cout<<ans<<endl;
    ans=1e9;
  }
}

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

void exec(int n);

int main() {
  int tmp;
  while (1) {
    cin >> tmp;
    if (tmp == 0) {
      break;
    }
    exec(tmp);
  }
}

void exec(int 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;

using ll = long long;
#define rep(i,n) for(int i = 0; i < n ;++i)
#define all(v) v.begin(),v.end()


int main(){
  ll n;
  while(cin >> n,n){
    vector<ll> v(n);
    rep(i,n){
      cin >> v[i];
    }
    sort(all(v));
    ll ans = 10000000000;
    rep(i,n-1){
      ans = min(ans,v[i+1]-v[i]);
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int a = 0;
	while (1)
	{
		int e = 1000000;
		cin >> a;
		if (a == 0)
		{
			break;
		}
		int d[1000];
		for (int i = 0; i < a; i++)
		{
			cin >> d[i];
		}
		sort(d, d + a);
		for (int i = 0; i < (a - 1); i++)
		{
			if (e > d[i + 1] - d[i])
			{
				e = d[i + 1] - d[i];
			}
		}
		cout << e << endl;
	}
return 0;
}

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

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

    sort(a.begin(),a.end());

    int min=10000000;
    for(int i=0;i<n-1;i++){
      int diff=a[i+1]-a[i];
      if(diff<min) min=diff;
    }
    cout<<min<<endl;
  }
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int a[1005];
    while(true) {
        int n;
        cin >> n;
        if(n == 0) break;
        for(int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        int i = 0;
        int j = 0;
        int now = 1e9;
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j < i; j++) {
                now = min(now, abs(a[i] - a[j]));
            }
        }
        cout << now << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
long long inf=1e9+7;

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

        vector<int> a(n);
        int m=inf;
        for (int i = 0; i < n; i++) cin >> a[i];

        sort(a.begin(), a.end());
        for (int i = 0; i < n-1; i++){
            m=min(m, a[i+1]-a[i]);
        }
        cout << m << endl;
    }
    
}
//g++ -o a.exe aa.cpp

C++: #include <iostream>
#include <algorithm>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
#define INF 100000000
using namespace std;

int N, A[1000000];

int main(void) {
  while(cin >> N, N) {
    REP(i, 0, N) cin >> A[i];
    sort(A, A + N);

    int ans = INF;
    REP(i, 0, N - 1) ans = min(ans, A[i + 1] - A[i]);
    cout << ans << endl;
  }

  return 0;
}

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

int main() {
    int n;
    while(cin >> n, n) {
        vector<int> v(n);
        for(int i=0; i<n; ++i) {
            cin >> v[i];
        }
        int res = 1e9;
        for(int i=0; i<n; ++i) {
            for(int j=i+1; j<n; ++j) {
                res = min(res, abs(v[i]-v[j]));
            }
        }
        cout << res << endl;
    }
}

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

using namespace std;

int abs(int a,int b){

  int result;

  if(a<b)
    result=b-a;
  else
    result=a-b;
  return result;
};

int main(void){

  int n;
  int min=1000000;
  int  temp;
  
  while(cin >> n,n!=0){

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

    sort(student.begin(),student.end(),greater<int>());

    for(int i=0;i<n;i++){
      
      temp=abs(student[i],student[i+1]);

      if(min>temp)
	min=temp;
    }

    cout << min <<endl;

    student.clear();
    min=1000000;

  }

  return 0;
  
}

C++: #include<iostream>
#include<cstdlib>
using namespace std;
int main(){
	int n;
	int a[1000];

	while(1){
		cin>>n;

		if(n==0)
			break;

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

		int diff=1000000;

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

		cout<<diff<<endl;
	
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;;

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        vector<int> a(n);
        rep(i, 0, n){
            cin >> a[i];
        }
        sort(a.begin(), a.end());
        int MIN = 1e9;
        rep(i, 0, n - 1){
            MIN = min(MIN, a[i + 1] - a[i]);
        }
        cout << MIN << endl;
    }
}