WeixiangYan/CodeTransOcean huggingface dataset:
Task: Ascending primes








VB: Module AscendingPrimes

    Function isPrime(n As Integer)
        n = Math.Abs(n)
        If n = 2 Then
            Return True
        End If
        If n = 1 Or n Mod 2 = 0 Then
            Return False
        End If
        Dim root As Integer = Math.Sqrt(n)
        For k = 3 To root Step 2
            If n Mod k = 0 Then
                Return False
            End If
        Next
        Return True
    End Function


    Sub Main()

        Dim queue As Queue(Of Integer) = New Queue(Of Integer)
        Dim primes As List(Of Integer) = New List(Of Integer)

        For k = 1 To 9
            queue.Enqueue(k)
        Next

        While queue.Count > 0
            Dim n As Integer = queue.Dequeue()
            If (isPrime(n)) Then
                primes.Add(n)
            End If
            For k = n Mod 10 + 1 To 9
                queue.Enqueue(n * 10 + k)
            Next
        End While

        For Each p As Integer In primes
            Console.Write(p)
            Console.Write(" ")
        Next
        Console.WriteLine()

    End Sub

End Module
Task: Ascending primes




Go: package main

import (
    "fmt"
    "rcu"
    "sort"
)

var ascPrimesSet = make(map[int]bool) 

func generate(first, cand, digits int) {
    if digits == 0 {
        if rcu.IsPrime(cand) {
            ascPrimesSet[cand] = true
        }
        return
    }
    for i := first; i < 10; i++ {
        next := cand*10 + i
        generate(i+1, next, digits-1)
    }
}

func main() {
    for digits := 1; digits < 10; digits++ {
        generate(1, 0, digits)
    }
    le := len(ascPrimesSet)
    ascPrimes := make([]int, le)
    i := 0
    for k := range ascPrimesSet {
        ascPrimes[i] = k
        i++
    }
    sort.Ints(ascPrimes)
    fmt.Println("There are", le, "ascending primes, namely:")
    for i := 0; i < le; i++ {
        fmt.Printf("%8d ", ascPrimes[i])
        if (i+1)%10 == 0 {
            fmt.Println()
        }
    }
}
Task: Ascending primes



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

namespace ascendingprimes
{
    class Program
    {
        static bool isPrime(uint n)
        {
            if (n == 2)
                return true;
            if (n == 1 || n % 2 = 0)
                return false;
            uint root = (uint)Math.Sqrt(n);
            for (uint k = 3; k <= root; k += 2)
                if (n % k == 0)
                    return false;
            return true;
        }
        static void Main(string[] args)
        {
            var queue = new Queue<uint>();
            var primes = new List<uint>();

            for (uint k = 1; k <= 9; k++)
                queue.Enqueue(k);
            while(queue.Count > 0)
            {
                uint n = queue.Dequeue();
                if (isPrime(n))
                    primes.Add(n);
                for (uint k = n % 10 + 1; k <= 9; k++)
                    queue.Enqueue(n * 10 + k);
            }

            foreach (uint p in primes)
            {
                Console.Write(p);
                Console.Write(" ");
            }
            Console.WriteLine();
        }
    }
}








Fortran: 



















    
program prog

    parameter (MAXSIZE = 1000)
    
    logical isprime
    dimension iqueue(MAXSIZE)
    dimension iprimes(MAXSIZE)
    
    ibegin = 1
    iend = 1
    n = 0

    do k = 1, 9
        iqueue(iend) = k
        iend = iend + 1
    end do
    
    do while (ibegin .lt. iend)
        iv = iqueue(ibegin)
        ibegin = ibegin + 1
        if (isprime(iv)) then
            n = n + 1
            iprimes(n) = iv
        end if
        lsd1 = mod(iv, 10) + 1
        if (lsd1 .le. 9) then
            do k = lsd1, 9
                iqueue(iend) = iv * 10 + k
                iend = iend + 1
            end do
        end if
    end do

    print *, (iprimes(i), i = 1, n)

end program


logical function isprime(n)
    









    isprime = .FALSE.
    if (n .eq. 0 .or. n .eq. 1) then
        return
    end if
    if (n .ne. 2) then
        if (mod(n, 2) .eq. 0) then
            return
        end if
        m = n**0.5
        do k = 3, m, 2
            if (mod(n, k) .eq. 0) then
                return
            end if
        end do
    end if
    isprime = .TRUE.
end function
Task: Ascending primes


C++: 

#include <cmath>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;


queue<unsigned> suspected;
vector<unsigned> primes;


bool isPrime(unsigned n)
{
    if (n == 2)
    {
        return true;
    }
    if (n == 1 || n % 2 == 0)
    {
        return false;
    }
    unsigned root = sqrt(n);
    for (unsigned k = 3; k <= root; k += 2)
    {
        if (n % k == 0)
        {
            return false;
        }
    }
    return true;
}


int main(int argc, char argv[])
{
    for (unsigned k = 1; k <= 9; k++)
    {
        suspected.push(k);
    }

    while (!suspected.empty())
    {
        int n = suspected.front();
        suspected.pop();

        if (isPrime(n))
        {
            primes.push_back(n);
        }

        
        
        for (unsigned k = n % 10 + 1; k <= 9; k++)
        {
            suspected.push(n * 10 + k);
        }
    }

    copy(primes.begin(), primes.end(), ostream_iterator<unsigned>(cout, " "));

    return EXIT_SUCCESS;
}









Fortran: 



















    
program prog

    parameter (MAXSIZE = 1000)
    
    logical isprime
    dimension iqueue(MAXSIZE)
    dimension iprimes(MAXSIZE)
    
    ibegin = 1
    iend = 1
    n = 0

    do k = 1, 9
        iqueue(iend) = k
        iend = iend + 1
    end do
    
    do while (ibegin .lt. iend)
        iv = iqueue(ibegin)
        ibegin = ibegin + 1
        if (isprime(iv)) then
            n = n + 1
            iprimes(n) = iv
        end if
        lsd1 = mod(iv, 10) + 1
        if (lsd1 .le. 9) then
            do k = lsd1, 9
                iqueue(iend) = iv * 10 + k
                iend = iend + 1
            end do
        end if
    end do

    print *, (iprimes(i), i = 1, n)

end program


logical function isprime(n)
    









    isprime = .FALSE.
    if (n .eq. 0 .or. n .eq. 1) then
        return
    end if
    if (n .ne. 2) then
        if (mod(n, 2) .eq. 0) then
            return
        end if
        m = n**0.5
        do k = 3, m, 2
            if (mod(n, k) .eq. 0) then
                return
            end if
        end do
    end if
    isprime = .TRUE.
end function
Task: Ascending primes

C: 

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

#if UINT_MAX < 123456789
#error "we need at least 9 decimal digits (32-bit integers)"
#endif


#define MAXSIZE 1000

unsigned queue[MAXSIZE];
unsigned primes[MAXSIZE];

unsigned begin = 0;
unsigned end = 0;
unsigned n = 0;


bool isPrime(unsigned n)
{
    if (n == 2)
    {
        return true;
    }
    if (n == 1 || n % 2 == 0)
    {
        return false;
    }
    unsigned root = sqrt(n);
    for (unsigned k = 3; k <= root; k += 2)
    {
        if (n % k == 0)
        {
            return false;
        }
    }
    return true;
}


int main(int argc, char argv[])
{
    for (int k = 1; k <= 9; k++)
    {
        queue[end++] = k;
    }

    while (begin < end)
    {
        int value = queue[begin++];
        if (isPrime(value))
        {
            primes[n++] = value;
        }
        for (int k = value % 10 + 1; k <= 9; k++)
        {
            queue[end++] = value * 10 + k;
        }
    }

    for (int k = 0; k < n; k++)
    {
        printf("%u ", primes[k]);
    }
 
    return EXIT_SUCCESS;
}










Fortran: 



















    
program prog

    parameter (MAXSIZE = 1000)
    
    logical isprime
    dimension iqueue(MAXSIZE)
    dimension iprimes(MAXSIZE)
    
    ibegin = 1
    iend = 1
    n = 0

    do k = 1, 9
        iqueue(iend) = k
        iend = iend + 1
    end do
    
    do while (ibegin .lt. iend)
        iv = iqueue(ibegin)
        ibegin = ibegin + 1
        if (isprime(iv)) then
            n = n + 1
            iprimes(n) = iv
        end if
        lsd1 = mod(iv, 10) + 1
        if (lsd1 .le. 9) then
            do k = lsd1, 9
                iqueue(iend) = iv * 10 + k
                iend = iend + 1
            end do
        end if
    end do

    print *, (iprimes(i), i = 1, n)

end program


logical function isprime(n)
    









    isprime = .FALSE.
    if (n .eq. 0 .or. n .eq. 1) then
        return
    end if
    if (n .ne. 2) then
        if (mod(n, 2) .eq. 0) then
            return
        end if
        m = n**0.5
        do k = 3, m, 2
            if (mod(n, k) .eq. 0) then
                return
            end if
        end do
    end if
    isprime = .TRUE.
end function
Task: Ascending primes




Go: package main

import (
    "fmt"
    "rcu"
    "sort"
)

var ascPrimesSet = make(map[int]bool) 

func generate(first, cand, digits int) {
    if digits == 0 {
        if rcu.IsPrime(cand) {
            ascPrimesSet[cand] = true
        }
        return
    }
    for i := first; i < 10; i++ {
        next := cand*10 + i
        generate(i+1, next, digits-1)
    }
}

func main() {
    for digits := 1; digits < 10; digits++ {
        generate(1, 0, digits)
    }
    le := len(ascPrimesSet)
    ascPrimes := make([]int, le)
    i := 0
    for k := range ascPrimesSet {
        ascPrimes[i] = k
        i++
    }
    sort.Ints(ascPrimes)
    fmt.Println("There are", le, "ascending primes, namely:")
    for i := 0; i < le; i++ {
        fmt.Printf("%8d ", ascPrimes[i])
        if (i+1)%10 == 0 {
            fmt.Println()
        }
    }
}







Fortran: 



















    
program prog

    parameter (MAXSIZE = 1000)
    
    logical isprime
    dimension iqueue(MAXSIZE)
    dimension iprimes(MAXSIZE)
    
    ibegin = 1
    iend = 1
    n = 0

    do k = 1, 9
        iqueue(iend) = k
        iend = iend + 1
    end do
    
    do while (ibegin .lt. iend)
        iv = iqueue(ibegin)
        ibegin = ibegin + 1
        if (isprime(iv)) then
            n = n + 1
            iprimes(n) = iv
        end if
        lsd1 = mod(iv, 10) + 1
        if (lsd1 .le. 9) then
            do k = lsd1, 9
                iqueue(iend) = iv * 10 + k
                iend = iend + 1
            end do
        end if
    end do

    print *, (iprimes(i), i = 1, n)

end program


logical function isprime(n)
    









    isprime = .FALSE.
    if (n .eq. 0 .or. n .eq. 1) then
        return
    end if
    if (n .ne. 2) then
        if (mod(n, 2) .eq. 0) then
            return
        end if
        m = n**0.5
        do k = 3, m, 2
            if (mod(n, k) .eq. 0) then
                return
            end if
        end do
    end if
    isprime = .TRUE.
end function
Task: Ascending primes





Java: 

package example.rossetacode.ascendingprimes;

import java.util.Arrays;

public class Program implements Runnable {

    public static void main(String[] args) {
        long t1 = System.nanoTime();
        new Program().run();
        long t2 = System.nanoTime();
        System.out.println(
                "total time consumed = " + (t2 - t1) * 1E-6 + " milliseconds");
    }

    public void run() {

        final int MAX_SIZE = 1000;
        final int[] queue = new int[MAX_SIZE];
        int begin = 0;
        int end = 0;

        for (int k = 1; k <= 9; k++) {
            queue[end++] = k;
        }

        while (begin < end) {
            int n = queue[begin++];
            for (int k = n % 10 + 1; k <= 9; k++) {
                queue[end++] = n * 10 + k;
            }
        }

        
        
        
        System.out.println(Arrays.stream(queue).filter(this::isPrime).boxed().toList());
    }

    private boolean isPrime(int n) {
        if (n == 2) {
            return true;
        }
        if (n == 1 || n % 2 == 0) {
            return false;
        }
        int root = (int) Math.sqrt(n);
        for (int k = 3; k <= root; k += 2) {
            if (n % k == 0) {
                return false;
            }
        }
        return true;
    }
}






Fortran: 



















    
program prog

    parameter (MAXSIZE = 1000)
    
    logical isprime
    dimension iqueue(MAXSIZE)
    dimension iprimes(MAXSIZE)
    
    ibegin = 1
    iend = 1
    n = 0

    do k = 1, 9
        iqueue(iend) = k
        iend = iend + 1
    end do
    
    do while (ibegin .lt. iend)
        iv = iqueue(ibegin)
        ibegin = ibegin + 1
        if (isprime(iv)) then
            n = n + 1
            iprimes(n) = iv
        end if
        lsd1 = mod(iv, 10) + 1
        if (lsd1 .le. 9) then
            do k = lsd1, 9
                iqueue(iend) = iv * 10 + k
                iend = iend + 1
            end do
        end if
    end do

    print *, (iprimes(i), i = 1, n)

end program


logical function isprime(n)
    









    isprime = .FALSE.
    if (n .eq. 0 .or. n .eq. 1) then
        return
    end if
    if (n .ne. 2) then
        if (mod(n, 2) .eq. 0) then
            return
        end if
        m = n**0.5
        do k = 3, m, 2
            if (mod(n, k) .eq. 0) then
                return
            end if
        end do
    end if
    isprime = .TRUE.
end function
Task: Ascending primes







Python: from sympy import isprime

def ascending(x=0):
    for y in range(x*10 + (x%10) + 1, x*10 + 10):
        yield from ascending(y)
        yield(y)

print(sorted(x for x in ascending() if isprime(x)))




Fortran: 



















    
program prog

    parameter (MAXSIZE = 1000)
    
    logical isprime
    dimension iqueue(MAXSIZE)
    dimension iprimes(MAXSIZE)
    
    ibegin = 1
    iend = 1
    n = 0

    do k = 1, 9
        iqueue(iend) = k
        iend = iend + 1
    end do
    
    do while (ibegin .lt. iend)
        iv = iqueue(ibegin)
        ibegin = ibegin + 1
        if (isprime(iv)) then
            n = n + 1
            iprimes(n) = iv
        end if
        lsd1 = mod(iv, 10) + 1
        if (lsd1 .le. 9) then
            do k = lsd1, 9
                iqueue(iend) = iv * 10 + k
                iend = iend + 1
            end do
        end if
    end do

    print *, (iprimes(i), i = 1, n)

end program


logical function isprime(n)
    









    isprime = .FALSE.
    if (n .eq. 0 .or. n .eq. 1) then
        return
    end if
    if (n .ne. 2) then
        if (mod(n, 2) .eq. 0) then
            return
        end if
        m = n**0.5
        do k = 3, m, 2
            if (mod(n, k) .eq. 0) then
                return
            end if
        end do
    end if
    isprime = .TRUE.
end function
Task: Ascending primes








VB: Module AscendingPrimes

    Function isPrime(n As Integer)
        n = Math.Abs(n)
        If n = 2 Then
            Return True
        End If
        If n = 1 Or n Mod 2 = 0 Then
            Return False
        End If
        Dim root As Integer = Math.Sqrt(n)
        For k = 3 To root Step 2
            If n Mod k = 0 Then
                Return False
            End If
        Next
        Return True
    End Function


    Sub Main()

        Dim queue As Queue(Of Integer) = New Queue(Of Integer)
        Dim primes As List(Of Integer) = New List(Of Integer)

        For k = 1 To 9
            queue.Enqueue(k)
        Next

        While queue.Count > 0
            Dim n As Integer = queue.Dequeue()
            If (isPrime(n)) Then
                primes.Add(n)
            End If
            For k = n Mod 10 + 1 To 9
                queue.Enqueue(n * 10 + k)
            Next
        End While

        For Each p As Integer In primes
            Console.Write(p)
            Console.Write(" ")
        Next
        Console.WriteLine()

    End Sub

End Module



Fortran: 



















    
program prog

    parameter (MAXSIZE = 1000)
    
    logical isprime
    dimension iqueue(MAXSIZE)
    dimension iprimes(MAXSIZE)
    
    ibegin = 1
    iend = 1
    n = 0

    do k = 1, 9
        iqueue(iend) = k
        iend = iend + 1
    end do
    
    do while (ibegin .lt. iend)
        iv = iqueue(ibegin)
        ibegin = ibegin + 1
        if (isprime(iv)) then
            n = n + 1
            iprimes(n) = iv
        end if
        lsd1 = mod(iv, 10) + 1
        if (lsd1 .le. 9) then
            do k = lsd1, 9
                iqueue(iend) = iv * 10 + k
                iend = iend + 1
            end do
        end if
    end do

    print *, (iprimes(i), i = 1, n)

end program


logical function isprime(n)
    









    isprime = .FALSE.
    if (n .eq. 0 .or. n .eq. 1) then
        return
    end if
    if (n .ne. 2) then
        if (mod(n, 2) .eq. 0) then
            return
        end if
        m = n**0.5
        do k = 3, m, 2
            if (mod(n, k) .eq. 0) then
                return
            end if
        end do
    end if
    isprime = .TRUE.
end function
Task: Ascending primes






PHP: <?php

function isPrime($n)
{
    if ($n == 2)
        return true;
    if ($n == 1 || $n % 2 == 0)
        return false;
    $root = intval(sqrt($n));
    for ($k = 3; $k <= $root; $k += 2)
        if ($n % $k == 0)
            return false;
    return true;    
}

$queue = [];
$primes = [];

$begin = 0;
$end = 0;

for ($k = 1; $k <= 9; $k++)
    $queue[$end++] = $k;

while ($begin < $end)
{
    $n = $queue[$begin++];

    if (isPrime($n))
        $primes[] = $n;
    for ($k = $n % 10 + 1; $k <= 9; $k++)
        $queue[$end++] = $n * 10 + $k;
}

foreach($primes as $p)
    echo "$p ";





Fortran: 



















    
program prog

    parameter (MAXSIZE = 1000)
    
    logical isprime
    dimension iqueue(MAXSIZE)
    dimension iprimes(MAXSIZE)
    
    ibegin = 1
    iend = 1
    n = 0

    do k = 1, 9
        iqueue(iend) = k
        iend = iend + 1
    end do
    
    do while (ibegin .lt. iend)
        iv = iqueue(ibegin)
        ibegin = ibegin + 1
        if (isprime(iv)) then
            n = n + 1
            iprimes(n) = iv
        end if
        lsd1 = mod(iv, 10) + 1
        if (lsd1 .le. 9) then
            do k = lsd1, 9
                iqueue(iend) = iv * 10 + k
                iend = iend + 1
            end do
        end if
    end do

    print *, (iprimes(i), i = 1, n)

end program


logical function isprime(n)
    









    isprime = .FALSE.
    if (n .eq. 0 .or. n .eq. 1) then
        return
    end if
    if (n .ne. 2) then
        if (mod(n, 2) .eq. 0) then
            return
        end if
        m = n**0.5
        do k = 3, m, 2
            if (mod(n, k) .eq. 0) then
                return
            end if
        end do
    end if
    isprime = .TRUE.
end function
Task: Ascending primes






PHP: <?php

function isPrime($n)
{
    if ($n == 2)
        return true;
    if ($n == 1 || $n % 2 == 0)
        return false;
    $root = intval(sqrt($n));
    for ($k = 3; $k <= $root; $k += 2)
        if ($n % $k == 0)
            return false;
    return true;    
}

$queue = [];
$primes = [];

$begin = 0;
$end = 0;

for ($k = 1; $k <= 9; $k++)
    $queue[$end++] = $k;

while ($begin < $end)
{
    $n = $queue[$begin++];

    if (isPrime($n))
        $primes[] = $n;
    for ($k = $n % 10 + 1; $k <= 9; $k++)
        $queue[$end++] = $n * 10 + $k;
}

foreach($primes as $p)
    echo "$p ";






Ada: #!/usr/local/bin/spar
  
pragma annotate( summary, "primes_asc" );
pragma annotate( description, "Generate and show all primes with strictly ascending decimal digits" );
pragma annotate( description, "Translation of Pascal" );
pragma annotate( see_also, "https://rosettacode.org/wiki/Ascending_primes" );
pragma annotate( author, "Ken O. Burtch" );

pragma software_model( nonstandard );
pragma restriction( no_external_commands );

procedure primes_asc is
  maxsize : constant natural := 1000;

  queue : array(1..maxsize) of natural;
  primes: array(1..maxsize) of natural;

  b : natural;
  e : natural;
  n : natural;
  v : natural;

function is_prime(num: integer) return boolean is
    found : boolean;
    num_root : natural;
    k : natural;
  begin
    if num = 2 then
      found;
    elsif (num = 1) or (num mod 2 = 0) then
      found := false;
    else
      num_root := numerics.truncation(numerics.sqrt(num));
      found;
      k := 3;
      while found and (k <= num_root) loop
        if num mod k = 0 then
          found := false;
        else
          k := @ + 2;
        end if;
      end loop;
   end if;
    return found;
  end is_prime;

begin
  b := 1;
  e := 1;
  n := 0;

  for k in 1..9 loop
    queue(e) := k;
    e := e + 1;
  end loop;

  while b < e loop
    v := queue(b);
    b := @ + 1;
    if is_prime(v) then
      n := @ + 1;
      primes(n) := v;
    end if;

    for k in v mod 10 + 1..9 loop
      queue(e) := v * 10 + k;
      e := @ + 1;
    end loop;
  end loop;

  for k in 1..n loop
    put(primes(k), "ZZZZZZZZ9");
    if k mod 8 = 0 then
       new_line;
    end if;
  end loop;
  new_line;
end primes_asc;
Task: Ascending primes






PHP: <?php

function isPrime($n)
{
    if ($n == 2)
        return true;
    if ($n == 1 || $n % 2 == 0)
        return false;
    $root = intval(sqrt($n));
    for ($k = 3; $k <= $root; $k += 2)
        if ($n % $k == 0)
            return false;
    return true;    
}

$queue = [];
$primes = [];

$begin = 0;
$end = 0;

for ($k = 1; $k <= 9; $k++)
    $queue[$end++] = $k;

while ($begin < $end)
{
    $n = $queue[$begin++];

    if (isPrime($n))
        $primes[] = $n;
    for ($k = $n % 10 + 1; $k <= 9; $k++)
        $queue[$end++] = $n * 10 + $k;
}

foreach($primes as $p)
    echo "$p ";
Task: Tic-tac-toe

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

int b[3][3]; 

int check_winner()
{
	int i;
	for (i = 0; i < 3; i++) {
		if (b[i][0] && b[i][1] == b[i][0] && b[i][2] == b[i][0])
			return b[i][0];
		if (b[0][i] && b[1][i] == b[0][i] && b[2][i] == b[0][i])
			return b[0][i];
	}
	if (!b[1][1]) return 0;

	if (b[1][1] == b[0][0] && b[2][2] == b[0][0]) return b[0][0];
	if (b[1][1] == b[2][0] && b[0][2] == b[1][1]) return b[1][1];

	return 0;
}

void showboard()
{
	const char *t = "X O";
	int i, j;
	for (i = 0; i < 3; i++, putchar('\n'))
		for (j = 0; j < 3; j++)
			printf("%c ", t[ b[i][j] + 1 ]);
	printf("-----\n");
}

#define for_ij for (i = 0; i < 3; i++) for (j = 0; j < 3; j++)
int best_i, best_j;
int test_move(int val, int depth)
{
	int i, j, score;
	int best = -1, changed = 0;

	if ((score = check_winner())) return (score == val) ? 1 : -1;

	for_ij {
		if (b[i][j]) continue;

		changed = b[i][j] = val;
		score = -test_move(-val, depth + 1);
		b[i][j] = 0;

		if (score <= best) continue;
		if (!depth) {
			best_i = i;
			best_j = j;
		}
		best = score;
	}

	return changed ? best : 0;
}

const char* game(int user)
{
	int i, j, k, move, win = 0;
	for_ij b[i][j] = 0;

	printf("Board postions are numbered so:\n1 2 3\n4 5 6\n7 8 9\n");
	printf("You have O, I have X.\n\n");
	for (k = 0; k < 9; k++, user = !user) {
		while(user) {
			printf("your move: ");
			if (!scanf("%d", &move)) {
				scanf("%*s");
				continue;
			}
			if (--move < 0 || move >= 9) continue;
			if (b[i = move / 3][j = move % 3]) continue;

			b[i][j] = 1;
			break;
		}
		if (!user) {
			if (!k) { 
				best_i = rand() % 3;
				best_j = rand() % 3;
			} else
				test_move(-1, 0);

			b[best_i][best_j] = -1;
			printf("My move: %d\n", best_i * 3 + best_j + 1);
		}

		showboard();
		if ((win = check_winner())) 
			return win == 1 ? "You win.\n\n": "I win.\n\n";
	}
	return "A draw.\n\n";
}

int main()
{
	int first = 0;
	while (1) printf("%s", game(first = !first));
	return 0;
}