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 <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;

#define INF 1e9

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

    while(1){
        int n;
        cin>>n;

        if(n==0)break;

        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++){
            int d=a[i+1]-a[i];
            ans=min(ans,d);
        }

        cout<<ans<<endl;

    }
    
}

C++: #include <iostream>
#include<stdio.h>
using namespace std;
int main(void){
  int i, j, tmp; 
  int number[1000]; 
  int n=0; 
  int min=1000000;
  while(1){

  scanf("%d", &n);
  if(n==0) {
      break;
  }
  for (i=0; i<n; i++){ 
    scanf("%d", &number[i]);
    }
  for (i=0; i<n-1; i++) { 
    for (j=i+1; j<n; j++) { 
        if(number[i]>number[j]){
        tmp =  number[i]; 
        number[i] = number[j]; 
        number[j] = tmp; 
        } 
    }
  }
  for(i=0;i<(n-1);i++){
      if(number[i+1]-number[i]<min){
          min=number[i+1]-number[i];
      }
  }
  cout<<min<<endl;
 }
    return 0;
}

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

using namespace std;

vector<int> ans;

int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		int a[1000];
		for(int i = 0;i < n;i++){
			cin >> a[i];
		}
		sort(a,a+n);
		int minn = 1e9;
		for(int i = 0;i < n-1;i++){
			int dif = abs(a[i] - a[i+1]);
			minn = min(minn,dif);
		}
		ans.push_back(minn);
	}
	for(int i = 0;i < ans.size();i++)cout << ans[i] << endl;
	return 0;
}

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

int main(){
	while (1){
		int n;
		vector<int> student;
		cin >> n;
		if (n == 0) break;
		for (int i = 0; i < n; i++){
			int s;
			cin >> s;
			student.push_back(s);
		}
		int ans = 10000;
		for (int i = 0; i < n; i++){
			for (int j = i + 1; j < n; j++){
				ans = min(ans, abs(student[i] - student[j]));
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
template<class T> istream& operator>>(istream &is,vector<T> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> istream& operator>>(istream &is,vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<T> &st){
  for(size_t i=0;i<st.size();++i){
    if(i==st.size()-1) os << st[i];
    else os << st[i] << " ";
  }
  return os;
}
template<class T> ostream& operator<<(ostream &os, const vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i){
    os << st[i];
    if(i!=st.size()-1) os << endl;
  }
  return os;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n,n){
    vi a(n);
    cin >> a;
    sort(ALL(a));
    int diff = INT_MAX;
    REP(i,n-1){
      mins(diff,abs(a[i]-a[i+1]));
    }
    cout << diff << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

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

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

using namespace std;

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 min_ = 1e+9;
    for (int i = 0; i < n - 1; i++) {
      min_ = min(min_, v[i + 1] - v[i]);
    }
    cout << min_ << endl;
  }
  
  return 0;
  
}

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;i++){
			
			sa=b[i+1]-b[i];
			
			if(min>sa) min=sa;
			
		}
		
		cout << min << endl;
		min=10000000;
	}
	
	return 0;
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(){
    while(1){
        int n; cin >> n;
        if(n == 0) break;
        int a[n];
        rep(i,0,n) cin >> a[i];
        sort(a,a+n);
        int ans = MOD;
        rep(i,0,n-1){
            ans = min(ans, abs(a[i]-a[i+1]));
        }
        cout << ans << "\n";
    }
	
}

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

int main(){
  int n;
  vector<int> a;
  while(cin >> n, n){
    a.clear();
    a.resize(n);
    int res = 99999999;
    for(int i=0;i<n;i++){
      cin >> a[i];
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n-1;i++){
      if(abs(a[i]-a[i+1])<res){
        res = abs(a[i]-a[i+1]);
      }
    }
    cout << res << endl;
  }
}

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;

    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 <iostream>
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;
}