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>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){

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

    vector<long> a(n);
    for(int i = 0 ; i < n ; i++)   cin >> a[i];
    sort(a.begin() , a.begin() + n);

    long ans = 1000000;
    for(int i = 1 ; i < n ; i++)
      ans = min(ans , a[i] - a[i - 1]);

      cout << ans << endl;
    }

  return 0;
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int main(void){
    int n, student[1000]={}, diff, tmp_diff;
    while(1){
        cin >> n;
        if(n==0) break;
        
        diff=1000000;
        for(int i=0;i<n; i++){
            cin >> student[i];
        }
        for(int i=0; i<n-1; i++){
            for(int j=i+1; j<n; j++){
                tmp_diff=abs(student[i]-student[j]);
                if(tmp_diff < diff){
                    diff = tmp_diff;
                }
            }
        }
        cout << diff << endl;
    }
}

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

int INF = 1 << 20;
int main(){
  int n;
  while(1){
    cin >> n;
    if(n == 0) break;
    vector<int> student;
    for(int i = 0; i < n; i++){
      int tmp;
      cin >> tmp;
      student.push_back(tmp);
    }

    int ans = INF;
    for(int i = 0; i < n - 1; i++){
      for(int j = i + 1; j < n; j++){
        int sub = abs(student[i] - student[j]);
        if(sub < ans) ans = sub;
      }
    }
    cout << ans << endl;
  }
}

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

using namespace std;

using i64 = long long int;
using ui64 = unsigned long long int;

////////

int main(){
    int n;
    while(cin >> n,n){
        vector<int> a(n);
        for(auto&& x:a)cin >> x;
        sort(a.begin(),a.end());
        int f = 1145141919;
        for(int i=0;i<n-1;i++){
            f = min(a[i+1] - a[i],f);
        }
        cout << f << endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
 
int main() {
    int n;
    while (std::cin >> n && n) {
        std::vector<int> a;
        int minLength = 10000000;
 
        for (int i = 0; i < n; i++) {
            int b;
            std::cin >> b;
            a.push_back(b);
        }
 
        std::sort(a.begin(), a.end());
 

        for (int i = 0; i < a.size() - 1; i++) {
            minLength = std::min(a[i + 1] - a[i], minLength);
        }
 
        std::cout << minLength << std::endl;
    }
    return 0;
}

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;
    
    mn = 1000000;
    
    for(int i=0;i<b;i++){
      cin >> a[i];
    }
    for(int j=0;j<b+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>
#include <algorithm>
#include <vector>
using namespace std;
const int INF = 1<<30;
int main(){
  while(true){
    int n;
    cin >> n;
    if(n == 0) return 0;
    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++){
      ans = min(ans, a[i+1] - a[i]);
    }
    cout << ans << endl;
  }
}

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

int m,nmin,nmax,ans,gap;
int a[1001];
int main(){
	while(1){
		cin >>m;
		if(m==0)break;
		for(int i=0;i<m;i++){
			cin >>a[i];
		}
		sort(a,a+(m));
		gap=1000001;
		for(int i=1;i<m;i++){
			if(a[i]-a[i-1]<=gap){
				gap=a[i]-a[i-1];
			}

		}
		cout << gap<<endl;
	}
	
}

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 = 999999999;
		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>
#define MOD 1000000007LL
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int n;
int a[1001];

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		int res=a[1]-a[0];
		for(int i=1;i<n;i++){
			res=min(res,a[i]-a[i-1]);
		}
		printf("%d\n",res);
	}
	return 0;
}

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

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];
   int mn = a[0];
    for(int i=0;i<n-1-i;i++){

     if(a[i]-a[n-1-i] >= 0) mn = min(mn, a[i]-a[n-1-i]);
      
     }
     
  cout<<mn<<endl;
  
  }

 return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

#define INF 1e10

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n;
	while(cin>>n, n!=0){
		vll a(n);
		rep(i, n) cin >> a[i];
		sort(all(a));

		ll mini=INF;
		rep(i, n-1){
			mini = min(mini, a[i+1]-a[i]);
		}
		cout << mini << "\n";
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
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 <iostream>
#include <cmath>

using namespace std;

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

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

        cout << mindif << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	while(true){
		int a,b,c;
		cin >> a;
		if(a==0)
			{break;}
		int student[a]={};
		for(int n=0;n<a;n++){
			cin >> b;
			student[n]=b;
		}
		sort(student,student+a);
		c=student[0]-student[1];
		for(int m=0;a-1>m;m++){
			if(c<student[m]-student[m+1]){
				c=student[m]-student[m+1];
		}}
		printf("%d\n",c*-1);
}}