WeixiangYan/CodeTransOcean huggingface dataset:
Task: Assertions

C: #include <assert.h>

int main(){
   int a;
   
   assert(a == 42); 

   return 0;
}


C++: #include <cassert> 

int main()
{
  int a;
  

  assert(a == 42); 
                    
}
Task: Assertions

C: #include <assert.h>

int main(){
   int a;
   
   assert(a == 42); 

   return 0;
}




Go: package main

func main() {
    x := 43
    if x != 42 {
        panic(42)
    }
}
Task: Assertions

C: #include <assert.h>

int main(){
   int a;
   
   assert(a == 42); 

   return 0;
}







Python: a = 5

assert a == 42 
assert a == 42, "Error message"
Task: Assertions

C: #include <assert.h>

int main(){
   int a;
   
   assert(a == 42); 

   return 0;
}








VB: Imports System.Diagnostics



Module Program
    Sub Main()
        Dim a As Integer = 0

        Console.WriteLine("Before")

        
        Trace.Assert(a = 42, "Trace assertion failed: The Answer was incorrect")

        Console.WriteLine("After Trace.Assert")

        
        Debug.Assert(a = 42, "Debug assertion failed: The Answer was incorrect")

        Console.WriteLine("After Debug.Assert")
    End Sub
End Module
Task: Assertions


C++: #include <cassert> 

int main()
{
  int a;
  

  assert(a == 42); 
                    
}


C#: using System.Diagnostics; 

static class Program
{
    static void Main()
    {
        int a = 0;

        Console.WriteLine("Before");

        
        Trace.Assert(a == 42, "Trace assertion failed");

        Console.WriteLine("After Trace.Assert");

        
        Debug.Assert(a == 42, "Debug assertion failed");

        Console.WriteLine("After Debug.Assert");
    }
}
Task: Assertions


C++: #include <cassert> 

int main()
{
  int a;
  

  assert(a == 42); 
                    
}







VB: Imports System.Diagnostics



Module Program
    Sub Main()
        Dim a As Integer = 0

        Console.WriteLine("Before")

        
        Trace.Assert(a = 42, "Trace assertion failed: The Answer was incorrect")

        Console.WriteLine("After Trace.Assert")

        
        Debug.Assert(a = 42, "Debug assertion failed: The Answer was incorrect")

        Console.WriteLine("After Debug.Assert")
    End Sub
End Module
Task: Assertions



C#: using System.Diagnostics; 

static class Program
{
    static void Main()
    {
        int a = 0;

        Console.WriteLine("Before");

        
        Trace.Assert(a == 42, "Trace assertion failed");

        Console.WriteLine("After Trace.Assert");

        
        Debug.Assert(a == 42, "Debug assertion failed");

        Console.WriteLine("After Debug.Assert");
    }
}



Java: public class Assertions {

    public static void main(String[] args) {
        int a = 13;

        

        assert a == 42;
        

        assert a == 42 : "Error message";
        
        
        
    }
}
Task: Assertions





Java: public class Assertions {

    public static void main(String[] args) {
        int a = 13;

        

        assert a == 42;
        

        assert a == 42 : "Error message";
        
        
        
    }
}




VB: Imports System.Diagnostics



Module Program
    Sub Main()
        Dim a As Integer = 0

        Console.WriteLine("Before")

        
        Trace.Assert(a = 42, "Trace assertion failed: The Answer was incorrect")

        Console.WriteLine("After Trace.Assert")

        
        Debug.Assert(a = 42, "Debug assertion failed: The Answer was incorrect")

        Console.WriteLine("After Debug.Assert")
    End Sub
End Module
Task: Assertions




Go: package main

func main() {
    x := 43
    if x != 42 {
        panic(42)
    }
}




Python: a = 5

assert a == 42 
assert a == 42, "Error message"
Task: Assertions




Go: package main

func main() {
    x := 43
    if x != 42 {
        panic(42)
    }
}





VB: Imports System.Diagnostics



Module Program
    Sub Main()
        Dim a As Integer = 0

        Console.WriteLine("Before")

        
        Trace.Assert(a = 42, "Trace assertion failed: The Answer was incorrect")

        Console.WriteLine("After Trace.Assert")

        
        Debug.Assert(a = 42, "Debug assertion failed: The Answer was incorrect")

        Console.WriteLine("After Debug.Assert")
    End Sub
End Module
Task: Assertions







Python: a = 5

assert a == 42 
assert a == 42, "Error message" 
       
       


VB: Imports System.Diagnostics



Module Program
    Sub Main()
        Dim a As Integer = 0

        Console.WriteLine("Before")

        
        Trace.Assert(a = 42, "Trace assertion failed: The Answer was incorrect")

        Console.WriteLine("After Trace.Assert")

        
        Debug.Assert(a = 42, "Debug assertion failed: The Answer was incorrect")

        Console.WriteLine("After Debug.Assert")
    End Sub
End Module
Task: Assertions

C: #include <assert.h>

int main(){
   int a;
   
   assert(a == 42); 

   return 0;
}



C#: using System.Diagnostics; 

static class Program
{
    static void Main()
    {
        int a = 0;

        Console.WriteLine("Before");

        
        Trace.Assert(a == 42, "Trace assertion failed");

        Console.WriteLine("After Trace.Assert");

        
        Debug.Assert(a == 42, "Debug assertion failed");

        Console.WriteLine("After Debug.Assert");
    }
}
Task: Assertions


C++: #include <cassert> 

int main()
{
  int a;
  

  assert(a == 42); 
                    
}



Go: package main

func main() {
    x := 43
    if x != 42 {
        panic(42)
    }
}
Task: Assertions


C++: #include <cassert> 

int main()
{
  int a;
  

  assert(a == 42); 
                    
}




Java: public class Assertions {

    public static void main(String[] args) {
        int a = 13;

        

        assert a == 42;
        

        assert a == 42 : "Error message";
        
        
        
    }
}
Task: Assertions


C++: #include <cassert> 

int main()
{
  int a;
  

  assert(a == 42); 
                    
}






Python: a = 5

assert a == 42 
assert a == 42, "Error message"
Task: Assertions



C#: using System.Diagnostics; 

static class Program
{
    static void Main()
    {
        int a = 0;

        Console.WriteLine("Before");

        
        Trace.Assert(a == 42, "Trace assertion failed");

        Console.WriteLine("After Trace.Assert");

        
        Debug.Assert(a == 42, "Debug assertion failed");

        Console.WriteLine("After Debug.Assert");
    }
}


Go: package main

func main() {
    x := 43
    if x != 42 {
        panic(42)
    }
}
Task: Assertions



C#: using System.Diagnostics; 

static class Program
{
    static void Main()
    {
        int a = 0;

        Console.WriteLine("Before");

        
        Trace.Assert(a == 42, "Trace assertion failed");

        Console.WriteLine("After Trace.Assert");

        
        Debug.Assert(a == 42, "Debug assertion failed");

        Console.WriteLine("After Debug.Assert");
    }
}





Python: a = 5

assert a == 42 
assert a == 42, "Error message"
Task: Assertions




Go: package main

func main() {
    x := 43
    if x != 42 {
        panic(42)
    }
}


Java: public class Assertions {

    public static void main(String[] args) {
        int a = 13;

        

        assert a == 42;
        

        assert a == 42 : "Error message";
        
        
        
    }
}
Task: Assertions





Java: public class Assertions {

    public static void main(String[] args) {
        int a = 13;

        

        assert a == 42;
        

        assert a == 42 : "Error message";
        
        
        
    }
}



Python: a = 5

assert a == 42 
assert a == 42, "Error message"
Task: Assertions

C: #include <assert.h>

int main(){
   int a;
   
   assert(a == 42); 

   return 0;
}





Java: public class Assertions {

    public static void main(String[] args) {
        int a = 13;

        

        assert a == 42;
        

        assert a == 42 : "Error message";
        
        
        
    }
}
Task: Assertions



C#: using System.Diagnostics; 

static class Program
{
    static void Main()
    {
        int a = 0;

        Console.WriteLine("Before");

        
        Trace.Assert(a == 42, "Trace assertion failed");

        Console.WriteLine("After Trace.Assert");

        
        Debug.Assert(a == 42, "Debug assertion failed");

        Console.WriteLine("After Debug.Assert");
    }
}






VB: Imports System.Diagnostics



Module Program
    Sub Main()
        Dim a As Integer = 0

        Console.WriteLine("Before")

        
        Trace.Assert(a = 42, "Trace assertion failed: The Answer was incorrect")

        Console.WriteLine("After Trace.Assert")

        
        Debug.Assert(a = 42, "Debug assertion failed: The Answer was incorrect")

        Console.WriteLine("After Debug.Assert")
    End Sub
End Module
Task: Assertions

C: #include <assert.h>

int main(){
   int a;
   
   assert(a == 42); 

   return 0;
}






PHP: <?php
$a = 5
#...input or change $a here
assert($a == 42) # when $a is not 42, take appropriate actions,
                 # which is set by assert_options()
?>
Task: Assertions



C#: using System.Diagnostics; 

static class Program
{
    static void Main()
    {
        int a = 0;

        Console.WriteLine("Before");

        
        Trace.Assert(a == 42, "Trace assertion failed");

        Console.WriteLine("After Trace.Assert");

        
        Debug.Assert(a == 42, "Debug assertion failed");

        Console.WriteLine("After Debug.Assert");
    }
}




PHP: <?php
$a = 5
#...input or change $a here
assert($a == 42) # when $a is not 42, take appropriate actions,
                 # which is set by assert_options()
?>
Task: Assertions


C++: #include <cassert> 

int main()
{
  int a;
  

  assert(a == 42); 
                    
}





PHP: <?php
$a = 5
#...input or change $a here
assert($a == 42) # when $a is not 42, take appropriate actions,
                 # which is set by assert_options()
?>
Task: Assertions




Go: package main

func main() {
    x := 43
    if x != 42 {
        panic(42)
    }
}



PHP: <?php
$a = 5
#...input or change $a here
assert($a == 42) # when $a is not 42, take appropriate actions,
                 # which is set by assert_options()
?>
Task: Assertions





Java: public class Assertions {

    public static void main(String[] args) {
        int a = 13;

        

        assert a == 42;
        

        assert a == 42 : "Error message";
        
        
        
    }
}


PHP: <?php
$a = 5
#...input or change $a here
assert($a == 42) # when $a is not 42, take appropriate actions,
                 # which is set by assert_options()
?>
Task: Assertions






PHP: <?php
$a = 5
#...input or change $a here
assert($a == 42) # when $a is not 42, take appropriate actions,
                 # which is set by assert_options()
?>


Python: a = 5

assert a == 42 
assert a == 42, "Error message"
Task: Assertions






PHP: <?php
$a = 5
#...input or change $a here
assert($a == 42) # when $a is not 42, take appropriate actions,
                 # which is set by assert_options()
?>



VB: Imports System.Diagnostics



Module Program
    Sub Main()
        Dim a As Integer = 0

        Console.WriteLine("Before")

        
        Trace.Assert(a = 42, "Trace assertion failed: The Answer was incorrect")

        Console.WriteLine("After Trace.Assert")

        
        Debug.Assert(a = 42, "Debug assertion failed: The Answer was incorrect")

        Console.WriteLine("After Debug.Assert")
    End Sub
End Module
Task: Primality by Wilson's theorem

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

uint64_t factorial(uint64_t n) {
    uint64_t product = 1;

    if (n < 2) {
        return 1;
    }

    for (; n > 0; n--) {
        uint64_t prev = product;
        product *= n;
        if (product < prev) {
            fprintf(stderr, "Overflowed\n");
            return product;
        }
    }

    return product;
}


bool isPrime(uint64_t n) {
    uint64_t large = factorial(n - 1) + 1;
    return (large % n) == 0;
}

int main() {
    uint64_t n;

    
    for (n = 2; n < 22; n++) {
        printf("Is %llu prime: %d\n", n, isPrime(n));
    }

    return 0;
}


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

int factorial_mod(int n, int p) {
    int f = 1;
    for (; n > 0 && f != 0; --n)
        f = (f * n) % p;
    return f;
}

bool is_prime(int p) {
    return p > 1 && factorial_mod(p - 1, p) == p - 1;
}

int main() {
    std::cout << "  n | prime?\n------------\n";
    std::cout << std::boolalpha;
    for (int p : {2, 3, 9, 15, 29, 37, 47, 57, 67, 77, 87, 97, 237, 409, 659})
        std::cout << std::setw(3) << p << " | " << is_prime(p) << '\n';

    std::cout << "\nFirst 120 primes by Wilson's theorem:\n";
    int n = 0, p = 1;
    for (; n < 120; ++p) {
        if (is_prime(p))
            std::cout << std::setw(3) << p << (++n % 20 == 0 ? '\n' : ' ');
    }

    std::cout << "\n1000th through 1015th primes:\n";
    for (int i = 0; n < 1015; ++p) {
        if (is_prime(p)) {
            if (++n >= 1000)
                std::cout << std::setw(4) << p << (++i % 16 == 0 ? '\n' : ' ');
        }
    }
}
Task: Primality by Wilson's theorem

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

uint64_t factorial(uint64_t n) {
    uint64_t product = 1;

    if (n < 2) {
        return 1;
    }

    for (; n > 0; n--) {
        uint64_t prev = product;
        product *= n;
        if (product < prev) {
            fprintf(stderr, "Overflowed\n");
            return product;
        }
    }

    return product;
}


bool isPrime(uint64_t n) {
    uint64_t large = factorial(n - 1) + 1;
    return (large % n) == 0;
}

int main() {
    uint64_t n;

    
    for (n = 2; n < 22; n++) {
        printf("Is %llu prime: %d\n", n, isPrime(n));
    }

    return 0;
}




Go: package main

import (
    "fmt"
    "math/big"
)

var (
    zero = big.NewInt(0)
    one  = big.NewInt(1)
    prev = big.NewInt(factorial(20))
)


func factorial(n int64) int64 {
    res := int64(1)
    for k := n; k > 1; k-- {
        res *= k
    }
    return res
}



func wilson(n int64, memo bool) bool {
    if n <= 1 || (n%2 == 0 && n != 2) {
        return false
    }
    if n <= 21 {
        return (factorial(n-1)+1)%n == 0
    }
    b := big.NewInt(n)
    r := big.NewInt(0)
    z := big.NewInt(0)
    if !memo {
        z.MulRange(2, n-1) 
    } else {
        prev.Mul(prev, r.MulRange(n-2, n-1)) 
        z.Set(prev)
    }
    z.Add(z, one)
    return r.Rem(z, b).Cmp(zero) == 0    
}

func main() {
    numbers := []int64{2, 3, 9, 15, 29, 37, 47, 57, 67, 77, 87, 97, 237, 409, 659}
    fmt.Println("  n  prime")
    fmt.Println("---  -----")
    for _, n := range numbers {
        fmt.Printf("%3d  %t\n", n, wilson(n, false))
    }

    
    fmt.Println("\nThe first 120 prime numbers are:")
    for i, count := int64(2), 0; count < 1015; i += 2 {
        if wilson(i, true) {
            count++
            if count <= 120 {
                fmt.Printf("%3d ", i)
                if count%20 == 0 {
                    fmt.Println()
                }
            } else if count >= 1000 {
                if count == 1000 {
                    fmt.Println("\nThe 1,000th to 1,015th prime numbers are:") 
                }
                fmt.Printf("%4d ", i)
            }            
        }
        if i == 2 {
            i--
        }
    }
    fmt.Println()    
}
Task: Primality by Wilson's theorem

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

uint64_t factorial(uint64_t n) {
    uint64_t product = 1;

    if (n < 2) {
        return 1;
    }

    for (; n > 0; n--) {
        uint64_t prev = product;
        product *= n;
        if (product < prev) {
            fprintf(stderr, "Overflowed\n");
            return product;
        }
    }

    return product;
}


bool isPrime(uint64_t n) {
    uint64_t large = factorial(n - 1) + 1;
    return (large % n) == 0;
}

int main() {
    uint64_t n;

    
    for (n = 2; n < 22; n++) {
        printf("Is %llu prime: %d\n", n, isPrime(n));
    }

    return 0;
}





Java: import java.math.BigInteger;

public class PrimaltyByWilsonsTheorem {

    public static void main(String[] args) {
        System.out.printf("Primes less than 100 testing by Wilson's Theorem%n");
        for ( int i = 0 ; i <= 100 ; i++ ) {
            if ( isPrime(i) ) {
                System.out.printf("%d ", i);
            }
        }
    }
    
    
    private static boolean isPrime(long p) {
        if ( p <= 1) {
            return false;
        }
        return fact(p-1).add(BigInteger.ONE).mod(BigInteger.valueOf(p)).compareTo(BigInteger.ZERO) == 0;
    }
    
    private static BigInteger fact(long n) {
        BigInteger fact = BigInteger.ONE;
        for ( int i = 2 ; i <= n ; i++ ) {
            fact = fact.multiply(BigInteger.valueOf(i));
        }
        return fact;
    }

}
Task: Primality by Wilson's theorem


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

int factorial_mod(int n, int p) {
    int f = 1;
    for (; n > 0 && f != 0; --n)
        f = (f * n) % p;
    return f;
}

bool is_prime(int p) {
    return p > 1 && factorial_mod(p - 1, p) == p - 1;
}

int main() {
    std::cout << "  n | prime?\n------------\n";
    std::cout << std::boolalpha;
    for (int p : {2, 3, 9, 15, 29, 37, 47, 57, 67, 77, 87, 97, 237, 409, 659})
        std::cout << std::setw(3) << p << " | " << is_prime(p) << '\n';

    std::cout << "\nFirst 120 primes by Wilson's theorem:\n";
    int n = 0, p = 1;
    for (; n < 120; ++p) {
        if (is_prime(p))
            std::cout << std::setw(3) << p << (++n % 20 == 0 ? '\n' : ' ');
    }

    std::cout << "\n1000th through 1015th primes:\n";
    for (int i = 0; n < 1015; ++p) {
        if (is_prime(p)) {
            if (++n >= 1000)
                std::cout << std::setw(4) << p << (++i % 16 == 0 ? '\n' : ' ');
        }
    }
}



Go: package main

import (
    "fmt"
    "math/big"
)

var (
    zero = big.NewInt(0)
    one  = big.NewInt(1)
    prev = big.NewInt(factorial(20))
)


func factorial(n int64) int64 {
    res := int64(1)
    for k := n; k > 1; k-- {
        res *= k
    }
    return res
}



func wilson(n int64, memo bool) bool {
    if n <= 1 || (n%2 == 0 && n != 2) {
        return false
    }
    if n <= 21 {
        return (factorial(n-1)+1)%n == 0
    }
    b := big.NewInt(n)
    r := big.NewInt(0)
    z := big.NewInt(0)
    if !memo {
        z.MulRange(2, n-1) 
    } else {
        prev.Mul(prev, r.MulRange(n-2, n-1)) 
        z.Set(prev)
    }
    z.Add(z, one)
    return r.Rem(z, b).Cmp(zero) == 0    
}

func main() {
    numbers := []int64{2, 3, 9, 15, 29, 37, 47, 57, 67, 77, 87, 97, 237, 409, 659}
    fmt.Println("  n  prime")
    fmt.Println("---  -----")
    for _, n := range numbers {
        fmt.Printf("%3d  %t\n", n, wilson(n, false))
    }

    
    fmt.Println("\nThe first 120 prime numbers are:")
    for i, count := int64(2), 0; count < 1015; i += 2 {
        if wilson(i, true) {
            count++
            if count <= 120 {
                fmt.Printf("%3d ", i)
                if count%20 == 0 {
                    fmt.Println()
                }
            } else if count >= 1000 {
                if count == 1000 {
                    fmt.Println("\nThe 1,000th to 1,015th prime numbers are:") 
                }
                fmt.Printf("%4d ", i)
            }            
        }
        if i == 2 {
            i--
        }
    }
    fmt.Println()    
}
Task: Primality by Wilson's theorem


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

int factorial_mod(int n, int p) {
    int f = 1;
    for (; n > 0 && f != 0; --n)
        f = (f * n) % p;
    return f;
}

bool is_prime(int p) {
    return p > 1 && factorial_mod(p - 1, p) == p - 1;
}

int main() {
    std::cout << "  n | prime?\n------------\n";
    std::cout << std::boolalpha;
    for (int p : {2, 3, 9, 15, 29, 37, 47, 57, 67, 77, 87, 97, 237, 409, 659})
        std::cout << std::setw(3) << p << " | " << is_prime(p) << '\n';

    std::cout << "\nFirst 120 primes by Wilson's theorem:\n";
    int n = 0, p = 1;
    for (; n < 120; ++p) {
        if (is_prime(p))
            std::cout << std::setw(3) << p << (++n % 20 == 0 ? '\n' : ' ');
    }

    std::cout << "\n1000th through 1015th primes:\n";
    for (int i = 0; n < 1015; ++p) {
        if (is_prime(p)) {
            if (++n >= 1000)
                std::cout << std::setw(4) << p << (++i % 16 == 0 ? '\n' : ' ');
        }
    }
}




Java: import java.math.BigInteger;

public class PrimaltyByWilsonsTheorem {

    public static void main(String[] args) {
        System.out.printf("Primes less than 100 testing by Wilson's Theorem%n");
        for ( int i = 0 ; i <= 100 ; i++ ) {
            if ( isPrime(i) ) {
                System.out.printf("%d ", i);
            }
        }
    }
    
    
    private static boolean isPrime(long p) {
        if ( p <= 1) {
            return false;
        }
        return fact(p-1).add(BigInteger.ONE).mod(BigInteger.valueOf(p)).compareTo(BigInteger.ZERO) == 0;
    }
    
    private static BigInteger fact(long n) {
        BigInteger fact = BigInteger.ONE;
        for ( int i = 2 ; i <= n ; i++ ) {
            fact = fact.multiply(BigInteger.valueOf(i));
        }
        return fact;
    }

}
Task: Primality by Wilson's theorem


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

int factorial_mod(int n, int p) {
    int f = 1;
    for (; n > 0 && f != 0; --n)
        f = (f * n) % p;
    return f;
}

bool is_prime(int p) {
    return p > 1 && factorial_mod(p - 1, p) == p - 1;
}

int main() {
    std::cout << "  n | prime?\n------------\n";
    std::cout << std::boolalpha;
    for (int p : {2, 3, 9, 15, 29, 37, 47, 57, 67, 77, 87, 97, 237, 409, 659})
        std::cout << std::setw(3) << p << " | " << is_prime(p) << '\n';

    std::cout << "\nFirst 120 primes by Wilson's theorem:\n";
    int n = 0, p = 1;
    for (; n < 120; ++p) {
        if (is_prime(p))
            std::cout << std::setw(3) << p << (++n % 20 == 0 ? '\n' : ' ');
    }

    std::cout << "\n1000th through 1015th primes:\n";
    for (int i = 0; n < 1015; ++p) {
        if (is_prime(p)) {
            if (++n >= 1000)
                std::cout << std::setw(4) << p << (++i % 16 == 0 ? '\n' : ' ');
        }
    }
}






Python: from math import factorial

def is_wprime(n):
    return n == 2 or (
        n > 1
        and n % 2 != 0
        and (factorial(n - 1) + 1) % n == 0
    )

if __name__ == '__main__':
    c = int(input('Enter upper limit: '))
    print(f'Primes under {c}:')
    print([n for n in range(c) if is_wprime(n)])