WeixiangYan/CodeTransOcean huggingface dataset:
Task: Short-circuit evaluation

C: #include <stdio.h>
#include <stdbool.h>

bool a(bool in)
{
  printf("I am a\n");
  return in;
}

bool b(bool in)
{
  printf("I am b\n");
  return in;
}

#define TEST(X,Y,O)						\
  do {								\
    x = a(X) O b(Y);						\
    printf(#X " " #O " " #Y " = %s\n\n", x ? "true" : "false");	\
  } while(false);

int main()
{
  bool x;

  TEST(false, true, &&); 
  TEST(true, false, ||); 
  TEST(true, false, &&); 
  TEST(false, false, ||); 

  return 0;
}










Fortran: program Short_Circuit_Eval
  implicit none

  logical :: x, y
  logical, dimension(2) :: l = (/ .false., .true. /)
  integer :: i, j

  do i = 1, 2
    do j = 1, 2
      write(*, "(a,l1,a,l1,a)") "Calculating x = a(", l(i), ") and b(", l(j), ")"   
      
      x = a(l(i))  
      if(x) then
        x = b(l(j))
        write(*, "(a,l1)") "x = ", x
      else
        write(*, "(a,l1)") "x = ", x
      end if
  
      write(*,*)
      write(*, "(a,l1,a,l1,a)") "Calculating y = a(", l(i), ") or b(", l(j), ")"   
      
      y = a(l(i))
      if(y) then
        write(*, "(a,l1)") "y = ", y
      else
        y = b(l(j))
        write(*, "(a,l1)") "y = ", y
      end if
      write(*,*)
    end do
  end do

contains

function a(value)
  logical :: a
  logical, intent(in) :: value

  a = value
  write(*, "(a,l1,a)") "Called function a(", value, ")"
end function

function b(value)
  logical :: b
  logical, intent(in) :: value
  
  b = value
  write(*, "(a,l1,a)") "Called function b(", value, ")"
end function
end program
Task: Short-circuit evaluation





Java: module test
    {
    @Inject Console console;

    static Boolean show(String name, Boolean value)
        {
        console.print($"{name}()={value}");
        return value;
        }

    void run()
        {
        val a = show("a", _);
        val b = show("b", _);

        for (Boolean v1 : False..True)
            {
            for (Boolean v2 : False..True)
                {
                console.print($"a({v1}) && b({v2}) == {a(v1) && b(v2)}");
                console.print();
                console.print($"a({v1}) || b({v2}) == {a(v1) || b(v2)}");
                console.print();
                }
            }
        }
    }






Fortran: program Short_Circuit_Eval
  implicit none

  logical :: x, y
  logical, dimension(2) :: l = (/ .false., .true. /)
  integer :: i, j

  do i = 1, 2
    do j = 1, 2
      write(*, "(a,l1,a,l1,a)") "Calculating x = a(", l(i), ") and b(", l(j), ")"   
      
      x = a(l(i))  
      if(x) then
        x = b(l(j))
        write(*, "(a,l1)") "x = ", x
      else
        write(*, "(a,l1)") "x = ", x
      end if
  
      write(*,*)
      write(*, "(a,l1,a,l1,a)") "Calculating y = a(", l(i), ") or b(", l(j), ")"   
      
      y = a(l(i))
      if(y) then
        write(*, "(a,l1)") "y = ", y
      else
        y = b(l(j))
        write(*, "(a,l1)") "y = ", y
      end if
      write(*,*)
    end do
  end do

contains

function a(value)
  logical :: a
  logical, intent(in) :: value

  a = value
  write(*, "(a,l1,a)") "Called function a(", value, ")"
end function

function b(value)
  logical :: b
  logical, intent(in) :: value
  
  b = value
  write(*, "(a,l1,a)") "Called function b(", value, ")"
end function
end program
Task: Short-circuit evaluation







Python: >>> def a(answer):
	print("  
	return answer

>>> def b(answer):
	print("  
	return answer

>>> for i in (False, True):
	for j in (False, True):
		print ("\nCalculating: x = a(i) and b(j)")
		x = a(i) and b(j)
		print ("Calculating: y = a(i) or  b(j)")
		y = a(i) or  b(j)

		

Calculating: x = a(i) and b(j)
  
Calculating: y = a(i) or  b(j)
  
  

Calculating: x = a(i) and b(j)
  
Calculating: y = a(i) or  b(j)
  
  

Calculating: x = a(i) and b(j)
  
  
Calculating: y = a(i) or  b(j)
  

Calculating: x = a(i) and b(j)
  
  
Calculating: y = a(i) or  b(j)
  




Fortran: program Short_Circuit_Eval
  implicit none

  logical :: x, y
  logical, dimension(2) :: l = (/ .false., .true. /)
  integer :: i, j

  do i = 1, 2
    do j = 1, 2
      write(*, "(a,l1,a,l1,a)") "Calculating x = a(", l(i), ") and b(", l(j), ")"   
      
      x = a(l(i))  
      if(x) then
        x = b(l(j))
        write(*, "(a,l1)") "x = ", x
      else
        write(*, "(a,l1)") "x = ", x
      end if
  
      write(*,*)
      write(*, "(a,l1,a,l1,a)") "Calculating y = a(", l(i), ") or b(", l(j), ")"   
      
      y = a(l(i))
      if(y) then
        write(*, "(a,l1)") "y = ", y
      else
        y = b(l(j))
        write(*, "(a,l1)") "y = ", y
      end if
      write(*,*)
    end do
  end do

contains

function a(value)
  logical :: a
  logical, intent(in) :: value

  a = value
  write(*, "(a,l1,a)") "Called function a(", value, ")"
end function

function b(value)
  logical :: b
  logical, intent(in) :: value
  
  b = value
  write(*, "(a,l1,a)") "Called function b(", value, ")"
end function
end program
Task: Short-circuit evaluation








VB: Private Function a(i As Variant) As Boolean
    Debug.Print "a:  "; i = 1,
    a = i
End Function
Private Function b(j As Variant) As Boolean
    Debug.Print "b: "; j = 1;
    b = j
End Function
Public Sub short_circuit()
    Dim x As Boolean, y As Boolean
    
    Debug.Print "=====AND=====" & vbCrLf
    For p = 0 To 1
        For q = 0 To 1
            If a(p) Then
                x = b(q)
            End If
            Debug.Print " = x"
        Next q
        Debug.Print
    Next p
    Debug.Print "======OR=====" & vbCrLf
    For p = 0 To 1
        For q = 0 To 1
            If Not a(p) Then
                x = b(q)
            End If
            Debug.Print " = x"
        Next q
        Debug.Print
    Next p
    Debug.Print
End Sub



Fortran: program Short_Circuit_Eval
  implicit none

  logical :: x, y
  logical, dimension(2) :: l = (/ .false., .true. /)
  integer :: i, j

  do i = 1, 2
    do j = 1, 2
      write(*, "(a,l1,a,l1,a)") "Calculating x = a(", l(i), ") and b(", l(j), ")"   
      
      x = a(l(i))  
      if(x) then
        x = b(l(j))
        write(*, "(a,l1)") "x = ", x
      else
        write(*, "(a,l1)") "x = ", x
      end if
  
      write(*,*)
      write(*, "(a,l1,a,l1,a)") "Calculating y = a(", l(i), ") or b(", l(j), ")"   
      
      y = a(l(i))
      if(y) then
        write(*, "(a,l1)") "y = ", y
      else
        y = b(l(j))
        write(*, "(a,l1)") "y = ", y
      end if
      write(*,*)
    end do
  end do

contains

function a(value)
  logical :: a
  logical, intent(in) :: value

  a = value
  write(*, "(a,l1,a)") "Called function a(", value, ")"
end function

function b(value)
  logical :: b
  logical, intent(in) :: value
  
  b = value
  write(*, "(a,l1,a)") "Called function b(", value, ")"
end function
end program
Task: Distributed programming



C#: using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading.Tasks;

using static System.Console;

class DistributedProgramming
{
    const int Port = 555;

    async static Task RunClient()
    {
        WriteLine("Connecting");
        var client = new TcpClient();
        await client.ConnectAsync("localhost", Port);

        using (var stream = client.GetStream())
        {
            WriteLine("Sending loot");
            var data = Serialize(new SampleData());
            await stream.WriteAsync(data, 0, data.Length);

            WriteLine("Receiving thanks");
            var buffer = new byte[80000];
            var bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length);
            var thanks = (string)Deserialize(buffer, bytesRead);
            WriteLine(thanks);
        }

        client.Close();
    }

    async static Task RunServer()
    {
        WriteLine("Listening");
        var listener = new TcpListener(IPAddress.Any, Port);
        listener.Start();
        var client = await listener.AcceptTcpClientAsync();

        using (var stream = client.GetStream())
        {
            WriteLine("Receiving loot");
            var buffer = new byte[80000];
            var bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length);
            var data = (SampleData)Deserialize(buffer, bytesRead);
            WriteLine($"{data.Loot} at {data.Latitude}, {data.Longitude}");

            WriteLine("Sending thanks");
            var thanks = Serialize("Thanks!");
            await stream.WriteAsync(thanks, 0, thanks.Length);
        }

        client.Close();
        listener.Stop();
        Write("Press a key");
        ReadKey();
    }

    static byte[] Serialize(object data)
    {
        using (var mem = new MemoryStream())
        {
            new BinaryFormatter().Serialize(mem, data);
            return mem.ToArray();
        }
    }

    static object Deserialize(byte[] data, int length)
    {
        using (var mem = new MemoryStream(data, 0, length))
        {
            return new BinaryFormatter().Deserialize(mem);
        }
    }

    static void Main(string[] args)
    {
        if (args.Length == 0) return;

        switch (args[0])
        {
            case "client": RunClient().Wait(); break;
            case "server": RunServer().Wait(); break;
        }
    }
}

[Serializable]
class SampleData
{
    public decimal Latitude = 44.33190m;
    public decimal Longitude = 114.84129m;
    public string Loot = "140 tonnes of jade";
}









Ada: package Server is
   pragma Remote_Call_Interface;
   procedure Foo;
   function Bar return Natural;
end Server;
Task: Distributed programming

C: #include <stdio.h>
#include <stdlib.h>
#include <pvm3.h>

int main(int c, char **v)
{
	int tids[10];
	int parent, spawn;
	int i_data, i2;
	double f_data;

	if (c > 1) {
		spawn = pvm_spawn("/tmp/a.out", 0, PvmTaskDefault, 0, 1, tids);
		if (spawn <= 0) {
			printf("Can't spawn task\n");
			return 1;
		}

		printf("Spawning successful\n");

		
		pvm_recv(-1, 2);
		pvm_unpackf("%d %d", &i_data, &i2);
		printf("got msg type 2: %d %d\n", i_data, i2);

		pvm_recv(-1, 1);
		pvm_unpackf("%d %lf", &i_data, &f_data);
		printf("got msg type 1: %d %f\n", i_data, f_data);
	} else {
		parent = pvm_parent();

		pvm_initsend(PvmDataDefault);
		i_data = rand();
		f_data = (double)rand() / RAND_MAX;
		pvm_packf("%d %lf", i_data, f_data);
		pvm_send(parent, 1);	

		pvm_initsend(PvmDataDefault);
		i2 = rand();
		pvm_packf("%d %d", i_data, i2);
		pvm_send(parent, 2);	
	}

	pvm_exit();
	return 0;
}











Ada: package Server is
   pragma Remote_Call_Interface;
   procedure Foo;
   function Bar return Natural;
end Server;
Task: Distributed programming




Go: package main

import (
    "errors"
    "log"
    "net"
    "net/http"
    "net/rpc"
)

type TaxComputer float64

func (taxRate TaxComputer) Tax(x float64, r *float64) error {
    if x < 0 {
        return errors.New("Negative values not allowed")
    }
    *r = x * float64(taxRate)
    return nil
}

func main() {
    c := TaxComputer(.05)
    rpc.Register(c)
    rpc.HandleHTTP()
    listener, err := net.Listen("tcp", ":1234")
    if err != nil {
        log.Fatal(err)
    }
    http.Serve(listener, nil)
}








Ada: package Server is
   pragma Remote_Call_Interface;
   procedure Foo;
   function Bar return Natural;
end Server;
Task: Distributed programming







Python: 


import SimpleXMLRPCServer

class MyHandlerInstance:
    def echo(self, data):
        
        return 'Server responded: %s' % data

    def div(self, num1, num2):
        
        return num1/num2

def foo_function():
    
    return True

HOST = "localhost"
PORT = 8000

server = SimpleXMLRPCServer.SimpleXMLRPCServer((HOST, PORT))


server.register_introspection_functions()


server.register_instance(MyHandlerInstance())


server.register_function(foo_function)

try:
    
    server.serve_forever()
except KeyboardInterrupt:
    print 'Exiting...'
    server.server_close()





Ada: package Server is
   pragma Remote_Call_Interface;
   procedure Foo;
   function Bar return Natural;
end Server;
Task: Distributed programming

C: #include <stdio.h>
#include <stdlib.h>
#include <pvm3.h>

int main(int c, char **v)
{
	int tids[10];
	int parent, spawn;
	int i_data, i2;
	double f_data;

	if (c > 1) {
		spawn = pvm_spawn("/tmp/a.out", 0, PvmTaskDefault, 0, 1, tids);
		if (spawn <= 0) {
			printf("Can't spawn task\n");
			return 1;
		}

		printf("Spawning successful\n");

		
		pvm_recv(-1, 2);
		pvm_unpackf("%d %d", &i_data, &i2);
		printf("got msg type 2: %d %d\n", i_data, i2);

		pvm_recv(-1, 1);
		pvm_unpackf("%d %lf", &i_data, &f_data);
		printf("got msg type 1: %d %f\n", i_data, f_data);
	} else {
		parent = pvm_parent();

		pvm_initsend(PvmDataDefault);
		i_data = rand();
		f_data = (double)rand() / RAND_MAX;
		pvm_packf("%d %lf", i_data, f_data);
		pvm_send(parent, 1);	

		pvm_initsend(PvmDataDefault);
		i2 = rand();
		pvm_packf("%d %d", i_data, i2);
		pvm_send(parent, 2);	
	}

	pvm_exit();
	return 0;
}
Task: Distributed programming



C#: using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading.Tasks;

using static System.Console;

class DistributedProgramming
{
    const int Port = 555;

    async static Task RunClient()
    {
        WriteLine("Connecting");
        var client = new TcpClient();
        await client.ConnectAsync("localhost", Port);

        using (var stream = client.GetStream())
        {
            WriteLine("Sending loot");
            var data = Serialize(new SampleData());
            await stream.WriteAsync(data, 0, data.Length);

            WriteLine("Receiving thanks");
            var buffer = new byte[80000];
            var bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length);
            var thanks = (string)Deserialize(buffer, bytesRead);
            WriteLine(thanks);
        }

        client.Close();
    }

    async static Task RunServer()
    {
        WriteLine("Listening");
        var listener = new TcpListener(IPAddress.Any, Port);
        listener.Start();
        var client = await listener.AcceptTcpClientAsync();

        using (var stream = client.GetStream())
        {
            WriteLine("Receiving loot");
            var buffer = new byte[80000];
            var bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length);
            var data = (SampleData)Deserialize(buffer, bytesRead);
            WriteLine($"{data.Loot} at {data.Latitude}, {data.Longitude}");

            WriteLine("Sending thanks");
            var thanks = Serialize("Thanks!");
            await stream.WriteAsync(thanks, 0, thanks.Length);
        }

        client.Close();
        listener.Stop();
        Write("Press a key");
        ReadKey();
    }

    static byte[] Serialize(object data)
    {
        using (var mem = new MemoryStream())
        {
            new BinaryFormatter().Serialize(mem, data);
            return mem.ToArray();
        }
    }

    static object Deserialize(byte[] data, int length)
    {
        using (var mem = new MemoryStream(data, 0, length))
        {
            return new BinaryFormatter().Deserialize(mem);
        }
    }

    static void Main(string[] args)
    {
        if (args.Length == 0) return;

        switch (args[0])
        {
            case "client": RunClient().Wait(); break;
            case "server": RunServer().Wait(); break;
        }
    }
}

[Serializable]
class SampleData
{
    public decimal Latitude = 44.33190m;
    public decimal Longitude = 114.84129m;
    public string Loot = "140 tonnes of jade";
}
Task: Distributed programming







Python: 


import SimpleXMLRPCServer

class MyHandlerInstance:
    def echo(self, data):
        
        return 'Server responded: %s' % data

    def div(self, num1, num2):
        
        return num1/num2

def foo_function():
    
    return True

HOST = "localhost"
PORT = 8000

server = SimpleXMLRPCServer.SimpleXMLRPCServer((HOST, PORT))


server.register_introspection_functions()


server.register_instance(MyHandlerInstance())


server.register_function(foo_function)

try:
    
    server.serve_forever()
except KeyboardInterrupt:
    print 'Exiting...'
    server.server_close()
Task: Distributed programming




Go: package main

import (
    "errors"
    "log"
    "net"
    "net/http"
    "net/rpc"
)

type TaxComputer float64

func (taxRate TaxComputer) Tax(x float64, r *float64) error {
    if x < 0 {
        return errors.New("Negative values not allowed")
    }
    *r = x * float64(taxRate)
    return nil
}

func main() {
    c := TaxComputer(.05)
    rpc.Register(c)
    rpc.HandleHTTP()
    listener, err := net.Listen("tcp", ":1234")
    if err != nil {
        log.Fatal(err)
    }
    http.Serve(listener, nil)
}
Task: ISBN13 check digit



C#: using System;
using System.Linq;

public class Program
{
    public static void Main() {
        Console.WriteLine(CheckISBN13("978-1734314502"));
        Console.WriteLine(CheckISBN13("978-1734314509"));
        Console.WriteLine(CheckISBN13("978-1788399081"));
        Console.WriteLine(CheckISBN13("978-1788399083"));

        static bool CheckISBN13(string code) {
            code = code.Replace("-", "").Replace(" ", "");
            if (code.Length != 13) return false;
            int sum = 0;
            foreach (var (index, digit) in code.Select((digit, index) => (index, digit))) {
                if (char.IsDigit(digit)) sum += (digit - '0') * (index % 2 == 0 ? 1 : 3);
                else return false;
            }
            return sum % 10 == 0;
        }
    }
}









Ada: with Ada.Text_IO;

procedure ISBN_Check is

   function Is_Valid (ISBN : String) return Boolean is
      Odd       : Boolean := True;
      Sum       : Integer := 0;
      Value     : Integer;
   begin
      for I in ISBN'Range loop
         if ISBN (I) in '0' .. '9' then
            Value := Character'Pos (ISBN (I)) - Character'Pos ('0');
            if Odd then
               Sum := Sum + Value;
            else
               Sum := Sum + 3 * Value;
            end if;
            Odd := not Odd;
         end if;
      end loop;
      return Sum mod 10 = 0;
   end Is_Valid;

   procedure Show (ISBN : String) is
      use Ada.Text_IO;
      Valid : constant Boolean := Is_Valid (ISBN);
   begin
      Put (ISBN); Put ("  ");
      Put ((if Valid then "Good" else "Bad"));
      New_Line;
   end Show;
begin
   Show ("978-1734314502");
   Show ("978-1734314509");
   Show ("978-1788399081");
   Show ("978-1788399083");
end ISBN_Check;
Task: ISBN13 check digit

C: #include <stdio.h>

int check_isbn13(const char *isbn) {
    int ch = *isbn, count = 0, sum = 0;
    
    for ( ; ch != 0; ch = *++isbn, ++count) {
        
        if (ch == ' ' || ch == '-') {
            --count;
            continue;
        }
        if (ch < '0' || ch > '9') {
            return 0;
        }
        if (count & 1) {
            sum += 3 * (ch - '0');
        } else {
            sum += ch - '0';
        }
    }
    if (count != 13) return 0;
    return !(sum%10);
}

int main() {
    int i;
    const char* isbns[] = {"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"};
    for (i = 0; i < 4; ++i) {
        printf("%s: %s\n", isbns[i], check_isbn13(isbns[i]) ? "good" : "bad");
    }
    return 0;
}











Ada: with Ada.Text_IO;

procedure ISBN_Check is

   function Is_Valid (ISBN : String) return Boolean is
      Odd       : Boolean := True;
      Sum       : Integer := 0;
      Value     : Integer;
   begin
      for I in ISBN'Range loop
         if ISBN (I) in '0' .. '9' then
            Value := Character'Pos (ISBN (I)) - Character'Pos ('0');
            if Odd then
               Sum := Sum + Value;
            else
               Sum := Sum + 3 * Value;
            end if;
            Odd := not Odd;
         end if;
      end loop;
      return Sum mod 10 = 0;
   end Is_Valid;

   procedure Show (ISBN : String) is
      use Ada.Text_IO;
      Valid : constant Boolean := Is_Valid (ISBN);
   begin
      Put (ISBN); Put ("  ");
      Put ((if Valid then "Good" else "Bad"));
      New_Line;
   end Show;
begin
   Show ("978-1734314502");
   Show ("978-1734314509");
   Show ("978-1788399081");
   Show ("978-1788399083");
end ISBN_Check;
Task: ISBN13 check digit


C++: #include <iostream>

bool check_isbn13(std::string isbn) {
    int count = 0;
    int sum = 0;

    for (auto ch : isbn) {
        
        if (ch == ' ' || ch == '-') {
            continue;
        }
        if (ch < '0' || ch > '9') {
            return false;
        }
        if (count & 1) {
            sum += 3 * (ch - '0');
        } else {
            sum += ch - '0';
        }
        count++;
    }

    if (count != 13) {
        return false;
    }
    return sum % 10 == 0;
}

int main() {
    auto isbns = { "978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083" };
    for (auto isbn : isbns) {
        std::cout << isbn << ": " << (check_isbn13(isbn) ? "good" : "bad") << '\n';
    }

    return 0;
}










Ada: with Ada.Text_IO;

procedure ISBN_Check is

   function Is_Valid (ISBN : String) return Boolean is
      Odd       : Boolean := True;
      Sum       : Integer := 0;
      Value     : Integer;
   begin
      for I in ISBN'Range loop
         if ISBN (I) in '0' .. '9' then
            Value := Character'Pos (ISBN (I)) - Character'Pos ('0');
            if Odd then
               Sum := Sum + Value;
            else
               Sum := Sum + 3 * Value;
            end if;
            Odd := not Odd;
         end if;
      end loop;
      return Sum mod 10 = 0;
   end Is_Valid;

   procedure Show (ISBN : String) is
      use Ada.Text_IO;
      Valid : constant Boolean := Is_Valid (ISBN);
   begin
      Put (ISBN); Put ("  ");
      Put ((if Valid then "Good" else "Bad"));
      New_Line;
   end Show;
begin
   Show ("978-1734314502");
   Show ("978-1734314509");
   Show ("978-1788399081");
   Show ("978-1788399083");
end ISBN_Check;
Task: ISBN13 check digit




Go: package main

import (
    "fmt"
    "strings"
    "unicode/utf8"
)

func checkIsbn13(isbn string) bool {
    
    isbn = strings.ReplaceAll(strings.ReplaceAll(isbn, "-", ""), " ", "")
    
    le := utf8.RuneCountInString(isbn)
    if le != 13 {
        return false
    }
    
    sum := int32(0)
    for i, c := range isbn {
        if c < '0' || c > '9' {
            return false
        }
        if i%2 == 0 {
            sum += c - '0'
        } else {
            sum += 3 * (c - '0')
        }
    }
    return sum%10 == 0
}

func main() {
    isbns := []string{"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"}
    for _, isbn := range isbns {
        res := "bad"
        if checkIsbn13(isbn) {
            res = "good"
        }
        fmt.Printf("%s: %s\n", isbn, res)
    }
}








Ada: with Ada.Text_IO;

procedure ISBN_Check is

   function Is_Valid (ISBN : String) return Boolean is
      Odd       : Boolean := True;
      Sum       : Integer := 0;
      Value     : Integer;
   begin
      for I in ISBN'Range loop
         if ISBN (I) in '0' .. '9' then
            Value := Character'Pos (ISBN (I)) - Character'Pos ('0');
            if Odd then
               Sum := Sum + Value;
            else
               Sum := Sum + 3 * Value;
            end if;
            Odd := not Odd;
         end if;
      end loop;
      return Sum mod 10 = 0;
   end Is_Valid;

   procedure Show (ISBN : String) is
      use Ada.Text_IO;
      Valid : constant Boolean := Is_Valid (ISBN);
   begin
      Put (ISBN); Put ("  ");
      Put ((if Valid then "Good" else "Bad"));
      New_Line;
   end Show;
begin
   Show ("978-1734314502");
   Show ("978-1734314509");
   Show ("978-1788399081");
   Show ("978-1788399083");
end ISBN_Check;