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 <cmath>
#define MIN(a,b) ((a>b)?(b):(a))
using namespace std;

int main(void){
	int n;
	int a[1000];
	while(cin>>n,n){
		int d=99999999;
		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++){
				d=MIN(d,abs(a[i]-a[j]));
			}
		}
		cout<<d<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	vector<long long>e;
	int n;
	while (cin >> n) {
		if (n == 0)break;
		vector<long long>l;
		for (int i = 0; i < n; i++) {
			long long a; cin >> a;
			l.push_back(a);
		}
		sort(l.begin(), l.end());
		long long num = l[1] - l[0];
		for (int i = 1; i < n - 1; i++)
			num = min(num, l[i + 1] - l[i]);
		e.push_back(num);
	}
	for (long long l : e) 
		cout << l << endl;
	return 0;
}

C++: /*  -*- coding: utf-8 -*-
 *
 * 1608.cc: Selection of Participants of an Experiment
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  for (int n; scanf("%d", &n) > 0 && n > 0;) {
    for (int i = 0; i < n; i++) scanf("%d", as + i);
    sort(as, as + n);

    int mind = INF;
    for (int i = 1; i < n; i++) {
      int d = as[i] - as[i - 1];
      if (mind > d) mind = d;
    }

    printf("%d\n", mind);
  }

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include <math.h>
#include <string>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
const ll INF =1LL << 62;
using namespace std;

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

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

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

int main(void){
	int n;
	while(cin >> n,n){
		int a[1010];
		for(int i = 0; i < n;++i) cin >> a[i];
		int ans = abs(a[0]-a[1]);

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

C++: #include <bits/stdc++.h>

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    while(true) {
        int N;
        std::cin >> N;
        if(N == 0) break;

        vector<int> A(N);
        REP(i, N) {
            std::cin >> A[i];
        }

        SORT(A);

        int ans = INF;
        for(int i = 0; i < N - 1; i++) {
            ans = min(ans, abs(A[i] - A[i + 1]));
        }

        std::cout << ans << std::endl;
    }

    return 0;
}

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


int main() {

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

		sort(a, a + n);
		int res = 1000000000;
		for (int i = 0; i < n - 1; i++) {
			if (res > a[i + 1] - a[i]) {
				res = a[i + 1] - a[i];
			}
		}
		result.push_back(res);
		
	}	

	for (auto a: result) {
		cout << a << endl;
	}

}

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

using namespace std;

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

int main()
{
	solve();
	return(0);
}

C++: #include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int N;
  while(cin>>N,N!=0){
    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++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int n;
	while (cin >> n, n) {
		vector<int>v(n);
		for (int i = 0; i < n; i++)cin >> v[i];
		sort(v.begin(), v.end());
		int a = 100000000;
		for (int i = 1; i < n; i++) {
			a = min(a, abs(v[i] - v[i - 1]));
		}
		cout << a << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>

using namespace std;

int main(){
  int a[1001];

  int c[1001];

  int b, mn;

  mn = 1000000;

  while(1){

    cin >> b;

    if(b == 0) break;
    
    mn = 1000000;
    
    for(int i=0;i<b;i++){
      cin >> a[i];
    }
    for(int j=0;j<b;j++){
      for(int i=0;i<b-1;i++){
	if(a[i] < a[i+1]) swap(a[i],a[i+1]);
      }
    }
    for(int i=0;i<b-1;i++){
      c[i] = a[i] - a[i+1];
    }

    for(int i=0;i<b-1;i++){
      if(c[i]<mn) mn = c[i];
    }

    cout << mn << endl;

  }


}

C++: #include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

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

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc133.contest.atcoder.jp/tasks/abc133_b

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

int main(){
    int n;
    while(cin>>n,n){
        vector<int> V(n);
        for(auto &v:V) cin>>v;
        sort(V.begin(), V.end());
        int ans=1000001;
        for(int i=0;i<n-1;i++){
            ans=min(ans,V[i+1]-V[i]);
        }
        cout<<ans<<endl;
    }

    return 0;
}