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 <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    long long int n;
    long long int ans=1000001;
long long int count=0;
    vector<long long int> b;
    while(cin>>n){
        if(n==0)break;
        else{
            count++;
            ans=1000;
            vector<long long int> v;

            for(int i=0;i<n;i++){
                long long int a;
                cin>>a;
                v.push_back(a);
            }

            sort(v.begin(),v.end());
            
            for(int i=0;i<n-1;i++){
                ans=min(ans,v[i+1]-v[i]);
            } 
            b.push_back(ans);
        }
    }
    
    for(int i=0;i<count;i++){
        cout<<b[i]<<endl;
    }
}

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

int main(){
  int n,a[1000],sa;
  while (1){
    cin >> n;
    if (n==0)return 0;
    for (int i=0;i<n;i++)cin >> a[i];
    sort(a,&a[n]);
    for (int i=0;i<n;i++)cout << a[i]<<endl;

    sa=1000001;
    for (int i=1;i<n;i++)
      if (abs(a[i-1]-a[i])<sa)sa=abs(a[i-1]-a[i]);
    cout << sa << endl;
  }
}

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

using namespace std;

int main(){
    while(1){
    int n=0;
    cin >> n;
    if(n==0)return 0;
    int score[n];
    int memory=0; 
    int min=100000000;
    for(int i=0; i<n; i++)cin >> score[i];
    for(int i=0; i<n; i++){
        for(int j = i+1; j<n; j++){
            memory = score[i]-score[j];
            if(memory < 0) memory *= -1;
            if(memory < min)min = memory;
        }
    }
        cout << min << endl;
    }
}

C++: using namespace std;
typedef long long ll;
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
  
int main(){
    int N;
    cin >> N;
    vector<ll> ans;
    while (N!=0)
    {
        vector<ll> a;
        a.resize(N);
        for (int i = 0; i < N; i++) cin >> a[i];
        ll thismin = 1e10;
        for (int i = 0; i < N;i++) {
            for (int n = 0; n < N; n++) {
                if (n == i) continue;
                thismin = min(thismin, abs(a[i] - a[n]));
            }
        }
        ans.push_back(thismin);
        cin >> N;
    }
    for (auto i : ans) {
        cout << i << endl;
    }
    return 0;
}

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

using namespace std;

int abnumber(int, int);

int main()
{
	int n,temp,dif=1000000;
	int a[1000];

	start:

	scanf("%d", &n);

	if (n == 0) {
		goto finish;
	}

	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 (a[i] < a[j]) {
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}

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

	n = 0;
	dif = 1000000;

	goto start;

	finish:

	return 0;
}

int abnumber(int i, int j) {
	if ((i - j) > 0) {
		return i - j;
	}
	else {
		return j - i;
	}
}

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

using namespace std;

int abs(int a,int b){

  int result;

  if(a<b)
    result=b-a;
  else
    result=a-b;
  return result;
};

int main(void){

  int n;
  int min=1000000;
  int  temp;
  
  while(cin >> n,n!=0){

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

    sort(student.begin(),student.end(),greater<int>());

    for(int i=0;i<n;i++){
      
      temp=abs(student[i],student[i+1]);

      if(min>temp)
	min=temp;
    }

    cout << min <<endl;

    min=1000000;

  }

  return 0;
  
}

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

int main(){
while(true){
 int n;
 int m=10000000;
 cin>>n;

 if(n==0)break;

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

 sort(s,s+n);

 for(int i=0;i<n-1;i++){
	if(s[i+1]-s[i]<m){
		m=s[i+1]-s[i];
	}
 }
 cout<<m<<endl;
}
 return 0;
}

C++: ///
// File:  1608.cpp
// Author: ymiyamoto
//
// Created on Fri Nov 10 22:59:44 2017
//

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int32_t main()
{
  while (true) {
    uint32_t n;
    cin >> n;
    if (n == 0) break;

    vector<uint32_t> points;
    for (uint32_t i = 0; i < n; i++) {
      uint32_t val;
      cin >> val;
      points.push_back(val);
    }

    sort(points.begin(), points.end());

    uint32_t min_diff = UINT32_MAX;
    for (uint32_t i = 0; i < points.size() - 1; i++) {
      uint32_t diff = points[i + 1] - points[i];
      min_diff = min(min_diff, diff);
    }

    cout << min_diff << 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-1]);
        int c=0;
        c = s[1]-s[0];
        if(c<0)
        {
            c= 2*(0-c);
        }
        for(int i = 1;i<n-1;i++)
        {
            int t = s[i+1]-s[i];
            if(t<0)
        {
            t= 2*(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(){
    int n;
    while(cin>>n,n){
        vector<int> V(n);
        for(auto &v:V) cin>>v;
        sort(V.begin(), V.end());
        int ans = 1e9;
        for(int i=1;i<n;i++){
            ans = min(ans, V[i]-V[i-1]);
        }
        cout<<ans<<endl;
    }

    return 0;
}

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