WeixiangYan/CodeTransOcean huggingface dataset:
Task: Prime decomposition








VB: Function PrimeFactors(n)
    arrP = Split(ListPrimes(n)," ")
    divnum = n
    Do Until divnum = 1
        
        For i = 0 To UBound(arrP)-1
            If divnum = 1 Then
                Exit For
            ElseIf divnum Mod arrP(i) = 0 Then
                divnum = divnum/arrP(i)
                PrimeFactors = PrimeFactors & arrP(i) & " "
            End If
        Next
    Loop
End Function

Function IsPrime(n)
    If n = 2 Then
        IsPrime = True
    ElseIf n <= 1 Or n Mod 2 = 0 Then
        IsPrime = False
    Else
        IsPrime = True
        For i = 3 To Int(Sqr(n)) Step 2
            If n Mod i = 0 Then
                IsPrime = False
                Exit For
            End If
        Next
    End If
End Function

Function ListPrimes(n)
    ListPrimes = ""
    For i = 1 To n
        If IsPrime(i) Then
            ListPrimes = ListPrimes & i & " "
        End If
    Next
End Function

WScript.StdOut.Write PrimeFactors(CInt(WScript.Arguments(0)))
WScript.StdOut.WriteLine
Task: Prime decomposition




Go: package main

import (
    "fmt"
    "math/big"
)

var (
    ZERO = big.NewInt(0)
    ONE  = big.NewInt(1)
)

func Primes(n *big.Int) []*big.Int {
    res := []*big.Int{}
    mod, div := new(big.Int), new(big.Int)
    for i := big.NewInt(2); i.Cmp(n) != 1; {
        div.DivMod(n, i, mod)
        for mod.Cmp(ZERO) == 0 {
            res = append(res, new(big.Int).Set(i))
            n.Set(div)
            div.DivMod(n, i, mod)
        }
        i.Add(i, ONE)
    }
    return res
}

func main() {
    vals := []int64{
        1 << 31,
        1234567,
        333333,
        987653,
        2 * 3 * 5 * 7 * 11 * 13 * 17,
    }
    for _, v := range vals {
        fmt.Println(v, "->", Primes(big.NewInt(v)))
    }
}
Task: Prime decomposition



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

namespace PrimeDecomposition
{
    class Program
    {
        static void Main(string[] args)
        {
            GetPrimes(12);
        }

        static List<int> GetPrimes(decimal n)
        {
            List<int> storage = new List<int>();
            while (n > 1)
            {
                int i = 1;
                while (true)
                {
                    if (IsPrime(i))
                    {                        
                        if (((decimal)n / i) == Math.Round((decimal) n / i))
                        {
                            n /= i;
                            storage.Add(i);                            
                            break;
                        }
                    }
                    i++;
                }
            }
            return storage;
        }

        static bool IsPrime(int n)
        {
            if (n <= 1) return false;
            for (int i = 2; i <= Math.Sqrt(n); i++)
                if (n % i == 0) return false;
            return true;
        }
    }
}








Fortran: module PrimeDecompose
  implicit none

  integer, parameter :: huge = selected_int_kind(18)
  

contains

  subroutine find_factors(n, d)
    integer(huge), intent(in) :: n
    integer, dimension(:), intent(out) :: d

    integer(huge) :: div, next, rest
    integer :: i

    i = 1
    div = 2; next = 3; rest = n
    
    do while ( rest /= 1 )
       do while ( mod(rest, div) == 0 ) 
          d(i) = div
          i = i + 1
          rest = rest / div
       end do
       div = next
       next = next + 2
    end do

  end subroutine find_factors

end module PrimeDecompose
Task: Prime decomposition


C++: #include <iostream>
#include <gmpxx.h>








template<typename Integer, typename OutputIterator>
 void decompose(Integer n, OutputIterator out)
{
  Integer i(2);

  while (n != 1)
  {
    while (n % i == Integer(0))
    {
      *out++ = i;
      n /= i;
    }
    ++i;
  }
}




template<typename T> class infix_ostream_iterator:
  public std::iterator<T, std::output_iterator_tag>
{
  class Proxy;
  friend class Proxy;
  class Proxy
  {
  public:
    Proxy(infix_ostream_iterator& iter): iterator(iter) {}
    Proxy& operator=(T const& value)
    {
      if (!iterator.first)
      {
        iterator.stream << iterator.infix;
      }
      iterator.stream << value;
    }
  private:
    infix_ostream_iterator& iterator;
  };
public:
  infix_ostream_iterator(std::ostream& os, char const* inf):
    stream(os),
    first(true),
    infix(inf)
  {
  }
  infix_ostream_iterator& operator++() { first = false; return *this; }
  infix_ostream_iterator operator++(int)
  {
    infix_ostream_iterator prev(*this);
    ++*this;
    return prev;
  }
  Proxy operator*() { return Proxy(*this); }
private:
  std::ostream& stream;
  bool first;
  char const* infix;
};

int main()
{
  std::cout << "please enter a positive number: ";
  mpz_class number;
  std::cin >> number;
  
  if (number <= 0)
    std::cout << "this number is not positive!\n;";
  else
  {
    std::cout << "decomposition: ";
    decompose(number, infix_ostream_iterator<mpz_class>(std::cout, " * "));
    std::cout << "\n";
  }
}









Fortran: module PrimeDecompose
  implicit none

  integer, parameter :: huge = selected_int_kind(18)
  

contains

  subroutine find_factors(n, d)
    integer(huge), intent(in) :: n
    integer, dimension(:), intent(out) :: d

    integer(huge) :: div, next, rest
    integer :: i

    i = 1
    div = 2; next = 3; rest = n
    
    do while ( rest /= 1 )
       do while ( mod(rest, div) == 0 ) 
          d(i) = div
          i = i + 1
          rest = rest / div
       end do
       div = next
       next = next + 2
    end do

  end subroutine find_factors

end module PrimeDecompose
Task: Prime decomposition




Go: package main

import (
    "fmt"
    "math/big"
)

var (
    ZERO = big.NewInt(0)
    ONE  = big.NewInt(1)
)

func Primes(n *big.Int) []*big.Int {
    res := []*big.Int{}
    mod, div := new(big.Int), new(big.Int)
    for i := big.NewInt(2); i.Cmp(n) != 1; {
        div.DivMod(n, i, mod)
        for mod.Cmp(ZERO) == 0 {
            res = append(res, new(big.Int).Set(i))
            n.Set(div)
            div.DivMod(n, i, mod)
        }
        i.Add(i, ONE)
    }
    return res
}

func main() {
    vals := []int64{
        1 << 31,
        1234567,
        333333,
        987653,
        2 * 3 * 5 * 7 * 11 * 13 * 17,
    }
    for _, v := range vals {
        fmt.Println(v, "->", Primes(big.NewInt(v)))
    }
}







Fortran: module PrimeDecompose
  implicit none

  integer, parameter :: huge = selected_int_kind(18)
  

contains

  subroutine find_factors(n, d)
    integer(huge), intent(in) :: n
    integer, dimension(:), intent(out) :: d

    integer(huge) :: div, next, rest
    integer :: i

    i = 1
    div = 2; next = 3; rest = n
    
    do while ( rest /= 1 )
       do while ( mod(rest, div) == 0 ) 
          d(i) = div
          i = i + 1
          rest = rest / div
       end do
       div = next
       next = next + 2
    end do

  end subroutine find_factors

end module PrimeDecompose
Task: Prime decomposition





Java: public boolean prime(BigInteger i);






Fortran: module PrimeDecompose
  implicit none

  integer, parameter :: huge = selected_int_kind(18)
  

contains

  subroutine find_factors(n, d)
    integer(huge), intent(in) :: n
    integer, dimension(:), intent(out) :: d

    integer(huge) :: div, next, rest
    integer :: i

    i = 1
    div = 2; next = 3; rest = n
    
    do while ( rest /= 1 )
       do while ( mod(rest, div) == 0 ) 
          d(i) = div
          i = i + 1
          rest = rest / div
       end do
       div = next
       next = next + 2
    end do

  end subroutine find_factors

end module PrimeDecompose
Task: Prime decomposition







Python: from __future__ import print_function

import sys
from itertools import cycle

def is_prime(n):
    return list(zip((True, False), decompose(n)))[-1][0]

class IsPrimeCached(dict):
    def __missing__(self, n):
        r = is_prime(n)
        self[n] = r
        return r

is_prime_cached = IsPrimeCached()

def croft():
    
    
    
    
    
    
    
    
    
    for p in (2, 3, 5):
        yield p
    roots = {}  
    not_primeroot = tuple(x not in {1,7,11,13,17,19,23,29} for x in range(30))
    q = 1
    for x in cycle((6, 4, 2, 4, 2, 4, 6, 2)):
        
        q += x
        
        
        if q in roots:
            p = roots.pop(q)
            x = q + p
            while not_primeroot[x % 30] or x in roots:
                x += p
            roots[x] = p
        else:
            roots[q * q] = q + q
            yield q
primes = croft

def decompose(n):
    for p in primes():
        if p*p > n: break
        while n % p == 0:
            yield p
            n //=p
    if n > 1:
        yield n


if __name__ == '__main__':
    

    import time

    for m in primes():
        p = 2 ** m - 1
        print( "2**{0:d}-1 = {1:d}, with factors:".format(m, p) )
        start = time.time()
        for factor in decompose(p):
            print(factor, end=' ')
            sys.stdout.flush()

        print( "=> {0:.2f}s".format( time.time()-start ) )
        if m >= 59:
            break




Fortran: module PrimeDecompose
  implicit none

  integer, parameter :: huge = selected_int_kind(18)
  

contains

  subroutine find_factors(n, d)
    integer(huge), intent(in) :: n
    integer, dimension(:), intent(out) :: d

    integer(huge) :: div, next, rest
    integer :: i

    i = 1
    div = 2; next = 3; rest = n
    
    do while ( rest /= 1 )
       do while ( mod(rest, div) == 0 ) 
          d(i) = div
          i = i + 1
          rest = rest / div
       end do
       div = next
       next = next + 2
    end do

  end subroutine find_factors

end module PrimeDecompose
Task: Prime decomposition








VB: Function PrimeFactors(n)
    arrP = Split(ListPrimes(n)," ")
    divnum = n
    Do Until divnum = 1
        
        For i = 0 To UBound(arrP)-1
            If divnum = 1 Then
                Exit For
            ElseIf divnum Mod arrP(i) = 0 Then
                divnum = divnum/arrP(i)
                PrimeFactors = PrimeFactors & arrP(i) & " "
            End If
        Next
    Loop
End Function

Function IsPrime(n)
    If n = 2 Then
        IsPrime = True
    ElseIf n <= 1 Or n Mod 2 = 0 Then
        IsPrime = False
    Else
        IsPrime = True
        For i = 3 To Int(Sqr(n)) Step 2
            If n Mod i = 0 Then
                IsPrime = False
                Exit For
            End If
        Next
    End If
End Function

Function ListPrimes(n)
    ListPrimes = ""
    For i = 1 To n
        If IsPrime(i) Then
            ListPrimes = ListPrimes & i & " "
        End If
    Next
End Function

WScript.StdOut.Write PrimeFactors(CInt(WScript.Arguments(0)))
WScript.StdOut.WriteLine



Fortran: module PrimeDecompose
  implicit none

  integer, parameter :: huge = selected_int_kind(18)
  

contains

  subroutine find_factors(n, d)
    integer(huge), intent(in) :: n
    integer, dimension(:), intent(out) :: d

    integer(huge) :: div, next, rest
    integer :: i

    i = 1
    div = 2; next = 3; rest = n
    
    do while ( rest /= 1 )
       do while ( mod(rest, div) == 0 ) 
          d(i) = div
          i = i + 1
          rest = rest / div
       end do
       div = next
       next = next + 2
    end do

  end subroutine find_factors

end module PrimeDecompose
Task: Events



C#: using System;
using System.Timers;

class Program
{
    static void Main()
    {
        var timer = new Timer(1000);
        timer.Elapsed += new ElapsedEventHandler(OnElapsed);
        Console.WriteLine(DateTime.Now);
        timer.Start();
        Console.ReadLine();
    }

    static void OnElapsed(object sender, ElapsedEventArgs eventArgs)
    {
        Console.WriteLine(eventArgs.SignalTime);
        ((Timer)sender).Stop();
    }
}









Ada: protected type Event is
   procedure Signal;
   procedure Reset;
   entry Wait;
private
   Fired : Boolean := False;
end Event;
Task: Events

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

int main()
{
	int p[2];
	pipe(p);
	if (fork()) {
		close(p[0]);
		sleep(1);
		write(p[1], p, 1);
		wait(0);
	} else {
		close(p[1]);
		read(p[0], p + 1, 1);
		puts("received signal from pipe");
	}
	return 0;
}











Ada: protected type Event is
   procedure Signal;
   procedure Reset;
   entry Wait;
private
   Fired : Boolean := False;
end Event;
Task: Events




Go: package main

import (
    "log"
    "os"
    "time"
)

func main() {
    l := log.New(os.Stdout, "", log.Ltime | log.Lmicroseconds)
    l.Println("program start")
    event := make(chan int)
    go func() {
        l.Println("task start")
        <-event
        l.Println("event reset by task")
    }()
    l.Println("program sleeping")
    time.Sleep(1 * time.Second)
    l.Println("program signaling event")
    event <- 0
    time.Sleep(100 * time.Millisecond)
}








Ada: protected type Event is
   procedure Signal;
   procedure Reset;
   entry Wait;
private
   Fired : Boolean := False;
end Event;
Task: Events







Python: import threading
import time


def wait_for_event(event):
    event.wait()
    print("Thread: Got event")

e = threading.Event()

t = threading.Thread(target=wait_for_event, args=(e,))
t.start()

print("Main: Waiting one second")
time.sleep(1.0)
print("Main: Setting event")
e.set()
time.sleep(1.0)
print("Main: Done")
t.join()





Ada: protected type Event is
   procedure Signal;
   procedure Reset;
   entry Wait;
private
   Fired : Boolean := False;
end Event;
Task: Events

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

int main()
{
	int p[2];
	pipe(p);
	if (fork()) {
		close(p[0]);
		sleep(1);
		write(p[1], p, 1);
		wait(0);
	} else {
		close(p[1]);
		read(p[0], p + 1, 1);
		puts("received signal from pipe");
	}
	return 0;
}
Task: Events



C#: using System;
using System.Timers;

class Program
{
    static void Main()
    {
        var timer = new Timer(1000);
        timer.Elapsed += new ElapsedEventHandler(OnElapsed);
        Console.WriteLine(DateTime.Now);
        timer.Start();
        Console.ReadLine();
    }

    static void OnElapsed(object sender, ElapsedEventArgs eventArgs)
    {
        Console.WriteLine(eventArgs.SignalTime);
        ((Timer)sender).Stop();
    }
}
Task: Events







Python: import threading
import time


def wait_for_event(event):
    event.wait()
    print("Thread: Got event")

e = threading.Event()

t = threading.Thread(target=wait_for_event, args=(e,))
t.start()

print("Main: Waiting one second")
time.sleep(1.0)
print("Main: Setting event")
e.set()
time.sleep(1.0)
print("Main: Done")
t.join()
Task: Events




Go: package main

import (
    "log"
    "os"
    "time"
)

func main() {
    l := log.New(os.Stdout, "", log.Ltime | log.Lmicroseconds)
    l.Println("program start")
    event := make(chan int)
    go func() {
        l.Println("task start")
        <-event
        l.Println("event reset by task")
    }()
    l.Println("program sleeping")
    time.Sleep(1 * time.Second)
    l.Println("program signaling event")
    event <- 0
    time.Sleep(100 * time.Millisecond)
}
Task: Happy numbers



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

namespace HappyNums
{
    class Program
    {
        public static bool ishappy(int n)
        {
            List<int> cache = new List<int>();
            int sum = 0;
            while (n != 1)
            {
                if (cache.Contains(n))
                {
                    return false;
                }
                cache.Add(n);
                while (n != 0)
                {
                    int digit = n % 10;
                    sum += digit * digit;
                    n /= 10;
                }
                n = sum;
                sum = 0;
            }
           return true;            
        }

        static void Main(string[] args)
        {
            int num = 1;
            List<int> happynums = new List<int>();

            while (happynums.Count < 8)
            {
                if (ishappy(num))
                {
                    happynums.Add(num);
                }
                num++;
            }
            Console.WriteLine("First 8 happy numbers : " + string.Join(",", happynums));
        }
    }
}









Ada: with Ada.Text_IO;  use Ada.Text_IO;
with Ada.Containers.Ordered_Sets;

procedure Test_Happy_Digits is
   function Is_Happy (N : Positive) return Boolean is
      package Sets_Of_Positive is new Ada.Containers.Ordered_Sets (Positive);
      use Sets_Of_Positive;
      function Next (N : Positive) return Natural is
         Sum   : Natural := 0;
         Accum : Natural := N;
      begin
         while Accum > 0 loop
            Sum   := Sum + (Accum mod 10) ** 2;
            Accum := Accum / 10;
         end loop;
         return Sum;
      end Next;
      Current : Positive := N;
      Visited : Set;
   begin
      loop
         if Current = 1 then
            return True;
         elsif Visited.Contains (Current) then
            return False;
         else
            Visited.Insert (Current);
            Current := Next (Current);
         end if;
      end loop;
   end Is_Happy;
   Found : Natural := 0;
begin
   for N in Positive'Range loop
      if Is_Happy (N) then
         Put (Integer'Image (N));
         Found := Found + 1;
         exit when Found = 8;
      end if;
   end loop;
end Test_Happy_Digits;
Task: Happy numbers

C: #include <stdio.h>

#define CACHE 256
enum { h_unknown = 0, h_yes, h_no };
unsigned char buf[CACHE] = {0, h_yes, 0};

int happy(int n)
{
	int sum = 0, x, nn;
	if (n < CACHE) {
		if (buf[n]) return 2 - buf[n];
		buf[n] = h_no;
	}

	for (nn = n; nn; nn /= 10) x = nn % 10, sum += x * x;

	x = happy(sum);
	if (n < CACHE) buf[n] = 2 - x;
	return x;
}

int main()
{
	int i, cnt = 8;
	for (i = 1; cnt || !printf("\n"); i++)
		if (happy(i)) --cnt, printf("%d ", i);

	printf("The %dth happy number: ", cnt = 1000000);
	for (i = 1; cnt; i++)
		if (happy(i)) --cnt || printf("%d\n", i);

	return 0;
}











Ada: with Ada.Text_IO;  use Ada.Text_IO;
with Ada.Containers.Ordered_Sets;

procedure Test_Happy_Digits is
   function Is_Happy (N : Positive) return Boolean is
      package Sets_Of_Positive is new Ada.Containers.Ordered_Sets (Positive);
      use Sets_Of_Positive;
      function Next (N : Positive) return Natural is
         Sum   : Natural := 0;
         Accum : Natural := N;
      begin
         while Accum > 0 loop
            Sum   := Sum + (Accum mod 10) ** 2;
            Accum := Accum / 10;
         end loop;
         return Sum;
      end Next;
      Current : Positive := N;
      Visited : Set;
   begin
      loop
         if Current = 1 then
            return True;
         elsif Visited.Contains (Current) then
            return False;
         else
            Visited.Insert (Current);
            Current := Next (Current);
         end if;
      end loop;
   end Is_Happy;
   Found : Natural := 0;
begin
   for N in Positive'Range loop
      if Is_Happy (N) then
         Put (Integer'Image (N));
         Found := Found + 1;
         exit when Found = 8;
      end if;
   end loop;
end Test_Happy_Digits;
Task: Happy numbers


C++: #include <map>
#include <set>

bool happy(int number) {
  static std::map<int, bool> cache;

  std::set<int> cycle;
  while (number != 1 && !cycle.count(number)) {
    if (cache.count(number)) {
      number = cache[number] ? 1 : 0;
      break;
    }
    cycle.insert(number);
    int newnumber = 0;
    while (number > 0) {
      int digit = number % 10;
      newnumber += digit * digit;
      number /= 10;
    }
    number = newnumber;
  }
  bool happiness = number == 1;
  for (std::set<int>::const_iterator it = cycle.begin();
       it != cycle.end(); it++)
    cache[*it] = happiness;
  return happiness;
}

#include <iostream>

int main() {
  for (int i = 1; i < 50; i++)
    if (happy(i))
      std::cout << i << std::endl;
  return 0;
}










Ada: with Ada.Text_IO;  use Ada.Text_IO;
with Ada.Containers.Ordered_Sets;

procedure Test_Happy_Digits is
   function Is_Happy (N : Positive) return Boolean is
      package Sets_Of_Positive is new Ada.Containers.Ordered_Sets (Positive);
      use Sets_Of_Positive;
      function Next (N : Positive) return Natural is
         Sum   : Natural := 0;
         Accum : Natural := N;
      begin
         while Accum > 0 loop
            Sum   := Sum + (Accum mod 10) ** 2;
            Accum := Accum / 10;
         end loop;
         return Sum;
      end Next;
      Current : Positive := N;
      Visited : Set;
   begin
      loop
         if Current = 1 then
            return True;
         elsif Visited.Contains (Current) then
            return False;
         else
            Visited.Insert (Current);
            Current := Next (Current);
         end if;
      end loop;
   end Is_Happy;
   Found : Natural := 0;
begin
   for N in Positive'Range loop
      if Is_Happy (N) then
         Put (Integer'Image (N));
         Found := Found + 1;
         exit when Found = 8;
      end if;
   end loop;
end Test_Happy_Digits;
Task: Happy numbers




Go: package main

import "fmt"

func happy(n int) bool {
	m := make(map[int]bool)
	for n > 1 {
		m[n] = true
		var x int
		for x, n = n, 0; x > 0; x /= 10 {
			d := x % 10
			n += d * d
		}
		if m[n] {
			return false
		}
	}
	return true
}

func main() {
	for found, n := 0, 1; found < 8; n++ {
		if happy(n) {
			fmt.Print(n, " ")
			found++
		}
	}
	fmt.Println()
}








Ada: with Ada.Text_IO;  use Ada.Text_IO;
with Ada.Containers.Ordered_Sets;

procedure Test_Happy_Digits is
   function Is_Happy (N : Positive) return Boolean is
      package Sets_Of_Positive is new Ada.Containers.Ordered_Sets (Positive);
      use Sets_Of_Positive;
      function Next (N : Positive) return Natural is
         Sum   : Natural := 0;
         Accum : Natural := N;
      begin
         while Accum > 0 loop
            Sum   := Sum + (Accum mod 10) ** 2;
            Accum := Accum / 10;
         end loop;
         return Sum;
      end Next;
      Current : Positive := N;
      Visited : Set;
   begin
      loop
         if Current = 1 then
            return True;
         elsif Visited.Contains (Current) then
            return False;
         else
            Visited.Insert (Current);
            Current := Next (Current);
         end if;
      end loop;
   end Is_Happy;
   Found : Natural := 0;
begin
   for N in Positive'Range loop
      if Is_Happy (N) then
         Put (Integer'Image (N));
         Found := Found + 1;
         exit when Found = 8;
      end if;
   end loop;
end Test_Happy_Digits;
Task: Happy numbers





Java: import java.util.HashSet;
public class Happy{
   public static boolean happy(long number){
       long m = 0;
       int digit = 0;
       HashSet<Long> cycle = new HashSet<Long>();
       while(number != 1 && cycle.add(number)){
           m = 0;
           while(number > 0){
               digit = (int)(number % 10);
               m += digit*digit;
               number /= 10;
           }
           number = m;
       }
       return number == 1;
   }

   public static void main(String[] args){
       for(long num = 1,count = 0;count<8;num++){
           if(happy(num)){
               System.out.println(num);
               count++;
           }
       }
   }
}







Ada: with Ada.Text_IO;  use Ada.Text_IO;
with Ada.Containers.Ordered_Sets;

procedure Test_Happy_Digits is
   function Is_Happy (N : Positive) return Boolean is
      package Sets_Of_Positive is new Ada.Containers.Ordered_Sets (Positive);
      use Sets_Of_Positive;
      function Next (N : Positive) return Natural is
         Sum   : Natural := 0;
         Accum : Natural := N;
      begin
         while Accum > 0 loop
            Sum   := Sum + (Accum mod 10) ** 2;
            Accum := Accum / 10;
         end loop;
         return Sum;
      end Next;
      Current : Positive := N;
      Visited : Set;
   begin
      loop
         if Current = 1 then
            return True;
         elsif Visited.Contains (Current) then
            return False;
         else
            Visited.Insert (Current);
            Current := Next (Current);
         end if;
      end loop;
   end Is_Happy;
   Found : Natural := 0;
begin
   for N in Positive'Range loop
      if Is_Happy (N) then
         Put (Integer'Image (N));
         Found := Found + 1;
         exit when Found = 8;
      end if;
   end loop;
end Test_Happy_Digits;