Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Generate a Go translation of this Racket snippet without changing its computational steps. | #lang racket
(require (only-in math/number-theory factorize))
(define ((k-almost-prime? k) n)
(= k (for/sum ((f (factorize n))) (cadr f))))
(define KAP-table-values
(for/list ((k (in-range 1 (add1 5))))
(define kap? (k-almost-prime? k))
(for/list ((j (in-range 10)) (i (sequence-filter kap? (in-naturals 1)... | package main
import "fmt"
func kPrime(n, k int) bool {
nf := 0
for i := 2; i <= n; i++ {
for n%i == 0 {
if nf == k {
return false
}
nf++
n /= i
}
}
return nf == k
}
func gen(k, n int) []int {
r := make([]int, n)
n... |
Generate a C translation of this COBOL snippet without changing its computational steps. | IDENTIFICATION DIVISION.
PROGRAM-ID. ALMOST-PRIME.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CONTROL-VARS.
03 K PIC 9.
03 I PIC 999.
03 SEEN PIC 99.
03 N PIC 999.
03 P ... | #include <stdio.h>
int kprime(int n, int k)
{
int p, f = 0;
for (p = 2; f < k && p*p <= n; p++)
while (0 == n % p)
n /= p, f++;
return f + (n > 1) == k;
}
int main(void)
{
int i, c, k;
for (k = 1; k <= 5; k++) {
printf("k = %d:", k);
for (i = 2, c = 0; c < 10; i++)
if (kprime(i, k)) {
printf("... |
Please provide an equivalent version of this COBOL code in C#. | IDENTIFICATION DIVISION.
PROGRAM-ID. ALMOST-PRIME.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CONTROL-VARS.
03 K PIC 9.
03 I PIC 999.
03 SEEN PIC 99.
03 N PIC 999.
03 P ... | using System;
using System.Collections.Generic;
using System.Linq;
namespace AlmostPrime
{
class Program
{
static void Main(string[] args)
{
foreach (int k in Enumerable.Range(1, 5))
{
KPrime kprime = new KPrime() { K = k };
Console.WriteL... |
Keep all operations the same but rewrite the snippet in C++. | IDENTIFICATION DIVISION.
PROGRAM-ID. ALMOST-PRIME.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CONTROL-VARS.
03 K PIC 9.
03 I PIC 999.
03 SEEN PIC 99.
03 N PIC 999.
03 P ... | #include <cstdlib>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <list>
bool k_prime(unsigned n, unsigned k) {
unsigned f = 0;
for (unsigned p = 2; f < k && p * p <= n; p++)
while (0 == n % p) { n /= p; f++; }
return f + (n > 1 ? 1 : 0) == k;
}
std::list<unsigned> primes(unsig... |
Write the same algorithm in Java as shown in this COBOL implementation. | IDENTIFICATION DIVISION.
PROGRAM-ID. ALMOST-PRIME.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CONTROL-VARS.
03 K PIC 9.
03 I PIC 999.
03 SEEN PIC 99.
03 N PIC 999.
03 P ... | public class AlmostPrime {
public static void main(String[] args) {
for (int k = 1; k <= 5; k++) {
System.out.print("k = " + k + ":");
for (int i = 2, c = 0; c < 10; i++) {
if (kprime(i, k)) {
System.out.print(" " + i);
c++;
... |
Can you help me rewrite this code in Python instead of COBOL, keeping it the same logically? | IDENTIFICATION DIVISION.
PROGRAM-ID. ALMOST-PRIME.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CONTROL-VARS.
03 K PIC 9.
03 I PIC 999.
03 SEEN PIC 99.
03 N PIC 999.
03 P ... | from prime_decomposition import decompose
from itertools import islice, count
try:
from functools import reduce
except:
pass
def almostprime(n, k=2):
d = decompose(n)
try:
terms = [next(d) for i in range(k)]
return reduce(int.__mul__, terms, 1) == n
except:
return False
... |
Translate the given COBOL code snippet into VB without altering its behavior. | IDENTIFICATION DIVISION.
PROGRAM-ID. ALMOST-PRIME.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CONTROL-VARS.
03 K PIC 9.
03 I PIC 999.
03 SEEN PIC 99.
03 N PIC 999.
03 P ... | for k = 1 to 5
print "k = "; k; " :";
i = 2
c = 0
while c < 10
if kPrime(i, k) then
print " "; using("###", i);
c = c +1
end if
i = i +1
wend
print
next k
end
function kPrime(n, k)
f = 0
for i = 2 to n
while n mod i = 0
... |
Write the same code in Go as shown below in COBOL. | IDENTIFICATION DIVISION.
PROGRAM-ID. ALMOST-PRIME.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CONTROL-VARS.
03 K PIC 9.
03 I PIC 999.
03 SEEN PIC 99.
03 N PIC 999.
03 P ... | package main
import "fmt"
func kPrime(n, k int) bool {
nf := 0
for i := 2; i <= n; i++ {
for n%i == 0 {
if nf == k {
return false
}
nf++
n /= i
}
}
return nf == k
}
func gen(k, n int) []int {
r := make([]int, n)
n... |
Change the following REXX code into C without altering its purpose. |
parse arg N K .
if N=='' | N=="," then N=10
if K=='' | K=="," then K= 5
do m=1 for K; $=2**m; fir=$
#=1; if #==N then leave
#=2; ... | #include <stdio.h>
int kprime(int n, int k)
{
int p, f = 0;
for (p = 2; f < k && p*p <= n; p++)
while (0 == n % p)
n /= p, f++;
return f + (n > 1) == k;
}
int main(void)
{
int i, c, k;
for (k = 1; k <= 5; k++) {
printf("k = %d:", k);
for (i = 2, c = 0; c < 10; i++)
if (kprime(i, k)) {
printf("... |
Convert the following code from REXX to C#, ensuring the logic remains intact. |
parse arg N K .
if N=='' | N=="," then N=10
if K=='' | K=="," then K= 5
do m=1 for K; $=2**m; fir=$
#=1; if #==N then leave
#=2; ... | using System;
using System.Collections.Generic;
using System.Linq;
namespace AlmostPrime
{
class Program
{
static void Main(string[] args)
{
foreach (int k in Enumerable.Range(1, 5))
{
KPrime kprime = new KPrime() { K = k };
Console.WriteL... |
Preserve the algorithm and functionality while converting the code from REXX to C++. |
parse arg N K .
if N=='' | N=="," then N=10
if K=='' | K=="," then K= 5
do m=1 for K; $=2**m; fir=$
#=1; if #==N then leave
#=2; ... | #include <cstdlib>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <list>
bool k_prime(unsigned n, unsigned k) {
unsigned f = 0;
for (unsigned p = 2; f < k && p * p <= n; p++)
while (0 == n % p) { n /= p; f++; }
return f + (n > 1 ? 1 : 0) == k;
}
std::list<unsigned> primes(unsig... |
Produce a language-to-language conversion: from REXX to Java, same semantics. |
parse arg N K .
if N=='' | N=="," then N=10
if K=='' | K=="," then K= 5
do m=1 for K; $=2**m; fir=$
#=1; if #==N then leave
#=2; ... | public class AlmostPrime {
public static void main(String[] args) {
for (int k = 1; k <= 5; k++) {
System.out.print("k = " + k + ":");
for (int i = 2, c = 0; c < 10; i++) {
if (kprime(i, k)) {
System.out.print(" " + i);
c++;
... |
Change the programming language of this snippet from REXX to Python without modifying what it does. |
parse arg N K .
if N=='' | N=="," then N=10
if K=='' | K=="," then K= 5
do m=1 for K; $=2**m; fir=$
#=1; if #==N then leave
#=2; ... | from prime_decomposition import decompose
from itertools import islice, count
try:
from functools import reduce
except:
pass
def almostprime(n, k=2):
d = decompose(n)
try:
terms = [next(d) for i in range(k)]
return reduce(int.__mul__, terms, 1) == n
except:
return False
... |
Rewrite this program in VB while keeping its functionality equivalent to the REXX version. |
parse arg N K .
if N=='' | N=="," then N=10
if K=='' | K=="," then K= 5
do m=1 for K; $=2**m; fir=$
#=1; if #==N then leave
#=2; ... | for k = 1 to 5
print "k = "; k; " :";
i = 2
c = 0
while c < 10
if kPrime(i, k) then
print " "; using("###", i);
c = c +1
end if
i = i +1
wend
print
next k
end
function kPrime(n, k)
f = 0
for i = 2 to n
while n mod i = 0
... |
Write a version of this REXX function in Go with identical behavior. |
parse arg N K .
if N=='' | N=="," then N=10
if K=='' | K=="," then K= 5
do m=1 for K; $=2**m; fir=$
#=1; if #==N then leave
#=2; ... | package main
import "fmt"
func kPrime(n, k int) bool {
nf := 0
for i := 2; i <= n; i++ {
for n%i == 0 {
if nf == k {
return false
}
nf++
n /= i
}
}
return nf == k
}
func gen(k, n int) []int {
r := make([]int, n)
n... |
Translate the given Ruby code snippet into C without altering its behavior. | require 'prime'
def almost_primes(k=2)
return to_enum(:almost_primes, k) unless block_given?
1.step {|n| yield n if n.prime_division.sum( &:last ) == k }
end
(1..5).each{|k| puts almost_primes(k).take(10).join(", ")}
| #include <stdio.h>
int kprime(int n, int k)
{
int p, f = 0;
for (p = 2; f < k && p*p <= n; p++)
while (0 == n % p)
n /= p, f++;
return f + (n > 1) == k;
}
int main(void)
{
int i, c, k;
for (k = 1; k <= 5; k++) {
printf("k = %d:", k);
for (i = 2, c = 0; c < 10; i++)
if (kprime(i, k)) {
printf("... |
Convert this Ruby snippet to C# and keep its semantics consistent. | require 'prime'
def almost_primes(k=2)
return to_enum(:almost_primes, k) unless block_given?
1.step {|n| yield n if n.prime_division.sum( &:last ) == k }
end
(1..5).each{|k| puts almost_primes(k).take(10).join(", ")}
| using System;
using System.Collections.Generic;
using System.Linq;
namespace AlmostPrime
{
class Program
{
static void Main(string[] args)
{
foreach (int k in Enumerable.Range(1, 5))
{
KPrime kprime = new KPrime() { K = k };
Console.WriteL... |
Convert the following code from Ruby to C++, ensuring the logic remains intact. | require 'prime'
def almost_primes(k=2)
return to_enum(:almost_primes, k) unless block_given?
1.step {|n| yield n if n.prime_division.sum( &:last ) == k }
end
(1..5).each{|k| puts almost_primes(k).take(10).join(", ")}
| #include <cstdlib>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <list>
bool k_prime(unsigned n, unsigned k) {
unsigned f = 0;
for (unsigned p = 2; f < k && p * p <= n; p++)
while (0 == n % p) { n /= p; f++; }
return f + (n > 1 ? 1 : 0) == k;
}
std::list<unsigned> primes(unsig... |
Can you help me rewrite this code in Java instead of Ruby, keeping it the same logically? | require 'prime'
def almost_primes(k=2)
return to_enum(:almost_primes, k) unless block_given?
1.step {|n| yield n if n.prime_division.sum( &:last ) == k }
end
(1..5).each{|k| puts almost_primes(k).take(10).join(", ")}
| public class AlmostPrime {
public static void main(String[] args) {
for (int k = 1; k <= 5; k++) {
System.out.print("k = " + k + ":");
for (int i = 2, c = 0; c < 10; i++) {
if (kprime(i, k)) {
System.out.print(" " + i);
c++;
... |
Change the following Ruby code into Python without altering its purpose. | require 'prime'
def almost_primes(k=2)
return to_enum(:almost_primes, k) unless block_given?
1.step {|n| yield n if n.prime_division.sum( &:last ) == k }
end
(1..5).each{|k| puts almost_primes(k).take(10).join(", ")}
| from prime_decomposition import decompose
from itertools import islice, count
try:
from functools import reduce
except:
pass
def almostprime(n, k=2):
d = decompose(n)
try:
terms = [next(d) for i in range(k)]
return reduce(int.__mul__, terms, 1) == n
except:
return False
... |
Write the same code in VB as shown below in Ruby. | require 'prime'
def almost_primes(k=2)
return to_enum(:almost_primes, k) unless block_given?
1.step {|n| yield n if n.prime_division.sum( &:last ) == k }
end
(1..5).each{|k| puts almost_primes(k).take(10).join(", ")}
| for k = 1 to 5
print "k = "; k; " :";
i = 2
c = 0
while c < 10
if kPrime(i, k) then
print " "; using("###", i);
c = c +1
end if
i = i +1
wend
print
next k
end
function kPrime(n, k)
f = 0
for i = 2 to n
while n mod i = 0
... |
Translate the given Ruby code snippet into Go without altering its behavior. | require 'prime'
def almost_primes(k=2)
return to_enum(:almost_primes, k) unless block_given?
1.step {|n| yield n if n.prime_division.sum( &:last ) == k }
end
(1..5).each{|k| puts almost_primes(k).take(10).join(", ")}
| package main
import "fmt"
func kPrime(n, k int) bool {
nf := 0
for i := 2; i <= n; i++ {
for n%i == 0 {
if nf == k {
return false
}
nf++
n /= i
}
}
return nf == k
}
func gen(k, n int) []int {
r := make([]int, n)
n... |
Change the programming language of this snippet from Scala to C without modifying what it does. | fun Int.k_prime(x: Int): Boolean {
var n = x
var f = 0
var p = 2
while (f < this && p * p <= n) {
while (0 == n % p) { n /= p; f++ }
p++
}
return f + (if (n > 1) 1 else 0) == this
}
fun Int.primes(n : Int) : List<Int> {
var i = 2
var list = mutableListOf<Int>()
while... | #include <stdio.h>
int kprime(int n, int k)
{
int p, f = 0;
for (p = 2; f < k && p*p <= n; p++)
while (0 == n % p)
n /= p, f++;
return f + (n > 1) == k;
}
int main(void)
{
int i, c, k;
for (k = 1; k <= 5; k++) {
printf("k = %d:", k);
for (i = 2, c = 0; c < 10; i++)
if (kprime(i, k)) {
printf("... |
Generate a C# translation of this Scala snippet without changing its computational steps. | fun Int.k_prime(x: Int): Boolean {
var n = x
var f = 0
var p = 2
while (f < this && p * p <= n) {
while (0 == n % p) { n /= p; f++ }
p++
}
return f + (if (n > 1) 1 else 0) == this
}
fun Int.primes(n : Int) : List<Int> {
var i = 2
var list = mutableListOf<Int>()
while... | using System;
using System.Collections.Generic;
using System.Linq;
namespace AlmostPrime
{
class Program
{
static void Main(string[] args)
{
foreach (int k in Enumerable.Range(1, 5))
{
KPrime kprime = new KPrime() { K = k };
Console.WriteL... |
Translate this program into C++ but keep the logic exactly as in Scala. | fun Int.k_prime(x: Int): Boolean {
var n = x
var f = 0
var p = 2
while (f < this && p * p <= n) {
while (0 == n % p) { n /= p; f++ }
p++
}
return f + (if (n > 1) 1 else 0) == this
}
fun Int.primes(n : Int) : List<Int> {
var i = 2
var list = mutableListOf<Int>()
while... | #include <cstdlib>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <list>
bool k_prime(unsigned n, unsigned k) {
unsigned f = 0;
for (unsigned p = 2; f < k && p * p <= n; p++)
while (0 == n % p) { n /= p; f++; }
return f + (n > 1 ? 1 : 0) == k;
}
std::list<unsigned> primes(unsig... |
Maintain the same structure and functionality when rewriting this code in Java. | fun Int.k_prime(x: Int): Boolean {
var n = x
var f = 0
var p = 2
while (f < this && p * p <= n) {
while (0 == n % p) { n /= p; f++ }
p++
}
return f + (if (n > 1) 1 else 0) == this
}
fun Int.primes(n : Int) : List<Int> {
var i = 2
var list = mutableListOf<Int>()
while... | public class AlmostPrime {
public static void main(String[] args) {
for (int k = 1; k <= 5; k++) {
System.out.print("k = " + k + ":");
for (int i = 2, c = 0; c < 10; i++) {
if (kprime(i, k)) {
System.out.print(" " + i);
c++;
... |
Maintain the same structure and functionality when rewriting this code in Python. | fun Int.k_prime(x: Int): Boolean {
var n = x
var f = 0
var p = 2
while (f < this && p * p <= n) {
while (0 == n % p) { n /= p; f++ }
p++
}
return f + (if (n > 1) 1 else 0) == this
}
fun Int.primes(n : Int) : List<Int> {
var i = 2
var list = mutableListOf<Int>()
while... | from prime_decomposition import decompose
from itertools import islice, count
try:
from functools import reduce
except:
pass
def almostprime(n, k=2):
d = decompose(n)
try:
terms = [next(d) for i in range(k)]
return reduce(int.__mul__, terms, 1) == n
except:
return False
... |
Preserve the algorithm and functionality while converting the code from Scala to VB. | fun Int.k_prime(x: Int): Boolean {
var n = x
var f = 0
var p = 2
while (f < this && p * p <= n) {
while (0 == n % p) { n /= p; f++ }
p++
}
return f + (if (n > 1) 1 else 0) == this
}
fun Int.primes(n : Int) : List<Int> {
var i = 2
var list = mutableListOf<Int>()
while... | for k = 1 to 5
print "k = "; k; " :";
i = 2
c = 0
while c < 10
if kPrime(i, k) then
print " "; using("###", i);
c = c +1
end if
i = i +1
wend
print
next k
end
function kPrime(n, k)
f = 0
for i = 2 to n
while n mod i = 0
... |
Convert this Scala block to Go, preserving its control flow and logic. | fun Int.k_prime(x: Int): Boolean {
var n = x
var f = 0
var p = 2
while (f < this && p * p <= n) {
while (0 == n % p) { n /= p; f++ }
p++
}
return f + (if (n > 1) 1 else 0) == this
}
fun Int.primes(n : Int) : List<Int> {
var i = 2
var list = mutableListOf<Int>()
while... | package main
import "fmt"
func kPrime(n, k int) bool {
nf := 0
for i := 2; i <= n; i++ {
for n%i == 0 {
if nf == k {
return false
}
nf++
n /= i
}
}
return nf == k
}
func gen(k, n int) []int {
r := make([]int, n)
n... |
Translate the given Swift code snippet into C without altering its behavior. | struct KPrimeGen: Sequence, IteratorProtocol {
let k: Int
private(set) var n: Int
private func isKPrime() -> Bool {
var primes = 0
var f = 2
var rem = n
while primes < k && rem > 1 {
while rem % f == 0 && rem > 1 {
rem /= f
primes += 1
}
f += 1
}
retur... | #include <stdio.h>
int kprime(int n, int k)
{
int p, f = 0;
for (p = 2; f < k && p*p <= n; p++)
while (0 == n % p)
n /= p, f++;
return f + (n > 1) == k;
}
int main(void)
{
int i, c, k;
for (k = 1; k <= 5; k++) {
printf("k = %d:", k);
for (i = 2, c = 0; c < 10; i++)
if (kprime(i, k)) {
printf("... |
Generate an equivalent C# version of this Swift code. | struct KPrimeGen: Sequence, IteratorProtocol {
let k: Int
private(set) var n: Int
private func isKPrime() -> Bool {
var primes = 0
var f = 2
var rem = n
while primes < k && rem > 1 {
while rem % f == 0 && rem > 1 {
rem /= f
primes += 1
}
f += 1
}
retur... | using System;
using System.Collections.Generic;
using System.Linq;
namespace AlmostPrime
{
class Program
{
static void Main(string[] args)
{
foreach (int k in Enumerable.Range(1, 5))
{
KPrime kprime = new KPrime() { K = k };
Console.WriteL... |
Write a version of this Swift function in C++ with identical behavior. | struct KPrimeGen: Sequence, IteratorProtocol {
let k: Int
private(set) var n: Int
private func isKPrime() -> Bool {
var primes = 0
var f = 2
var rem = n
while primes < k && rem > 1 {
while rem % f == 0 && rem > 1 {
rem /= f
primes += 1
}
f += 1
}
retur... | #include <cstdlib>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <list>
bool k_prime(unsigned n, unsigned k) {
unsigned f = 0;
for (unsigned p = 2; f < k && p * p <= n; p++)
while (0 == n % p) { n /= p; f++; }
return f + (n > 1 ? 1 : 0) == k;
}
std::list<unsigned> primes(unsig... |
Convert this Swift block to Java, preserving its control flow and logic. | struct KPrimeGen: Sequence, IteratorProtocol {
let k: Int
private(set) var n: Int
private func isKPrime() -> Bool {
var primes = 0
var f = 2
var rem = n
while primes < k && rem > 1 {
while rem % f == 0 && rem > 1 {
rem /= f
primes += 1
}
f += 1
}
retur... | public class AlmostPrime {
public static void main(String[] args) {
for (int k = 1; k <= 5; k++) {
System.out.print("k = " + k + ":");
for (int i = 2, c = 0; c < 10; i++) {
if (kprime(i, k)) {
System.out.print(" " + i);
c++;
... |
Port the following code from Swift to Python with equivalent syntax and logic. | struct KPrimeGen: Sequence, IteratorProtocol {
let k: Int
private(set) var n: Int
private func isKPrime() -> Bool {
var primes = 0
var f = 2
var rem = n
while primes < k && rem > 1 {
while rem % f == 0 && rem > 1 {
rem /= f
primes += 1
}
f += 1
}
retur... | from prime_decomposition import decompose
from itertools import islice, count
try:
from functools import reduce
except:
pass
def almostprime(n, k=2):
d = decompose(n)
try:
terms = [next(d) for i in range(k)]
return reduce(int.__mul__, terms, 1) == n
except:
return False
... |
Translate this program into VB but keep the logic exactly as in Swift. | struct KPrimeGen: Sequence, IteratorProtocol {
let k: Int
private(set) var n: Int
private func isKPrime() -> Bool {
var primes = 0
var f = 2
var rem = n
while primes < k && rem > 1 {
while rem % f == 0 && rem > 1 {
rem /= f
primes += 1
}
f += 1
}
retur... | for k = 1 to 5
print "k = "; k; " :";
i = 2
c = 0
while c < 10
if kPrime(i, k) then
print " "; using("###", i);
c = c +1
end if
i = i +1
wend
print
next k
end
function kPrime(n, k)
f = 0
for i = 2 to n
while n mod i = 0
... |
Translate the given Swift code snippet into Go without altering its behavior. | struct KPrimeGen: Sequence, IteratorProtocol {
let k: Int
private(set) var n: Int
private func isKPrime() -> Bool {
var primes = 0
var f = 2
var rem = n
while primes < k && rem > 1 {
while rem % f == 0 && rem > 1 {
rem /= f
primes += 1
}
f += 1
}
retur... | package main
import "fmt"
func kPrime(n, k int) bool {
nf := 0
for i := 2; i <= n; i++ {
for n%i == 0 {
if nf == k {
return false
}
nf++
n /= i
}
}
return nf == k
}
func gen(k, n int) []int {
r := make([]int, n)
n... |
Can you help me rewrite this code in C instead of Tcl, keeping it the same logically? | package require Tcl 8.6
package require math::numtheory
proc firstNprimes n {
for {set result {};set i 2} {[llength $result] < $n} {incr i} {
if {[::math::numtheory::isprime $i]} {
lappend result $i
}
}
return $result
}
proc firstN_KalmostPrimes {n k} {
set p [firstNprimes $n]
set i [lrepea... | #include <stdio.h>
int kprime(int n, int k)
{
int p, f = 0;
for (p = 2; f < k && p*p <= n; p++)
while (0 == n % p)
n /= p, f++;
return f + (n > 1) == k;
}
int main(void)
{
int i, c, k;
for (k = 1; k <= 5; k++) {
printf("k = %d:", k);
for (i = 2, c = 0; c < 10; i++)
if (kprime(i, k)) {
printf("... |
Produce a language-to-language conversion: from Tcl to C#, same semantics. | package require Tcl 8.6
package require math::numtheory
proc firstNprimes n {
for {set result {};set i 2} {[llength $result] < $n} {incr i} {
if {[::math::numtheory::isprime $i]} {
lappend result $i
}
}
return $result
}
proc firstN_KalmostPrimes {n k} {
set p [firstNprimes $n]
set i [lrepea... | using System;
using System.Collections.Generic;
using System.Linq;
namespace AlmostPrime
{
class Program
{
static void Main(string[] args)
{
foreach (int k in Enumerable.Range(1, 5))
{
KPrime kprime = new KPrime() { K = k };
Console.WriteL... |
Convert this Tcl block to C++, preserving its control flow and logic. | package require Tcl 8.6
package require math::numtheory
proc firstNprimes n {
for {set result {};set i 2} {[llength $result] < $n} {incr i} {
if {[::math::numtheory::isprime $i]} {
lappend result $i
}
}
return $result
}
proc firstN_KalmostPrimes {n k} {
set p [firstNprimes $n]
set i [lrepea... | #include <cstdlib>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <list>
bool k_prime(unsigned n, unsigned k) {
unsigned f = 0;
for (unsigned p = 2; f < k && p * p <= n; p++)
while (0 == n % p) { n /= p; f++; }
return f + (n > 1 ? 1 : 0) == k;
}
std::list<unsigned> primes(unsig... |
Generate a Java translation of this Tcl snippet without changing its computational steps. | package require Tcl 8.6
package require math::numtheory
proc firstNprimes n {
for {set result {};set i 2} {[llength $result] < $n} {incr i} {
if {[::math::numtheory::isprime $i]} {
lappend result $i
}
}
return $result
}
proc firstN_KalmostPrimes {n k} {
set p [firstNprimes $n]
set i [lrepea... | public class AlmostPrime {
public static void main(String[] args) {
for (int k = 1; k <= 5; k++) {
System.out.print("k = " + k + ":");
for (int i = 2, c = 0; c < 10; i++) {
if (kprime(i, k)) {
System.out.print(" " + i);
c++;
... |
Translate this program into Python but keep the logic exactly as in Tcl. | package require Tcl 8.6
package require math::numtheory
proc firstNprimes n {
for {set result {};set i 2} {[llength $result] < $n} {incr i} {
if {[::math::numtheory::isprime $i]} {
lappend result $i
}
}
return $result
}
proc firstN_KalmostPrimes {n k} {
set p [firstNprimes $n]
set i [lrepea... | from prime_decomposition import decompose
from itertools import islice, count
try:
from functools import reduce
except:
pass
def almostprime(n, k=2):
d = decompose(n)
try:
terms = [next(d) for i in range(k)]
return reduce(int.__mul__, terms, 1) == n
except:
return False
... |
Produce a functionally identical VB code for the snippet given in Tcl. | package require Tcl 8.6
package require math::numtheory
proc firstNprimes n {
for {set result {};set i 2} {[llength $result] < $n} {incr i} {
if {[::math::numtheory::isprime $i]} {
lappend result $i
}
}
return $result
}
proc firstN_KalmostPrimes {n k} {
set p [firstNprimes $n]
set i [lrepea... | for k = 1 to 5
print "k = "; k; " :";
i = 2
c = 0
while c < 10
if kPrime(i, k) then
print " "; using("###", i);
c = c +1
end if
i = i +1
wend
print
next k
end
function kPrime(n, k)
f = 0
for i = 2 to n
while n mod i = 0
... |
Convert this Tcl snippet to Go and keep its semantics consistent. | package require Tcl 8.6
package require math::numtheory
proc firstNprimes n {
for {set result {};set i 2} {[llength $result] < $n} {incr i} {
if {[::math::numtheory::isprime $i]} {
lappend result $i
}
}
return $result
}
proc firstN_KalmostPrimes {n k} {
set p [firstNprimes $n]
set i [lrepea... | package main
import "fmt"
func kPrime(n, k int) bool {
nf := 0
for i := 2; i <= n; i++ {
for n%i == 0 {
if nf == k {
return false
}
nf++
n /= i
}
}
return nf == k
}
func gen(k, n int) []int {
r := make([]int, n)
n... |
Port the provided Rust code into PHP while preserving the original functionality. | fn is_kprime(n: u32, k: u32) -> bool {
let mut primes = 0;
let mut f = 2;
let mut rem = n;
while primes < k && rem > 1{
while (rem % f) == 0 && rem > 1{
rem /= f;
primes += 1;
}
f += 1;
}
rem == 1 && primes == k
}
struct KPrimeGen {
k: u32,
... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Rewrite the snippet below in PHP so it works the same as the original Ada code. | with Prime_Numbers, Ada.Text_IO;
procedure Test_Kth_Prime is
package Integer_Numbers is new
Prime_Numbers (Natural, 0, 1, 2);
use Integer_Numbers;
Out_Length: constant Positive := 10;
N: Positive;
begin
for K in 1 .. 5 loop
Ada.Text_IO.Put("K =" & Integer'Image(K) &": ");
... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Write a version of this Arturo function in PHP with identical behavior. | almostPrime: function [k, listLen][
result: new []
test: 2
c: 0
while [c < listLen][
i: 2
m: 0
n: test
while [i =< n][
if? zero? n % i [
n: n / i
m: m + 1
]
else -> i: i + 1
]
if m = k [... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Write a version of this AutoHotKey function in PHP with identical behavior. | kprime(n,k) {
p:=2, f:=0
while( (f<k) && (p*p<=n) ) {
while ( 0==mod(n,p) ) {
n/=p
f++
}
p++
}
return f + (n>1) == k
}
k:=1, results:=""
while( k<=5 ) {
i:=2, c:=0, results:=results "k =" k ":"
while( c<10 ) {
if (kprime(i,k)) {
results:=results " " i
c++
}
i++
}
results:=results "`n"
... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Maintain the same structure and functionality when rewriting this code in PHP. |
BEGIN {
for (k=1; k<=5; k++) {
printf("%d:",k)
c = 0
i = 1
while (c < 10) {
if (kprime(++i,k)) {
printf(" %d",i)
c++
}
}
printf("\n")
}
exit(0)
}
function kprime(n,k, f,p) {
for (p=2; f<k && p*p<=n; p++) {
while (n % p == 0)... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Change the following Clojure code into PHP without altering its purpose. | (ns clojure.examples.almostprime
(:gen-class))
(defn divisors [n]
" Finds divisors by looping through integers 2, 3,...i.. up to sqrt (n) [note: rather than compute sqrt(), test with i*i <=n] "
(let [div (some #(if (= 0 (mod n %)) % nil) (take-while #(<= (* % %) n) (iterate inc 2)))]
(if div ... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Port the following code from Common_Lisp to PHP with equivalent syntax and logic. | (defun start ()
(loop for k from 1 to 5
do (format t "k = ~a: ~a~%" k (collect-k-almost-prime k))))
(defun collect-k-almost-prime (k &optional (d 2) (lst nil))
(cond ((= (length lst) 10) (reverse lst))
((= (?-primality d) k) (collect-k-almost-prime k (+ d 1) (cons d lst)))
(t (collect-k-almost-... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Rewrite this program in PHP while keeping its functionality equivalent to the D version. | import std.stdio, std.algorithm, std.traits;
Unqual!T[] decompose(T)(in T number) pure nothrow
in {
assert(number > 1);
} body {
typeof(return) result;
Unqual!T n = number;
for (Unqual!T i = 2; n % i == 0; n /= i)
result ~= i;
for (Unqual!T i = 3; n >= i * i; i += 2)
for (; n % i =... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Convert the following code from Delphi to PHP, ensuring the logic remains intact. | program AlmostPrime;
function IsKPrime(const n, k: Integer): Boolean;
var
p, f, v: Integer;
begin
f := 0;
p := 2;
v := n;
while (f < k) and (p*p <= n) do begin
while (v mod p) = 0 do begin
v := v div p;
Inc(f);
end;
Inc(p);
end;
if v > 1 then Inc(f);
Result := f = k;
end;
var... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Can you help me rewrite this code in PHP instead of Elixir, keeping it the same logically? | defmodule Factors do
def factors(n), do: factors(n,2,[])
defp factors(1,_,acc), do: acc
defp factors(n,k,acc) when rem(n,k)==0, do: factors(div(n,k),k,[k|acc])
defp factors(n,k,acc) , do: factors(n,k+1,acc)
def kfactors(n,k), do: kfactors(n,k,1,1,[])
defp kfactors(_tn,tk,_n,k,_acc) ... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Can you help me rewrite this code in PHP instead of Erlang, keeping it the same logically? | -module(factors).
-export([factors/1,kfactors/0,kfactors/2]).
factors(N) ->
factors(N,2,[]).
... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Maintain the same structure and functionality when rewriting this code in PHP. | let rec genFactor (f, n) =
if f > n then None
elif n % f = 0 then Some (f, (f, n/f))
else genFactor (f+1, n)
let factorsOf (num) =
Seq.unfold (fun (f, n) -> genFactor (f, n)) (2, num)
let kFactors k = Seq.unfold (fun n ->
let rec loop m =
if Seq.length (factorsOf m) = k then m
els... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Write a version of this Factor function in PHP with identical behavior. | USING: formatting fry kernel lists lists.lazy locals
math.combinatorics math.primes.factors math.ranges sequences ;
IN: rosetta-code.almost-prime
: k-almost-prime? ( n k -- ? )
'[ factors _ <combinations> [ product ] map ]
[ [ = ] curry ] bi any? ;
:: first10 ( k -- seq )
10 0 lfrom [ k k-almost-prime... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Generate a PHP translation of this Fortran snippet without changing its computational steps. | program almost_prime
use iso_fortran_env, only: output_unit
implicit none
integer :: i, c, k
do k = 1, 5
write(output_unit,'(A3,x,I0,x,A1,x)', advance="no") "k =", k, ":"
i = 2
c = 0
do
if (c >= 10) exit
if (kprime(i, k)) then
wr... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Please provide an equivalent version of this Groovy code in PHP. |
public class almostprime
{
public static boolean kprime(int n,int k)
{
int i,div=0;
for(i=2;(i*i <= n) && (div<k);i++)
{
while(n%i==0)
{
n = n/i;
div++;
}
}
return div + ((n > 1)?1:0) == k;
}
public static void main(String[] args)
... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Write the same code in PHP as shown below in Haskell. | isPrime :: Integral a => a -> Bool
isPrime n = not $ any ((0 ==) . (mod n)) [2..(truncate $ sqrt $ fromIntegral n)]
primes :: [Integer]
primes = filter isPrime [2..]
isKPrime :: (Num a, Eq a) => a -> Integer -> Bool
isKPrime 1 n = isPrime n
isKPrime k n = any (isKPrime (k - 1)) sprimes
where
sprimes = map fst $... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Translate this program into PHP but keep the logic exactly as in J. | (10 {. [:~.[:/:~[:,*/~)^:(i.5)~p:i.10
2 3 5 7 11 13 17 19 23 29
4 6 9 10 14 15 21 22 25 26
8 12 18 20 27 28 30 42 44 45
16 24 36 40 54 56 60 81 84 88
32 48 72 80 108 112 120 162 168 176
| <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Write a version of this Julia function in PHP with identical behavior. | using Primes
isalmostprime(n::Integer, k::Integer) = sum(values(factor(n))) == k
function almostprimes(N::Integer, k::Integer)
P = Vector{typeof(k)}(undef,N)
i = 0; n = 2
while i < N
if isalmostprime(n, k) P[i += 1] = n end
n += 1
end
return P
end
for k in 1:5
println("$k-Alm... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Produce a functionally identical PHP code for the snippet given in Lua. |
function almostPrime (n, k)
local divisor, count = 2, 0
while count < k + 1 and n ~= 1 do
if n % divisor == 0 then
n = n / divisor
count = count + 1
else
divisor = divisor + 1
end
end
return count == k
end
function kList (k)
local n, kT... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Translate the given Mathematica code snippet into PHP without altering its behavior. | kprimes[k_,n_] :=
Module[{firstnprimes, runningkprimes = {}},
firstnprimes = Prime[Range[n]];
runningkprimes = firstnprimes;
Do[
runningkprimes =
Outer[Times, firstnprimes , runningkprimes ] // Flatten // Union // Take[#, n] & ;
, {i, 1, k - 1}];
runningkprimes
]
Table[Flatten[{"k = " ... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Transform the following Nim implementation into PHP, maintaining the same output and logic. | proc prime(k: int, listLen: int): seq[int] =
result = @[]
var
test: int = 2
curseur: int = 0
while curseur < listLen:
var
i: int = 2
compte = 0
n = test
while i <= n:
if (n mod i)==0:
n = n div i
compte += 1
else:
i += 1
if compte == k:
result.add(test)
curseur += 1
test ... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Translate this program into PHP but keep the logic exactly as in Pascal. | program AlmostPrime;
uses
primtrial;
var
i,K,cnt : longWord;
BEGIN
K := 1;
repeat
cnt := 0;
i := 2;
write('K=',K:2,':');
repeat
if isAlmostPrime(i,K) then
Begin
write(i:6,' ');
inc(cnt);
end;
inc(i);
until cnt = 9;
writeln;
inc(k);
until... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Please provide an equivalent version of this Perl code in PHP. | use ntheory qw/factor/;
sub almost {
my($k,$n) = @_;
my $i = 1;
map { $i++ while scalar factor($i) != $k; $i++ } 1..$n;
}
say "$_ : ", join(" ", almost($_,10)) for 1..5;
| <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Convert the following code from Racket to PHP, ensuring the logic remains intact. | #lang racket
(require (only-in math/number-theory factorize))
(define ((k-almost-prime? k) n)
(= k (for/sum ((f (factorize n))) (cadr f))))
(define KAP-table-values
(for/list ((k (in-range 1 (add1 5))))
(define kap? (k-almost-prime? k))
(for/list ((j (in-range 10)) (i (sequence-filter kap? (in-naturals 1)... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Port the provided COBOL code into PHP while preserving the original functionality. | IDENTIFICATION DIVISION.
PROGRAM-ID. ALMOST-PRIME.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CONTROL-VARS.
03 K PIC 9.
03 I PIC 999.
03 SEEN PIC 99.
03 N PIC 999.
03 P ... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Translate this program into PHP but keep the logic exactly as in REXX. |
parse arg N K .
if N=='' | N=="," then N=10
if K=='' | K=="," then K= 5
do m=1 for K; $=2**m; fir=$
#=1; if #==N then leave
#=2; ... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Maintain the same structure and functionality when rewriting this code in PHP. | require 'prime'
def almost_primes(k=2)
return to_enum(:almost_primes, k) unless block_given?
1.step {|n| yield n if n.prime_division.sum( &:last ) == k }
end
(1..5).each{|k| puts almost_primes(k).take(10).join(", ")}
| <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Please provide an equivalent version of this Scala code in PHP. | fun Int.k_prime(x: Int): Boolean {
var n = x
var f = 0
var p = 2
while (f < this && p * p <= n) {
while (0 == n % p) { n /= p; f++ }
p++
}
return f + (if (n > 1) 1 else 0) == this
}
fun Int.primes(n : Int) : List<Int> {
var i = 2
var list = mutableListOf<Int>()
while... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Convert this Swift block to PHP, preserving its control flow and logic. | struct KPrimeGen: Sequence, IteratorProtocol {
let k: Int
private(set) var n: Int
private func isKPrime() -> Bool {
var primes = 0
var f = 2
var rem = n
while primes < k && rem > 1 {
while rem % f == 0 && rem > 1 {
rem /= f
primes += 1
}
f += 1
}
retur... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Rewrite the snippet below in PHP so it works the same as the original Tcl code. | package require Tcl 8.6
package require math::numtheory
proc firstNprimes n {
for {set result {};set i 2} {[llength $result] < $n} {incr i} {
if {[::math::numtheory::isprime $i]} {
lappend result $i
}
}
return $result
}
proc firstN_KalmostPrimes {n k} {
set p [firstNprimes $n]
set i [lrepea... | <?php
function isKPrime($n, $k)
{
$f = 0;
for ($j = 2; $j <= $n; $j++) {
while ($n % $j == 0) {
if ($f == $k)
return false;
$f++;
$n = floor($n / $j);
} // while
} // for $j
return ($f == $k);
}
for ($k = 1; $k <= 5; $k++) {
echo... |
Write the same code in Rust as shown below in C. | #include <stdio.h>
int kprime(int n, int k)
{
int p, f = 0;
for (p = 2; f < k && p*p <= n; p++)
while (0 == n % p)
n /= p, f++;
return f + (n > 1) == k;
}
int main(void)
{
int i, c, k;
for (k = 1; k <= 5; k++) {
printf("k = %d:", k);
for (i = 2, c = 0; c < 10; i++)
if (kprime(i, k)) {
printf("... | fn is_kprime(n: u32, k: u32) -> bool {
let mut primes = 0;
let mut f = 2;
let mut rem = n;
while primes < k && rem > 1{
while (rem % f) == 0 && rem > 1{
rem /= f;
primes += 1;
}
f += 1;
}
rem == 1 && primes == k
}
struct KPrimeGen {
k: u32,
... |
Maintain the same structure and functionality when rewriting this code in Rust. | #include <cstdlib>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <list>
bool k_prime(unsigned n, unsigned k) {
unsigned f = 0;
for (unsigned p = 2; f < k && p * p <= n; p++)
while (0 == n % p) { n /= p; f++; }
return f + (n > 1 ? 1 : 0) == k;
}
std::list<unsigned> primes(unsig... | fn is_kprime(n: u32, k: u32) -> bool {
let mut primes = 0;
let mut f = 2;
let mut rem = n;
while primes < k && rem > 1{
while (rem % f) == 0 && rem > 1{
rem /= f;
primes += 1;
}
f += 1;
}
rem == 1 && primes == k
}
struct KPrimeGen {
k: u32,
... |
Can you help me rewrite this code in Rust instead of Java, keeping it the same logically? | public class AlmostPrime {
public static void main(String[] args) {
for (int k = 1; k <= 5; k++) {
System.out.print("k = " + k + ":");
for (int i = 2, c = 0; c < 10; i++) {
if (kprime(i, k)) {
System.out.print(" " + i);
c++;
... | fn is_kprime(n: u32, k: u32) -> bool {
let mut primes = 0;
let mut f = 2;
let mut rem = n;
while primes < k && rem > 1{
while (rem % f) == 0 && rem > 1{
rem /= f;
primes += 1;
}
f += 1;
}
rem == 1 && primes == k
}
struct KPrimeGen {
k: u32,
... |
Change the following Go code into Rust without altering its purpose. | package main
import "fmt"
func kPrime(n, k int) bool {
nf := 0
for i := 2; i <= n; i++ {
for n%i == 0 {
if nf == k {
return false
}
nf++
n /= i
}
}
return nf == k
}
func gen(k, n int) []int {
r := make([]int, n)
n... | fn is_kprime(n: u32, k: u32) -> bool {
let mut primes = 0;
let mut f = 2;
let mut rem = n;
while primes < k && rem > 1{
while (rem % f) == 0 && rem > 1{
rem /= f;
primes += 1;
}
f += 1;
}
rem == 1 && primes == k
}
struct KPrimeGen {
k: u32,
... |
Change the programming language of this snippet from Rust to Python without modifying what it does. | fn is_kprime(n: u32, k: u32) -> bool {
let mut primes = 0;
let mut f = 2;
let mut rem = n;
while primes < k && rem > 1{
while (rem % f) == 0 && rem > 1{
rem /= f;
primes += 1;
}
f += 1;
}
rem == 1 && primes == k
}
struct KPrimeGen {
k: u32,
... | from prime_decomposition import decompose
from itertools import islice, count
try:
from functools import reduce
except:
pass
def almostprime(n, k=2):
d = decompose(n)
try:
terms = [next(d) for i in range(k)]
return reduce(int.__mul__, terms, 1) == n
except:
return False
... |
Write a version of this Rust function in VB with identical behavior. | fn is_kprime(n: u32, k: u32) -> bool {
let mut primes = 0;
let mut f = 2;
let mut rem = n;
while primes < k && rem > 1{
while (rem % f) == 0 && rem > 1{
rem /= f;
primes += 1;
}
f += 1;
}
rem == 1 && primes == k
}
struct KPrimeGen {
k: u32,
... | Private Function kprime(ByVal n As Integer, k As Integer) As Boolean
Dim p As Integer, factors As Integer
p = 2
factors = 0
Do While factors < k And p * p <= n
Do While n Mod p = 0
n = n / p
factors = factors + 1
Loop
p = p + 1
Loop
factors = facto... |
Preserve the algorithm and functionality while converting the code from C# to Rust. | using System;
using System.Collections.Generic;
using System.Linq;
namespace AlmostPrime
{
class Program
{
static void Main(string[] args)
{
foreach (int k in Enumerable.Range(1, 5))
{
KPrime kprime = new KPrime() { K = k };
Console.WriteL... | fn is_kprime(n: u32, k: u32) -> bool {
let mut primes = 0;
let mut f = 2;
let mut rem = n;
while primes < k && rem > 1{
while (rem % f) == 0 && rem > 1{
rem /= f;
primes += 1;
}
f += 1;
}
rem == 1 && primes == k
}
struct KPrimeGen {
k: u32,
... |
Change the programming language of this snippet from Ada to C# without modifying what it does. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_Io;
procedure Compare_Ints is
A, B : Integer;
begin
Get(Item => A);
Get(Item => B);
if A = B then
Put_Line("A equals B");
end if;
if A < B then
Put_Line("A is less than B");
end if;
if A... | using System;
class Program
{
static void Main()
{
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
if (a < b)
Console.WriteLine("{0} is less than {1}", a, b);
if (a == b)
Console.WriteLine("{0} equals {1}", a, b);
if ... |
Translate this program into C but keep the logic exactly as in Ada. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_Io;
procedure Compare_Ints is
A, B : Integer;
begin
Get(Item => A);
Get(Item => B);
if A = B then
Put_Line("A equals B");
end if;
if A < B then
Put_Line("A is less than B");
end if;
if A... | #include <stdio.h>
int main()
{
int a, b;
scanf("%d %d", &a, &b);
if (a < b)
printf("%d is less than %d\n", a, b);
if (a == b)
printf("%d is equal to %d\n", a, b);
if (a > b)
printf("%d is greater than %d\n", a, b);
return 0;
}
|
Generate a C++ translation of this Ada snippet without changing its computational steps. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_Io;
procedure Compare_Ints is
A, B : Integer;
begin
Get(Item => A);
Get(Item => B);
if A = B then
Put_Line("A equals B");
end if;
if A < B then
Put_Line("A is less than B");
end if;
if A... | #include <iostream>
int main()
{
int a, b;
if (!(std::cin >> a >> b)) {
std::cerr << "could not read the numbers\n";
return 1;
}
if (a < b)
std::cout << a << " is less than " << b << "\n";
if (a == b)
std::cout << a << " is equal to " << b << "\n";
if (a > b)
std::cout << a... |
Write a version of this Ada function in Go with identical behavior. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_Io;
procedure Compare_Ints is
A, B : Integer;
begin
Get(Item => A);
Get(Item => B);
if A = B then
Put_Line("A equals B");
end if;
if A < B then
Put_Line("A is less than B");
end if;
if A... | package main
import (
"fmt"
"log"
)
func main() {
var n1, n2 int
fmt.Print("enter number: ")
if _, err := fmt.Scan(&n1); err != nil {
log.Fatal(err)
}
fmt.Print("enter number: ")
if _, err := fmt.Scan(&n2); err != nil {
log.Fatal(err)
}
switch {
case n1 < n2:
fmt.Println(n1, "less than", n2)
case n1... |
Produce a functionally identical Java code for the snippet given in Ada. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_Io;
procedure Compare_Ints is
A, B : Integer;
begin
Get(Item => A);
Get(Item => B);
if A = B then
Put_Line("A equals B");
end if;
if A < B then
Put_Line("A is less than B");
end if;
if A... | import java.io.*;
public class compInt {
public static void main(String[] args) {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int nbr1 = Integer.parseInt(in.readLine());
int nbr2 = Integer.parseInt(in.readLine());
if(nbr1<nbr2)... |
Transform the following Ada implementation into Python, maintaining the same output and logic. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_Io;
procedure Compare_Ints is
A, B : Integer;
begin
Get(Item => A);
Get(Item => B);
if A = B then
Put_Line("A equals B");
end if;
if A < B then
Put_Line("A is less than B");
end if;
if A... | let a = input('Enter value of a: ')
let b = input('Enter value of b: ')
if a < b:
print 'a is less than b'
elif a > b:
print 'a is greater than b'
elif a == b:
print 'a is equal to b'
|
Produce a language-to-language conversion: from Ada to VB, same semantics. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_Io;
procedure Compare_Ints is
A, B : Integer;
begin
Get(Item => A);
Get(Item => B);
if A = B then
Put_Line("A equals B");
end if;
if A < B then
Put_Line("A is less than B");
end if;
if A... | Public Sub integer_comparison()
first_integer = CInt(InputBox("Give me an integer."))
second_integer = CInt(InputBox("Give me another integer."))
Debug.Print IIf(first_integer < second_integer, "first integer is smaller than second integer", "first integer is not smaller than second integer")
Debug.Prin... |
Convert this Arturo block to C, preserving its control flow and logic. | a: to :integer input "enter a value for a: "
b: to :integer input "enter a value for b: "
if a<b [ print [ a "is less than" b ] ]
if a>b [ print [ a "is greater than" b ] ]
if a=b [ print [ a "is equal to" b ] ]
| #include <stdio.h>
int main()
{
int a, b;
scanf("%d %d", &a, &b);
if (a < b)
printf("%d is less than %d\n", a, b);
if (a == b)
printf("%d is equal to %d\n", a, b);
if (a > b)
printf("%d is greater than %d\n", a, b);
return 0;
}
|
Preserve the algorithm and functionality while converting the code from Arturo to C#. | a: to :integer input "enter a value for a: "
b: to :integer input "enter a value for b: "
if a<b [ print [ a "is less than" b ] ]
if a>b [ print [ a "is greater than" b ] ]
if a=b [ print [ a "is equal to" b ] ]
| using System;
class Program
{
static void Main()
{
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
if (a < b)
Console.WriteLine("{0} is less than {1}", a, b);
if (a == b)
Console.WriteLine("{0} equals {1}", a, b);
if ... |
Produce a language-to-language conversion: from Arturo to C++, same semantics. | a: to :integer input "enter a value for a: "
b: to :integer input "enter a value for b: "
if a<b [ print [ a "is less than" b ] ]
if a>b [ print [ a "is greater than" b ] ]
if a=b [ print [ a "is equal to" b ] ]
| #include <iostream>
int main()
{
int a, b;
if (!(std::cin >> a >> b)) {
std::cerr << "could not read the numbers\n";
return 1;
}
if (a < b)
std::cout << a << " is less than " << b << "\n";
if (a == b)
std::cout << a << " is equal to " << b << "\n";
if (a > b)
std::cout << a... |
Ensure the translated Java code behaves exactly like the original Arturo snippet. | a: to :integer input "enter a value for a: "
b: to :integer input "enter a value for b: "
if a<b [ print [ a "is less than" b ] ]
if a>b [ print [ a "is greater than" b ] ]
if a=b [ print [ a "is equal to" b ] ]
| import java.io.*;
public class compInt {
public static void main(String[] args) {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int nbr1 = Integer.parseInt(in.readLine());
int nbr2 = Integer.parseInt(in.readLine());
if(nbr1<nbr2)... |
Translate the given Arturo code snippet into Python without altering its behavior. | a: to :integer input "enter a value for a: "
b: to :integer input "enter a value for b: "
if a<b [ print [ a "is less than" b ] ]
if a>b [ print [ a "is greater than" b ] ]
if a=b [ print [ a "is equal to" b ] ]
| let a = input('Enter value of a: ')
let b = input('Enter value of b: ')
if a < b:
print 'a is less than b'
elif a > b:
print 'a is greater than b'
elif a == b:
print 'a is equal to b'
|
Translate the given Arturo code snippet into VB without altering its behavior. | a: to :integer input "enter a value for a: "
b: to :integer input "enter a value for b: "
if a<b [ print [ a "is less than" b ] ]
if a>b [ print [ a "is greater than" b ] ]
if a=b [ print [ a "is equal to" b ] ]
| Public Sub integer_comparison()
first_integer = CInt(InputBox("Give me an integer."))
second_integer = CInt(InputBox("Give me another integer."))
Debug.Print IIf(first_integer < second_integer, "first integer is smaller than second integer", "first integer is not smaller than second integer")
Debug.Prin... |
Generate an equivalent Go version of this Arturo code. | a: to :integer input "enter a value for a: "
b: to :integer input "enter a value for b: "
if a<b [ print [ a "is less than" b ] ]
if a>b [ print [ a "is greater than" b ] ]
if a=b [ print [ a "is equal to" b ] ]
| package main
import (
"fmt"
"log"
)
func main() {
var n1, n2 int
fmt.Print("enter number: ")
if _, err := fmt.Scan(&n1); err != nil {
log.Fatal(err)
}
fmt.Print("enter number: ")
if _, err := fmt.Scan(&n2); err != nil {
log.Fatal(err)
}
switch {
case n1 < n2:
fmt.Println(n1, "less than", n2)
case n1... |
Produce a language-to-language conversion: from AutoHotKey to C, same semantics. | Gui, Add, Edit
Gui, Add, UpDown, vVar1
Gui, Add, Edit
Gui, Add, UpDown, vVar2
Gui, Add, Button, Default, Submit
Gui, Show
Return
ButtonSubmit:
Gui, Submit, NoHide
If (Var1 = Var2)
MsgBox, % Var1 "=" Var2
Else If (Var1 < Var2)
MsgBox, % Var1 "<" Var2
Else If (Var1 > Var2)
MsgBox, % Var1 ">" Var2
Ret... | #include <stdio.h>
int main()
{
int a, b;
scanf("%d %d", &a, &b);
if (a < b)
printf("%d is less than %d\n", a, b);
if (a == b)
printf("%d is equal to %d\n", a, b);
if (a > b)
printf("%d is greater than %d\n", a, b);
return 0;
}
|
Keep all operations the same but rewrite the snippet in C#. | Gui, Add, Edit
Gui, Add, UpDown, vVar1
Gui, Add, Edit
Gui, Add, UpDown, vVar2
Gui, Add, Button, Default, Submit
Gui, Show
Return
ButtonSubmit:
Gui, Submit, NoHide
If (Var1 = Var2)
MsgBox, % Var1 "=" Var2
Else If (Var1 < Var2)
MsgBox, % Var1 "<" Var2
Else If (Var1 > Var2)
MsgBox, % Var1 ">" Var2
Ret... | using System;
class Program
{
static void Main()
{
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
if (a < b)
Console.WriteLine("{0} is less than {1}", a, b);
if (a == b)
Console.WriteLine("{0} equals {1}", a, b);
if ... |
Generate a C++ translation of this AutoHotKey snippet without changing its computational steps. | Gui, Add, Edit
Gui, Add, UpDown, vVar1
Gui, Add, Edit
Gui, Add, UpDown, vVar2
Gui, Add, Button, Default, Submit
Gui, Show
Return
ButtonSubmit:
Gui, Submit, NoHide
If (Var1 = Var2)
MsgBox, % Var1 "=" Var2
Else If (Var1 < Var2)
MsgBox, % Var1 "<" Var2
Else If (Var1 > Var2)
MsgBox, % Var1 ">" Var2
Ret... | #include <iostream>
int main()
{
int a, b;
if (!(std::cin >> a >> b)) {
std::cerr << "could not read the numbers\n";
return 1;
}
if (a < b)
std::cout << a << " is less than " << b << "\n";
if (a == b)
std::cout << a << " is equal to " << b << "\n";
if (a > b)
std::cout << a... |
Rewrite the snippet below in Java so it works the same as the original AutoHotKey code. | Gui, Add, Edit
Gui, Add, UpDown, vVar1
Gui, Add, Edit
Gui, Add, UpDown, vVar2
Gui, Add, Button, Default, Submit
Gui, Show
Return
ButtonSubmit:
Gui, Submit, NoHide
If (Var1 = Var2)
MsgBox, % Var1 "=" Var2
Else If (Var1 < Var2)
MsgBox, % Var1 "<" Var2
Else If (Var1 > Var2)
MsgBox, % Var1 ">" Var2
Ret... | import java.io.*;
public class compInt {
public static void main(String[] args) {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int nbr1 = Integer.parseInt(in.readLine());
int nbr2 = Integer.parseInt(in.readLine());
if(nbr1<nbr2)... |
Rewrite this program in Python while keeping its functionality equivalent to the AutoHotKey version. | Gui, Add, Edit
Gui, Add, UpDown, vVar1
Gui, Add, Edit
Gui, Add, UpDown, vVar2
Gui, Add, Button, Default, Submit
Gui, Show
Return
ButtonSubmit:
Gui, Submit, NoHide
If (Var1 = Var2)
MsgBox, % Var1 "=" Var2
Else If (Var1 < Var2)
MsgBox, % Var1 "<" Var2
Else If (Var1 > Var2)
MsgBox, % Var1 ">" Var2
Ret... | let a = input('Enter value of a: ')
let b = input('Enter value of b: ')
if a < b:
print 'a is less than b'
elif a > b:
print 'a is greater than b'
elif a == b:
print 'a is equal to b'
|
Port the provided AutoHotKey code into VB while preserving the original functionality. | Gui, Add, Edit
Gui, Add, UpDown, vVar1
Gui, Add, Edit
Gui, Add, UpDown, vVar2
Gui, Add, Button, Default, Submit
Gui, Show
Return
ButtonSubmit:
Gui, Submit, NoHide
If (Var1 = Var2)
MsgBox, % Var1 "=" Var2
Else If (Var1 < Var2)
MsgBox, % Var1 "<" Var2
Else If (Var1 > Var2)
MsgBox, % Var1 ">" Var2
Ret... | Public Sub integer_comparison()
first_integer = CInt(InputBox("Give me an integer."))
second_integer = CInt(InputBox("Give me another integer."))
Debug.Print IIf(first_integer < second_integer, "first integer is smaller than second integer", "first integer is not smaller than second integer")
Debug.Prin... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.