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 rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

void print_vec(vector<int> vec) {
  cout << "[";
  for (int i = 0; i < vec.size(); i++) {
    if (i) {
      cout << ", ";
    }
    cout << vec.at(i);
  }
  cout << "]...size: " << vec.size() << endl;
}

int main() {
  vector<int> abses;

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

    vector<int> vec(n);
    rep(i, n) { cin >> vec.at(i); }
    int min_abs = 1001001001;

    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        int current_abs = abs(vec.at(i) - vec.at(j));
        min_abs = min(min_abs, current_abs);
      }
    }

    abses.push_back(min_abs);
  }

  for (auto &&i : abses) {
    printf("%d\n", i);
  }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#define SEISEKI 1000001

using namespace std;

int main() {
	while (1) {
		int n,data;
		int ans=SEISEKI;
		vector<int> a;

		cin >> n;
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> data;
			a.push_back(data);
		}
		sort(a.begin(), a.end());	//昇順
		for (int i = 0; i< n; i++) {
			ans = min(ans,a[i]-a[i - 1]);
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main(){
  int n;
  while(1){
    cin >> n;
    if(n==0)break;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    sort(a.begin(),a.end(),greater<int>());
    int mini=10000000;
    rep(i,n-1){
      mini = min(mini,a[i]-a[i+1]);
      if(mini==0)break;
    }
    cout << mini << endl;
  }
  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<algorithm>
using namespace std;
int main(){
  while(1){
    int n,a[1001],min=10000000;
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(int i=1;i<n;i++){
      int b=a[i]-a[i-1];
      if(b<min)min=b;
    }
    cout<<min<<endl;
  }
  return 0;
}

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

int main() {
    int n;
    while (1) {
        cin >> n;
        if (!n) return 0;
        vector<int> v(n);
        
        for (int i = 0; i < n; i++) {
            cin >> v.at(i);
        }
        
        sort(v.begin(), v.end());
        
        int diff;
        for (int i = 1; i < n; i++) {
            if (i == 1) {
                diff = v.at(i) - v.at(i-1);
            } else {
                if (diff > (v.at(i) - v.at(i-1))) {
                    diff = v.at(i) - v.at(i-1);
                }
            }
        }
        
        cout << diff << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define MAX_N 1111
int main()
{
	while(true){
		int N;
		int A[MAX_N];
		scanf("%d",&N);
		if(N==0){break;}
		for(int i=0;i<N;i++){scanf("%d",&A[i]);}
		sort(A,A+N);
		int ans=1000001;
		for(int i=0;i<N-1;i++){
			ans=min(ans,A[i+1]-A[i]);
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
    while(1){
    int n = 0;
    scanf("%d",&n);
    if(n==0)break;
    
    int a[1000] = { 0 };
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    
    long long int sa = 1000000;
    
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(a[i]>a[j]){
                if(a[i]-a[j]<sa && a[i]-a[j]>=0)sa = a[i]-a[j];
            }
            else{
                if(a[j]-a[i]<sa&& a[j]-a[i]>=0)sa = a[j]-a[i];
            }
        }
    }
    
    cout << sa << endl;
    }
    
    return 0;
}

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

int main(){
        int n, i, j;
        while(cin >> n && n != 0){
                int ans = 1e6;
                vector<int> a(n);
                for (i = 0; i < n; i++) cin >> a[i];
                for (i = 0; i < n - 1; i++){
                        for (j = i + 1; j < n; j++){
                                ans =min(ans, abs(a[i] - a[j]));
                        }
                }
                cout << ans << endl;
        }
        return 0;
}

C++: #include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

int main(int argc, char const *argv[]) {
  int n,between,temp;
  while (1) {
    scanf("%d",&n);
    if(n==0){
      return 0;
    }
    std::vector<int> a(n);
    for (size_t i = 0; i < n; i++) {
      scanf("%d",&a[i]);
    }
    sort(all(a));
  between=a[1]-a[0];
    for (size_t i = 1; i < n-1; i++) {
      temp=a[i+1]-a[i];
      if(between>temp){
        between=temp;
      }
    }
    printf("%d\n",between);
  }

  return 0;
}

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

//	データセットの終わりを処理したら0,
//	それ以外なら1を返す関数
//	問題を解く部分
int solve();

int main() 
{
	while(solve()){}
	return 0;
}

int solve() 
{
	//	入力ここから
	int n;
	cin >> n;
	if(!n) { return 0; }
	
	vector<int> a(n);
	for(int& i: a)
		cin >> i;
	//	入力ここまで
	
	//	差の絶対値の最小値を調べる
	//	全探索でO(n^2)
	
	int ans = 1000000+1;
	for(int i = 0; i < n; i++)
		for( int j = i + 1; j < n; j++)
			ans = min( abs(a[i]-a[j]), ans);
			
	//	出力
	cout << ans << endl;
	
	return 1;
}

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

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

    if(n==0)
      break;

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

    int min=1000000;

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

    cout << min << endl;
  }
}

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

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

int main(void) {
	while (1) {
		int n;
		int mini = INF;
		int a[1001] = {};

		cin >> n;
		if (n == 0) {
			break;
		}
		FOR(i, 0, n - 1) {
			cin >> a[i];
		}
		sort(a, a + n);
		FOR(i, 0, n - 2) {
			if (a[i + 1] - a[i] < mini) {
				mini = a[i + 1] - a[i];
			}
		}
		cout << mini << endl;
	}
}