Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Produce a language-to-language conversion: from Racket to VB, same semantics.
#lang racket (require math) (define (mersenne-prime? p) (divides? (- (expt 2 p) 1) (S (- p 1)))) (define (S n) (if (= n 1) 4 (- (sqr (S (- n 1))) 2))) (define (loop p) (when (mersenne-prime? p) (displayln p)) (loop (next-prime p))) (loop 3)
iexpmax = 15 n=1 out="" For iexp = 2 To iexpmax If iexp = 2 Then s = 0 Else s = 4 End If n = (n + 1) * 2 - 1 For i = 1 To iexp - 2 s = (s * s - 2) Mod n Next If s = 0 Then out=out & "M" & iexp & " " End If Next Wscript.echo out
Write the same algorithm in Go as shown in this Racket implementation.
#lang racket (require math) (define (mersenne-prime? p) (divides? (- (expt 2 p) 1) (S (- p 1)))) (define (S n) (if (= n 1) 4 (- (sqr (S (- n 1))) 2))) (define (loop p) (when (mersenne-prime? p) (displayln p)) (loop (next-prime p))) (loop 3)
package main import ( "fmt" "math/big" ) var primes = []uint{3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127} var mersennes = []uint{521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 8...
Can you help me rewrite this code in C instead of REXX, keeping it the same logically?
@.=0; @.2=1; @.3=1; @.5=1; @.7=1; @.11=1; @.13=1 !.=@.; !.0=1; !.2=1; !.4=1; !.5=1; !.6=1; !.8=1 parse arg limit . if limit=='' then limit= 200 say center('Mersenne prime index list',70-3,"═") say right('M'2, 25) " [1 decimal digit]" ...
#include <stdio.h> #include <stdlib.h> #include <limits.h> #include <gmp.h> int lucas_lehmer(unsigned long p) { mpz_t V, mp, t; unsigned long k, tlim; int res; if (p == 2) return 1; if (!(p&1)) return 0; mpz_init_set_ui(t, p); if (!mpz_probab_prime_p(t, 25)) { mpz_clear(t); return 0; } if (p < ...
Produce a language-to-language conversion: from REXX to C#, same semantics.
@.=0; @.2=1; @.3=1; @.5=1; @.7=1; @.11=1; @.13=1 !.=@.; !.0=1; !.2=1; !.4=1; !.5=1; !.6=1; !.8=1 parse arg limit . if limit=='' then limit= 200 say center('Mersenne prime index list',70-3,"═") say right('M'2, 25) " [1 decimal digit]" ...
using System; using System.Collections.Generic; using System.Numerics; using System.Threading.Tasks; namespace LucasLehmerTestForRosettaCode { public class LucasLehmerTest { static BigInteger ZERO = new BigInteger(0); static BigInteger ONE = new BigInteger(1); static BigInteger TWO = ne...
Port the following code from REXX to C++ with equivalent syntax and logic.
@.=0; @.2=1; @.3=1; @.5=1; @.7=1; @.11=1; @.13=1 !.=@.; !.0=1; !.2=1; !.4=1; !.5=1; !.6=1; !.8=1 parse arg limit . if limit=='' then limit= 200 say center('Mersenne prime index list',70-3,"═") say right('M'2, 25) " [1 decimal digit]" ...
#include <iostream> #include <gmpxx.h> static bool is_mersenne_prime(mpz_class p) { if( 2 == p ) { return true; } mpz_class s(4); mpz_class div( (mpz_class(1) << p.get_ui()) - 1 ); for( mpz_class i(3); i <= p; ++i ) { s = (s * s - mpz_...
Convert the following code from REXX to Java, ensuring the logic remains intact.
@.=0; @.2=1; @.3=1; @.5=1; @.7=1; @.11=1; @.13=1 !.=@.; !.0=1; !.2=1; !.4=1; !.5=1; !.6=1; !.8=1 parse arg limit . if limit=='' then limit= 200 say center('Mersenne prime index list',70-3,"═") say right('M'2, 25) " [1 decimal digit]" ...
import java.math.BigInteger; public class Mersenne { public static boolean isPrime(int p) { if (p == 2) return true; else if (p <= 1 || p % 2 == 0) return false; else { int to = (int)Math.sqrt(p); for (int i = 3; i <= to; i += 2) ...
Preserve the algorithm and functionality while converting the code from REXX to Python.
@.=0; @.2=1; @.3=1; @.5=1; @.7=1; @.11=1; @.13=1 !.=@.; !.0=1; !.2=1; !.4=1; !.5=1; !.6=1; !.8=1 parse arg limit . if limit=='' then limit= 200 say center('Mersenne prime index list',70-3,"═") say right('M'2, 25) " [1 decimal digit]" ...
from sys import stdout from math import sqrt, log def is_prime ( p ): if p == 2: return True elif p <= 1 or p % 2 == 0: return False else: for i in range(3, int(sqrt(p))+1, 2 ): if p % i == 0: return False return True def is_mersenne_prime ( p ): if p == 2: return True else: m_p = ( ...
Write the same algorithm in VB as shown in this REXX implementation.
@.=0; @.2=1; @.3=1; @.5=1; @.7=1; @.11=1; @.13=1 !.=@.; !.0=1; !.2=1; !.4=1; !.5=1; !.6=1; !.8=1 parse arg limit . if limit=='' then limit= 200 say center('Mersenne prime index list',70-3,"═") say right('M'2, 25) " [1 decimal digit]" ...
iexpmax = 15 n=1 out="" For iexp = 2 To iexpmax If iexp = 2 Then s = 0 Else s = 4 End If n = (n + 1) * 2 - 1 For i = 1 To iexp - 2 s = (s * s - 2) Mod n Next If s = 0 Then out=out & "M" & iexp & " " End If Next Wscript.echo out
Translate this program into Go but keep the logic exactly as in REXX.
@.=0; @.2=1; @.3=1; @.5=1; @.7=1; @.11=1; @.13=1 !.=@.; !.0=1; !.2=1; !.4=1; !.5=1; !.6=1; !.8=1 parse arg limit . if limit=='' then limit= 200 say center('Mersenne prime index list',70-3,"═") say right('M'2, 25) " [1 decimal digit]" ...
package main import ( "fmt" "math/big" ) var primes = []uint{3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127} var mersennes = []uint{521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 8...
Change the following Ruby code into C without altering its purpose.
require "big" def is_prime(n) return n | 1 == 3 if n < 5 return false if n.gcd(6) != 1 pc1, pc2 = -1, 1 until (pc1 += 6) > Math.sqrt(n).to_i return false if n % pc1 == 0 || n % (pc2 += 6) == 0 end true end def is_mersen...
#include <stdio.h> #include <stdlib.h> #include <limits.h> #include <gmp.h> int lucas_lehmer(unsigned long p) { mpz_t V, mp, t; unsigned long k, tlim; int res; if (p == 2) return 1; if (!(p&1)) return 0; mpz_init_set_ui(t, p); if (!mpz_probab_prime_p(t, 25)) { mpz_clear(t); return 0; } if (p < ...
Rewrite the snippet below in C# so it works the same as the original Ruby code.
require "big" def is_prime(n) return n | 1 == 3 if n < 5 return false if n.gcd(6) != 1 pc1, pc2 = -1, 1 until (pc1 += 6) > Math.sqrt(n).to_i return false if n % pc1 == 0 || n % (pc2 += 6) == 0 end true end def is_mersen...
using System; using System.Collections.Generic; using System.Numerics; using System.Threading.Tasks; namespace LucasLehmerTestForRosettaCode { public class LucasLehmerTest { static BigInteger ZERO = new BigInteger(0); static BigInteger ONE = new BigInteger(1); static BigInteger TWO = ne...
Can you help me rewrite this code in C++ instead of Ruby, keeping it the same logically?
require "big" def is_prime(n) return n | 1 == 3 if n < 5 return false if n.gcd(6) != 1 pc1, pc2 = -1, 1 until (pc1 += 6) > Math.sqrt(n).to_i return false if n % pc1 == 0 || n % (pc2 += 6) == 0 end true end def is_mersen...
#include <iostream> #include <gmpxx.h> static bool is_mersenne_prime(mpz_class p) { if( 2 == p ) { return true; } mpz_class s(4); mpz_class div( (mpz_class(1) << p.get_ui()) - 1 ); for( mpz_class i(3); i <= p; ++i ) { s = (s * s - mpz_...
Translate the given Ruby code snippet into Java without altering its behavior.
require "big" def is_prime(n) return n | 1 == 3 if n < 5 return false if n.gcd(6) != 1 pc1, pc2 = -1, 1 until (pc1 += 6) > Math.sqrt(n).to_i return false if n % pc1 == 0 || n % (pc2 += 6) == 0 end true end def is_mersen...
import java.math.BigInteger; public class Mersenne { public static boolean isPrime(int p) { if (p == 2) return true; else if (p <= 1 || p % 2 == 0) return false; else { int to = (int)Math.sqrt(p); for (int i = 3; i <= to; i += 2) ...
Can you help me rewrite this code in Python instead of Ruby, keeping it the same logically?
require "big" def is_prime(n) return n | 1 == 3 if n < 5 return false if n.gcd(6) != 1 pc1, pc2 = -1, 1 until (pc1 += 6) > Math.sqrt(n).to_i return false if n % pc1 == 0 || n % (pc2 += 6) == 0 end true end def is_mersen...
from sys import stdout from math import sqrt, log def is_prime ( p ): if p == 2: return True elif p <= 1 or p % 2 == 0: return False else: for i in range(3, int(sqrt(p))+1, 2 ): if p % i == 0: return False return True def is_mersenne_prime ( p ): if p == 2: return True else: m_p = ( ...
Translate this program into VB but keep the logic exactly as in Ruby.
require "big" def is_prime(n) return n | 1 == 3 if n < 5 return false if n.gcd(6) != 1 pc1, pc2 = -1, 1 until (pc1 += 6) > Math.sqrt(n).to_i return false if n % pc1 == 0 || n % (pc2 += 6) == 0 end true end def is_mersen...
iexpmax = 15 n=1 out="" For iexp = 2 To iexpmax If iexp = 2 Then s = 0 Else s = 4 End If n = (n + 1) * 2 - 1 For i = 1 To iexp - 2 s = (s * s - 2) Mod n Next If s = 0 Then out=out & "M" & iexp & " " End If Next Wscript.echo out
Port the provided Ruby code into Go while preserving the original functionality.
require "big" def is_prime(n) return n | 1 == 3 if n < 5 return false if n.gcd(6) != 1 pc1, pc2 = -1, 1 until (pc1 += 6) > Math.sqrt(n).to_i return false if n % pc1 == 0 || n % (pc2 += 6) == 0 end true end def is_mersen...
package main import ( "fmt" "math/big" ) var primes = []uint{3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127} var mersennes = []uint{521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 8...
Change the programming language of this snippet from Scala to C without modifying what it does.
import java.math.BigInteger const val MAX = 19 val bigTwo = BigInteger.valueOf(2L) val bigFour = bigTwo * bigTwo fun isPrime(n: Int): Boolean { if (n < 2) return false if (n % 2 == 0) return n == 2 if (n % 3 == 0) return n == 3 var d : Int = 5 while (d * d <= n) { if (n % d == 0) retu...
#include <stdio.h> #include <stdlib.h> #include <limits.h> #include <gmp.h> int lucas_lehmer(unsigned long p) { mpz_t V, mp, t; unsigned long k, tlim; int res; if (p == 2) return 1; if (!(p&1)) return 0; mpz_init_set_ui(t, p); if (!mpz_probab_prime_p(t, 25)) { mpz_clear(t); return 0; } if (p < ...
Translate the given Scala code snippet into C# without altering its behavior.
import java.math.BigInteger const val MAX = 19 val bigTwo = BigInteger.valueOf(2L) val bigFour = bigTwo * bigTwo fun isPrime(n: Int): Boolean { if (n < 2) return false if (n % 2 == 0) return n == 2 if (n % 3 == 0) return n == 3 var d : Int = 5 while (d * d <= n) { if (n % d == 0) retu...
using System; using System.Collections.Generic; using System.Numerics; using System.Threading.Tasks; namespace LucasLehmerTestForRosettaCode { public class LucasLehmerTest { static BigInteger ZERO = new BigInteger(0); static BigInteger ONE = new BigInteger(1); static BigInteger TWO = ne...
Convert this Scala snippet to C++ and keep its semantics consistent.
import java.math.BigInteger const val MAX = 19 val bigTwo = BigInteger.valueOf(2L) val bigFour = bigTwo * bigTwo fun isPrime(n: Int): Boolean { if (n < 2) return false if (n % 2 == 0) return n == 2 if (n % 3 == 0) return n == 3 var d : Int = 5 while (d * d <= n) { if (n % d == 0) retu...
#include <iostream> #include <gmpxx.h> static bool is_mersenne_prime(mpz_class p) { if( 2 == p ) { return true; } mpz_class s(4); mpz_class div( (mpz_class(1) << p.get_ui()) - 1 ); for( mpz_class i(3); i <= p; ++i ) { s = (s * s - mpz_...
Convert this Scala snippet to Java and keep its semantics consistent.
import java.math.BigInteger const val MAX = 19 val bigTwo = BigInteger.valueOf(2L) val bigFour = bigTwo * bigTwo fun isPrime(n: Int): Boolean { if (n < 2) return false if (n % 2 == 0) return n == 2 if (n % 3 == 0) return n == 3 var d : Int = 5 while (d * d <= n) { if (n % d == 0) retu...
import java.math.BigInteger; public class Mersenne { public static boolean isPrime(int p) { if (p == 2) return true; else if (p <= 1 || p % 2 == 0) return false; else { int to = (int)Math.sqrt(p); for (int i = 3; i <= to; i += 2) ...
Rewrite this program in Python while keeping its functionality equivalent to the Scala version.
import java.math.BigInteger const val MAX = 19 val bigTwo = BigInteger.valueOf(2L) val bigFour = bigTwo * bigTwo fun isPrime(n: Int): Boolean { if (n < 2) return false if (n % 2 == 0) return n == 2 if (n % 3 == 0) return n == 3 var d : Int = 5 while (d * d <= n) { if (n % d == 0) retu...
from sys import stdout from math import sqrt, log def is_prime ( p ): if p == 2: return True elif p <= 1 or p % 2 == 0: return False else: for i in range(3, int(sqrt(p))+1, 2 ): if p % i == 0: return False return True def is_mersenne_prime ( p ): if p == 2: return True else: m_p = ( ...
Rewrite the snippet below in VB so it works the same as the original Scala code.
import java.math.BigInteger const val MAX = 19 val bigTwo = BigInteger.valueOf(2L) val bigFour = bigTwo * bigTwo fun isPrime(n: Int): Boolean { if (n < 2) return false if (n % 2 == 0) return n == 2 if (n % 3 == 0) return n == 3 var d : Int = 5 while (d * d <= n) { if (n % d == 0) retu...
iexpmax = 15 n=1 out="" For iexp = 2 To iexpmax If iexp = 2 Then s = 0 Else s = 4 End If n = (n + 1) * 2 - 1 For i = 1 To iexp - 2 s = (s * s - 2) Mod n Next If s = 0 Then out=out & "M" & iexp & " " End If Next Wscript.echo out
Produce a functionally identical Go code for the snippet given in Scala.
import java.math.BigInteger const val MAX = 19 val bigTwo = BigInteger.valueOf(2L) val bigFour = bigTwo * bigTwo fun isPrime(n: Int): Boolean { if (n < 2) return false if (n % 2 == 0) return n == 2 if (n % 3 == 0) return n == 3 var d : Int = 5 while (d * d <= n) { if (n % d == 0) retu...
package main import ( "fmt" "math/big" ) var primes = []uint{3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127} var mersennes = []uint{521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 8...
Change the programming language of this snippet from Swift to C without modifying what it does.
import BigInt import Darwin func Eratosthenes(upTo: Int) -> [Int] { let maxroot = Int(sqrt(Double(upTo))) var isprime = [Bool](repeating: true, count: upTo+1 ) for i in 2...maxroot { if isprime[i] { for k in stride(from: upTo/i, through: i, by: -1) { i...
#include <stdio.h> #include <stdlib.h> #include <limits.h> #include <gmp.h> int lucas_lehmer(unsigned long p) { mpz_t V, mp, t; unsigned long k, tlim; int res; if (p == 2) return 1; if (!(p&1)) return 0; mpz_init_set_ui(t, p); if (!mpz_probab_prime_p(t, 25)) { mpz_clear(t); return 0; } if (p < ...
Write the same algorithm in C# as shown in this Swift implementation.
import BigInt import Darwin func Eratosthenes(upTo: Int) -> [Int] { let maxroot = Int(sqrt(Double(upTo))) var isprime = [Bool](repeating: true, count: upTo+1 ) for i in 2...maxroot { if isprime[i] { for k in stride(from: upTo/i, through: i, by: -1) { i...
using System; using System.Collections.Generic; using System.Numerics; using System.Threading.Tasks; namespace LucasLehmerTestForRosettaCode { public class LucasLehmerTest { static BigInteger ZERO = new BigInteger(0); static BigInteger ONE = new BigInteger(1); static BigInteger TWO = ne...
Write the same algorithm in C++ as shown in this Swift implementation.
import BigInt import Darwin func Eratosthenes(upTo: Int) -> [Int] { let maxroot = Int(sqrt(Double(upTo))) var isprime = [Bool](repeating: true, count: upTo+1 ) for i in 2...maxroot { if isprime[i] { for k in stride(from: upTo/i, through: i, by: -1) { i...
#include <iostream> #include <gmpxx.h> static bool is_mersenne_prime(mpz_class p) { if( 2 == p ) { return true; } mpz_class s(4); mpz_class div( (mpz_class(1) << p.get_ui()) - 1 ); for( mpz_class i(3); i <= p; ++i ) { s = (s * s - mpz_...
Convert this Swift snippet to Java and keep its semantics consistent.
import BigInt import Darwin func Eratosthenes(upTo: Int) -> [Int] { let maxroot = Int(sqrt(Double(upTo))) var isprime = [Bool](repeating: true, count: upTo+1 ) for i in 2...maxroot { if isprime[i] { for k in stride(from: upTo/i, through: i, by: -1) { i...
import java.math.BigInteger; public class Mersenne { public static boolean isPrime(int p) { if (p == 2) return true; else if (p <= 1 || p % 2 == 0) return false; else { int to = (int)Math.sqrt(p); for (int i = 3; i <= to; i += 2) ...
Generate a Python translation of this Swift snippet without changing its computational steps.
import BigInt import Darwin func Eratosthenes(upTo: Int) -> [Int] { let maxroot = Int(sqrt(Double(upTo))) var isprime = [Bool](repeating: true, count: upTo+1 ) for i in 2...maxroot { if isprime[i] { for k in stride(from: upTo/i, through: i, by: -1) { i...
from sys import stdout from math import sqrt, log def is_prime ( p ): if p == 2: return True elif p <= 1 or p % 2 == 0: return False else: for i in range(3, int(sqrt(p))+1, 2 ): if p % i == 0: return False return True def is_mersenne_prime ( p ): if p == 2: return True else: m_p = ( ...
Translate the given Swift code snippet into VB without altering its behavior.
import BigInt import Darwin func Eratosthenes(upTo: Int) -> [Int] { let maxroot = Int(sqrt(Double(upTo))) var isprime = [Bool](repeating: true, count: upTo+1 ) for i in 2...maxroot { if isprime[i] { for k in stride(from: upTo/i, through: i, by: -1) { i...
iexpmax = 15 n=1 out="" For iexp = 2 To iexpmax If iexp = 2 Then s = 0 Else s = 4 End If n = (n + 1) * 2 - 1 For i = 1 To iexp - 2 s = (s * s - 2) Mod n Next If s = 0 Then out=out & "M" & iexp & " " End If Next Wscript.echo out
Transform the following Swift implementation into Go, maintaining the same output and logic.
import BigInt import Darwin func Eratosthenes(upTo: Int) -> [Int] { let maxroot = Int(sqrt(Double(upTo))) var isprime = [Bool](repeating: true, count: upTo+1 ) for i in 2...maxroot { if isprime[i] { for k in stride(from: upTo/i, through: i, by: -1) { i...
package main import ( "fmt" "math/big" ) var primes = []uint{3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127} var mersennes = []uint{521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 8...
Convert this Tcl snippet to C and keep its semantics consistent.
proc main argv { set n 0 set t [clock seconds] show_mersenne 2 [incr n] t for {set p 3} {$p <= [lindex $argv 0]} {incr p 2} { if {![prime $p]} continue if {[LucasLehmer $p]} { show_mersenne $p [incr n] t } } } proc show_mersenne {p n timevar} { upvar 1 $timev...
#include <stdio.h> #include <stdlib.h> #include <limits.h> #include <gmp.h> int lucas_lehmer(unsigned long p) { mpz_t V, mp, t; unsigned long k, tlim; int res; if (p == 2) return 1; if (!(p&1)) return 0; mpz_init_set_ui(t, p); if (!mpz_probab_prime_p(t, 25)) { mpz_clear(t); return 0; } if (p < ...
Change the programming language of this snippet from Tcl to C# without modifying what it does.
proc main argv { set n 0 set t [clock seconds] show_mersenne 2 [incr n] t for {set p 3} {$p <= [lindex $argv 0]} {incr p 2} { if {![prime $p]} continue if {[LucasLehmer $p]} { show_mersenne $p [incr n] t } } } proc show_mersenne {p n timevar} { upvar 1 $timev...
using System; using System.Collections.Generic; using System.Numerics; using System.Threading.Tasks; namespace LucasLehmerTestForRosettaCode { public class LucasLehmerTest { static BigInteger ZERO = new BigInteger(0); static BigInteger ONE = new BigInteger(1); static BigInteger TWO = ne...
Write the same algorithm in C++ as shown in this Tcl implementation.
proc main argv { set n 0 set t [clock seconds] show_mersenne 2 [incr n] t for {set p 3} {$p <= [lindex $argv 0]} {incr p 2} { if {![prime $p]} continue if {[LucasLehmer $p]} { show_mersenne $p [incr n] t } } } proc show_mersenne {p n timevar} { upvar 1 $timev...
#include <iostream> #include <gmpxx.h> static bool is_mersenne_prime(mpz_class p) { if( 2 == p ) { return true; } mpz_class s(4); mpz_class div( (mpz_class(1) << p.get_ui()) - 1 ); for( mpz_class i(3); i <= p; ++i ) { s = (s * s - mpz_...
Ensure the translated Java code behaves exactly like the original Tcl snippet.
proc main argv { set n 0 set t [clock seconds] show_mersenne 2 [incr n] t for {set p 3} {$p <= [lindex $argv 0]} {incr p 2} { if {![prime $p]} continue if {[LucasLehmer $p]} { show_mersenne $p [incr n] t } } } proc show_mersenne {p n timevar} { upvar 1 $timev...
import java.math.BigInteger; public class Mersenne { public static boolean isPrime(int p) { if (p == 2) return true; else if (p <= 1 || p % 2 == 0) return false; else { int to = (int)Math.sqrt(p); for (int i = 3; i <= to; i += 2) ...
Translate this program into Python but keep the logic exactly as in Tcl.
proc main argv { set n 0 set t [clock seconds] show_mersenne 2 [incr n] t for {set p 3} {$p <= [lindex $argv 0]} {incr p 2} { if {![prime $p]} continue if {[LucasLehmer $p]} { show_mersenne $p [incr n] t } } } proc show_mersenne {p n timevar} { upvar 1 $timev...
from sys import stdout from math import sqrt, log def is_prime ( p ): if p == 2: return True elif p <= 1 or p % 2 == 0: return False else: for i in range(3, int(sqrt(p))+1, 2 ): if p % i == 0: return False return True def is_mersenne_prime ( p ): if p == 2: return True else: m_p = ( ...
Please provide an equivalent version of this Tcl code in VB.
proc main argv { set n 0 set t [clock seconds] show_mersenne 2 [incr n] t for {set p 3} {$p <= [lindex $argv 0]} {incr p 2} { if {![prime $p]} continue if {[LucasLehmer $p]} { show_mersenne $p [incr n] t } } } proc show_mersenne {p n timevar} { upvar 1 $timev...
iexpmax = 15 n=1 out="" For iexp = 2 To iexpmax If iexp = 2 Then s = 0 Else s = 4 End If n = (n + 1) * 2 - 1 For i = 1 To iexp - 2 s = (s * s - 2) Mod n Next If s = 0 Then out=out & "M" & iexp & " " End If Next Wscript.echo out
Generate a Go translation of this Tcl snippet without changing its computational steps.
proc main argv { set n 0 set t [clock seconds] show_mersenne 2 [incr n] t for {set p 3} {$p <= [lindex $argv 0]} {incr p 2} { if {![prime $p]} continue if {[LucasLehmer $p]} { show_mersenne $p [incr n] t } } } proc show_mersenne {p n timevar} { upvar 1 $timev...
package main import ( "fmt" "math/big" ) var primes = []uint{3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127} var mersennes = []uint{521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 8...
Rewrite the snippet below in Rust so it works the same as the original C code.
#include <stdio.h> #include <stdlib.h> #include <limits.h> #include <gmp.h> int lucas_lehmer(unsigned long p) { mpz_t V, mp, t; unsigned long k, tlim; int res; if (p == 2) return 1; if (!(p&1)) return 0; mpz_init_set_ui(t, p); if (!mpz_probab_prime_p(t, 25)) { mpz_clear(t); return 0; } if (p < ...
extern crate rug; extern crate primal; use rug::Integer; use rug::ops::Pow; use std::thread::spawn; fn is_mersenne (p : usize) { let p = p as u32; let mut m = Integer::from(1); m = m << p; m = Integer::from(&m - 1); let mut flag1 = false; for k in 1..10_000 { let mut flag2 = false; ...
Translate the given Java code snippet into Rust without altering its behavior.
import java.math.BigInteger; public class Mersenne { public static boolean isPrime(int p) { if (p == 2) return true; else if (p <= 1 || p % 2 == 0) return false; else { int to = (int)Math.sqrt(p); for (int i = 3; i <= to; i += 2) ...
extern crate rug; extern crate primal; use rug::Integer; use rug::ops::Pow; use std::thread::spawn; fn is_mersenne (p : usize) { let p = p as u32; let mut m = Integer::from(1); m = m << p; m = Integer::from(&m - 1); let mut flag1 = false; for k in 1..10_000 { let mut flag2 = false; ...
Produce a functionally identical Rust code for the snippet given in Go.
package main import ( "fmt" "math/big" ) var primes = []uint{3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127} var mersennes = []uint{521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 8...
extern crate rug; extern crate primal; use rug::Integer; use rug::ops::Pow; use std::thread::spawn; fn is_mersenne (p : usize) { let p = p as u32; let mut m = Integer::from(1); m = m << p; m = Integer::from(&m - 1); let mut flag1 = false; for k in 1..10_000 { let mut flag2 = false; ...
Write the same algorithm in Python as shown in this Rust implementation.
extern crate rug; extern crate primal; use rug::Integer; use rug::ops::Pow; use std::thread::spawn; fn is_mersenne (p : usize) { let p = p as u32; let mut m = Integer::from(1); m = m << p; m = Integer::from(&m - 1); let mut flag1 = false; for k in 1..10_000 { let mut flag2 = false; ...
from sys import stdout from math import sqrt, log def is_prime ( p ): if p == 2: return True elif p <= 1 or p % 2 == 0: return False else: for i in range(3, int(sqrt(p))+1, 2 ): if p % i == 0: return False return True def is_mersenne_prime ( p ): if p == 2: return True else: m_p = ( ...
Generate an equivalent VB version of this Rust code.
extern crate rug; extern crate primal; use rug::Integer; use rug::ops::Pow; use std::thread::spawn; fn is_mersenne (p : usize) { let p = p as u32; let mut m = Integer::from(1); m = m << p; m = Integer::from(&m - 1); let mut flag1 = false; for k in 1..10_000 { let mut flag2 = false; ...
iexpmax = 15 n=1 out="" For iexp = 2 To iexpmax If iexp = 2 Then s = 0 Else s = 4 End If n = (n + 1) * 2 - 1 For i = 1 To iexp - 2 s = (s * s - 2) Mod n Next If s = 0 Then out=out & "M" & iexp & " " End If Next Wscript.echo out
Convert this C++ snippet to Rust and keep its semantics consistent.
#include <iostream> #include <gmpxx.h> static bool is_mersenne_prime(mpz_class p) { if( 2 == p ) return true; else { mpz_class s(4); mpz_class div( (mpz_class(1) << p.get_ui()) - 1 ); for( mpz_class i(3); i <= p; ++i ) ...
extern crate rug; extern crate primal; use rug::Integer; use rug::ops::Pow; use std::thread::spawn; fn is_mersenne (p : usize) { let p = p as u32; let mut m = Integer::from(1); m = m << p; m = Integer::from(&m - 1); let mut flag1 = false; for k in 1..10_000 { let mut flag2 = false; ...
Write a version of this C# function in Rust with identical behavior.
using System; using System.Collections.Generic; using System.Numerics; using System.Threading.Tasks; namespace LucasLehmerTestForRosettaCode { public class LucasLehmerTest { static BigInteger ZERO = new BigInteger(0); static BigInteger ONE = new BigInteger(1); static BigInteger TWO = ne...
extern crate rug; extern crate primal; use rug::Integer; use rug::ops::Pow; use std::thread::spawn; fn is_mersenne (p : usize) { let p = p as u32; let mut m = Integer::from(1); m = m << p; m = Integer::from(&m - 1); let mut flag1 = false; for k in 1..10_000 { let mut flag2 = false; ...
Write the same algorithm in C# as shown in this Ada implementation.
with Ada.Text_IO; use Ada.Text_IO; procedure Fizzbuzz is begin for I in 1..100 loop if I mod 15 = 0 then Put_Line("FizzBuzz"); elsif I mod 5 = 0 then Put_Line("Buzz"); elsif I mod 3 = 0 then Put_Line("Fizz"); else Put_Line(Integer'Image(I)); end if;...
class Program { public void FizzBuzzGo() { Boolean Fizz = false; Boolean Buzz = false; for (int count = 1; count <= 100; count ++) { Fizz = count % 3 == 0; Buzz = count % 5 == 0; if (Fizz && Buzz) { Console.WriteLine...
Port the provided Ada code into C while preserving the original functionality.
with Ada.Text_IO; use Ada.Text_IO; procedure Fizzbuzz is begin for I in 1..100 loop if I mod 15 = 0 then Put_Line("FizzBuzz"); elsif I mod 5 = 0 then Put_Line("Buzz"); elsif I mod 3 = 0 then Put_Line("Fizz"); else Put_Line(Integer'Image(I)); end if;...
int i = 0 ; char B[88] ; while ( i++ < 100 ) !sprintf( B, "%s%s", i%3 ? "":"Fizz", i%5 ? "":"Buzz" ) ? sprintf( B, "%d", i ):0, printf( ", %s", B );
Port the provided Ada code into C++ while preserving the original functionality.
with Ada.Text_IO; use Ada.Text_IO; procedure Fizzbuzz is begin for I in 1..100 loop if I mod 15 = 0 then Put_Line("FizzBuzz"); elsif I mod 5 = 0 then Put_Line("Buzz"); elsif I mod 3 = 0 then Put_Line("Fizz"); else Put_Line(Integer'Image(I)); end if;...
#include <iostream> #include <chrono> int main() { int fizz = 0, buzz = 0, fizzbuzz = 0; bool isFizz = false; auto startTime = std::chrono::high_resolution_clock::now(); for (unsigned int i = 1; i <= 4000000000; i++) { isFizz = false; if (i % 3 == 0) { isFizz = true; fizz++; } if (i % 5 == 0) {...
Change the programming language of this snippet from Ada to Go without modifying what it does.
with Ada.Text_IO; use Ada.Text_IO; procedure Fizzbuzz is begin for I in 1..100 loop if I mod 15 = 0 then Put_Line("FizzBuzz"); elsif I mod 5 = 0 then Put_Line("Buzz"); elsif I mod 3 = 0 then Put_Line("Fizz"); else Put_Line(Integer'Image(I)); end if;...
package main import "fmt" func main() { for i := 1; i <= 100; i++ { switch { case i%15==0: fmt.Println("FizzBuzz") case i%3==0: fmt.Println("Fizz") case i%5==0: fmt.Println("Buzz") default: fmt.Println(i) } } }
Can you help me rewrite this code in Java instead of Ada, keeping it the same logically?
with Ada.Text_IO; use Ada.Text_IO; procedure Fizzbuzz is begin for I in 1..100 loop if I mod 15 = 0 then Put_Line("FizzBuzz"); elsif I mod 5 = 0 then Put_Line("Buzz"); elsif I mod 3 = 0 then Put_Line("Fizz"); else Put_Line(Integer'Image(I)); end if;...
module FizzBuzz { void run() { @Inject Console console; for (Int x : 1..100) { console.print(switch (x % 3, x % 5) { case (0, 0): "FizzBuzz"; case (0, _): "Fizz"; case (_, 0): "Buzz"; ...
Write the same algorithm in Python as shown in this Ada implementation.
with Ada.Text_IO; use Ada.Text_IO; procedure Fizzbuzz is begin for I in 1..100 loop if I mod 15 = 0 then Put_Line("FizzBuzz"); elsif I mod 5 = 0 then Put_Line("Buzz"); elsif I mod 3 = 0 then Put_Line("Fizz"); else Put_Line(Integer'Image(I)); end if;...
for i in xrange(1, 101): if i % 15 == 0: print "FizzBuzz" elif i % 3 == 0: print "Fizz" elif i % 5 == 0: print "Buzz" else: print i
Port the following code from Ada to VB with equivalent syntax and logic.
with Ada.Text_IO; use Ada.Text_IO; procedure Fizzbuzz is begin for I in 1..100 loop if I mod 15 = 0 then Put_Line("FizzBuzz"); elsif I mod 5 = 0 then Put_Line("Buzz"); elsif I mod 3 = 0 then Put_Line("Fizz"); else Put_Line(Integer'Image(I)); end if;...
Option Explicit Sub FizzBuzz() Dim Tb(1 To 100) As Variant Dim i As Integer For i = 1 To 100 If i Mod 15 = 0 Then Tb(i) = "FizzBuzz" ElseIf i Mod 5 = 0 Then Tb(i) = "Buzz" ElseIf i Mod 3 = 0 Then Tb(i) = "Fizz" Else Tb(i) = i ...
Generate a C translation of this Arturo snippet without changing its computational steps.
loop 1..100 [x][ case [] when? [0=x%15] -> print "FizzBuzz" when? [0=x%3] -> print "Fizz" when? [0=x%5] -> print "Buzz" else -> print x ]
int i = 0 ; char B[88] ; while ( i++ < 100 ) !sprintf( B, "%s%s", i%3 ? "":"Fizz", i%5 ? "":"Buzz" ) ? sprintf( B, "%d", i ):0, printf( ", %s", B );
Convert the following code from Arturo to C#, ensuring the logic remains intact.
loop 1..100 [x][ case [] when? [0=x%15] -> print "FizzBuzz" when? [0=x%3] -> print "Fizz" when? [0=x%5] -> print "Buzz" else -> print x ]
class Program { public void FizzBuzzGo() { Boolean Fizz = false; Boolean Buzz = false; for (int count = 1; count <= 100; count ++) { Fizz = count % 3 == 0; Buzz = count % 5 == 0; if (Fizz && Buzz) { Console.WriteLine...
Produce a language-to-language conversion: from Arturo to C++, same semantics.
loop 1..100 [x][ case [] when? [0=x%15] -> print "FizzBuzz" when? [0=x%3] -> print "Fizz" when? [0=x%5] -> print "Buzz" else -> print x ]
#include <iostream> #include <chrono> int main() { int fizz = 0, buzz = 0, fizzbuzz = 0; bool isFizz = false; auto startTime = std::chrono::high_resolution_clock::now(); for (unsigned int i = 1; i <= 4000000000; i++) { isFizz = false; if (i % 3 == 0) { isFizz = true; fizz++; } if (i % 5 == 0) {...
Write a version of this Arturo function in Java with identical behavior.
loop 1..100 [x][ case [] when? [0=x%15] -> print "FizzBuzz" when? [0=x%3] -> print "Fizz" when? [0=x%5] -> print "Buzz" else -> print x ]
module FizzBuzz { void run() { @Inject Console console; for (Int x : 1..100) { console.print(switch (x % 3, x % 5) { case (0, 0): "FizzBuzz"; case (0, _): "Fizz"; case (_, 0): "Buzz"; ...
Preserve the algorithm and functionality while converting the code from Arturo to Python.
loop 1..100 [x][ case [] when? [0=x%15] -> print "FizzBuzz" when? [0=x%3] -> print "Fizz" when? [0=x%5] -> print "Buzz" else -> print x ]
for i in xrange(1, 101): if i % 15 == 0: print "FizzBuzz" elif i % 3 == 0: print "Fizz" elif i % 5 == 0: print "Buzz" else: print i
Generate a VB translation of this Arturo snippet without changing its computational steps.
loop 1..100 [x][ case [] when? [0=x%15] -> print "FizzBuzz" when? [0=x%3] -> print "Fizz" when? [0=x%5] -> print "Buzz" else -> print x ]
Option Explicit Sub FizzBuzz() Dim Tb(1 To 100) As Variant Dim i As Integer For i = 1 To 100 If i Mod 15 = 0 Then Tb(i) = "FizzBuzz" ElseIf i Mod 5 = 0 Then Tb(i) = "Buzz" ElseIf i Mod 3 = 0 Then Tb(i) = "Fizz" Else Tb(i) = i ...
Produce a functionally identical Go code for the snippet given in Arturo.
loop 1..100 [x][ case [] when? [0=x%15] -> print "FizzBuzz" when? [0=x%3] -> print "Fizz" when? [0=x%5] -> print "Buzz" else -> print x ]
package main import "fmt" func main() { for i := 1; i <= 100; i++ { switch { case i%15==0: fmt.Println("FizzBuzz") case i%3==0: fmt.Println("Fizz") case i%5==0: fmt.Println("Buzz") default: fmt.Println(i) } } }
Rewrite the snippet below in C so it works the same as the original AutoHotKey code.
Loop, 100 { If (Mod(A_Index, 15) = 0) output .= "FizzBuzz`n" Else If (Mod(A_Index, 3) = 0) output .= "Fizz`n" Else If (Mod(A_Index, 5) = 0) output .= "Buzz`n" Else output .= A_Index "`n" } FileDelete, output.txt FileAppend, %output%, output.txt Run, cmd /k type output.txt
int i = 0 ; char B[88] ; while ( i++ < 100 ) !sprintf( B, "%s%s", i%3 ? "":"Fizz", i%5 ? "":"Buzz" ) ? sprintf( B, "%d", i ):0, printf( ", %s", B );
Change the programming language of this snippet from AutoHotKey to C# without modifying what it does.
Loop, 100 { If (Mod(A_Index, 15) = 0) output .= "FizzBuzz`n" Else If (Mod(A_Index, 3) = 0) output .= "Fizz`n" Else If (Mod(A_Index, 5) = 0) output .= "Buzz`n" Else output .= A_Index "`n" } FileDelete, output.txt FileAppend, %output%, output.txt Run, cmd /k type output.txt
class Program { public void FizzBuzzGo() { Boolean Fizz = false; Boolean Buzz = false; for (int count = 1; count <= 100; count ++) { Fizz = count % 3 == 0; Buzz = count % 5 == 0; if (Fizz && Buzz) { Console.WriteLine...
Write the same algorithm in C++ as shown in this AutoHotKey implementation.
Loop, 100 { If (Mod(A_Index, 15) = 0) output .= "FizzBuzz`n" Else If (Mod(A_Index, 3) = 0) output .= "Fizz`n" Else If (Mod(A_Index, 5) = 0) output .= "Buzz`n" Else output .= A_Index "`n" } FileDelete, output.txt FileAppend, %output%, output.txt Run, cmd /k type output.txt
#include <iostream> #include <chrono> int main() { int fizz = 0, buzz = 0, fizzbuzz = 0; bool isFizz = false; auto startTime = std::chrono::high_resolution_clock::now(); for (unsigned int i = 1; i <= 4000000000; i++) { isFizz = false; if (i % 3 == 0) { isFizz = true; fizz++; } if (i % 5 == 0) {...
Generate an equivalent Java version of this AutoHotKey code.
Loop, 100 { If (Mod(A_Index, 15) = 0) output .= "FizzBuzz`n" Else If (Mod(A_Index, 3) = 0) output .= "Fizz`n" Else If (Mod(A_Index, 5) = 0) output .= "Buzz`n" Else output .= A_Index "`n" } FileDelete, output.txt FileAppend, %output%, output.txt Run, cmd /k type output.txt
module FizzBuzz { void run() { @Inject Console console; for (Int x : 1..100) { console.print(switch (x % 3, x % 5) { case (0, 0): "FizzBuzz"; case (0, _): "Fizz"; case (_, 0): "Buzz"; ...
Can you help me rewrite this code in Python instead of AutoHotKey, keeping it the same logically?
Loop, 100 { If (Mod(A_Index, 15) = 0) output .= "FizzBuzz`n" Else If (Mod(A_Index, 3) = 0) output .= "Fizz`n" Else If (Mod(A_Index, 5) = 0) output .= "Buzz`n" Else output .= A_Index "`n" } FileDelete, output.txt FileAppend, %output%, output.txt Run, cmd /k type output.txt
for i in xrange(1, 101): if i % 15 == 0: print "FizzBuzz" elif i % 3 == 0: print "Fizz" elif i % 5 == 0: print "Buzz" else: print i
Maintain the same structure and functionality when rewriting this code in VB.
Loop, 100 { If (Mod(A_Index, 15) = 0) output .= "FizzBuzz`n" Else If (Mod(A_Index, 3) = 0) output .= "Fizz`n" Else If (Mod(A_Index, 5) = 0) output .= "Buzz`n" Else output .= A_Index "`n" } FileDelete, output.txt FileAppend, %output%, output.txt Run, cmd /k type output.txt
Option Explicit Sub FizzBuzz() Dim Tb(1 To 100) As Variant Dim i As Integer For i = 1 To 100 If i Mod 15 = 0 Then Tb(i) = "FizzBuzz" ElseIf i Mod 5 = 0 Then Tb(i) = "Buzz" ElseIf i Mod 3 = 0 Then Tb(i) = "Fizz" Else Tb(i) = i ...
Keep all operations the same but rewrite the snippet in Go.
Loop, 100 { If (Mod(A_Index, 15) = 0) output .= "FizzBuzz`n" Else If (Mod(A_Index, 3) = 0) output .= "Fizz`n" Else If (Mod(A_Index, 5) = 0) output .= "Buzz`n" Else output .= A_Index "`n" } FileDelete, output.txt FileAppend, %output%, output.txt Run, cmd /k type output.txt
package main import "fmt" func main() { for i := 1; i <= 100; i++ { switch { case i%15==0: fmt.Println("FizzBuzz") case i%3==0: fmt.Println("Fizz") case i%5==0: fmt.Println("Buzz") default: fmt.Println(i) } } }
Ensure the translated C code behaves exactly like the original Clojure snippet.
(doseq [x (range 1 101)] (println x (str (when (zero? (mod x 3)) "fizz") (when (zero? (mod x 5)) "buzz"))))
int i = 0 ; char B[88] ; while ( i++ < 100 ) !sprintf( B, "%s%s", i%3 ? "":"Fizz", i%5 ? "":"Buzz" ) ? sprintf( B, "%d", i ):0, printf( ", %s", B );
Rewrite this program in C# while keeping its functionality equivalent to the Clojure version.
(doseq [x (range 1 101)] (println x (str (when (zero? (mod x 3)) "fizz") (when (zero? (mod x 5)) "buzz"))))
class Program { public void FizzBuzzGo() { Boolean Fizz = false; Boolean Buzz = false; for (int count = 1; count <= 100; count ++) { Fizz = count % 3 == 0; Buzz = count % 5 == 0; if (Fizz && Buzz) { Console.WriteLine...
Keep all operations the same but rewrite the snippet in C++.
(doseq [x (range 1 101)] (println x (str (when (zero? (mod x 3)) "fizz") (when (zero? (mod x 5)) "buzz"))))
#include <iostream> #include <chrono> int main() { int fizz = 0, buzz = 0, fizzbuzz = 0; bool isFizz = false; auto startTime = std::chrono::high_resolution_clock::now(); for (unsigned int i = 1; i <= 4000000000; i++) { isFizz = false; if (i % 3 == 0) { isFizz = true; fizz++; } if (i % 5 == 0) {...
Write the same code in Java as shown below in Clojure.
(doseq [x (range 1 101)] (println x (str (when (zero? (mod x 3)) "fizz") (when (zero? (mod x 5)) "buzz"))))
module FizzBuzz { void run() { @Inject Console console; for (Int x : 1..100) { console.print(switch (x % 3, x % 5) { case (0, 0): "FizzBuzz"; case (0, _): "Fizz"; case (_, 0): "Buzz"; ...
Can you help me rewrite this code in Python instead of Clojure, keeping it the same logically?
(doseq [x (range 1 101)] (println x (str (when (zero? (mod x 3)) "fizz") (when (zero? (mod x 5)) "buzz"))))
for i in xrange(1, 101): if i % 15 == 0: print "FizzBuzz" elif i % 3 == 0: print "Fizz" elif i % 5 == 0: print "Buzz" else: print i
Convert this Clojure snippet to VB and keep its semantics consistent.
(doseq [x (range 1 101)] (println x (str (when (zero? (mod x 3)) "fizz") (when (zero? (mod x 5)) "buzz"))))
Option Explicit Sub FizzBuzz() Dim Tb(1 To 100) As Variant Dim i As Integer For i = 1 To 100 If i Mod 15 = 0 Then Tb(i) = "FizzBuzz" ElseIf i Mod 5 = 0 Then Tb(i) = "Buzz" ElseIf i Mod 3 = 0 Then Tb(i) = "Fizz" Else Tb(i) = i ...
Change the following Clojure code into Go without altering its purpose.
(doseq [x (range 1 101)] (println x (str (when (zero? (mod x 3)) "fizz") (when (zero? (mod x 5)) "buzz"))))
package main import "fmt" func main() { for i := 1; i <= 100; i++ { switch { case i%15==0: fmt.Println("FizzBuzz") case i%3==0: fmt.Println("Fizz") case i%5==0: fmt.Println("Buzz") default: fmt.Println(i) } } }
Please provide an equivalent version of this Common_Lisp code in C.
(defun fizzbuzz-r (i) (declare (xargs :measure (nfix (- 100 i)))) (prog2$ (cond ((= (mod i 15) 0) (cw "FizzBuzz~%")) ((= (mod i 5) 0) (cw "Buzz~%")) ((= (mod i 3) 0) (cw "Fizz~%")) (t (cw "~x0~%" i))) (if (zp (- 100 i)) nil (fizzbuzz-r (1+ i))))) (defun fizzb...
int i = 0 ; char B[88] ; while ( i++ < 100 ) !sprintf( B, "%s%s", i%3 ? "":"Fizz", i%5 ? "":"Buzz" ) ? sprintf( B, "%d", i ):0, printf( ", %s", B );
Change the following Common_Lisp code into C# without altering its purpose.
(defun fizzbuzz-r (i) (declare (xargs :measure (nfix (- 100 i)))) (prog2$ (cond ((= (mod i 15) 0) (cw "FizzBuzz~%")) ((= (mod i 5) 0) (cw "Buzz~%")) ((= (mod i 3) 0) (cw "Fizz~%")) (t (cw "~x0~%" i))) (if (zp (- 100 i)) nil (fizzbuzz-r (1+ i))))) (defun fizzb...
class Program { public void FizzBuzzGo() { Boolean Fizz = false; Boolean Buzz = false; for (int count = 1; count <= 100; count ++) { Fizz = count % 3 == 0; Buzz = count % 5 == 0; if (Fizz && Buzz) { Console.WriteLine...
Rewrite this program in C++ while keeping its functionality equivalent to the Common_Lisp version.
(defun fizzbuzz-r (i) (declare (xargs :measure (nfix (- 100 i)))) (prog2$ (cond ((= (mod i 15) 0) (cw "FizzBuzz~%")) ((= (mod i 5) 0) (cw "Buzz~%")) ((= (mod i 3) 0) (cw "Fizz~%")) (t (cw "~x0~%" i))) (if (zp (- 100 i)) nil (fizzbuzz-r (1+ i))))) (defun fizzb...
#include <iostream> #include <chrono> int main() { int fizz = 0, buzz = 0, fizzbuzz = 0; bool isFizz = false; auto startTime = std::chrono::high_resolution_clock::now(); for (unsigned int i = 1; i <= 4000000000; i++) { isFizz = false; if (i % 3 == 0) { isFizz = true; fizz++; } if (i % 5 == 0) {...
Write a version of this Common_Lisp function in Java with identical behavior.
(defun fizzbuzz-r (i) (declare (xargs :measure (nfix (- 100 i)))) (prog2$ (cond ((= (mod i 15) 0) (cw "FizzBuzz~%")) ((= (mod i 5) 0) (cw "Buzz~%")) ((= (mod i 3) 0) (cw "Fizz~%")) (t (cw "~x0~%" i))) (if (zp (- 100 i)) nil (fizzbuzz-r (1+ i))))) (defun fizzb...
module FizzBuzz { void run() { @Inject Console console; for (Int x : 1..100) { console.print(switch (x % 3, x % 5) { case (0, 0): "FizzBuzz"; case (0, _): "Fizz"; case (_, 0): "Buzz"; ...
Change the following Common_Lisp code into Python without altering its purpose.
(defun fizzbuzz-r (i) (declare (xargs :measure (nfix (- 100 i)))) (prog2$ (cond ((= (mod i 15) 0) (cw "FizzBuzz~%")) ((= (mod i 5) 0) (cw "Buzz~%")) ((= (mod i 3) 0) (cw "Fizz~%")) (t (cw "~x0~%" i))) (if (zp (- 100 i)) nil (fizzbuzz-r (1+ i))))) (defun fizzb...
for i in xrange(1, 101): if i % 15 == 0: print "FizzBuzz" elif i % 3 == 0: print "Fizz" elif i % 5 == 0: print "Buzz" else: print i
Can you help me rewrite this code in VB instead of Common_Lisp, keeping it the same logically?
(defun fizzbuzz-r (i) (declare (xargs :measure (nfix (- 100 i)))) (prog2$ (cond ((= (mod i 15) 0) (cw "FizzBuzz~%")) ((= (mod i 5) 0) (cw "Buzz~%")) ((= (mod i 3) 0) (cw "Fizz~%")) (t (cw "~x0~%" i))) (if (zp (- 100 i)) nil (fizzbuzz-r (1+ i))))) (defun fizzb...
Option Explicit Sub FizzBuzz() Dim Tb(1 To 100) As Variant Dim i As Integer For i = 1 To 100 If i Mod 15 = 0 Then Tb(i) = "FizzBuzz" ElseIf i Mod 5 = 0 Then Tb(i) = "Buzz" ElseIf i Mod 3 = 0 Then Tb(i) = "Fizz" Else Tb(i) = i ...
Convert this Common_Lisp snippet to Go and keep its semantics consistent.
(defun fizzbuzz-r (i) (declare (xargs :measure (nfix (- 100 i)))) (prog2$ (cond ((= (mod i 15) 0) (cw "FizzBuzz~%")) ((= (mod i 5) 0) (cw "Buzz~%")) ((= (mod i 3) 0) (cw "Fizz~%")) (t (cw "~x0~%" i))) (if (zp (- 100 i)) nil (fizzbuzz-r (1+ i))))) (defun fizzb...
package main import "fmt" func main() { for i := 1; i <= 100; i++ { switch { case i%15==0: fmt.Println("FizzBuzz") case i%3==0: fmt.Println("Fizz") case i%5==0: fmt.Println("Buzz") default: fmt.Println(i) } } }
Port the following code from D to C with equivalent syntax and logic.
import std.stdio, std.algorithm, std.conv; void fizzBuzz(in uint n) { foreach (immutable i; 1 .. n + 1) if (!(i % 15)) "FizzBuzz".writeln; else if (!(i % 3)) "Fizz".writeln; else if (!(i % 5)) "Buzz".writeln; else i.writeln; } void ...
int i = 0 ; char B[88] ; while ( i++ < 100 ) !sprintf( B, "%s%s", i%3 ? "":"Fizz", i%5 ? "":"Buzz" ) ? sprintf( B, "%d", i ):0, printf( ", %s", B );
Preserve the algorithm and functionality while converting the code from D to C#.
import std.stdio, std.algorithm, std.conv; void fizzBuzz(in uint n) { foreach (immutable i; 1 .. n + 1) if (!(i % 15)) "FizzBuzz".writeln; else if (!(i % 3)) "Fizz".writeln; else if (!(i % 5)) "Buzz".writeln; else i.writeln; } void ...
class Program { public void FizzBuzzGo() { Boolean Fizz = false; Boolean Buzz = false; for (int count = 1; count <= 100; count ++) { Fizz = count % 3 == 0; Buzz = count % 5 == 0; if (Fizz && Buzz) { Console.WriteLine...
Rewrite the snippet below in C++ so it works the same as the original D code.
import std.stdio, std.algorithm, std.conv; void fizzBuzz(in uint n) { foreach (immutable i; 1 .. n + 1) if (!(i % 15)) "FizzBuzz".writeln; else if (!(i % 3)) "Fizz".writeln; else if (!(i % 5)) "Buzz".writeln; else i.writeln; } void ...
#include <iostream> #include <chrono> int main() { int fizz = 0, buzz = 0, fizzbuzz = 0; bool isFizz = false; auto startTime = std::chrono::high_resolution_clock::now(); for (unsigned int i = 1; i <= 4000000000; i++) { isFizz = false; if (i % 3 == 0) { isFizz = true; fizz++; } if (i % 5 == 0) {...
Change the programming language of this snippet from D to Java without modifying what it does.
import std.stdio, std.algorithm, std.conv; void fizzBuzz(in uint n) { foreach (immutable i; 1 .. n + 1) if (!(i % 15)) "FizzBuzz".writeln; else if (!(i % 3)) "Fizz".writeln; else if (!(i % 5)) "Buzz".writeln; else i.writeln; } void ...
module FizzBuzz { void run() { @Inject Console console; for (Int x : 1..100) { console.print(switch (x % 3, x % 5) { case (0, 0): "FizzBuzz"; case (0, _): "Fizz"; case (_, 0): "Buzz"; ...
Write the same algorithm in Python as shown in this D implementation.
import std.stdio, std.algorithm, std.conv; void fizzBuzz(in uint n) { foreach (immutable i; 1 .. n + 1) if (!(i % 15)) "FizzBuzz".writeln; else if (!(i % 3)) "Fizz".writeln; else if (!(i % 5)) "Buzz".writeln; else i.writeln; } void ...
for i in xrange(1, 101): if i % 15 == 0: print "FizzBuzz" elif i % 3 == 0: print "Fizz" elif i % 5 == 0: print "Buzz" else: print i
Convert this D snippet to VB and keep its semantics consistent.
import std.stdio, std.algorithm, std.conv; void fizzBuzz(in uint n) { foreach (immutable i; 1 .. n + 1) if (!(i % 15)) "FizzBuzz".writeln; else if (!(i % 3)) "Fizz".writeln; else if (!(i % 5)) "Buzz".writeln; else i.writeln; } void ...
Option Explicit Sub FizzBuzz() Dim Tb(1 To 100) As Variant Dim i As Integer For i = 1 To 100 If i Mod 15 = 0 Then Tb(i) = "FizzBuzz" ElseIf i Mod 5 = 0 Then Tb(i) = "Buzz" ElseIf i Mod 3 = 0 Then Tb(i) = "Fizz" Else Tb(i) = i ...
Ensure the translated Go code behaves exactly like the original D snippet.
import std.stdio, std.algorithm, std.conv; void fizzBuzz(in uint n) { foreach (immutable i; 1 .. n + 1) if (!(i % 15)) "FizzBuzz".writeln; else if (!(i % 3)) "Fizz".writeln; else if (!(i % 5)) "Buzz".writeln; else i.writeln; } void ...
package main import "fmt" func main() { for i := 1; i <= 100; i++ { switch { case i%15==0: fmt.Println("FizzBuzz") case i%3==0: fmt.Println("Fizz") case i%5==0: fmt.Println("Buzz") default: fmt.Println(i) } } }
Can you help me rewrite this code in C instead of Delphi, keeping it the same logically?
program FizzBuzz; uses SysUtils; var i: Integer; begin for i := 1 to 100 do begin if i mod 15 = 0 then Writeln('FizzBuzz') else if i mod 3 = 0 then Writeln('Fizz') else if i mod 5 = 0 then Writeln('Buzz') else Writeln(i); end; end.
int i = 0 ; char B[88] ; while ( i++ < 100 ) !sprintf( B, "%s%s", i%3 ? "":"Fizz", i%5 ? "":"Buzz" ) ? sprintf( B, "%d", i ):0, printf( ", %s", B );
Transform the following Delphi implementation into C#, maintaining the same output and logic.
program FizzBuzz; uses SysUtils; var i: Integer; begin for i := 1 to 100 do begin if i mod 15 = 0 then Writeln('FizzBuzz') else if i mod 3 = 0 then Writeln('Fizz') else if i mod 5 = 0 then Writeln('Buzz') else Writeln(i); end; end.
class Program { public void FizzBuzzGo() { Boolean Fizz = false; Boolean Buzz = false; for (int count = 1; count <= 100; count ++) { Fizz = count % 3 == 0; Buzz = count % 5 == 0; if (Fizz && Buzz) { Console.WriteLine...
Convert this Delphi snippet to C++ and keep its semantics consistent.
program FizzBuzz; uses SysUtils; var i: Integer; begin for i := 1 to 100 do begin if i mod 15 = 0 then Writeln('FizzBuzz') else if i mod 3 = 0 then Writeln('Fizz') else if i mod 5 = 0 then Writeln('Buzz') else Writeln(i); end; end.
#include <iostream> #include <chrono> int main() { int fizz = 0, buzz = 0, fizzbuzz = 0; bool isFizz = false; auto startTime = std::chrono::high_resolution_clock::now(); for (unsigned int i = 1; i <= 4000000000; i++) { isFizz = false; if (i % 3 == 0) { isFizz = true; fizz++; } if (i % 5 == 0) {...
Port the following code from Delphi to Java with equivalent syntax and logic.
program FizzBuzz; uses SysUtils; var i: Integer; begin for i := 1 to 100 do begin if i mod 15 = 0 then Writeln('FizzBuzz') else if i mod 3 = 0 then Writeln('Fizz') else if i mod 5 = 0 then Writeln('Buzz') else Writeln(i); end; end.
module FizzBuzz { void run() { @Inject Console console; for (Int x : 1..100) { console.print(switch (x % 3, x % 5) { case (0, 0): "FizzBuzz"; case (0, _): "Fizz"; case (_, 0): "Buzz"; ...
Translate the given Delphi code snippet into Python without altering its behavior.
program FizzBuzz; uses SysUtils; var i: Integer; begin for i := 1 to 100 do begin if i mod 15 = 0 then Writeln('FizzBuzz') else if i mod 3 = 0 then Writeln('Fizz') else if i mod 5 = 0 then Writeln('Buzz') else Writeln(i); end; end.
for i in xrange(1, 101): if i % 15 == 0: print "FizzBuzz" elif i % 3 == 0: print "Fizz" elif i % 5 == 0: print "Buzz" else: print i
Produce a functionally identical VB code for the snippet given in Delphi.
program FizzBuzz; uses SysUtils; var i: Integer; begin for i := 1 to 100 do begin if i mod 15 = 0 then Writeln('FizzBuzz') else if i mod 3 = 0 then Writeln('Fizz') else if i mod 5 = 0 then Writeln('Buzz') else Writeln(i); end; end.
Option Explicit Sub FizzBuzz() Dim Tb(1 To 100) As Variant Dim i As Integer For i = 1 To 100 If i Mod 15 = 0 Then Tb(i) = "FizzBuzz" ElseIf i Mod 5 = 0 Then Tb(i) = "Buzz" ElseIf i Mod 3 = 0 Then Tb(i) = "Fizz" Else Tb(i) = i ...
Preserve the algorithm and functionality while converting the code from Delphi to Go.
program FizzBuzz; uses SysUtils; var i: Integer; begin for i := 1 to 100 do begin if i mod 15 = 0 then Writeln('FizzBuzz') else if i mod 3 = 0 then Writeln('Fizz') else if i mod 5 = 0 then Writeln('Buzz') else Writeln(i); end; end.
package main import "fmt" func main() { for i := 1; i <= 100; i++ { switch { case i%15==0: fmt.Println("FizzBuzz") case i%3==0: fmt.Println("Fizz") case i%5==0: fmt.Println("Buzz") default: fmt.Println(i) } } }
Change the following Elixir code into C without altering its purpose.
Enum.each 1..100, fn x -> IO.puts(case { rem(x,3) == 0, rem(x,5) == 0 } do { true, true } -> "FizzBuzz" { true, false } -> "Fizz" { false, true } -> "Buzz" { false, false } -> x end) end
int i = 0 ; char B[88] ; while ( i++ < 100 ) !sprintf( B, "%s%s", i%3 ? "":"Fizz", i%5 ? "":"Buzz" ) ? sprintf( B, "%d", i ):0, printf( ", %s", B );
Translate this program into C# but keep the logic exactly as in Elixir.
Enum.each 1..100, fn x -> IO.puts(case { rem(x,3) == 0, rem(x,5) == 0 } do { true, true } -> "FizzBuzz" { true, false } -> "Fizz" { false, true } -> "Buzz" { false, false } -> x end) end
class Program { public void FizzBuzzGo() { Boolean Fizz = false; Boolean Buzz = false; for (int count = 1; count <= 100; count ++) { Fizz = count % 3 == 0; Buzz = count % 5 == 0; if (Fizz && Buzz) { Console.WriteLine...
Transform the following Elixir implementation into C++, maintaining the same output and logic.
Enum.each 1..100, fn x -> IO.puts(case { rem(x,3) == 0, rem(x,5) == 0 } do { true, true } -> "FizzBuzz" { true, false } -> "Fizz" { false, true } -> "Buzz" { false, false } -> x end) end
#include <iostream> #include <chrono> int main() { int fizz = 0, buzz = 0, fizzbuzz = 0; bool isFizz = false; auto startTime = std::chrono::high_resolution_clock::now(); for (unsigned int i = 1; i <= 4000000000; i++) { isFizz = false; if (i % 3 == 0) { isFizz = true; fizz++; } if (i % 5 == 0) {...
Translate this program into Java but keep the logic exactly as in Elixir.
Enum.each 1..100, fn x -> IO.puts(case { rem(x,3) == 0, rem(x,5) == 0 } do { true, true } -> "FizzBuzz" { true, false } -> "Fizz" { false, true } -> "Buzz" { false, false } -> x end) end
module FizzBuzz { void run() { @Inject Console console; for (Int x : 1..100) { console.print(switch (x % 3, x % 5) { case (0, 0): "FizzBuzz"; case (0, _): "Fizz"; case (_, 0): "Buzz"; ...
Port the following code from Elixir to Python with equivalent syntax and logic.
Enum.each 1..100, fn x -> IO.puts(case { rem(x,3) == 0, rem(x,5) == 0 } do { true, true } -> "FizzBuzz" { true, false } -> "Fizz" { false, true } -> "Buzz" { false, false } -> x end) end
for i in xrange(1, 101): if i % 15 == 0: print "FizzBuzz" elif i % 3 == 0: print "Fizz" elif i % 5 == 0: print "Buzz" else: print i
Transform the following Elixir implementation into VB, maintaining the same output and logic.
Enum.each 1..100, fn x -> IO.puts(case { rem(x,3) == 0, rem(x,5) == 0 } do { true, true } -> "FizzBuzz" { true, false } -> "Fizz" { false, true } -> "Buzz" { false, false } -> x end) end
Option Explicit Sub FizzBuzz() Dim Tb(1 To 100) As Variant Dim i As Integer For i = 1 To 100 If i Mod 15 = 0 Then Tb(i) = "FizzBuzz" ElseIf i Mod 5 = 0 Then Tb(i) = "Buzz" ElseIf i Mod 3 = 0 Then Tb(i) = "Fizz" Else Tb(i) = i ...
Please provide an equivalent version of this Elixir code in Go.
Enum.each 1..100, fn x -> IO.puts(case { rem(x,3) == 0, rem(x,5) == 0 } do { true, true } -> "FizzBuzz" { true, false } -> "Fizz" { false, true } -> "Buzz" { false, false } -> x end) end
package main import "fmt" func main() { for i := 1; i <= 100; i++ { switch { case i%15==0: fmt.Println("FizzBuzz") case i%3==0: fmt.Println("Fizz") case i%5==0: fmt.Println("Buzz") default: fmt.Println(i) } } }