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;
int n;
vector<int> a(1000);
int main () {
  while(cin >> n, n) {
    int min = INT_MAX;
    for(int i = 0; i < n; i++) cin >> a[i];
    
    for(int i = 0; i < n; i++) {
      for(int j  = 0; j < n; j++) {
	if(i != j && min > abs(a[i] - a[j])) {
	  min = abs(a[i] - a[j]);
	}
      }
    }
    cout << min << endl;
  }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
using namespace std;
#define N (1000000000+7)
typedef pair<int,int> P;
typedef long long ll;
int d[100010][3];
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
char board[1010][1010];

struct edge{
    int to,cost;
};

int a[105];


vector<edge>graph[100010];

int main(void){
    int n;
    while(true){
        cin>>n;
        if(n==0)break;
        int suma=0,sumb=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int ans=(int)abs(a[0]-a[1]);
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i==j)continue;
                if(ans>(int)abs(a[i]-a[j]))ans=(int)abs(a[i]-a[j]);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

typedef pair<int, int> P;

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int N;
    while( cin >> N, N ){
        vector<int> a( N );
        REP( i, N ) cin >> a[i];

        sort( ALL( a ) );

        int ans = INF;
        REP( i, N - 1 ){
            chmin( ans, a[i + 1] - a[i] );
        }
        cout << ans << endl;
    }
}

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

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

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

  int min = 1000000;
  for(int j=0; j<n-1; j++){
   for(int i=j+1; i<n; i++){
    if(a[j]>=a[i] && a[j]-a[i]<min){
     min = a[j]-a[i];
    }else if(a[j]<a[i] && a[i]-a[j]<min){
     min = a[i]-a[j];
    }
   }
  }

  cout << min <<endl;
 }

 return 0;
}

C++: #include<bits/stdc++.h>
 
using namespace std;
 
int main() {
  int n;
  while( cin >> n, n ) {
    vector<int> vec(n);
    for(int i=0;i<n;++i) cin >> vec[i];
    sort(vec.begin(),vec.end());
    int mini = INT_MAX;
    for(int i=0;i<n-1;++i) {
      mini = min(mini,vec[i+1]-vec[i]);
    }
    cout << mini << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <math.h>
using namespace std;

int main(){
	double n,a[1001],ans;
	while(1){
		cin >> n;
		if(n == 0)break;
		ans = 1000000;
		for(int i = 0;i < n;i++){
			cin >> a[i];
		}
		for(int i = 0;i < n;i++){
			for(int j = i+1;j < n;j++){
				ans = min(ans,sqrt(pow(a[i]-a[j],2)));
			}
		}
		cout << ans <<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  while(1){
    int n;
    int mi=1000001;
    cin >> n;
    if(n==0)break;
    vector<int>a(n,0);
    for(int i=0;i<n;i++){
      cin >> a[i];
    }
    sort(a.begin(),a.end());
    for(int i=1;i<n;i++){
      mi=min(mi,a[i]-a[i-1]);
    }
    cout << mi << endl;
  }
  return 0;
}

C++: 
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;
/*
//単一連結リストの実装
struct ListNode {
	int data;
	struct ListNode* next;
};*//*
int ListLength(struct ListNode* head) {
	struct ListNode* current = head;
	int count = 0;
	while (current != NULL) {
		count++;
		current = current -> next;
	}
	return count;
}
*/

int main()
{
	int n = 0;
	int owari = 11451414;
	int result[50010] = {};
	int sa = owari;
	int count = 0;
	while (true) {
		int dataset[50010];
		cin >> n;
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			cin >> dataset[i];
		}
		sort(dataset, dataset + n);
		sa = owari;
		for (int i = 1; i < n; i++) {
			if (abs(dataset[i] - dataset[i - 1]) < sa) {
				sa = abs(dataset[i] - dataset[i - 1]);
			}
		}
		result[count] = sa;
		count++;
	}
	for (int i = 0; i < count; i++) {
		cout << result[i] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int s[1010];
    cin >>n;
    for(int i = 0;i<n;i++)
        cin >>s[i];
    while(n >=2 &&n <= 1000)
    {
        sort(&s[0],&s[n]);
        int c;
        c = s[1]-s[0];
        if(c<0)
        {
            c= 0-c;
        }
        for(int i = 1;i<n-1;i++)
        {
            int t = s[i+1]-s[i];
            if(t<0)
        {
            t=0-t;
        }
            if(t <c)
                c = t;
        }
        cout <<c<<endl;

        cin >>n;

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

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

using namespace std;

int main(void) {
	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 res = 1000000;
		for (int i = 0; i < n-1; ++i) {
			if (a[i+1]-a[i] < res) {
				res = a[i+1]-a[i];
			}
		}
		cout << res << endl;
	}
	return 0;
}

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

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

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){
			break;
		}
		int mDistance = 1000000;
		int data[1000000] = {0};
		for(int i = 0; i < n; i++){
			int a = 0;
			cin >> a;
			if(data[a] == 1){
				mDistance = 0;
			}
			data[a] = 1;
			if(mDistance != 0){
			for(int j = 1; i + j < 1000000 && j <= mDistance; j++){
				if(data[i + j] == 1){
					mDistance = j;
					break;
				}
			}
			for(int j = 1; i - j >= 0 && j <= mDistance; j++){
				if(data[i - j] == 1){
					mDistance = j;
					break;
				}
			}
			}
		}
		cout << mDistance << endl;
	}
	return 0;
}