Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Please provide an equivalent version of this Python code in COBOL. | limit = 1000
print("working...")
def isprime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
def issquare(x):
for n in range(1,x+1):
if (x == n*n):
return 1
return 0
for n in range(limit-1):
if issquare(n) and isprime(n+1):
print(n,end=" ")
print()
prin... | IDENTIFICATION DIVISION.
PROGRAM-ID. SQUARE-PLUS-1-PRIME.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 N PIC 999.
01 P PIC 9999 VALUE ZERO.
01 PRIMETEST.
03 DSOR PIC 9999.
03 PRIME-FLAG PIC X... |
Write the same algorithm in COBOL as shown in this Python implementation. |
from itertools import count
def firstSquareWithPrefix(n):
pfx = str(n)
lng = len(pfx)
return int(
next(
s for s in (
str(x * x) for x in count(0)
)
if pfx == s[0:lng]
)
)
def main():
print('\n'.join([
str(... | IDENTIFICATION DIVISION.
PROGRAM-ID. SMALLEST-SQUARE-BEGINS-WITH-N.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 N PIC 99.
01 SQUARE-NO PIC 999.
01 SQUARE PIC 9(5).
01 OUT-FMT PIC Z(4)9.
PROCEDURE DIVISION.
BEGIN.
... |
Ensure the translated COBOL code behaves exactly like the original Python snippet. |
from itertools import count
def firstSquareWithPrefix(n):
pfx = str(n)
lng = len(pfx)
return int(
next(
s for s in (
str(x * x) for x in count(0)
)
if pfx == s[0:lng]
)
)
def main():
print('\n'.join([
str(... | IDENTIFICATION DIVISION.
PROGRAM-ID. SMALLEST-SQUARE-BEGINS-WITH-N.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 N PIC 99.
01 SQUARE-NO PIC 999.
01 SQUARE PIC 9(5).
01 OUT-FMT PIC Z(4)9.
PROCEDURE DIVISION.
BEGIN.
... |
Write the same algorithm in COBOL as shown in this Python implementation. | import ctypes
import os
from ctypes import c_ubyte, c_int
code = bytes([0x8b, 0x44, 0x24, 0x04, 0x03, 0x44, 0x24, 0x08, 0xc3])
code_size = len(code)
if (os.name == 'posix'):
import mmap
executable_map = mmap.mmap(-1, code_size, mmap.MAP_PRIVATE | mmap.MAP_ANON, mmap.PROT_READ | mmap.PROT_WRITE | mmap.PROT_EX... | >>SOURCE FORMAT IS FIXED
IDENTIFICATION DIVISION.
PROGRAM-ID. MC.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INSTRUCTIONS.
03 USAGE BINARY-CHAR UNSIGNED VALUE H'55'.
03 USAGE BINARY-CHAR UNSIGNED VALUE H'48'.
03 USAGE BINARY-CHAR UN... |
Rewrite this program in COBOL while keeping its functionality equivalent to the Python version. | def min_cells_matrix(siz):
return [[min(row, col, siz - row - 1, siz - col - 1) for col in range(siz)] for row in range(siz)]
def display_matrix(mat):
siz = len(mat)
spaces = 2 if siz < 20 else 3 if siz < 200 else 4
print(f"\nMinimum number of cells after, before, above and below {siz} x {siz} square:"... | IDENTIFICATION DIVISION.
PROGRAM-ID. MINIMUM-CELLS-N-BY-N.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 TABLE-SIZE PIC 99 VALUE 10.
01 X PIC 99.
01 Y PIC 99.
01 ITEM PIC 99.
01 MIN PIC ... |
Maintain the same structure and functionality when rewriting this code in COBOL. | Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> from sympy import isprime
>>> [x for x in range(101,500)
if isprime(sum(int(c) for c in str(x)[:2])) and
isprime(sum(int(c) for c in str(x)[1:]))]
[111, ... | IDENTIFICATION DIVISION.
PROGRAM-ID. STRANGE-PLUS-NUMBERS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 VARIABLES.
03 CANDIDATE PIC 999.
03 DIGITS REDEFINES CANDIDATE,
PIC 9 OCCURS 3 TIMES.
03 LEFT... |
Convert this Python block to COBOL, preserving its control flow and logic. | Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> from sympy import isprime
>>> [x for x in range(101,500)
if isprime(sum(int(c) for c in str(x)[:2])) and
isprime(sum(int(c) for c in str(x)[1:]))]
[111, ... | IDENTIFICATION DIVISION.
PROGRAM-ID. STRANGE-PLUS-NUMBERS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 VARIABLES.
03 CANDIDATE PIC 999.
03 DIGITS REDEFINES CANDIDATE,
PIC 9 OCCURS 3 TIMES.
03 LEFT... |
Convert this Python snippet to COBOL and keep its semantics consistent. |
from itertools import count, islice
def a131382():
return (
elemIndex(x)(
productDigitSums(x)
) for x in count(1)
)
def productDigitSums(n):
return (digitSum(n * x) for x in count(0))
def main():
print(
table(10)([
str(x) for x ... | IDENTIFICATION DIVISION.
PROGRAM-ID. A131382.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 VARIABLES.
03 MAXIMUM PIC 99 VALUE 40.
03 N PIC 999.
03 M PIC 9(9).
03 N-TIMES-M PIC 9(9).
03 DIGITS P... |
Produce a language-to-language conversion: from Python to COBOL, same semantics. | >>> def isint(f):
return complex(f).imag == 0 and complex(f).real.is_integer()
>>> [isint(f) for f in (1.0, 2, (3.0+0.0j), 4.1, (3+4j), (5.6+0j))]
[True, True, True, False, False, False]
>>>
...
>>> isint(25.000000)
True
>>> isint(24.999999)
False
>>> isint(25.000100)
False
>>> isint(-2.1e120)
True
>>> isint(-5... | IDENTIFICATION DIVISION.
PROGRAM-ID. INTEGERNESS-PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INTEGERS-OR-ARE-THEY.
05 POSSIBLE-INTEGER PIC S9(9)V9(9).
05 DEFINITE-INTEGER PIC S9(9).
01 COMPLEX-NUMBER.
05 REAL-PART PIC S9(9)V9(9).
05 IMAGINARY-PART PIC S9(9)V9(9).
PROCEDURE DIVISION.
T... |
Ensure the translated COBOL code behaves exactly like the original Python snippet. | from Xlib import X, display
class Window:
def __init__(self, display, msg):
self.display = display
self.msg = msg
self.screen = self.display.screen()
self.window = self.screen.root.create_window(
10, 10, 100, 100, 1,
self.screen.root_depth,
... | identification division.
program-id. x11-hello.
installation. cobc -x x11-hello.cob -lX11
remarks. Use of private data is likely not cross platform.
data division.
working-storage section.
01 msg.
05 filler value z"S'up, Earth?".
01 msg-len ... |
Convert this Python block to COBOL, preserving its control flow and logic. |
from datetime import date, timedelta
from math import floor, sin, pi
def biorhythms(birthdate,targetdate):
print("Born: "+birthdate+" Target: "+targetdate)
birthdate = date.fromisoformat(birthdate)
targetdate = date.fromisoformat(targetdate)
days ... |
identification division.
program-id. bio.
environment division.
*************************************************************
**** To execute on command line enter program name followed
**** by birth date ccyymmdd and then target date.
**** Example: bio 180... |
Write the same algorithm in COBOL as shown in this Python implementation. |
from datetime import date, timedelta
from math import floor, sin, pi
def biorhythms(birthdate,targetdate):
print("Born: "+birthdate+" Target: "+targetdate)
birthdate = date.fromisoformat(birthdate)
targetdate = date.fromisoformat(targetdate)
days ... |
identification division.
program-id. bio.
environment division.
*************************************************************
**** To execute on command line enter program name followed
**** by birth date ccyymmdd and then target date.
**** Example: bio 180... |
Port the following code from Python to COBOL with equivalent syntax and logic. | import logging, logging.handlers
LOG_FILENAME = "logdemo.log"
FORMAT_STRING = "%(levelname)s:%(asctime)s:%(name)s:%(funcName)s:line-%(lineno)d: %(message)s"
LOGLEVEL = logging.DEBUG
def print_squares(number):
logger.info("In print_squares")
for i in range(number):
print("square of {0} is {1}".format(... | gcobol
identification division.
program-id. steptrace.
data division.
working-storage section.
procedure division.
steptrace-main.
display "explicit line" upon syserr
>>Ddisplay "debug line" upon syserr
display "from " FUNCTION... |
Please provide an equivalent version of this Python code in COBOL. |
def reverse(n):
u = 0
while n:
u = 10 * u + n % 10
n = int(n / 10)
return u
c = 0
for n in range(1, 200):
u = reverse(n)
s = True
for d in range (1, n):
if n % d == 0:
b = reverse(d)
if u % b != 0:
s = False
if s:
... | IDENTIFICATION DIVISION.
PROGRAM-ID. SPECIAL-DIVISORS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 VARIABLES.
02 CANDIDATE PIC 999.
02 CAND-REV PIC 999.
02 REVERSE PIC 999.
02 REV-DIGITS REDEFIN... |
Rewrite this program in COBOL while keeping its functionality equivalent to the Python version. |
from sympy import factorint
NUM_WANTED = 100
for num in range(1, NUM_WANTED + 1):
fac = factorint(num, multiple=True)
product = fac[0] * fac[-1] if len(fac) > 0 else 1
print(f'{product:5}', end='\n' if num % 10 == 0 else '')
| IDENTIFICATION DIVISION.
PROGRAM-ID. MIN-MAX-PRIME-FACTOR-PRODUCT.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 SIEVE-DATA.
03 FLAG-DATA PIC X(100) VALUE SPACES.
03 FLAGS REDEFINES FLAG-DATA,
PIC X OCCURS 100 T... |
Write the same code in Arturo as shown below in Java. | import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class Main
{
public static void main(String[] args) throws UnsupportedEncodingException
{
String normal = "http:
String encoded = URLEncoder.encode(normal, "utf-8");
System.out.println(encoded);
}
}
| encoded: encode.url.slashes "http://foo bar/"
print encoded
|
Translate this program into Arturo but keep the logic exactly as in Java. | import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class Main
{
public static void main(String[] args) throws UnsupportedEncodingException
{
String normal = "http:
String encoded = URLEncoder.encode(normal, "utf-8");
System.out.println(encoded);
}
}
| encoded: encode.url.slashes "http://foo bar/"
print encoded
|
Generate a Arturo translation of this Java snippet without changing its computational steps. | module OptionalParameters
{
typedef Type<String >.Orderer as ColumnOrderer;
typedef Type<String[]>.Orderer as RowOrderer;
static String[][] sort(String[][] table,
ColumnOrderer? orderer = Null,
Int column = 0,
... | sortTable: function [tbl][
column: "0"
reversed?: false
unless null? c: <= attr 'column -> column: to :string c
unless null? attr 'reverse -> reversed?: true
result: new sort.by: column map tbl 'r [
to :dictionary flatten couple 0..dec size r r
]
if reversed? -> reverse 'result
... |
Rewrite this program in Arturo while keeping its functionality equivalent to the Java version. |
import java.util.*;
import java.io.*;
public class TPKA {
public static void main(String... args) {
double[] input = new double[11];
double userInput = 0.0;
Scanner in = new Scanner(System.in);
for(int i = 0; i < 11; i++) {
System.out.print("Please enter a number: ");
String s = in.nextLine();
try ... | proc: function [x]->
((abs x) ^ 0.5) + 5 * x ^ 3
ask: function [msg][
to [:floating] first.n: 11 split.words strip input msg
]
loop reverse ask "11 numbers: " 'n [
result: proc n
print [n ":" (result > 400)? -> "TOO LARGE!" -> result]
]
|
Preserve the algorithm and functionality while converting the code from Java to Arturo. | class Metronome{
double bpm;
int measure, counter;
public Metronome(double bpm, int measure){
this.bpm = bpm;
this.measure = measure;
}
public void start(){
while(true){
try {
Thread.sleep((long)(1000*(60.0/bpm)));
}catch(InterruptedException e) {
e.printStackTrace();
}
counter++;
if ... | startMetronome: function [bpm,msr][
freq: 60000/bpm
i: 0
while [true][
loop msr-1 'x[
prints "\a"
pause freq
]
inc 'i
print ~"\aAND |i|"
pause freq
]
]
tempo: to :integer arg\0
beats: to :integer arg\1
startMetronome tempo beats
|
Write the same algorithm in Arturo as shown in this Java implementation. | public class RepString {
static final String[] input = {"1001110011", "1110111011", "0010010010",
"1010101010", "1111111111", "0100101101", "0100100", "101", "11",
"00", "1", "0100101"};
public static void main(String[] args) {
for (String s : input)
System.out.printf("%s :... | repeated?: function [text][
loop ((size text)/2)..0 'x [
if prefix? text slice text x (size text)-1 [
(x>0)? -> return slice text 0 x-1
-> return false
]
]
return false
]
strings: {
1001110011
1110111011
0010010010
1010101010
1111111111
... |
Produce a language-to-language conversion: from Java to Arturo, same semantics. | public class AntiPrimesPlus {
static int count_divisors(int n) {
int count = 0;
for (int i = 1; i * i <= n; ++i) {
if (n % i == 0) {
if (i == n / i)
count++;
else
count += 2;
}
}
return c... | i: new 0
next: new 1
MAX: 15
while [next =< MAX][
if next = size factors i [
prints ~"|i| "
inc 'next
]
inc 'i
]
print ""
|
Please provide an equivalent version of this Java code in Arturo. | public class McNuggets {
public static void main(String... args) {
int[] SIZES = new int[] { 6, 9, 20 };
int MAX_TOTAL = 100;
int numSizes = SIZES.length;
int[] counts = new int[numSizes];
int maxFound = MAX_TOTAL + 1;
boolean[] found = new boolean[maxFound]... | nonMcNuggets: function [lim][
result: new 0..lim
loop range.step:6 1 lim 'x [
loop range.step:9 1 lim 'y [
loop range.step:20 1 lim 'z
-> 'result -- sum @[x y z]
]
]
return result
]
print max nonMcNuggets 100
|
Write the same code in Arturo as shown below in Java. | import java.util.stream.IntStream;
public class Letters {
public static void main(String[] args) throws Exception {
System.out.print("Upper case: ");
IntStream.rangeClosed(0, 0x10FFFF)
.filter(Character::isUpperCase)
.limit(72)
.forEach(n -> System... | print ["lowercase letters:" `a`..`z`]
print ["uppercase letters:" `A`..`Z`]
|
Rewrite this program in Arturo while keeping its functionality equivalent to the Java version. | public class JaroDistance {
public static double jaro(String s, String t) {
int s_len = s.length();
int t_len = t.length();
if (s_len == 0 && t_len == 0) return 1;
int match_distance = Integer.max(s_len, t_len) / 2 - 1;
boolean[] s_matches = new boolean[s_len];
boo... | loop [
["MARTHA" "MARHTA"]
["DIXON" "DICKSONX"]
["JELLYFISH" "SMELLYFISH"]
] 'pair ->
print [pair "-> Jaro similarity:" round.to: 3 jaro first pair last pair]
|
Change the programming language of this snippet from Java to Arturo without modifying what it does. | public class SelfDescribingNumbers{
public static boolean isSelfDescribing(int a){
String s = Integer.toString(a);
for(int i = 0; i < s.length(); i++){
String s0 = s.charAt(i) + "";
int b = Integer.parseInt(s0);
int count = 0;
for(int j = 0; j < s.len... | selfDescribing?: function [x][
digs: digits x
loop.with:'i digs 'd [
if d <> size select digs 'z [z=i]
-> return false
]
return true
]
print select 1..22000 => selfDescribing?
|
Write the same algorithm in Arturo as shown in this Java implementation. | import java.io.*;
import java.util.*;
public class ChangeableWords {
public static void main(String[] args) {
try {
final String fileName = "unixdict.txt";
List<String> dictionary = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(fileNam... | wordset: map read.lines relative "unixdict.txt" => strip
wordset: select wordset 'word -> 12 =< size word
results: new []
loop wordset 'a [
loop select wordset 'word [equal? size a size word] 'b [
if a <> b [
if 1 = levenshtein a b [
'results ++ @[sort @[a b]]
]
... |
Preserve the algorithm and functionality while converting the code from Java to Arturo. |
size(1000,1000);
textSize(50);
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
noFill();
square(i*100,j*100,100);
fill(#000000);
if((i+j)%2==0){
text("1",i*100+50,j*100+50);
}
else{
text("0",i*100+50,j*100+50);
}
}
}
| drawSquare: function [side][
loop 1..side 'x ->
print map 1..side 'y [
(equal? x%2 y%2)? -> 1 -> 0
]
]
drawSquare 6
print ""
drawSquare 9
|
Generate a Arturo translation of this Java snippet without changing its computational steps. | import java.util.List;
import java.util.Arrays;
import java.util.Collections;
public class RotateLeft {
public static void main(String[] args) {
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
System.out.println("original: " + list);
Collections.rotate(list, -3);
Syst... | lst: [1 2 3 4 5 6 7 8 9]
print rotate.left lst 3
|
Convert this Java block to Arturo, preserving its control flow and logic. | package example.diagdiag;
public class Program {
public static void main(String[] args) {
DiagonalDiagonalMatrix A = new DiagonalDiagonalMatrix(7);
System.out.println(A);
}
}
class DiagonalDiagonalMatrix {
final int n;
private double[][] a = null;
public Matrix(int n) {
... | drawSquare: function [side][
loop 1..side 'x ->
print map 1..side 'y [
(any? @[x=y side=x+y-1])? -> 1 -> 0
]
]
drawSquare 6
print ""
drawSquare 9
|
Rewrite the snippet below in Arturo so it works the same as the original Java code. | import java.util.List;
public class App {
private static String lcs(List<String> a) {
var le = a.size();
if (le == 0) {
return "";
}
if (le == 1) {
return a.get(0);
}
var le0 = a.get(0).length();
var minLen = le0;
for (int i = ... | lcs: function [l][
ret: ""
idx: 0
lst: map l => reverse
while [true] [
thisLetter: ""
loop lst 'word [
if idx=size word -> return reverse ret
if thisLetter="" -> thisLetter: get split word idx
if thisLetter<>get split word idx -> return reverse ret
]
... |
Convert the following code from Java to Arturo, ensuring the logic remains intact. | public class NumericSeparatorSyntax {
public static void main(String[] args) {
runTask("Underscore allowed as seperator", 1_000);
runTask("Multiple consecutive underscores allowed:", 1__0_0_0);
runTask("Many multiple consecutive underscores allowed:", 1________________________00);
r... | a: 1234567
b: 3.14
print a
print b
|
Translate the given Java code snippet into Arturo without altering its behavior. | public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
| print "Hello World!!"
|
Keep all operations the same but rewrite the snippet in Arturo. | public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
| print "Hello World!!"
|
Produce a language-to-language conversion: from Java to Arturo, same semantics. | package rosettacode.heredoc;
public class MainApp {
public static void main(String[] args) {
String hereDoc = """
This is a multiline string.
It includes all of this text,
but on separate lines in the code.
""";
System.out.println(hereDoc);
}
}
| print {:
The “Red Death” had long devastated the country.
No pestilence had ever been so fatal, or so hideous.
Blood was its Avator and its seal—
the redness and the horror of blood.
There were sharp pains,
and sudden dizziness,
and then profuse bleeding at the pores, ... |
Rewrite this program in Arturo while keeping its functionality equivalent to the Java version. | package rosettacode.heredoc;
public class MainApp {
public static void main(String[] args) {
String hereDoc = """
This is a multiline string.
It includes all of this text,
but on separate lines in the code.
""";
System.out.println(hereDoc);
}
}
| print {:
The “Red Death” had long devastated the country.
No pestilence had ever been so fatal, or so hideous.
Blood was its Avator and its seal—
the redness and the horror of blood.
There were sharp pains,
and sudden dizziness,
and then profuse bleeding at the pores, ... |
Translate the given Java code snippet into Arturo without altering its behavior. | import java.io.*;
import java.util.*;
public class OddWords {
public static void main(String[] args) {
try {
Set<String> dictionary = new TreeSet<>();
final int minLength = 5;
String fileName = "unixdict.txt";
if (args.length != 0)
fileName = ... | words: read.lines relative "unixdict.txt"
getOdd: function [w][
odd: new ""
loop.with:'i w 'ch [
if even? i -> 'odd ++ ch
]
odd
]
loop words 'word [
ow: getOdd word
if and? [4 < size ow][contains? words ow] ->
print [word "=>" ow]
]
|
Rewrite this program in Arturo while keeping its functionality equivalent to the Java version. | module MultiplyExample
{
static <Value extends Number> Value multiply(Value n1, Value n2)
{
return n1 * n2;
}
void run()
{
(Int i1, Int i2) = (7, 3);
Int i3 = multiply(i1, i2);
(Double d1, Double d2) = (2.7182818, 3.1415);
Double d3 = multiply... | multiply: func [a b][a * b]
|
Write the same code in Arturo as shown below in Java. | import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SuccessivePrimeDifferences {
private static Integer[] sieve(int limit) {
List<Integer> primes = new ArrayList<>();
primes.add(2);
boolean[] c = new boolean[limit + 1];
int p = 3;
... | LIM: 1000000
findDiffs: function [r][
if r=[1] -> return [[2 3]]
i: 3
tupled: map 0..dec size r 'x -> fold slice r 0 x [a b][a+b]
diffs: new []
while [i < LIM][
if prime? i [
prset: map tupled 't -> i + t
if every? prset 'elem -> prime? elem [
'diffs ... |
Change the programming language of this snippet from Java to Arturo without modifying what it does. | public class NthPrime {
public static void main(String[] args) {
System.out.printf("The 10,001st prime is %,d.\n", nthPrime(10001));
}
private static int nthPrime(int n) {
assert n > 0;
PrimeGenerator primeGen = new PrimeGenerator(10000, 100000);
int prime = primeGen.nextPri... | primes: select 2..110000 => prime?
print primes\[10000]
|
Translate this program into Arturo but keep the logic exactly as in Java. | public class NthPrime {
public static void main(String[] args) {
System.out.printf("The 10,001st prime is %,d.\n", nthPrime(10001));
}
private static int nthPrime(int n) {
assert n > 0;
PrimeGenerator primeGen = new PrimeGenerator(10000, 100000);
int prime = primeGen.nextPri... | primes: select 2..110000 => prime?
print primes\[10000]
|
Can you help me rewrite this code in Arturo instead of Java, keeping it the same logically? | class SpecialPrimes {
private static boolean isPrime(int n) {
if (n < 2) return false;
if (n%2 == 0) return n == 2;
if (n%3 == 0) return n == 3;
int d = 5;
while (d*d <= n) {
if (n%d == 0) return false;
d += 2;
if (n%d == 0) return false;
... | specials: new [2 3]
lim: 1050
lastP: 3
lastGap: 1
loop 5.. .step:2 lim 'n [
if not? prime? n -> continue
if lastGap < n - lastP [
lastGap: n - lastP
lastP: n
'specials ++ n
]
]
print "List of next special primes less than 1050:"
print specials
|
Rewrite this program in Arturo while keeping its functionality equivalent to the Java version. | class SpecialPrimes {
private static boolean isPrime(int n) {
if (n < 2) return false;
if (n%2 == 0) return n == 2;
if (n%3 == 0) return n == 3;
int d = 5;
while (d*d <= n) {
if (n%d == 0) return false;
d += 2;
if (n%d == 0) return false;
... | specials: new [2 3]
lim: 1050
lastP: 3
lastGap: 1
loop 5.. .step:2 lim 'n [
if not? prime? n -> continue
if lastGap < n - lastP [
lastGap: n - lastP
lastP: n
'specials ++ n
]
]
print "List of next special primes less than 1050:"
print specials
|
Translate this program into Arturo but keep the logic exactly as in Java. | public class LynchBell {
static String s = "";
public static void main(String args[]) {
int i = 98764321;
boolean isUnique = true;
boolean canBeDivided = true;
while (i>0) {
s = String.valueOf(i);
isUnique = uniqueDigits(i);
... | lynchBell?: function [num][
hset: new []
loop digits num 'd [
if d=0 -> return false
if or? [0 <> mod num d]
[contains? hset d] -> return false
'hset ++ d
unique 'hset
]
return true
]
Magic: 9 * 8 * 7
High: ((from.hex "9876432") / Magic) * Magic
loop rang... |
Maintain the same structure and functionality when rewriting this code in Arturo. | public class LynchBell {
static String s = "";
public static void main(String args[]) {
int i = 98764321;
boolean isUnique = true;
boolean canBeDivided = true;
while (i>0) {
s = String.valueOf(i);
isUnique = uniqueDigits(i);
... | lynchBell?: function [num][
hset: new []
loop digits num 'd [
if d=0 -> return false
if or? [0 <> mod num d]
[contains? hset d] -> return false
'hset ++ d
unique 'hset
]
return true
]
Magic: 9 * 8 * 7
High: ((from.hex "9876432") / Magic) * Magic
loop rang... |
Maintain the same structure and functionality when rewriting this code in Arturo. | public class JacobiSymbol {
public static void main(String[] args) {
int max = 30;
System.out.printf("n\\k ");
for ( int k = 1 ; k <= max ; k++ ) {
System.out.printf("%2d ", k);
}
System.out.printf("%n");
for ( int n = 1 ; n <= max ; n += 2 ) {
... | jacobi: function [n,k][
N: n % k
K: k
result: 1
while [N <> 0][
while [even? N][
N: shr N 1
if contains? [3 5] and K 7 ->
result: neg result
]
[N,K]: @[K,N]
if and? 3=and N 3 3=and K 3 ->
result: neg result
N: N... |
Write a version of this Java function in Arturo with identical behavior. | public class JacobiSymbol {
public static void main(String[] args) {
int max = 30;
System.out.printf("n\\k ");
for ( int k = 1 ; k <= max ; k++ ) {
System.out.printf("%2d ", k);
}
System.out.printf("%n");
for ( int n = 1 ; n <= max ; n += 2 ) {
... | jacobi: function [n,k][
N: n % k
K: k
result: 1
while [N <> 0][
while [even? N][
N: shr N 1
if contains? [3 5] and K 7 ->
result: neg result
]
[N,K]: @[K,N]
if and? 3=and N 3 3=and K 3 ->
result: neg result
N: N... |
Rewrite this program in Arturo while keeping its functionality equivalent to the Java version. | import java.util.Scanner;
public class MatrixArithmetic {
public static double[][] minor(double[][] a, int x, int y){
int length = a.length-1;
double[][] result = new double[length][length];
for(int i=0;i<length;i++) for(int j=0;j<length;j++){
if(i<x && j<y){
result[i][j] = a[i][j];
}else if(i>=x && j... | printMatrix: function [m][
loop m 'row -> print map row 'val [pad to :string .format:".2f" val 6]
print "--------------------------------"
]
permutations: function [arr][
d: 1
c: array.of: size arr 0
xs: new arr
sign: 1
ret: new @[@[xs, sign]]
while [true][
while [d > 1][
... |
Preserve the algorithm and functionality while converting the code from Java to Arturo. | import java.util.Scanner;
public class MatrixArithmetic {
public static double[][] minor(double[][] a, int x, int y){
int length = a.length-1;
double[][] result = new double[length][length];
for(int i=0;i<length;i++) for(int j=0;j<length;j++){
if(i<x && j<y){
result[i][j] = a[i][j];
}else if(i>=x && j... | printMatrix: function [m][
loop m 'row -> print map row 'val [pad to :string .format:".2f" val 6]
print "--------------------------------"
]
permutations: function [arr][
d: 1
c: array.of: size arr 0
xs: new arr
sign: 1
ret: new @[@[xs, sign]]
while [true][
while [d > 1][
... |
Please provide an equivalent version of this Java code in Arturo. | private static final Random rng = new Random();
void sattoloCycle(Object[] items) {
for (int i = items.length-1; i > 0; i--) {
int j = rng.nextInt(i);
Object tmp = items[i];
items[i] = items[j];
items[j] = tmp;
}
}
| cycle: function [arr][
if 2 > size arr -> return arr
lastIndex: (size arr)-1
result: new arr
loop lastIndex..1 'i [
j: random 0 i-1
tmp: result\[i]
set result i result\[j]
set result j tmp
]
return result
]
lists: [
[]
[10]
[10 20]
[10 20 30]
... |
Can you help me rewrite this code in Arturo instead of Java, keeping it the same logically? | private static final Random rng = new Random();
void sattoloCycle(Object[] items) {
for (int i = items.length-1; i > 0; i--) {
int j = rng.nextInt(i);
Object tmp = items[i];
items[i] = items[j];
items[j] = tmp;
}
}
| cycle: function [arr][
if 2 > size arr -> return arr
lastIndex: (size arr)-1
result: new arr
loop lastIndex..1 'i [
j: random 0 i-1
tmp: result\[i]
set result i result\[j]
set result j tmp
]
return result
]
lists: [
[]
[10]
[10 20]
[10 20 30]
... |
Write a version of this Java function in Arturo with identical behavior. | import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
public class FTPconn {
public static void main(String... | system/schemes/ftp/passive: on
print read ftp://kernel.org/pub/linux/kernel/
write/binary %README read/binary ftp://kernel.org/pub/linux/kernel/README
|
Produce a language-to-language conversion: from Java to Arturo, same semantics. | import java.util.Arrays;
public class CycleSort {
public static void main(String[] args) {
int[] arr = {5, 0, 1, 2, 2, 3, 5, 1, 1, 0, 5, 6, 9, 8, 0, 1};
System.out.println(Arrays.toString(arr));
int writes = cycleSort(arr);
System.out.println(Arrays.toString(arr));
System... | cycleSort: function [items][
a: new items
position: 0
loop 0..dec dec size a 'cycleStart [
item: a\[cycleStart]
position: cycleStart
loop (cycleStart+1)..dec size a 'i [
if (get a i) < item -> position: position + 1
]
if position = cycleStart -> continue
... |
Translate the given Java code snippet into Arturo without altering its behavior. | import java.util.Arrays;
public class CycleSort {
public static void main(String[] args) {
int[] arr = {5, 0, 1, 2, 2, 3, 5, 1, 1, 0, 5, 6, 9, 8, 0, 1};
System.out.println(Arrays.toString(arr));
int writes = cycleSort(arr);
System.out.println(Arrays.toString(arr));
System... | cycleSort: function [items][
a: new items
position: 0
loop 0..dec dec size a 'cycleStart [
item: a\[cycleStart]
position: cycleStart
loop (cycleStart+1)..dec size a 'i [
if (get a i) < item -> position: position + 1
]
if position = cycleStart -> continue
... |
Maintain the same structure and functionality when rewriting this code in Arturo. | import java.math.BigInteger;
import java.util.Scanner;
public class twinPrimes {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Search Size: ");
BigInteger max = input.nextBigInteger();
int counter = 0;
for(BigInteger x =... | pairsOfPrimes: function [upperLim][
count: 0
j: 0
k: 1
i: 0
while [i=<upperLim][
i: (6 * k) - 1
j: i + 2
if and? [prime? i] [prime? j] [
count: count + 1
]
k: k + 1
]
return count + 1
]
ToNum: 10
while [ToNum =< 1000000][
x: pairsOfPri... |
Keep all operations the same but rewrite the snippet in Arturo. | import java.math.BigInteger;
import java.util.List;
public class Brazilian {
private static final List<Integer> primeList = List.of(
2, 3, 5, 7, 9, 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, 131, 137, 139, 149, 151, 157, 163, 16... | brazilian?: function [n][
if n < 7 -> return false
if zero? and n 1 -> return true
loop 2..n-2 'b [
if 1 = size unique digits.base:b n ->
return true
]
return false
]
printFirstByRule: function [rule,title][
print ~"First 20 |title|brazilian numbers:"
i: 7
found: new... |
Convert this Java block to Arturo, preserving its control flow and logic. | import java.math.BigInteger;
import java.util.List;
public class Brazilian {
private static final List<Integer> primeList = List.of(
2, 3, 5, 7, 9, 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, 131, 137, 139, 149, 151, 157, 163, 16... | brazilian?: function [n][
if n < 7 -> return false
if zero? and n 1 -> return true
loop 2..n-2 'b [
if 1 = size unique digits.base:b n ->
return true
]
return false
]
printFirstByRule: function [rule,title][
print ~"First 20 |title|brazilian numbers:"
i: 7
found: new... |
Generate an equivalent Arturo version of this Java code. | import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
public class CreateFile {
public static void main(String[] args) throws IOException {
String os = System.getProperty("os.name");
if (os.contains("Windows")) {... | write "TAPE.FILE" {
This code
should be able to write
a file
to magnetic tape
}
|
Rewrite this program in Arturo while keeping its functionality equivalent to the Java version. | import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class RecamanSequence {
public static void main(String[] args) {
List<Integer> a = new ArrayList<>();
a.add(0);
Set<Integer> used = new HashSet<>();
used.add(0);
Set<I... | recamanSucc: function [seen, n, r].memoize[
back: r - n
(or? 0 > back contains? seen back)? -> n + r
-> back
]
recamanUntil: function [p][
n: new 1
r: 0
rs: new @[r]
seen: rs
blnNew: true
while [not? do p][
r: recamanSucc seen n r
... |
Generate a Arturo translation of this Java snippet without changing its computational steps. | import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class RecamanSequence {
public static void main(String[] args) {
List<Integer> a = new ArrayList<>();
a.add(0);
Set<Integer> used = new HashSet<>();
used.add(0);
Set<I... | recamanSucc: function [seen, n, r].memoize[
back: r - n
(or? 0 > back contains? seen back)? -> n + r
-> back
]
recamanUntil: function [p][
n: new 1
r: 0
rs: new @[r]
seen: rs
blnNew: true
while [not? do p][
r: recamanSucc seen n r
... |
Maintain the same structure and functionality when rewriting this code in Arturo. | import java.util.function.Function;
public interface YCombinator {
interface RecursiveFunction<F> extends Function<RecursiveFunction<F>, F> { }
public static <A,B> Function<A,B> Y(Function<Function<A,B>, Function<A,B>> f) {
RecursiveFunction<Function<A,B>> r = w -> f.apply(x -> w.apply(w).apply(x));
return... | Y: closure [g] [do func [f] [f :f] closure [f] [g func [x] [do f :f :x]]]
|
Convert this Java block to Arturo, preserving its control flow and logic. | public class CirclesTotalArea {
private static double distSq(double x1, double y1, double x2, double y2) {
return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
}
private static boolean rectangleFullyInsideCircle(double[] rect, double[] circ) {
double r2 = circ[2] * circ[2];
... | circles: @[
@[ 1.6417233788 1.6121789534 0.0848270516]
@[neg 1.4944608174 1.2077959613 1.1039549836]
@[ 0.6110294452 neg 0.6907087527 0.9089162485]
@[ 0.3844862411 0.2923344616 0.2375743054]
@[neg 0.2495892950 neg 0.3832854473 1.0845181219]
@[ 1.7813504266 1.617823703... |
Can you help me rewrite this code in Arturo instead of Java, keeping it the same logically? | public class CirclesTotalArea {
private static double distSq(double x1, double y1, double x2, double y2) {
return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
}
private static boolean rectangleFullyInsideCircle(double[] rect, double[] circ) {
double r2 = circ[2] * circ[2];
... | circles: @[
@[ 1.6417233788 1.6121789534 0.0848270516]
@[neg 1.4944608174 1.2077959613 1.1039549836]
@[ 0.6110294452 neg 0.6907087527 0.9089162485]
@[ 0.3844862411 0.2923344616 0.2375743054]
@[neg 0.2495892950 neg 0.3832854473 1.0845181219]
@[ 1.7813504266 1.617823703... |
Convert this Java block to Arturo, preserving its control flow and logic. | public class Factorion {
public static void main(String [] args){
System.out.println("Base 9:");
for(int i = 1; i <= 1499999; i++){
String iStri = String.valueOf(i);
int multiplied = operate(iStri,9);
if(multiplied == i){
System.out.print(i + "\t")... | factorials: [1 1 2 6 24 120 720 5040 40320 362880 3628800 39916800]
factorion?: function [n, base][
try? [
n = sum map digits.base:base n 'x -> factorials\[x]
]
else [
print ["n:" n "base:" base]
false
]
]
loop 9..12 'base ->
print ["Base" base "factorions:" select 1..45000... |
Rewrite the snippet below in Arturo so it works the same as the original Java code. | public class Factorion {
public static void main(String [] args){
System.out.println("Base 9:");
for(int i = 1; i <= 1499999; i++){
String iStri = String.valueOf(i);
int multiplied = operate(iStri,9);
if(multiplied == i){
System.out.print(i + "\t")... | factorials: [1 1 2 6 24 120 720 5040 40320 362880 3628800 39916800]
factorion?: function [n, base][
try? [
n = sum map digits.base:base n 'x -> factorials\[x]
]
else [
print ["n:" n "base:" base]
false
]
]
loop 9..12 'base ->
print ["Base" base "factorions:" select 1..45000... |
Generate a Arturo translation of this Java snippet without changing its computational steps. | public class DivisorSum {
private static long divisorSum(long n) {
var total = 1L;
var power = 2L;
for (; (n & 1) == 0; power <<= 1, n >>= 1) {
total += power;
}
for (long p = 3; p * p <= n; p += 2) {
long sum = 1;
for (po... | loop split.every:10 map 1..100 'x -> sum factors x 'row [
print map row 'r -> pad to :string r 4
]
|
Please provide an equivalent version of this Java code in Arturo. | import java.util.*;
public class SortComp1 {
public static void main(String[] args) {
List<String> items = Arrays.asList("violet", "red", "green", "indigo", "blue", "yellow", "orange");
List<String> sortedItems = new ArrayList<>();
Comparator<String> interactiveCompare = new Comparator<Stri... | lst: ["violet" "red" "green" "indigo" "blue" "yellow" "orange"]
count: 0
findSpot: function [l,e][
if empty? l -> return 0
loop.with:'i l 'item [
answer: input ~"Is |item| greater than |e| [y/n]? "
if answer="y" -> return i
]
return dec size l
]
sortedLst: new []
loop lst 'element -... |
Write the same code in Arturo as shown below in Java. | import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class FermatNumbers {
public static void main(String[] args) {
System.out.println("First 10 Fermat numbers:");
for ( int i = 0 ... | nPowers: [1 2 4 8 16 32 64 128 256 512]
fermatSet: map 0..9 'x -> 1 + 2 ^ nPowers\[x]
loop 0..9 'i ->
print ["F(" i ") =" fermatSet\[i]]
print ""
loop 0..9 'i ->
print ["Prime factors of F(" i ") =" factors.prime fermatSet\[i]]
|
Write a version of this Java function in Arturo with identical behavior. | public class BeadSort
{
public static void main(String[] args)
{
BeadSort now=new BeadSort();
int[] arr=new int[(int)(Math.random()*11)+5];
for(int i=0;i<arr.length;i++)
arr[i]=(int)(Math.random()*10);
System.out.print("Unsorted: ");
now.display1D(arr);
int[] sort=now.beadSort(arr);
System.out.pr... | beadSort: function [items][
a: new items
m: neg infinity
s: 0
loop a 'x [
if x > m -> m: x
]
beads: array.of: m * size a 0
loop 0..dec size a 'i [
loop 0..dec a\[i] 'j ->
beads\[j + i * m]: 1
]
loop 0..dec m 'j [
s: 0
loop 0..dec size a... |
Write the same code in Arturo as shown below in Java. | import java.util.*;
import java.util.stream.IntStream;
public class CastingOutNines {
public static void main(String[] args) {
System.out.println(castOut(16, 1, 255));
System.out.println(castOut(10, 1, 99));
System.out.println(castOut(17, 1, 288));
}
static List<Integer> castOut(i... | N: 2
base: 10
c1: 0
c2: 0
loop 1..(base^N)-1 'k [
c1: c1 + 1
if (k%base-1)= (k*k)%base-1 [
c2: c2 + 1
prints ~"|k| "
]
]
print ""
print ["Trying" c2 "numbers instead of" c1 "numbers saves" 100.0 - 100.0*c2//c1 "%"]
|
Convert the following code from Java to Arturo, ensuring the logic remains intact. | import java.util.*;
import java.util.stream.IntStream;
public class CastingOutNines {
public static void main(String[] args) {
System.out.println(castOut(16, 1, 255));
System.out.println(castOut(10, 1, 99));
System.out.println(castOut(17, 1, 288));
}
static List<Integer> castOut(i... | N: 2
base: 10
c1: 0
c2: 0
loop 1..(base^N)-1 'k [
c1: c1 + 1
if (k%base-1)= (k*k)%base-1 [
c2: c2 + 1
prints ~"|k| "
]
]
print ""
print ["Trying" c2 "numbers instead of" c1 "numbers saves" 100.0 - 100.0*c2//c1 "%"]
|
Change the following Java code into Arturo without altering its purpose. | import java.io.*;
import java.text.*;
import java.util.*;
public class SimpleDatabase {
final static String filename = "simdb.csv";
public static void main(String[] args) {
if (args.length < 1 || args.length > 3) {
printUsage();
return;
}
switch (args[0].toLow... | rebol [author: "Nick Antonaccio"]
write/append %rdb "" db: load %rdb
switch system/options/args/1 [
"new" [write/append %rdb rejoin [now " " mold/only next system/options/args newline]]
"latest" [print copy/part tail sort/skip db 4 -4]
"latestcat" [
foreach cat unique extract at db 3 4 [
... |
Please provide an equivalent version of this Java code in Arturo. | package keybord.macro.demo;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
class KeyboardMacroDemo {
public static void main( String [] args ) {
final JFrame frame = new JFrame();
String directions = "<html><b>Ctrl-S... | REBOL [
Title: "Keyboard Macros"
URL: http://rosettacode.org/wiki/Keyboard_macros
]
view layout [
style btn button coal 46
across
display: h1 100 red maroon right "" return
btn "1" #"1" [set-face display "1"]
btn "+" #"+" [set-face display ""]
return
pad 54
btn "=" #"=" [set-face display ... |
Rewrite the snippet below in Arturo so it works the same as the original Java code. | public class TauFunction {
private static long divisorCount(long n) {
long total = 1;
for (; (n & 1) == 0; n >>= 1) {
++total;
}
for (long p = 3; p * p <= n; p += 2) {
long count = 1;
for (; n % p == 0; n /= p) {
+... | tau: function [x] -> size factors x
loop split.every:20 1..100 => [
print map & => [pad to :string tau & 3]
]
|
Can you help me rewrite this code in Arturo instead of Java, keeping it the same logically? | public class TauFunction {
private static long divisorCount(long n) {
long total = 1;
for (; (n & 1) == 0; n >>= 1) {
++total;
}
for (long p = 3; p * p <= n; p += 2) {
long count = 1;
for (; n % p == 0; n /= p) {
+... | tau: function [x] -> size factors x
loop split.every:20 1..100 => [
print map & => [pad to :string tau & 3]
]
|
Produce a functionally identical Arturo code for the snippet given in Java. | public class MöbiusFunction {
public static void main(String[] args) {
System.out.printf("First 199 terms of the möbius function are as follows:%n ");
for ( int n = 1 ; n < 200 ; n++ ) {
System.out.printf("%2d ", möbiusFunction(n));
if ( (n+1) % 20 == 0 ) {
... | mobius: function [n][
if n=0 -> return ""
if n=1 -> return 1
f: factors.prime n
if f <> unique f -> return 0
if? odd? size f -> return neg 1
else -> return 1
]
loop split.every:20 map 0..199 => mobius 'a ->
print map a => [pad to :string & 3]
|
Rewrite this program in Arturo while keeping its functionality equivalent to the Java version. | import java.io.IOException;
public class Interpreter {
public final static int MEMORY_SIZE = 65536;
private final char[] memory = new char[MEMORY_SIZE];
private int dp;
private int ip;
private int border;
private void reset() {
for (int i = 0; i < MEMORY_SIZE; i++) {
mem... |
Tape: [0]
DataPointer: new 0
InstructionPointer: new 0
precomputeJumps: function [][
vstack: new []
jumphash: new #[]
instrPointer: 0
while [instrPointer<CodeLength] [
command: get split Code instrPointer
if? command="[" -> 'vstack ++ instrPointer
else [
... |
Translate this program into Arturo but keep the logic exactly as in Java. | import java.io.IOException;
public class Interpreter {
public final static int MEMORY_SIZE = 65536;
private final char[] memory = new char[MEMORY_SIZE];
private int dp;
private int ip;
private int border;
private void reset() {
for (int i = 0; i < MEMORY_SIZE; i++) {
mem... |
Tape: [0]
DataPointer: new 0
InstructionPointer: new 0
precomputeJumps: function [][
vstack: new []
jumphash: new #[]
instrPointer: 0
while [instrPointer<CodeLength] [
command: get split Code instrPointer
if? command="[" -> 'vstack ++ instrPointer
else [
... |
Write the same algorithm in Arturo as shown in this Java implementation. | public class MertensFunction {
public static void main(String[] args) {
System.out.printf("First 199 terms of the merten function are as follows:%n ");
for ( int n = 1 ; n < 200 ; n++ ) {
System.out.printf("%2d ", mertenFunction(n));
if ( (n+1) % 20 == 0 ) {
... | mobius: function [n][
if n=0 -> return ""
if n=1 -> return 1
f: factors.prime n
if f <> unique f -> return 0
if? odd? size f -> return neg 1
else -> return 1
]
mertens: function [z][sum map 1..z => mobius]
print "The first 99 Mertens numbers are:"
loop split.every:20 [""]++map 1..99 => merten... |
Keep all operations the same but rewrite the snippet in Arturo. | public class ProductOfDivisors {
private static long divisorCount(long n) {
long total = 1;
for (; (n & 1) == 0; n >>= 1) {
++total;
}
for (long p = 3; p * p <= n; p += 2) {
long count = 1;
for (; n % p == 0; n /= p) {
... | loop split.every:5 to [:string] map 1..50 => [product factors &] 'line [
print map line 'i -> pad i 10
]
|
Port the provided Java code into Arturo while preserving the original functionality. | public class ProductOfDivisors {
private static long divisorCount(long n) {
long total = 1;
for (; (n & 1) == 0; n >>= 1) {
++total;
}
for (long p = 3; p * p <= n; p += 2) {
long count = 1;
for (; n % p == 0; n /= p) {
... | loop split.every:5 to [:string] map 1..50 => [product factors &] 'line [
print map line 'i -> pad i 10
]
|
Ensure the translated Arturo code behaves exactly like the original Java snippet. | import java.util.*;
public class ErdosPrimes {
public static void main(String[] args) {
boolean[] sieve = primeSieve(1000000);
int maxPrint = 2500;
int maxCount = 7875;
System.out.printf("Erd\u0151s primes less than %d:\n", maxPrint);
for (int count = 0, prime = 1; count < m... | factorials: map 1..20 => [product 1..&]
erdos?: function [x][
if not? prime? x -> return false
loop factorials 'f [
if f >= x -> break
if prime? x - f -> return false
]
return true
]
loop split.every:10 select 2..2500 => erdos? 'a ->
print map a => [pad to :string & 5]
|
Convert this Java block to Arturo, preserving its control flow and logic. | import java.util.*;
public class ErdosPrimes {
public static void main(String[] args) {
boolean[] sieve = primeSieve(1000000);
int maxPrint = 2500;
int maxCount = 7875;
System.out.printf("Erd\u0151s primes less than %d:\n", maxPrint);
for (int count = 0, prime = 1; count < m... | factorials: map 1..20 => [product 1..&]
erdos?: function [x][
if not? prime? x -> return false
loop factorials 'f [
if f >= x -> break
if prime? x - f -> return false
]
return true
]
loop split.every:10 select 2..2500 => erdos? 'a ->
print map a => [pad to :string & 5]
|
Ensure the translated Arturo code behaves exactly like the original Java snippet. | public enum Pip { Two, Three, Four, Five, Six, Seven,
Eight, Nine, Ten, Jack, Queen, King, Ace }
|
Red [Title: "Playing Cards"]
pip: ["a" "2" "3" "4" "5" "6" "7" "8" "9" "10" "j" "q" "k"]
suit: ["♣" "♦" "♥" "♠"]
make-deck: function [] [
new-deck: make block! 52
foreach s suit [foreach p pip [append/only new-deck reduce [p s]]]
return new-deck
]
shuffle: function [deck [block!]] [deck: random deck]
deal: fun... |
Write the same code in Arturo as shown below in Java. | import java.util.ArrayList;
import java.util.List;
public class PerfectTotientNumbers {
public static void main(String[] args) {
computePhi();
int n = 20;
System.out.printf("The first %d perfect totient numbers:%n%s%n", n, perfectTotient(n));
}
private static final List<Intege... | totient: function [n][
tt: new n
nn: new n
i: new 2
while [nn >= i ^ 2][
if zero? nn % i [
while [zero? nn % i]->
'nn / i
'tt - tt/i
]
if i = 2 ->
i: new 1
'i + 2
]
if nn > 1 ->
'tt - tt/nn
return... |
Please provide an equivalent version of this Java code in Arturo. | import java.util.ArrayList;
import java.util.List;
public class PerfectTotientNumbers {
public static void main(String[] args) {
computePhi();
int n = 20;
System.out.printf("The first %d perfect totient numbers:%n%s%n", n, perfectTotient(n));
}
private static final List<Intege... | totient: function [n][
tt: new n
nn: new n
i: new 2
while [nn >= i ^ 2][
if zero? nn % i [
while [zero? nn % i]->
'nn / i
'tt - tt/i
]
if i = 2 ->
i: new 1
'i + 2
]
if nn > 1 ->
'tt - tt/nn
return... |
Preserve the algorithm and functionality while converting the code from Java to Arturo. | import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
public class LahNumbers {
public static void main(String[] args) {
System.out.println("Show the unsigned Lah numbers up to n = 12:");
for ( int n = 0 ; n <= 12 ; n++ ) {
System.out.printf("%5s", n);
... | factorial: function [n]-> product 1..n
lah: function [n,k][
if k=1 -> return factorial n
if k=n -> return 1
if k>n -> return 0
if or? k<1 n<1 -> return 0
return (((factorial n)*factorial n-1) / ((factorial k) * factorial k-1)) / factorial n-k
]
print @["n/k"] ++ map to [:string] 1..12 's -> pad s ... |
Keep all operations the same but rewrite the snippet in Arturo. | import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
public class LahNumbers {
public static void main(String[] args) {
System.out.println("Show the unsigned Lah numbers up to n = 12:");
for ( int n = 0 ; n <= 12 ; n++ ) {
System.out.printf("%5s", n);
... | factorial: function [n]-> product 1..n
lah: function [n,k][
if k=1 -> return factorial n
if k=n -> return 1
if k>n -> return 0
if or? k<1 n<1 -> return 0
return (((factorial n)*factorial n-1) / ((factorial k) * factorial k-1)) / factorial n-k
]
print @["n/k"] ++ map to [:string] 1..12 's -> pad s ... |
Produce a functionally identical Arturo code for the snippet given in Java. | import java.util.Arrays;
public class TwoSum {
public static void main(String[] args) {
long sum = 21;
int[] arr = {0, 2, 11, 19, 90};
System.out.println(Arrays.toString(twoSum(arr, sum)));
}
public static int[] twoSum(int[] a, long target) {
int i = 0, j = a.length - 1;
... | twoSum: function [numbers, s][
loop.with:'i numbers 'x [
if not? null? j: <= index numbers s-x ->
return @[i j]
]
return []
]
nums: [0 2 11 19 90]
print ["twoSum 21:" twoSum nums 21]
print ["twoSum 25:" twoSum nums 25]
|
Convert the following code from Java to Arturo, ensuring the logic remains intact. | import java.util.Arrays;
public class TwoSum {
public static void main(String[] args) {
long sum = 21;
int[] arr = {0, 2, 11, 19, 90};
System.out.println(Arrays.toString(twoSum(arr, sum)));
}
public static int[] twoSum(int[] a, long target) {
int i = 0, j = a.length - 1;
... | twoSum: function [numbers, s][
loop.with:'i numbers 'x [
if not? null? j: <= index numbers s-x ->
return @[i j]
]
return []
]
nums: [0 2 11 19 90]
print ["twoSum 21:" twoSum nums 21]
print ["twoSum 25:" twoSum nums 25]
|
Generate a Arturo translation of this Java snippet without changing its computational steps. | import java.util.*;
public class CocktailSort {
public static void main(String[] args) {
Integer[] array = new Integer[]{ 5, 1, -6, 12, 3, 13, 2, 4, 0, 15 };
System.out.println("before: " + Arrays.toString(array));
cocktailSort(array);
System.out.println("after: " + Arrays.toString(... | cocktailShiftSort: function [items][
a: new items
beginIdx: 0
endIdx: (size a)-2
while [beginIdx =< endIdx][
newBeginIdx: endIdx
newEndIdx: beginIdx
loop beginIdx..endIdx 'i [
if a\[i] > a\[i+1] [
tmp: a\[i]
a\[i]: a\[i+1]
... |
Can you help me rewrite this code in Arturo instead of Java, keeping it the same logically? | public class UnprimeableNumbers {
private static int MAX = 10_000_000;
private static boolean[] primes = new boolean[MAX];
public static void main(String[] args) {
sieve();
System.out.println("First 35 unprimeable numbers:");
displayUnprimeableNumbers(35);
int n = 600;
... | unprimeable?: function [n][
if prime? n -> return false
nd: to :string n
loop.with:'i nd 'prevDigit [
loop `0`..`9` 'newDigit [
if newDigit <> prevDigit [
nd\[i]: newDigit
if prime? to :integer nd -> return false
]
]
nd\[i]: pre... |
Preserve the algorithm and functionality while converting the code from Java to Arturo. | public class Tau {
private static long divisorCount(long n) {
long total = 1;
for (; (n & 1) == 0; n >>= 1) {
++total;
}
for (long p = 3; p * p <= n; p += 2) {
long count = 1;
for (; n % p == 0; n /= p) {
++count;
... | tau: function [x] -> size factors x
found: 0
i:1
while [found<100][
if 0 = i % tau i [
prints pad to :string i 5
found: found + 1
if 0 = found % 10 -> print ""
]
i: i + 1
]
|
Translate the given Java code snippet into Arturo without altering its behavior. | import java.math.BigInteger;
public class PrimeSum {
private static int digitSum(BigInteger bi) {
int sum = 0;
while (bi.compareTo(BigInteger.ZERO) > 0) {
BigInteger[] dr = bi.divideAndRemainder(BigInteger.TEN);
sum += dr[1].intValue();
bi = dr[0];
}
... | primes: select 1..5000 => prime?
loop split.every: 3 select primes 'p [25 = sum digits p] 'a ->
print map a => [pad to :string & 5]
|
Transform the following Java implementation into Arturo, maintaining the same output and logic. | import java.math.BigInteger;
public class PrimeSum {
private static int digitSum(BigInteger bi) {
int sum = 0;
while (bi.compareTo(BigInteger.ZERO) > 0) {
BigInteger[] dr = bi.divideAndRemainder(BigInteger.TEN);
sum += dr[1].intValue();
bi = dr[0];
}
... | primes: select 1..5000 => prime?
loop split.every: 3 select primes 'p [25 = sum digits p] 'a ->
print map a => [pad to :string & 5]
|
Please provide an equivalent version of this Java code in Arturo. | public class PrimeDigits {
private static boolean primeDigitsSum13(int n) {
int sum = 0;
while (n > 0) {
int r = n % 10;
if (r != 2 && r != 3 && r != 5 && r != 7) {
return false;
}
n /= 10;
sum += r;
}
return... | pDigits: [2 3 5 7]
lst: map pDigits 'd -> @[d]
result: new []
while [0 <> size lst][
nextList: new []
loop lst 'digitSeq [
currSum: sum digitSeq
loop pDigits 'n [
newSum: currSum + n
newDigitSeq: digitSeq ++ n
case [newSum]
when? [<13] -> 'ne... |
Keep all operations the same but rewrite the snippet in Arturo. | public class PrimeDigits {
private static boolean primeDigitsSum13(int n) {
int sum = 0;
while (n > 0) {
int r = n % 10;
if (r != 2 && r != 3 && r != 5 && r != 7) {
return false;
}
n /= 10;
sum += r;
}
return... | pDigits: [2 3 5 7]
lst: map pDigits 'd -> @[d]
result: new []
while [0 <> size lst][
nextList: new []
loop lst 'digitSeq [
currSum: sum digitSeq
loop pDigits 'n [
newSum: currSum + n
newDigitSeq: digitSeq ++ n
case [newSum]
when? [<13] -> 'ne... |
Convert this Java snippet to Arturo and keep its semantics consistent. | import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class DeepCopy {
public static void main(String[] args) {
Person p1 = new Person("Clark", "Kent", new Address("1 World Center"... | x: #[
name: "John"
surname: "Doe"
age: 34
hobbies: [
"Cycling",
"History",
"Programming",
"Languages",
"Psychology",
"Buddhism"
]
sayHello: function [][
print "Hello there!"
]
]
print ["Name of first person:" x\name]
y: new x
y\na... |
Convert the following code from Java to Arturo, ensuring the logic remains intact. | import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class DeepCopy {
public static void main(String[] args) {
Person p1 = new Person("Clark", "Kent", new Address("1 World Center"... | x: #[
name: "John"
surname: "Doe"
age: 34
hobbies: [
"Cycling",
"History",
"Programming",
"Languages",
"Psychology",
"Buddhism"
]
sayHello: function [][
print "Hello there!"
]
]
print ["Name of first person:" x\name]
y: new x
y\na... |
Maintain the same structure and functionality when rewriting this code in Arturo. | import java.math.BigInteger;
import java.util.Arrays;
public class CircularPrimes {
public static void main(String[] args) {
System.out.println("First 19 circular primes:");
int p = 2;
for (int count = 0; count < 19; ++p) {
if (isCircularPrime(p)) {
if (count > 0... | perms: function [n][
str: repeat to :string n 2
result: new []
lim: dec size digits n
loop 0..lim 'd ->
'result ++ slice str d lim+d
return to [:integer] result
]
circulars: new []
circular?: function [x][
if not? prime? x -> return false
loop perms x 'y [
if not? prime? ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.