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;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int32 N;
	while(cin >> N && N){
		vector<int32> x(N);
		REP(i, N) cin >> x[i];
		int32 res = 0;
		sort(all(x));
		REP(i, n-1) res = min(res, x[i+1]-x[i]);
		cout << res << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#define SEISEKI 10000000

using namespace std;

int main() {
	while (1) {
		int n;
		int ans=SEISEKI;

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

		sort(a, a+n-1);	//昇順

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

C++: #include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main(void)
{
        int i,j,num,diff;
            
        while(1){
                int min = 1000000;
                cin >> num;
                if(num == 0){ 
                        break;
                }   
                    
                vector<int> data(num);
                for(i = 0; i < num; i++){
                        cin >> data[i];
                }   
                    
                for(i = 0; i < num - 1; i++){
                        for(j = i + 1; j < num; j++){
                                diff = abs(data[i] - data[j]);
                                if(diff <= min){
                                        min = diff;
                                }   
                        }   
                }   
                cout << min <<endl;
        }   
        return 0;
}

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

int main(){
    while(1){

    int n;

    cin>>n;

    if(n == 0) break;

    vector <int> data(n);

    for(int i=0; i<n; i++){

        cin>>data.at(i);
    }

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

    reverse(data.begin(),data.end());

    

    vector <int> gap(n);

    for(int i=0; i<n-1; i++){

        gap.at(i) = data.at(i) - data.at(i+1);

        
    }

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

    if(gap.at(0) == 0) cout<<gap.at(1)<<endl;

    else cout<<gap.at(0)<<endl;


    }

    return 0;
    
}

C++: #include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define P(s) cout << s << endl
#define PC(condition, _true, _false) if (condition) _true; else _false;
#define toInt(_char) _char - '0'

using namespace std;
//
// Created by karayuu on 2018-12-18.
//

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

        if (n == 0) break;

        int a[1001];
        FOR(i, 0, n) {
            cin >> a[i];
        }

        int dif = 999999999;

        FOR(i, 0, n) {
            FOR(j, i + 1, n) {
                dif = min(dif, abs(a[i] - a[j]));
            }
        }

        P(dif);
    }
}

C++: #include <iostream> 
#include<vector>
#include<algorithm>
using namespace std; 
int main() {
	int n;
	int cnt = 10000000;
	while (cin >> n, n != 0) {
		vector <int> vec(n);
		for (int i = 0; i < n; i++) {
			cin >> vec.at(i);
		}
		sort(vec.begin(), vec.end());
		for (int j = 0; j < n-1; j++) {
			cnt = min(cnt, vec.at(j + 1) - vec.at(j));
		}
		cout << cnt << endl;
		cnt = 10000000;
	}
}

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

int main(){
  int n,a[1000],mina;
  while(1){
    cin>>n;
    if(n==0)
      break;
    for(int i=0;i<n;i++)
      cin>>a[i];
    sort(a,a+n);
    mina=1000000;
    for(int i=0;i<n-1;i++)
      if(a[i+1]-a[i]<mina)
        mina=a[i+1]-a[i];
    cout<<mina<<endl;
  }
}

C++: // 2017/12/13 Tazoe

#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 <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int n;

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

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

using namespace std;

int main(){
  int a[1000];

  int c[1000];

  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;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 <bits/stdc++.h>

using namespace std;

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

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

using namespace std;

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

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