WeixiangYan/CodeTransOcean huggingface dataset:
Task: Palindrome detection




Go: 
var str;
str = argument0

str = string_lettersdigits(string_lower(string_replace(str,' ','')));
var inv;
inv = '';

var i;
for (i = 0; i < string_length(str); i += 1;)
    {
    inv += string_copy(str,string_length(str)-i,1);
    }

return (str == inv);



PHP: <?php
function is_palindrome($string) {
  return $string == strrev($string);
}
?>
Task: Palindrome detection





Java: public static boolean pali(String testMe){
	StringBuilder sb = new StringBuilder(testMe);
	return testMe.equals(sb.reverse().toString());
}


PHP: <?php
function is_palindrome($string) {
  return $string == strrev($string);
}
?>
Task: Palindrome detection






PHP: <?php
function is_palindrome($string) {
  return $string == strrev($string);
}
?>


Python: def is_palindrome(s):
  return s == s[::-1]
Task: Palindrome detection






PHP: <?php
function is_palindrome($string) {
  return $string == strrev($string);
}
?>



VB: function Squish( s1 )
	dim sRes
	sRes = vbNullString
	dim i, c
	for i = 1 to len( s1 )
		c = lcase( mid( s1, i, 1 ))
		if instr( "abcdefghijklmnopqrstuvwxyz0123456789", c ) then
			sRes = sRes & c
		end if
	next
	Squish = sRes
end function
		
function isPalindrome( s1 )
	dim squished
	squished = Squish( s1 )
	isPalindrome = ( squished = StrReverse( squished ) )
end function
Task: Cuban primes


C++: #include <iostream> 
#include <vector> 
#include <chrono>
#include <climits>
#include <cmath>

using namespace std;

vector <long long> primes{ 3, 5 };

int main()
{
	cout.imbue(locale(""));
	const int cutOff = 200, bigUn = 100000,
	          chunks = 50, little = bigUn / chunks;
    const char tn[] = " cuban prime";
	cout << "The first " << cutOff << tn << "s:" << endl;
	int c = 0;
	bool showEach = true;
	long long u = 0, v = 1;
	auto st = chrono::system_clock::now();

	for (long long i = 1; i <= LLONG_MAX; i++)
	{
		bool found = false;
		long long mx = (long long)(ceil(sqrt(v += (u += 6))));
		for (long long item : primes)
		{
			if (item > mx) break;
			if (v % item == 0) { found = true; break; }
		}
		if (!found)
		{
			c += 1; if (showEach)
			{
				for (long long z = primes.back() + 2; z <= v - 2; z += 2)
				{
					bool fnd = false;
					for (long long item : primes)
					{
						if (item > mx) break;
						if (z % item == 0) { fnd = true; break; }
					}
					if (!fnd) primes.push_back(z);
				}
				primes.push_back(v); cout.width(11); cout << v;
				if (c % 10 == 0) cout << endl;
				if (c == cutOff)
				{
					showEach = false;
					cout << "\nProgress to the " << bigUn << "th" << tn << ": ";
				}
			}
			if (c % little == 0) { cout << "."; if (c == bigUn) break; }
		}
	}
	cout << "\nThe " << c << "th" << tn << " is " << v;
	chrono::duration<double> elapsed_seconds = chrono::system_clock::now() - st;
	cout << "\nComputation time was " << elapsed_seconds.count() << " seconds" << endl;
	return 0;
}



Go: package main

import (
    "fmt"
    "math/big"
)

func commatize(n uint64) string {
    s := fmt.Sprintf("%d", n)
    le := len(s)
    for i := le - 3; i >= 1; i -= 3 {
        s = s[0:i] + "," + s[i:]
    }
    return s
}

func main() {
    var z big.Int
    var cube1, cube2, cube100k, diff uint64
    cubans := make([]string, 200)
    cube1 = 1
    count := 0
    for i := 1; ; i++ {
        j := i + 1
        cube2 = uint64(j * j * j)
        diff = cube2 - cube1
        z.SetUint64(diff)
        if z.ProbablyPrime(0) { 
            if count < 200 {
                cubans[count] = commatize(diff)
            }
            count++
            if count == 100000 {
                cube100k = diff
                break
            }
        }
        cube1 = cube2
    }
    fmt.Println("The first 200 cuban primes are:-")
    for i := 0; i < 20; i++ {
        j := i * 10 
        fmt.Printf("%9s\n", cubans[j : j+10]) 
    }
    fmt.Println("\nThe 100,000th cuban prime is", commatize(cube100k))
}
Task: Cuban primes


C++: #include <iostream> 
#include <vector> 
#include <chrono>
#include <climits>
#include <cmath>

using namespace std;

vector <long long> primes{ 3, 5 };

int main()
{
	cout.imbue(locale(""));
	const int cutOff = 200, bigUn = 100000,
	          chunks = 50, little = bigUn / chunks;
    const char tn[] = " cuban prime";
	cout << "The first " << cutOff << tn << "s:" << endl;
	int c = 0;
	bool showEach = true;
	long long u = 0, v = 1;
	auto st = chrono::system_clock::now();

	for (long long i = 1; i <= LLONG_MAX; i++)
	{
		bool found = false;
		long long mx = (long long)(ceil(sqrt(v += (u += 6))));
		for (long long item : primes)
		{
			if (item > mx) break;
			if (v % item == 0) { found = true; break; }
		}
		if (!found)
		{
			c += 1; if (showEach)
			{
				for (long long z = primes.back() + 2; z <= v - 2; z += 2)
				{
					bool fnd = false;
					for (long long item : primes)
					{
						if (item > mx) break;
						if (z % item == 0) { fnd = true; break; }
					}
					if (!fnd) primes.push_back(z);
				}
				primes.push_back(v); cout.width(11); cout << v;
				if (c % 10 == 0) cout << endl;
				if (c == cutOff)
				{
					showEach = false;
					cout << "\nProgress to the " << bigUn << "th" << tn << ": ";
				}
			}
			if (c % little == 0) { cout << "."; if (c == bigUn) break; }
		}
	}
	cout << "\nThe " << c << "th" << tn << " is " << v;
	chrono::duration<double> elapsed_seconds = chrono::system_clock::now() - st;
	cout << "\nComputation time was " << elapsed_seconds.count() << " seconds" << endl;
	return 0;
}






Python: import datetime
import math

primes = [ 3, 5 ]

cutOff = 200

bigUn =  100_000
chunks = 50
little = bigUn / chunks

tn = " cuban prime"
print ("The first {:,}{}s:".format(cutOff, tn))

c = 0
showEach = True
u = 0
v = 1
st = datetime.datetime.now()

for i in range(1, int(math.pow(2,20))):
	found = False
	u += 6
	v += u
	mx = int(math.sqrt(v))
	
	for item in primes:
		if (item > mx):
			break
		if (v % item == 0):
			found = True
			break
	
	if (found == 0):
		c += 1
		if (showEach):
			z = primes[-1]
			while (z <= v - 2):
				z += 2
				
				fnd = False
				for item in primes:
					if (item > mx):
						break
					if (z % item == 0):
						fnd = True
						break
				
				if (not fnd):
					primes.append(z)
			
			primes.append(v)
			print("{:>11,}".format(v), end='')
			
			if (c % 10 == 0):
				print("");
			if (c == cutOff):
				showEach = False
				print ("Progress to the {:,}th {}:".format(bigUn, tn), end='')
		if (c % little == 0):
			print('.', end='')
		if (c == bigUn):
			break

print("");
print ("The {:,}th{} is {:,}".format(c, tn, v))
print("Computation time was {} seconds".format((datetime.datetime.now() - st).seconds))
Task: Cuban primes



C#: using System;
using System.Collections.Generic;
using System.Linq;

static class Program
{
    static List<long> primes = new List<long>() { 3, 5 };

     static void Main(string[] args)
    {
        const int cutOff = 200;
        const int bigUn = 100000;
        const int chunks = 50;
        const int little = bigUn / chunks;
        const string tn = " cuban prime";
        Console.WriteLine("The first {0:n0}{1}s:", cutOff, tn);
        int c = 0;
        bool showEach = true;
        long u = 0, v = 1;
        DateTime st = DateTime.Now;
        for (long i = 1; i <= long.MaxValue; i++)
        {
            bool found = false;
            int mx = System.Convert.ToInt32(Math.Ceiling(Math.Sqrt(v += (u += 6))));
            foreach (long item in primes)
            {
                if (item > mx) break;
                if (v % item == 0) { found = true; break; }
            }
            if (!found)
            {
                c += 1; if (showEach)
                {
                    for (var z = primes.Last() + 2; z <= v - 2; z += 2)
                    {
                        bool fnd = false;
                        foreach (long item in primes)
                        {
                            if (item > mx) break;
                            if (z % item == 0) { fnd = true; break; }
                        }
                        if (!fnd) primes.Add(z);
                    }
                    primes.Add(v); Console.Write("{0,11:n0}", v);
                    if (c % 10 == 0) Console.WriteLine();
                    if (c == cutOff)
                    {
                        showEach = false;
                        Console.Write("\nProgress to the {0:n0}th{1}: ", bigUn, tn);
                    }
                }
                if (c % little == 0) { Console.Write("."); if (c == bigUn) break; }
            }
        }
        Console.WriteLine("\nThe {1:n0}th{2} is {0,17:n0}", v, c, tn);
        Console.WriteLine("Computation time was {0} seconds", (DateTime.Now - st).TotalSeconds);
        if (System.Diagnostics.Debugger.IsAttached) Console.ReadKey();
    }
}


Go: package main

import (
    "fmt"
    "math/big"
)

func commatize(n uint64) string {
    s := fmt.Sprintf("%d", n)
    le := len(s)
    for i := le - 3; i >= 1; i -= 3 {
        s = s[0:i] + "," + s[i:]
    }
    return s
}

func main() {
    var z big.Int
    var cube1, cube2, cube100k, diff uint64
    cubans := make([]string, 200)
    cube1 = 1
    count := 0
    for i := 1; ; i++ {
        j := i + 1
        cube2 = uint64(j * j * j)
        diff = cube2 - cube1
        z.SetUint64(diff)
        if z.ProbablyPrime(0) { 
            if count < 200 {
                cubans[count] = commatize(diff)
            }
            count++
            if count == 100000 {
                cube100k = diff
                break
            }
        }
        cube1 = cube2
    }
    fmt.Println("The first 200 cuban primes are:-")
    for i := 0; i < 20; i++ {
        j := i * 10 
        fmt.Printf("%9s\n", cubans[j : j+10]) 
    }
    fmt.Println("\nThe 100,000th cuban prime is", commatize(cube100k))
}
Task: Cuban primes


C++: #include <iostream> 
#include <vector> 
#include <chrono>
#include <climits>
#include <cmath>

using namespace std;

vector <long long> primes{ 3, 5 };

int main()
{
	cout.imbue(locale(""));
	const int cutOff = 200, bigUn = 100000,
	          chunks = 50, little = bigUn / chunks;
    const char tn[] = " cuban prime";
	cout << "The first " << cutOff << tn << "s:" << endl;
	int c = 0;
	bool showEach = true;
	long long u = 0, v = 1;
	auto st = chrono::system_clock::now();

	for (long long i = 1; i <= LLONG_MAX; i++)
	{
		bool found = false;
		long long mx = (long long)(ceil(sqrt(v += (u += 6))));
		for (long long item : primes)
		{
			if (item > mx) break;
			if (v % item == 0) { found = true; break; }
		}
		if (!found)
		{
			c += 1; if (showEach)
			{
				for (long long z = primes.back() + 2; z <= v - 2; z += 2)
				{
					bool fnd = false;
					for (long long item : primes)
					{
						if (item > mx) break;
						if (z % item == 0) { fnd = true; break; }
					}
					if (!fnd) primes.push_back(z);
				}
				primes.push_back(v); cout.width(11); cout << v;
				if (c % 10 == 0) cout << endl;
				if (c == cutOff)
				{
					showEach = false;
					cout << "\nProgress to the " << bigUn << "th" << tn << ": ";
				}
			}
			if (c % little == 0) { cout << "."; if (c == bigUn) break; }
		}
	}
	cout << "\nThe " << c << "th" << tn << " is " << v;
	chrono::duration<double> elapsed_seconds = chrono::system_clock::now() - st;
	cout << "\nComputation time was " << elapsed_seconds.count() << " seconds" << endl;
	return 0;
}




Java: public class CubanPrimes {

    private static int MAX = 1_400_000;
    private static boolean[] primes = new boolean[MAX];
    
    public static void main(String[] args) {
        preCompute();
        cubanPrime(200, true);
        for ( int i = 1 ; i <= 5 ; i++ ) {
            int max = (int) Math.pow(10, i);
            System.out.printf("%,d-th cuban prime = %,d%n", max, cubanPrime(max, false));
        }
    }
    
    private static long cubanPrime(int n, boolean display) {
        int count = 0;
        long result = 0;
        for ( long i = 0 ; count < n ; i++ ) {
            long test = 1l + 3 * i * (i+1);
            if ( isPrime(test) ) {
                count++;
                result = test;
                if ( display ) {
                    System.out.printf("%10s%s", String.format("%,d", test), count % 10 == 0 ? "\n" : "");
                }
            }
        }
        return result;
    }
    
    private static boolean isPrime(long n) {
        if ( n < MAX ) {
            return primes[(int)n];
        }
        int max = (int) Math.sqrt(n);
        for ( int i = 3 ; i <= max ; i++ ) {
            if ( primes[i] && n % i == 0 ) {
                return false;
            }
        }
        return true;
    }

    private static final void preCompute() {
        
        for ( int i = 2 ; i < MAX ; i++ ) {
            primes[i] = true;            
        }
        for ( int i = 2 ; i < MAX ; i++ ) {
            if ( primes[i] ) {
                for ( int j = 2*i ; j < MAX ; j += i ) {
                    primes[j] = false;
                }
            }
        }
    }
}
Task: Cuban primes




Go: package main

import (
    "fmt"
    "math/big"
)

func commatize(n uint64) string {
    s := fmt.Sprintf("%d", n)
    le := len(s)
    for i := le - 3; i >= 1; i -= 3 {
        s = s[0:i] + "," + s[i:]
    }
    return s
}

func main() {
    var z big.Int
    var cube1, cube2, cube100k, diff uint64
    cubans := make([]string, 200)
    cube1 = 1
    count := 0
    for i := 1; ; i++ {
        j := i + 1
        cube2 = uint64(j * j * j)
        diff = cube2 - cube1
        z.SetUint64(diff)
        if z.ProbablyPrime(0) { 
            if count < 200 {
                cubans[count] = commatize(diff)
            }
            count++
            if count == 100000 {
                cube100k = diff
                break
            }
        }
        cube1 = cube2
    }
    fmt.Println("The first 200 cuban primes are:-")
    for i := 0; i < 20; i++ {
        j := i * 10 
        fmt.Printf("%9s\n", cubans[j : j+10]) 
    }
    fmt.Println("\nThe 100,000th cuban prime is", commatize(cube100k))
}


Java: public class CubanPrimes {

    private static int MAX = 1_400_000;
    private static boolean[] primes = new boolean[MAX];
    
    public static void main(String[] args) {
        preCompute();
        cubanPrime(200, true);
        for ( int i = 1 ; i <= 5 ; i++ ) {
            int max = (int) Math.pow(10, i);
            System.out.printf("%,d-th cuban prime = %,d%n", max, cubanPrime(max, false));
        }
    }
    
    private static long cubanPrime(int n, boolean display) {
        int count = 0;
        long result = 0;
        for ( long i = 0 ; count < n ; i++ ) {
            long test = 1l + 3 * i * (i+1);
            if ( isPrime(test) ) {
                count++;
                result = test;
                if ( display ) {
                    System.out.printf("%10s%s", String.format("%,d", test), count % 10 == 0 ? "\n" : "");
                }
            }
        }
        return result;
    }
    
    private static boolean isPrime(long n) {
        if ( n < MAX ) {
            return primes[(int)n];
        }
        int max = (int) Math.sqrt(n);
        for ( int i = 3 ; i <= max ; i++ ) {
            if ( primes[i] && n % i == 0 ) {
                return false;
            }
        }
        return true;
    }

    private static final void preCompute() {
        
        for ( int i = 2 ; i < MAX ; i++ ) {
            primes[i] = true;            
        }
        for ( int i = 2 ; i < MAX ; i++ ) {
            if ( primes[i] ) {
                for ( int j = 2*i ; j < MAX ; j += i ) {
                    primes[j] = false;
                }
            }
        }
    }
}
Task: Cuban primes





Java: public class CubanPrimes {

    private static int MAX = 1_400_000;
    private static boolean[] primes = new boolean[MAX];
    
    public static void main(String[] args) {
        preCompute();
        cubanPrime(200, true);
        for ( int i = 1 ; i <= 5 ; i++ ) {
            int max = (int) Math.pow(10, i);
            System.out.printf("%,d-th cuban prime = %,d%n", max, cubanPrime(max, false));
        }
    }
    
    private static long cubanPrime(int n, boolean display) {
        int count = 0;
        long result = 0;
        for ( long i = 0 ; count < n ; i++ ) {
            long test = 1l + 3 * i * (i+1);
            if ( isPrime(test) ) {
                count++;
                result = test;
                if ( display ) {
                    System.out.printf("%10s%s", String.format("%,d", test), count % 10 == 0 ? "\n" : "");
                }
            }
        }
        return result;
    }
    
    private static boolean isPrime(long n) {
        if ( n < MAX ) {
            return primes[(int)n];
        }
        int max = (int) Math.sqrt(n);
        for ( int i = 3 ; i <= max ; i++ ) {
            if ( primes[i] && n % i == 0 ) {
                return false;
            }
        }
        return true;
    }

    private static final void preCompute() {
        
        for ( int i = 2 ; i < MAX ; i++ ) {
            primes[i] = true;            
        }
        for ( int i = 2 ; i < MAX ; i++ ) {
            if ( primes[i] ) {
                for ( int j = 2*i ; j < MAX ; j += i ) {
                    primes[j] = false;
                }
            }
        }
    }
}



Python: import datetime
import math

primes = [ 3, 5 ]

cutOff = 200

bigUn =  100_000
chunks = 50
little = bigUn / chunks

tn = " cuban prime"
print ("The first {:,}{}s:".format(cutOff, tn))

c = 0
showEach = True
u = 0
v = 1
st = datetime.datetime.now()

for i in range(1, int(math.pow(2,20))):
	found = False
	u += 6
	v += u
	mx = int(math.sqrt(v))
	
	for item in primes:
		if (item > mx):
			break
		if (v % item == 0):
			found = True
			break
	
	if (found == 0):
		c += 1
		if (showEach):
			z = primes[-1]
			while (z <= v - 2):
				z += 2
				
				fnd = False
				for item in primes:
					if (item > mx):
						break
					if (z % item == 0):
						fnd = True
						break
				
				if (not fnd):
					primes.append(z)
			
			primes.append(v)
			print("{:>11,}".format(v), end='')
			
			if (c % 10 == 0):
				print("");
			if (c == cutOff):
				showEach = False
				print ("Progress to the {:,}th {}:".format(bigUn, tn), end='')
		if (c % little == 0):
			print('.', end='')
		if (c == bigUn):
			break

print("");
print ("The {:,}th{} is {:,}".format(c, tn, v))
print("Computation time was {} seconds".format((datetime.datetime.now() - st).seconds))
Task: Cuban primes




Go: package main

import (
    "fmt"
    "math/big"
)

func commatize(n uint64) string {
    s := fmt.Sprintf("%d", n)
    le := len(s)
    for i := le - 3; i >= 1; i -= 3 {
        s = s[0:i] + "," + s[i:]
    }
    return s
}

func main() {
    var z big.Int
    var cube1, cube2, cube100k, diff uint64
    cubans := make([]string, 200)
    cube1 = 1
    count := 0
    for i := 1; ; i++ {
        j := i + 1
        cube2 = uint64(j * j * j)
        diff = cube2 - cube1
        z.SetUint64(diff)
        if z.ProbablyPrime(0) { 
            if count < 200 {
                cubans[count] = commatize(diff)
            }
            count++
            if count == 100000 {
                cube100k = diff
                break
            }
        }
        cube1 = cube2
    }
    fmt.Println("The first 200 cuban primes are:-")
    for i := 0; i < 20; i++ {
        j := i * 10 
        fmt.Printf("%9s\n", cubans[j : j+10]) 
    }
    fmt.Println("\nThe 100,000th cuban prime is", commatize(cube100k))
}




Python: import datetime
import math

primes = [ 3, 5 ]

cutOff = 200

bigUn =  100_000
chunks = 50
little = bigUn / chunks

tn = " cuban prime"
print ("The first {:,}{}s:".format(cutOff, tn))

c = 0
showEach = True
u = 0
v = 1
st = datetime.datetime.now()

for i in range(1, int(math.pow(2,20))):
	found = False
	u += 6
	v += u
	mx = int(math.sqrt(v))
	
	for item in primes:
		if (item > mx):
			break
		if (v % item == 0):
			found = True
			break
	
	if (found == 0):
		c += 1
		if (showEach):
			z = primes[-1]
			while (z <= v - 2):
				z += 2
				
				fnd = False
				for item in primes:
					if (item > mx):
						break
					if (z % item == 0):
						fnd = True
						break
				
				if (not fnd):
					primes.append(z)
			
			primes.append(v)
			print("{:>11,}".format(v), end='')
			
			if (c % 10 == 0):
				print("");
			if (c == cutOff):
				showEach = False
				print ("Progress to the {:,}th {}:".format(bigUn, tn), end='')
		if (c % little == 0):
			print('.', end='')
		if (c == bigUn):
			break

print("");
print ("The {:,}th{} is {:,}".format(c, tn, v))
print("Computation time was {} seconds".format((datetime.datetime.now() - st).seconds))
Task: Bitcoin_address validation

C: #include <stdio.h>
#include <string.h>
#include <openssl/sha.h>

const char *coin_err;
#define bail(s) { coin_err = s; return 0; }

int unbase58(const char *s, unsigned char *out) {
	static const char *tmpl = "123456789"
		"ABCDEFGHJKLMNPQRSTUVWXYZ"
		"abcdefghijkmnopqrstuvwxyz";
	int i, j, c;
	const char *p;

	memset(out, 0, 25);
	for (i = 0; s[i]; i++) {
		if (!(p = strchr(tmpl, s[i])))
			bail("bad char");

		c = p - tmpl;
		for (j = 25; j--; ) {
			c += 58 * out[j];
			out[j] = c % 256;
			c /= 256;
		}

		if (c) bail("address too long");
	}

	return 1;
}

int valid(const char *s) {
	unsigned char dec[32], d1[SHA256_DIGEST_LENGTH], d2[SHA256_DIGEST_LENGTH];

	coin_err = "";
	if (!unbase58(s, dec)) return 0;

	SHA256(SHA256(dec, 21, d1), SHA256_DIGEST_LENGTH, d2);

	if (memcmp(dec + 21, d2, 4))
		bail("bad digest");

	return 1;
}

int main (void) {
	const char *s[] = {
		"1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9",
		"1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i",
		"1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nJ9",
		"1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62I",
		0 };
	int i;
	for (i = 0; s[i]; i++) {
		int status = valid(s[i]);
		printf("%s: %s\n", s[i], status ? "Ok" : coin_err);
	}

	return 0;
}




Go: package main

import (
    "bytes"
    "crypto/sha256"
    "errors"
    "os"
)









type A25 [25]byte
    
func (a *A25) Version() byte {
    return a[0]
}
    
func (a *A25) EmbeddedChecksum() (c [4]byte) {
    copy(c[:], a[21:])
    return
}





func (a *A25) doubleSHA256() []byte {
    h := sha256.New()
    h.Write(a[:21])
    d := h.Sum([]byte{})
    h = sha256.New()
    h.Write(d)
    return h.Sum(d[:0])
}



func (a *A25) ComputeChecksum() (c [4]byte) {
    copy(c[:], a.doubleSHA256())
    return
} 



var tmpl = []byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")





func (a *A25) Set58(s []byte) error {
    for _, s1 := range s {
        c := bytes.IndexByte(tmpl, s1)
        if c < 0 {
            return errors.New("bad char")
        }
        for j := 24; j >= 0; j-- {
            c += 58 * int(a[j])
            a[j] = byte(c % 256)
            c /= 256
        }
        if c > 0 {
            return errors.New("too long")
        }
    }
    return nil
}






func ValidA58(a58 []byte) (ok bool, err error) {
    var a A25
    if err := a.Set58(a58); err != nil {
        return false, err
    }
    if a.Version() != 0 {
        return false, errors.New("not version 0")
    }
    return a.EmbeddedChecksum() == a.ComputeChecksum(), nil
}



func main() {
    if len(os.Args) != 2 {
        errorExit("Usage: valid <base58 address>")
    }
    switch ok, err := ValidA58([]byte(os.Args[1])); {
    case ok:
    case err == nil:
        errorExit("Invalid")
    default:
        errorExit(err.Error())
    }
}

func errorExit(m string) {
    os.Stderr.WriteString(m + "\n")
    os.Exit(1)
}