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 <algorithm>
using namespace std;

int n, a[1000];

int main() {

	while (true) {
		cin >> n;

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

		sort(a, a + n);

		int Min = INT32_MAX;
		for (int i = 0; i < n - 1; i++) {
			if (a[i + 1] - a[i] < Min) {
				Min = a[i + 1] - a[i];
			}
		}

		cout << Min << endl;
	}
}

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

void solve(int n){
    int t;
    vector<int> v,va;
    for(int i=0;i<n;i++){
        cin >> t;
        v.push_back(t);
    }
    sort(v.rbegin(),v.rend());
    for(auto itr=v.begin();itr!=v.end()-1;itr++){
        va.push_back(*itr-*(itr+1));
    }
    int mini=va.front();
    for(int x:va){
        mini=min(mini,x);
    }
    
    
    cout<<mini<<endl;
    
}

int main(void){
    int a;
    while(cin>>a,a){
        solve(a);
    }
    
    
    
}

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

std::vector<int> a(1000);
int main() {
    int i, n;
    while(std::cin >> n, n != 0) {
        for(i=0; i<n; ++i) {
            std::cin >> a[i];
        }
        std::sort(a.begin(), a.begin()+n);
        
        int min = INT_MAX;
        for(i=0; i<n-1; ++i) {
            min = std::min(min, a[i+1] - a[i]);
        }
        std::cout << min << std::endl;
    }
}

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

int main(){
	
	int N;
	cin >> N;
	while(N>0){
		int a[1001];
		a[1000] = 0;
		REP(i, N)cin >> a[i];
		sort(a,a+N);
		int m = 1e9;
		REP(i,N){
			m = min(m, abs(a[i+1]-a[i]));
		}
		cout << m << endl;
		cin >> N;
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;

    while (cin >> n && n) {
        VI a(n);
        REP(i,n) cin >> a[i];
        sort(a.begin(), a.end());
        int ans = 1e9;
        REP(i,n-1) ans = min(ans, a[i+1]-a[i]);
        cout << ans << endl;
    }

    return 0;
}

C++: #include <stdio.h>
#include <algorithm>
#include <limits.h>
#include <math.h>

using namespace std;

int main(void){
	int num, min, a[1000];

	while(1){
		scanf("%d", &num);
		if(!num) break;
		for(int i=0; i<num; i++){
			scanf("%d", &a[i]);
		}

		sort(a, a+num);
		min=INT_MAX;
		for(int i=0; i<num-1; i++){
			min = fmin(min, a[i+1]-a[i]);
		}

		printf("%d\n", min);
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <stdlib.h> //for exit
#include <algorithm> //for sort...etc
#include <numeric> //for accumulate
using namespace std;

int main()
{
    while(1)
    {
        int n,score=10000000;
        vector<int> a;
        cin >> n;
        if(n == 0) exit(0);
        for(int i = 0 ; i < n; i++)
        {
            int tpn;
            cin >> tpn;
            a.push_back(tpn);
        }

        for(int i = 0; i < n; i++)
        {
            for(int k = 0; k < n; k++)
            {
                int tpscore = abs(a[i] - a[k]);
                if((tpscore < score) && (i!=k))
                {
                    score = tpscore;
                }
            }
        }

        cout << score << endl;
    }
}

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

int main() {
    int n;
    while (true) {
        cin >> n;
        if (n == 0) break;
        
        vector<int> a(n), d(n-1);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        sort(a.begin(), a.end());
        for (int i = 0; i < n-1; i++) {
            d[i] = a[i+1] - a[i];
        }
        
        int ans = *min_element(d.begin(), d.end());
        cout << ans << '\n';
    }
    return 0;
}

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

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

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

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

using namespace std;

static const int INF = 1e9 + 7;

void hawawa()
{
  int n;
  while (cin >> n && n) {
    vector<int> a(n);
    for (auto&& i : a) {
      cin >> i;
    }
    sort(begin(a), end(a));
    int ans = INF;
    for (int i = 1; i < n; i++) {
      ans = min(ans, a[i] - a[i - 1]);
    }
    cout << ans << "\n";
  }
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  hawawa();
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
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];
        }
        
        sort(a,a+n);
        
        int ans = 10000000;
        for(int i=1; i<n; i++){
            ans = min(ans,a[i]-a[i-1]);
        }
        cout<<ans<<endl;
    }
    return 0;
    
}

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

int main(){
  int n,smin;
  while(true){
    smin= 10000000;
    cin >> n;
    if(n == 0) break;
    int s[n];
    for(int i = 0 ; i < n ; i++) scanf("%d",&s[i]);
    for(int i = 0; i < n-1; i++){
      for(int j = i+1; j<n; j++){
        smin = min( (abs(s[i]-s[j])) ,smin);
      }
    }
    cout << smin << endl;
  }
  return 0;
}

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

using namespace std;

const int INF=1000000;

int N;
int temp;
int ans;
vector<int> student;

int main() {
	while(true){
		//?????????
		ans=INF;
		while(student.size()>0)student.pop_back();


		cin>>N;
		if(N==0)break;

		for (int i = 0; i < N; i++) {
			cin>>temp;
			student.push_back(temp);
		}
		sort(student.begin(),student.end());
		for (int i = 0; i < N - 1; i++) {
			ans=min(ans,student[i+1]-student[i]);
			cout<<student[i]<<" ";
		}
		cout<<endl;
		cout<<ans<<endl;
	}
	return 0;
}