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>

using namespace std;

int main(){

  int n;

  while(1){
	cin >> n;

	if(n == 0)
	  break;

	vector<int> a(n);

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

	int min_g = 1000000;
	
	for(int i = 0;i < n - 1;++i){
	  for(int j = i + 1;j < n;++j){
		min_g = min(min_g,abs(a[i] - a[j]));
	  }
	}

	cout << min_g << endl;
	
  }

}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<limits.h>
#include<set>
#include<map>
#include<string.h>
#include<queue>
#include<math.h>
#include<stdio.h>
#include<unordered_set>
using namespace std;

int main(){
    int n;
    while(cin>>n,n){
        vector<int>a;
        for(int i=0;i<n;i++){
            int x;
            cin>>x;
            a.push_back(x);
        }
        sort(a.begin(),a.end());
        int mi=INT_MAX;
        for(int i=1;i<n;i++){
            if(a[i]-a[i-1]<mi){
                mi=a[i]-a[i-1];
            }
        }
        cout<<mi<<endl;
    }
    return 0;
}

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

int main(){
    int n;
    while(scanf("%d",&n), n != 0){
        int a[1001]={0};
        for(int i=0;i<n;++i)scanf("%d ",&a[i]);
        int mini = INT_MAX;
        for(int i=0;i<n;++i){
            for(int j=i+1;j<n;++j){
                int d = abs(a[i] - a[j]);
                if(d < mini)mini = d;
            }
        }
        printf("%d\n",mini);
    }

    return 0;
}

C++: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;



int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	while (N) {
		int num[100000];
		for (int i = 0; i < N; i++)cin >> num[i];
		sort(num, num + N);
		int ret = 100000;
		for (int i = 1; i < N; i++)ret = min(ret, num[i] - num[i - 1]);
		cout << ret << endl;
		cin >> N;
	}
	return 0;
}

C++: int main(){
  int a[1001];

  int c[1001];

  int b, mn;

  mn = 1000000;

  while(1){

    cin >> b;

    if(b == 0) break;

    for(int i=0;i<b;i++){
      cin >> a[i];
    }
    for(int j=0;j<b+1;j++){
      for(int i=0;i<b;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 <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int t, n, k, x, ans,a;

  while(1) {
    vector<int> point;
    cin >> n;

    if(n == 0){
      break;
    }

    for(int i = 0; i < n; ++i) {
      cin >> x;
      point.push_back(x);
    }

    sort(point.begin(),point.end());
    reverse(point.begin(),point.end());

    t = point[0];

    for(int i = 1; i < n; ++i) {
      k = point[i];
      if(i == 1){
        ans = t - k;
      }
      else {
        a = t - k;
        if(ans > a){
          ans = a;
        }
      }
      t = k;
    }

    cout << ans << endl;
  }

  return 0;
}

C++: #include<stdio.h>

int main(void){
 int n,a[1001],i,j,b,c,min;

 while(1){
  scanf_s("%d",&n);
  min=1000000;

  if(n==0){
   break;
  }
  for(i=0;i<n;i++){
   scanf_s("%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 <cstdlib>
using namespace std;

int main()
{
  while(true){
    int n;
    cin >> n;

    if(n==0)
      break;

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

    int dif = 1000001;

    for(int i=0; i<n-1; i++){
      for(int j=i+1; j<n; j++){
	int d = abs(a[i]-a[j]);

	if(d<dif){
	  dif = d;
	}
      }
    }

    cout << dif << endl;
  }

  return 0;
}

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

using namespace std;

long main(){
	long n, tmp;
	while(cin >> n, n){
		vector<long> polong;
		long min = 1000001;
		long res;
		for(long i=0;i<n;i++){
			cin >> tmp;
			polong.push_back(tmp);
		}
		sort(polong.begin(),polong.end(),greater<long>());

		for(long i=0;i<n;i++){
			if(polong[i] - polong[i+1] < min){
				min = polong[i] - polong[i+1];
			}
		}
		cout << min << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    while (true)
    {
        int n;
        int a[10000];
        cin >> n;
        if (n == 0)
            break;
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        sort(a, a + n);
        int ans = 10000000;
        for (int i = 1; i < n; i++)
        {
            ans = min(ans, a[i] - a[i - 1]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		ll a[n];
		for(int i=0;i<n;i++)cin>>a[i];
		int ans = 1e9;
		int t[n];
		sort(a,a+n);
		for(int i=0;i<n;i++){
			t[i]=1e9;
		}
		for(int i=0;i<n-1;i++){
			t[i] = abs(a[i]-a[i+1]);
		}
		sort(t,t+n);
		ans=t[0];
		cout<<ans<<endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;


int main()
{
    return 0;
}

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

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

C++: #include "bits/stdc++.h"
#define INF (1<<30)
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n;
	while (cin >> n, n) {
		vector<int> a(n);
		for (int i = 0; i < n;i++) cin >> a[i];
		int Ans = INF;
		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;
	}
}

C++: #include <vector>
#include <algorithm>
#include <cstdio>
int main(){
	int n;
	for(;scanf("%d",&n),n;){
		std::vector<int>v(n);
		for(int i=0;i<n;i++)scanf("%d",&v[i]);
		std::sort(v.begin(),v.end());
		int r=v[1]-v[0];
		for(int i=2;i<n;i++)r=std::min(r,v[i]-v[i-1]);
		printf("%d\n",r);
	}
}