WeixiangYan/CodeTransOcean huggingface dataset:
Task: Attractive numbers



C#: using System;

namespace AttractiveNumbers {
    class Program {
        const int MAX = 120;

        static bool IsPrime(int n) {
            if (n < 2) return false;
            if (n % 2 == 0) return n == 2;
            if (n % 3 == 0) return n == 3;
            int d = 5;
            while (d * d <= n) {
                if (n % d == 0) return false;
                d += 2;
                if (n % d == 0) return false;
                d += 4;
            }
            return true;
        }

        static int PrimeFactorCount(int n) {
            if (n == 1) return 0;
            if (IsPrime(n)) return 1;
            int count = 0;
            int f = 2;
            while (true) {
                if (n % f == 0) {
                    count++;
                    n /= f;
                    if (n == 1) return count;
                    if (IsPrime(n)) f = n;
                } else if (f >= 3) {
                    f += 2;
                } else {
                    f = 3;
                }
            }
        }

        static void Main(string[] args) {
            Console.WriteLine("The attractive numbers up to and including {0} are:", MAX);
            int i = 1;
            int count = 0;
            while (i <= MAX) {
                int n = PrimeFactorCount(i);
                if (IsPrime(n)) {
                    Console.Write("{0,4}", i);
                    if (++count % 20 == 0) Console.WriteLine();
                }
                ++i;
            }
            Console.WriteLine();
        }
    }
}
Task: Attractive numbers


C++: #include <iostream>
#include <iomanip>

#define MAX 120

using namespace std;

bool is_prime(int n) {   
    if (n < 2) return false;
    if (!(n % 2)) return n == 2;
    if (!(n % 3)) return n == 3;
    int d = 5;
    while (d *d <= n) {
        if (!(n % d)) return false;
        d += 2;
        if (!(n % d)) return false;
        d += 4;
    }
    return true;
}

int count_prime_factors(int n) {    
    if (n == 1) return 0;
    if (is_prime(n)) return 1;
    int count = 0, f = 2;
    while (true) {
        if (!(n % f)) {
            count++;
            n /= f;
            if (n == 1) return count;
            if (is_prime(n)) f = n;
        } 
        else if (f >= 3) f += 2;
        else f = 3;
    }
}

int main() {
    cout << "The attractive numbers up to and including " << MAX << " are:" << endl;
    for (int i = 1, count = 0; i <= MAX; ++i) {
        int n = count_prime_factors(i);
        if (is_prime(n)) {
            cout << setw(4) << i;
            if (!(++count % 20)) cout << endl;
        }
    }
    cout << endl;
    return 0;
}
Task: Attractive numbers





Java: public class Attractive {

    static boolean is_prime(int n) {
        if (n < 2) return false;
        if (n % 2 == 0) return n == 2;
        if (n % 3 == 0) return n == 3;
        int d = 5;
        while (d *d <= n) {
            if (n % d == 0) return false;
            d += 2;
            if (n % d == 0) return false;
            d += 4;
        }
        return true;
    }

    static int count_prime_factors(int n) {
        if (n == 1) return 0;
        if (is_prime(n)) return 1;
        int count = 0, f = 2;
        while (true) {
            if (n % f == 0) {
                count++;
                n /= f;
                if (n == 1) return count;
                if (is_prime(n)) f = n;
            }
            else if (f >= 3) f += 2;
            else f = 3;
        }
    }

    public static void main(String[] args) {
        final int max = 120;
        System.out.printf("The attractive numbers up to and including %d are:\n", max);
        for (int i = 1, count = 0; i <= max; ++i) {
            int n = count_prime_factors(i);
            if (is_prime(n)) {
                System.out.printf("%4d", i);
                if (++count % 20 == 0) System.out.println();
            }
        }
        System.out.println();
    }
}
Task: Attractive numbers







Python: from sympy import sieve 

def get_pfct(n): 
	i = 2; factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return len(factors) 

sieve.extend(110) 
primes=sieve._list

pool=[]

for each in xrange(0,121):
	pool.append(get_pfct(each))

for i,each in enumerate(pool):
	if each in primes:
		print i,
Task: Attractive numbers








VB: Module Module1
    Const MAX = 120

    Function IsPrime(n As Integer) As Boolean
        If n < 2 Then Return False
        If n Mod 2 = 0 Then Return n = 2
        If n Mod 3 = 0 Then Return n = 3
        Dim d = 5
        While d * d <= n
            If n Mod d = 0 Then Return False
            d += 2
            If n Mod d = 0 Then Return False
            d += 4
        End While
        Return True
    End Function

    Function PrimefactorCount(n As Integer) As Integer
        If n = 1 Then Return 0
        If IsPrime(n) Then Return 1
        Dim count = 0
        Dim f = 2
        While True
            If n Mod f = 0 Then
                count += 1
                n /= f
                If n = 1 Then Return count
                If IsPrime(n) Then f = n
            ElseIf f >= 3 Then
                f += 2
            Else
                f = 3
            End If
        End While
        Throw New Exception("Unexpected")
    End Function

    Sub Main()
        Console.WriteLine("The attractive numbers up to and including {0} are:", MAX)
        Dim i = 1
        Dim count = 0
        While i <= MAX
            Dim n = PrimefactorCount(i)
            If IsPrime(n) Then
                Console.Write("{0,4}", i)
                count += 1
                If count Mod 20 = 0 Then
                    Console.WriteLine()
                End If
            End If
                i += 1
        End While
        Console.WriteLine()
    End Sub

End Module
Task: Attractive numbers




Go: package main

import "fmt"

func isPrime(n int) bool {
    switch {
    case n < 2:
        return false
    case n%2 == 0:
        return n == 2
    case n%3 == 0:
        return n == 3
    default:
        d := 5
        for d*d <= n {
            if n%d == 0 {
                return false
            }
            d += 2
            if n%d == 0 {
                return false
            }
            d += 4
        }
        return true
    }
}

func countPrimeFactors(n int) int {
    switch {
    case n == 1:
        return 0
    case isPrime(n):
        return 1
    default:
        count, f := 0, 2
        for {
            if n%f == 0 {
                count++
                n /= f
                if n == 1 {
                    return count
                }
                if isPrime(n) {
                    f = n
                }
            } else if f >= 3 {
                f += 2
            } else {
                f = 3
            }
        }
        return count
    }
}

func main() {
    const max = 120
    fmt.Println("The attractive numbers up to and including", max, "are:")
    count := 0
    for i := 1; i <= max; i++ {
        n := countPrimeFactors(i)
        if isPrime(n) {
            fmt.Printf("%4d", i)
            count++
            if count % 20 == 0 {
                fmt.Println()
            }
        }       
    }
    fmt.Println()
}
Task: Attractive numbers







Python: from sympy import sieve 

def get_pfct(n): 
	i = 2; factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return len(factors) 

sieve.extend(110) 
primes=sieve._list

pool=[]

for each in xrange(0,121):
	pool.append(get_pfct(each))

for i,each in enumerate(pool):
	if each in primes:
		print i,




Fortran: program attractive_numbers
    use iso_fortran_env, only: output_unit
    implicit none

    integer, parameter  :: maximum=120, line_break=20
    integer             :: i, counter

    write(output_unit,'(A,x,I0,x,A)') "The attractive numbers up to and including", maximum, "are:"

    counter = 0
    do i = 1, maximum
        if (is_prime(count_prime_factors(i))) then
            write(output_unit,'(I0,x)',advance="no") i
            counter = counter + 1
            if (modulo(counter, line_break) == 0) write(output_unit,*)
        end if
    end do
    write(output_unit,*)
contains
    pure function is_prime(n)
        integer, intent(in) :: n
        logical             :: is_prime
        integer             :: d

        is_prime = .false.

        d = 5
        if (n < 2) return
        if (modulo(n, 2) == 0) then
            is_prime = n==2
            return
        end if
        if (modulo(n, 3) == 0) then
            is_prime = n==3
            return
        end if

        do
            if (d**2 > n) then
                is_prime = .true.
                return
            end if
            if (modulo(n, d) == 0) then
                is_prime = .false.
                return
            end if
            d = d + 2
            if (modulo(n, d) == 0) then
                is_prime = .false.
                return
            end if
            d = d + 4
        end do

        is_prime = .true.
    end function is_prime

    pure function count_prime_factors(n)
        integer, intent(in)     :: n
        integer                 :: count_prime_factors
        integer                 :: i, f

        count_prime_factors = 0
        if (n == 1) return
        if (is_prime(n)) then
            count_prime_factors = 1
            return
        end if
        count_prime_factors = 0
        f = 2
        i = n

        do
            if (modulo(i, f) == 0) then
                count_prime_factors = count_prime_factors + 1
                i = i/f
                if (i == 1) exit
                if (is_prime(i)) f = i
            else if (f >= 3) then
                f = f + 2
            else
                f = 3
            end if
        end do
    end function count_prime_factors
end program attractive_numbers
Task: Attractive numbers






PHP: <?php
  function isPrime ($x) {
    if ($x < 2) return false;
    if ($x < 4) return true;
    if ($x % 2 == 0) return false;
    for ($d = 3; $d < sqrt($x); $d++) {
      if ($x % $d == 0) return false;
    }
    return true;
  }
  
  function countFacs ($n) {
    $count = 0;
    $divisor = 1;
    if ($n < 2) return 0;
    while (!isPrime($n)) {
      while (!isPrime($divisor)) $divisor++;
      while ($n % $divisor == 0) {
        $n /= $divisor;
        $count++;
      }
      $divisor++;
      if ($n == 1) return $count;
    }
  return $count + 1;
  }
  
  for ($i = 1; $i <= 120; $i++) {
    if (isPrime(countFacs($i))) echo $i."&ensp;";
  }
?>





Fortran: program attractive_numbers
    use iso_fortran_env, only: output_unit
    implicit none

    integer, parameter  :: maximum=120, line_break=20
    integer             :: i, counter

    write(output_unit,'(A,x,I0,x,A)') "The attractive numbers up to and including", maximum, "are:"

    counter = 0
    do i = 1, maximum
        if (is_prime(count_prime_factors(i))) then
            write(output_unit,'(I0,x)',advance="no") i
            counter = counter + 1
            if (modulo(counter, line_break) == 0) write(output_unit,*)
        end if
    end do
    write(output_unit,*)
contains
    pure function is_prime(n)
        integer, intent(in) :: n
        logical             :: is_prime
        integer             :: d

        is_prime = .false.

        d = 5
        if (n < 2) return
        if (modulo(n, 2) == 0) then
            is_prime = n==2
            return
        end if
        if (modulo(n, 3) == 0) then
            is_prime = n==3
            return
        end if

        do
            if (d**2 > n) then
                is_prime = .true.
                return
            end if
            if (modulo(n, d) == 0) then
                is_prime = .false.
                return
            end if
            d = d + 2
            if (modulo(n, d) == 0) then
                is_prime = .false.
                return
            end if
            d = d + 4
        end do

        is_prime = .true.
    end function is_prime

    pure function count_prime_factors(n)
        integer, intent(in)     :: n
        integer                 :: count_prime_factors
        integer                 :: i, f

        count_prime_factors = 0
        if (n == 1) return
        if (is_prime(n)) then
            count_prime_factors = 1
            return
        end if
        count_prime_factors = 0
        f = 2
        i = n

        do
            if (modulo(i, f) == 0) then
                count_prime_factors = count_prime_factors + 1
                i = i/f
                if (i == 1) exit
                if (is_prime(i)) f = i
            else if (f >= 3) then
                f = f + 2
            else
                f = 3
            end if
        end do
    end function count_prime_factors
end program attractive_numbers
Task: Attractive numbers







Python: from sympy import sieve 

def get_pfct(n): 
	i = 2; factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return len(factors) 

sieve.extend(110) 
primes=sieve._list

pool=[]

for each in xrange(0,121):
	pool.append(get_pfct(each))

for i,each in enumerate(pool):
	if each in primes:
		print i,



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ATTRACTIVE-NUMBERS.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 MAXIMUM         PIC 999 VALUE 120.
       01 SIEVE-DATA      VALUE SPACES.
          03 MARKER       PIC X OCCURS 120 TIMES.
             88 PRIME     VALUE SPACE.
          03 SIEVE-MAX    PIC 999.
          03 COMPOSITE    PIC 999.
          03 CANDIDATE    PIC 999.

       01 FACTORIZE-DATA.
          03 FACTOR-NUM   PIC 999.
          03 FACTORS      PIC 999.
          03 FACTOR       PIC 999.
          03 QUOTIENT     PIC 999V999.
          03 FILLER       REDEFINES QUOTIENT.
             05 FILLER    PIC 999.
             05 DECIMAL   PIC 999.

       01 OUTPUT-FORMAT.
          03 OUT-NUM      PIC ZZZ9.
          03 OUT-LINE     PIC X(72) VALUE SPACES.
          03 COL-PTR      PIC 99 VALUE 1.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM SIEVE.
           PERFORM CHECK-ATTRACTIVE
               VARYING CANDIDATE FROM 2 BY 1
               UNTIL CANDIDATE IS GREATER THAN MAXIMUM.
           PERFORM WRITE-LINE.
           STOP RUN.

       CHECK-ATTRACTIVE.
           MOVE CANDIDATE TO FACTOR-NUM.
           PERFORM FACTORIZE.
           IF PRIME(FACTORS), PERFORM ADD-TO-OUTPUT.

       ADD-TO-OUTPUT.
           MOVE CANDIDATE TO OUT-NUM.
           STRING OUT-NUM DELIMITED BY SIZE INTO OUT-LINE
               WITH POINTER COL-PTR.
           IF COL-PTR IS EQUAL TO 73, PERFORM WRITE-LINE.

       WRITE-LINE.
           DISPLAY OUT-LINE.
           MOVE SPACES TO OUT-LINE.
           MOVE 1 TO COL-PTR.

       FACTORIZE SECTION.
       BEGIN.
           MOVE ZERO TO FACTORS.
           PERFORM DIVIDE-PRIME
               VARYING FACTOR FROM 2 BY 1
               UNTIL FACTOR IS GREATER THAN MAXIMUM.
           GO TO DONE.

       DIVIDE-PRIME.
           IF PRIME(FACTOR),
               DIVIDE FACTOR-NUM BY FACTOR GIVING QUOTIENT,
               IF DECIMAL IS EQUAL TO ZERO,
                   ADD 1 TO FACTORS,
                   MOVE QUOTIENT TO FACTOR-NUM,
                   GO TO DIVIDE-PRIME.
       DONE.
           EXIT.

       SIEVE SECTION.
       BEGIN.
           MOVE 'X' TO MARKER(1).
           DIVIDE MAXIMUM BY 2 GIVING SIEVE-MAX.
           PERFORM SET-COMPOSITES THRU SET-COMPOSITES-LOOP
               VARYING CANDIDATE FROM 2 BY 1
               UNTIL CANDIDATE IS GREATER THAN SIEVE-MAX.
           GO TO DONE.

       SET-COMPOSITES.
           MULTIPLY CANDIDATE BY 2 GIVING COMPOSITE.
       SET-COMPOSITES-LOOP.
           IF COMPOSITE IS NOT GREATER THAN MAXIMUM,
               MOVE 'X' TO MARKER(COMPOSITE),
               ADD CANDIDATE TO COMPOSITE,
               GO TO SET-COMPOSITES-LOOP.
       DONE.
           EXIT.
Task: Attractive numbers






PHP: <?php
  function isPrime ($x) {
    if ($x < 2) return false;
    if ($x < 4) return true;
    if ($x % 2 == 0) return false;
    for ($d = 3; $d < sqrt($x); $d++) {
      if ($x % $d == 0) return false;
    }
    return true;
  }
  
  function countFacs ($n) {
    $count = 0;
    $divisor = 1;
    if ($n < 2) return 0;
    while (!isPrime($n)) {
      while (!isPrime($divisor)) $divisor++;
      while ($n % $divisor == 0) {
        $n /= $divisor;
        $count++;
      }
      $divisor++;
      if ($n == 1) return $count;
    }
  return $count + 1;
  }
  
  for ($i = 1; $i <= 120; $i++) {
    if (isPrime(countFacs($i))) echo $i."&ensp;";
  }
?>
Task: Attractive numbers






PHP: <?php
  function isPrime ($x) {
    if ($x < 2) return false;
    if ($x < 4) return true;
    if ($x % 2 == 0) return false;
    for ($d = 3; $d < sqrt($x); $d++) {
      if ($x % $d == 0) return false;
    }
    return true;
  }
  
  function countFacs ($n) {
    $count = 0;
    $divisor = 1;
    if ($n < 2) return 0;
    while (!isPrime($n)) {
      while (!isPrime($divisor)) $divisor++;
      while ($n % $divisor == 0) {
        $n /= $divisor;
        $count++;
      }
      $divisor++;
      if ($n == 1) return $count;
    }
  return $count + 1;
  }
  
  for ($i = 1; $i <= 120; $i++) {
    if (isPrime(countFacs($i))) echo $i."&ensp;";
  }
?>






Ada: with Ada.Text_IO;

procedure Attractive_Numbers is

   function Is_Prime (N : in Natural) return Boolean is
      D : Natural := 5;
   begin
      if N < 2       then  return False;  end if;
      if N mod 2 = 0 then  return N = 2;  end if;
      if N mod 3 = 0 then  return N = 3;  end if;

      while D * D <= N loop
         if N mod D = 0 then  return False;  end if;
         D := D + 2;
         if N mod D = 0 then  return False;  end if;
         D := D + 4;
      end loop;
      return True;
   end Is_Prime;

   function Count_Prime_Factors (N : in Natural) return Natural is
      NC    : Natural := N;
      Count : Natural := 0;
      F     : Natural := 2;
   begin
      if NC = 1        then  return 0;  end if;
      if Is_Prime (NC) then  return 1;  end if;
      loop
         if NC mod F = 0 then
            Count := Count + 1;
            NC := NC / F;

            if NC = 1 then
               return Count;
            end if;

            if Is_Prime (NC) then F := NC; end if;
         elsif F >= 3 then
            F := F + 2;
         else
            F := 3;
         end if;
      end loop;
   end Count_Prime_Factors;

   procedure Show_Attractive (Max : in Natural)
   is
      use Ada.Text_IO;
      package Integer_IO is
         new Ada.Text_IO.Integer_IO (Integer);
      N     : Natural;
      Count : Natural := 0;
   begin
      Put_Line ("The attractive numbers up to and including " & Max'Image & " are:");
      for I in 1 .. Max loop
         N := Count_Prime_Factors (I);
         if Is_Prime (N) then
            Integer_IO.Put (I, Width => 5);
            Count := Count + 1;
            if Count mod 20 = 0 then New_Line; end if;
         end if;
      end loop;
   end Show_Attractive;

begin
   Show_Attractive (Max => 120);
end Attractive_Numbers;
Task: Convex hull







Python: from __future__ import print_function
from shapely.geometry import MultiPoint

if __name__=="__main__":
	pts = MultiPoint([(16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2), (12,10)])
	print (pts.convex_hull)





Ada: with Ada.Text_IO;
with Ada.Containers.Vectors;

procedure Convex_Hull is

   type Point is record
      X, Y : Integer;
   end record;

   package Point_Vectors is
      new Ada.Containers.Vectors (Index_Type   => Positive,
                                  Element_Type => Point);
   use Point_Vectors;

   function Find_Convex_Hull (Vec : in Vector) return Vector is

      function Counter_Clock_Wise (A, B, C : in Point) return Boolean is
         ((B.X - A.X) * (C.Y - A.Y) > (B.Y - A.Y) * (C.X - A.X));

      function Less_Than (Left, Right : Point) return Boolean is
         (Left.X < Right.X);

      package Sorter is
         new Point_Vectors.Generic_Sorting (Less_Than);

      Sorted : Vector := Vec;
      Result : Vector := Empty_vector;
      use type Ada.Containers.Count_Type;
   begin
      if Vec = Empty_Vector then
         return Empty_Vector;
      end if;

      Sorter.Sort (Sorted);

      
      for Index in Sorted.First_Index .. Sorted.Last_Index loop
         while
           Result.Length >= 2 and then
           not Counter_Clock_Wise (Result (Result.Last_Index - 1),
                                   Result (Result.Last_Index),
                                   Sorted (Index))
         loop
            Result.Delete_Last;
         end loop;
         Result.Append (Sorted (Index));
      end loop;

      
      declare
         T : constant Ada.Containers.Count_Type := Result.Length + 1;
      begin
         for Index in reverse Sorted.First_Index .. Sorted.Last_Index loop
            while
              Result.Length >= T and then
              not Counter_Clock_Wise (Result (Result.Last_Index - 1),
                                      Result (Result.Last_Index),
                                      Sorted (Index))
            loop
               Result.Delete_Last;
            end loop;
            Result.Append (Sorted (Index));
         end loop;
      end;

      Result.Delete_Last;
      return Result;
   end Find_Convex_Hull;

   procedure Show (Vec : in Vector) is
      use Ada.Text_IO;
   begin
      Put ("[ ");
      for Point of Vec loop
         Put ("(" & Point.X'Image & "," & Point.Y'Image & ")");
      end loop;
      Put (" ]");
   end Show;

   Vec : constant Vector :=
     (16, 3) & (12,17) & ( 0, 6) & (-4,-6) & (16, 6) &
     (16,-7) & (16,-3) & (17,-4) & ( 5,19) & (19,-8) &
     ( 3,16) & (12,13) & ( 3,-4) & (17, 5) & (-3,15) &
     (-3,-9) & ( 0,11) & (-9,-3) & (-4,-2) & (12,10);
begin
   Show (Find_Convex_Hull (Vec));
   Ada.Text_IO.New_Line;
end Convex_Hull;