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>

using namespace std;

int myabs(int i){
  if(i > 0){return i;}
  else{return -i;}
}

int main(void){
  while(1){
    int n;
    cin >> n;
    if(n == 0) {return 0;}

    int a[n];

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

    int diff;
    int ans = 500000;

    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < n ; j++){
        diff = myabs(a[i] - a[j]);
        if(i != j && ans > diff){
          ans = diff;
        }
      }
    }

    cout << ans << endl;
  }
}

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

using namespace std;

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

C++: #include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

void f(int n){
  int a[1000000];

  rep(i,n){
    cin>>a[i];
  }

  sort(a,a+n);
  int ans = inf;
  rep(i,n-1){
    ans = min(ans,abs(a[i]-a[i+1]));
  }

  cout<<ans<<endl;
}


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

  return 0;
}

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

int main()
{
	int a[1000];
	int n = 1;
	
	while (cin >> n) {
		int ans = 100000;
		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]);
			}
		}
			cout << ans << endl;

	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
  int p=100000000;
  for(int i=0;i<n-1;i++)p=min(p,a[i+1]-a[i]);
    cout<<p<<endl;
}

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

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 sa;
			int ans = INT_MAX;
			for(int i=1;i<n;i++){
					sa  = a[i] - a[i-1];
					if(ans > sa){
							ans = sa;
					}
			}
			cout << ans << endl;
	}
}

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

int n;
int as[11451419];

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;

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

    int ans = 1145141919;
    for (int i=0; i<n-1; i++) {
      ans = min(ans, abs(as[i]-as[i+1]));
    }
    printf("%d\n", ans);
  }
}

C++: #include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        int n; cin >> n;
        if(n == 0) return 0;
        else{
            vector<int> score(n);
            REP(i, n) cin >> score[i];
            whole(sort, score);
            int ans = INF;
            REP(i, n - 1) ans = min(ans, score[i + 1] - score[i]);
            cout << ans << endl;
        }
    }
}

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

	long long int n;


	while(cin>>n){
		vector<long long int> v;
		if(n==0)break;
		long long int ans=10000001;

		for(int i=0;i<n;i++){
			long long int a;
			cin>>a;
			v.push_back(a); 
		}

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

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

		cout<<ans<<endl;


	}
}

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

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 = a[n - 1] - a[0];
        for (int i = 0; i < n - 1; ++i)
            for (int j = i + 1; j < n; ++j)
                ans = min(ans, abs(a[j] - a[i]));

        cout << ans << '\n';
    }

    return 0;
}

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

int main() {

    int n;
    while (cin >> n, n) {
        vector<int> a(n);
        rep(i, n) cin >> a[i];

        sort(a.begin(), a.end());
        ll ans = 1e8;
        for (int i=0; i<n-1; ++i) {
            ans = min(ans, (ll)abs(a[i] - a[i+1]));
        }

        cout << ans << endl;
    }
}

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

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

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

int main()
{

	int n = 1;
	
	while (cin >> n) {
		if (n == 0)
			break;
		int a[1000];
		for (int i = 0;i < n;i++) {
			cin >> a[i];
		}
                
                int ans = 100000;
		
                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]);
			}
		}
	        cout << ans << endl;

	}
	return 0;
}

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

int main()
{
	int a[1000];
	int n = 1;
	int ans = 100000;
	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 <vector>
#include <cstdlib>
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;
}