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

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	for(int n; cin >> n && n;) {
		vector<int> a(n);
		for(auto &e : a) cin >> e;
		sort(begin(a), end(a));

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

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

int main() {
	
	int a,min=10000000,sa,i;
	
	while(1){
		cin >> a;
		
		if(a==0) break;
		
		int b[a];
		
		for(i=0;i<a;i++){
			cin >> b[i];
		}
		
		sort(b,b+a);
		
		for(i=0;i<a-1;i++){
			
			sa=b[i+1]-b[i];
			
			if(min>sa) min=sa;
			
		}
		
		cout << min << endl;
		min=10000000;
	}
	
	return 0;
}

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

const int INF = 1 << 30;

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

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

int main(){
    int N;
    while(cin >> N, N){
        vector<int> vec(N);
        for(auto &v: vec)
            cin >> v;
        sort(vec.begin(), vec.end());
        int diff = 1e7;
        for(int i=1; i<N; i++){
            diff = min(diff, vec[i]-vec[i-1]);
        }
        cout << diff << endl;
    }
    return 0;
}

C++: #include <stdio.h>
int main()
{
	int n, a[1000], i, j, v, gap, ans;
for(;;){
	scanf("%d", &n);
if(n==0) break;
else{
	for (i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	for (i = 2; i <= n; i++) {
		j = i - 1;
		while (j >= 1 && a[j] > a[j + 1]) {
			v = a[j + 1];
			a[j + 1] = a[j];
			a[j] = v;
			j--;
		}
	}
	ans = 1000000;
	for (i = 1; i <= n - 1; i++) {
		gap = a[i + 1] - a[i];
		if (ans>gap) ans = gap;
	}

	printf("%d\n", ans);}}
	return 0;
}

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

int main()
{
	int a[1000];
	int n = 1;
	int ans = 0;
	while (cin >> n) {
		if (n == 0)
			break;
		for (int i = 0;i < n;i++) {
			cin >> a[i];
		}
		for (int i = 0;i < n - 1;i++) {
			for (int j = i + 1;j < n;j++) {
				if (ans > abs(a[i] - a[j]))
					ans = abs(a[i] - a[j]);
			}
		}
		if (ans >= 0)
			cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	for (int u = 0; u < 50; u++)
	{
		long n,a[1001];

		cin >> n;
		if (n == 0)
		{
			break;
		}

		long p = 1000001;

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

		sort(a,a + n);

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

		cout << p << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
using namespace std;

int main() {
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	//cout << fixed << setprecision(10);
	long long int  n, m, a[2000], b, c, d, k, h, w, left = 1, right = 0;
	long long int sc, sr, num2, no[1005][1005] = {}, res = 999999999, count = 0, now = 0, mi = 9999999999;

	string str, t;

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

		cin >> n;
	}
	
}

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

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

C++: #include <iostream>
#include <cstdlib>
using namespace std;
int main(){
  int n;
  cin >> n;
  long long int a[n];
  for(int i = 0; i < n; ++i){
    cin >> a[i];
  }

  long long int ans = 1000001;

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

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

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

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define debug(var) do{cout << #var << " : "; print(var); } while(0)
using namespace std;
typedef long long ll;
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); }
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }
const int INF = 1e9;
const int MOD = 1e9+7;

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

	while (true) {
		int n; cin >> n;
		if (!n) break;

		vector<int> vec(n);
		rep(i, n) cin >> vec[i];
		sort(all(vec));

		int ans = INF;
		rep(i, n-1) ans = min(ans, vec[i+1]-vec[i]);

		cout << ans << endl;
	}
}

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

vector<int> ans;

int main(){
  int n;

  while(cin >> n,n){
    vector<int> val;
    int ans_t=1000;
    for(int i=0; i<n; ++i){
      int tmp;
      cin >> tmp;
      val.push_back(tmp);
    }
    sort(val.begin(),val.end(),greater<int>());
    for(int i=0; i<n-1; ++i){
      int tmp = val[i]-val[i+1];
      if(ans_t > tmp){
	ans_t = tmp;
      }
    }
    ans_t =abs(ans_t);
    ans.push_back(ans_t);
  }

  for(auto i:ans){
    cout << i << endl;
  }
  return 0;
}

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

vector<int> ans;

int main(){
  int n;

  while(cin >> n,n){
    vector<int> val;
    int ans_t=1000001;
    for(int i=0; i<n; ++i){
      int tmp;
      cin >> tmp;
      val.push_back(tmp);
    }
    sort(val.begin(),val.end(),greater<int>());
    for(int i=0; i<n-1; ++i){
      int tmp = val[i]-val[i+1];
      if(ans_t > tmp){
	ans_t = tmp;
      }
    }
    ans_t =abs(ans_t);
    ans.push_back(ans_t);
  }

  for(auto i:ans){
    cout << i << endl;
  }
  return 0;
}