Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Change the following C code into Pascal without altering its purpose. | '--- added a flush to exit cleanly
PRAGMA LDFLAGS `pkg-config --cflags --libs x11`
PRAGMA INCLUDE <X11/Xlib.h>
PRAGMA INCLUDE <X11/Xutil.h>
OPTION PARSE FALSE
'---XLIB is so ugly
ALIAS XNextEvent TO EVENT
ALIAS XOpenDisplay TO DISPLAY
ALIAS DefaultScreen TO SCREEN
ALIAS XCreateSimpleWindow TO CREATE
ALIAS XCloseD... | program xshowwindow;
uses
xlib, x, ctypes;
procedure ModalShowX11Window(AMsg: string);
var
d: PDisplay;
w: TWindow;
e: TXEvent;
msg: PChar;
s: cint;
begin
msg := PChar(AMsg);
d := XOpenDisplay(nil);
if (d = nil) then
begin
WriteLn('[ModalShowX11Window] Cannot open display');
exit;
... |
Ensure the translated Pascal code behaves exactly like the original C snippet. | #include <inttypes.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <gmp.h>
int es_check(uint32_t *sieve, uint64_t n)
{
if ((n != 2 && !(n & 1)) || (n < 2))
return 0;
else
return !(sieve[n >> 6] & (1 << (n >> 1 & 31)));
}
uint32_t *e... |
uses
sysutils,mp_types,mp_base,mp_prime,mp_numth;
var
x: mp_int;
t0,t1: TDateTime;
s: AnsiString;
var
i,cnt : NativeInt;
ctx :TPrimeContext;
begin
mp_init(x);
cnt := 1;
i := 2;
FindFirstPrime32(i,ctx);
i := 10;
t0 := time;
repeat
repeat
FindNextPrime32(ctx);
inc(cnt);
until ... |
Generate a Pascal translation of this C snippet without changing its computational steps. | #include <stdio.h>
#include <math.h>
#define N 5
double Pi;
double lroots[N];
double weight[N];
double lcoef[N + 1][N + 1] = {{0}};
void lege_coef()
{
int n, i;
lcoef[0][0] = lcoef[1][1] = 1;
for (n = 2; n <= N; n++) {
lcoef[n][0] = -(n - 1) * lcoef[n - 2][0] / n;
for (i = 1; i <= n; i++)
lcoef[n][i] = ((2 ... | program Legendre(output);
const Order = 5;
Order1 = Order - 1;
Epsilon = 1E-12;
Pi = 3.1415926;
var Roots : array[0..Order1] of real;
Weight : array[0..Order1] of real;
LegCoef : array [0..Order,0..Order] of real;
I : integer;
function F(X:real) : real;
begin
F := Exp(X);
en... |
Write the same algorithm in Pascal as shown in this C implementation. | #include <stdio.h>
#include <stdlib.h>
int
main()
{
int i;
srand(time(NULL));
for (i = 0; i < 10; i++)
puts((rand() % 2) ? "heads" : "tails");
return 0;
}
| unit delphicompatiblerandom;
interface
function LCGRandom: extended; overload;inline;
function LCGRandom(const range:longint):longint;overload;inline;
implementation
function IM:cardinal;inline;
begin
RandSeed := RandSeed * 134775813 + 1;
Result := RandSeed;
end;
function LCGRandom: extended; overload;i... |
Convert the following code from C to Pascal, ensuring the logic remains intact. | #include <stdio.h>
#include <stdlib.h>
int
main()
{
int i;
srand(time(NULL));
for (i = 0; i < 10; i++)
puts((rand() % 2) ? "heads" : "tails");
return 0;
}
| unit delphicompatiblerandom;
interface
function LCGRandom: extended; overload;inline;
function LCGRandom(const range:longint):longint;overload;inline;
implementation
function IM:cardinal;inline;
begin
RandSeed := RandSeed * 134775813 + 1;
Result := RandSeed;
end;
function LCGRandom: extended; overload;i... |
Translate the given C code snippet into Pascal without altering its behavior. | #include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
typedef long long llong_t;
struct PrimeArray {
llong_t *ptr;
size_t size;
size_t capacity;
};
struct PrimeArray allocate() {
struct PrimeArray primes;
primes.size = 0;
primes.capacity = 10;
p... | program CubanPrimes;
uses
primTrial;
const
COLUMNCOUNT = 10*10;
procedure FormOut(Cuban:Uint64;ColSize:Uint32);
var
s : String;
pI,pJ :pChar;
i,j : NativeInt;
Begin
str(Cuban,s);
i := length(s);
If i>3 then
Begin
j := i+ (i-1) div 3;
setlength(s,j);
pI := @s[i];
pJ := ... |
Generate an equivalent Pascal version of this C code. | #include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<time.h>
#define pi M_PI
int main(){
time_t t;
double side, vertices[3][3],seedX,seedY,windowSide;
int i,iter,choice;
printf("Enter triangle side length : ");
scanf("%lf",&side);
printf("Enter number of iterations : ");
sc... | program ChaosGame;
uses
Graph, windows, math;
Function PointOfCircle(Angle: SmallInt; Radius: integer): TPoint;
var Ia: Double;
begin
Ia:=DegToRad(-Angle);
result.x:=round(cos(Ia)*Radius);
result.y:=round(sin(Ia)*Radius);
end;
var
GraphDev,GraphMode: smallint;
Triangle: array[0..2] of Tpoint;
Tr... |
Generate a Pascal translation of this C snippet without changing its computational steps. | #include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<time.h>
#define pi M_PI
int main(){
time_t t;
double side, vertices[3][3],seedX,seedY,windowSide;
int i,iter,choice;
printf("Enter triangle side length : ");
scanf("%lf",&side);
printf("Enter number of iterations : ");
sc... | program ChaosGame;
uses
Graph, windows, math;
Function PointOfCircle(Angle: SmallInt; Radius: integer): TPoint;
var Ia: Double;
begin
Ia:=DegToRad(-Angle);
result.x:=round(cos(Ia)*Radius);
result.y:=round(sin(Ia)*Radius);
end;
var
GraphDev,GraphMode: smallint;
Triangle: array[0..2] of Tpoint;
Tr... |
Write the same algorithm in Pascal as shown in this C implementation. | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
int p[512];
double fade(double t) { return t * t * t * (t * (t * 6 - 15) + 10); }
double lerp(double t, double a, double b) { return a + t * (b - a); }
double grad(int hash, double x, double y, double z) {
int h = hash & 15;
doubl... | program perlinNoise;
uses
sysutils;
type
float64 = double;
const
p : array[0..255] of byte = (
151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225,
140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148,
247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11,... |
Preserve the algorithm and functionality while converting the code from C to Pascal. | #include <math.h>
#include <stdio.h>
int p(int l, int n) {
int test = 0;
double logv = log(2.0) / log(10.0);
int factor = 1;
int loop = l;
while (loop > 10) {
factor *= 10;
loop /= 10;
}
while (n > 0) {
int val;
test++;
val = (int)(factor * pow(10.0,... | program Power2FirstDigits;
uses
sysutils,
strUtils;
const
ld10 :double = ln(2)/ln(10);
ld10 = 0.30102999566398119521373889472449;
function Numb2USA(const S: string): string;
var
i, NA: Integer;
begin
i := Length(S);
Result := S;
NA := 0;
while (i > 0) do
begin
if ((Length(Result) - i + ... |
Write the same algorithm in Pascal as shown in this C implementation. | #include <math.h>
#include <stdio.h>
int p(int l, int n) {
int test = 0;
double logv = log(2.0) / log(10.0);
int factor = 1;
int loop = l;
while (loop > 10) {
factor *= 10;
loop /= 10;
}
while (n > 0) {
int val;
test++;
val = (int)(factor * pow(10.0,... | program Power2FirstDigits;
uses
sysutils,
strUtils;
const
ld10 :double = ln(2)/ln(10);
ld10 = 0.30102999566398119521373889472449;
function Numb2USA(const S: string): string;
var
i, NA: Integer;
begin
i := Length(S);
Result := S;
NA := 0;
while (i > 0) do
begin
if ((Length(Result) - i + ... |
Change the following C code into Pascal without altering its purpose. | #include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
void* xmalloc(size_t n) {
void* ptr = malloc(n);
if (ptr == NULL) {
fprintf(stderr, "Out of memory\n");
exit(1);
}
return ptr;
}
void* xrealloc(void* p, size_t n) {
void* ptr = realloc(... | program nSmoothNumbers(output);
const
primeCount = 538;
cardinalMax = 3888;
type
cardinal = 0..cardinalMax;
cardinals = set of cardinal;
cardinalPositive = 1..cardinalMax;
natural = 1..maxInt;
primeIndex = 1..primeCount;
list = array[primeIndex] of cardinal;
var
prime: list;
function primeFactoriz... |
Can you help me rewrite this code in Pascal instead of C, keeping it the same logically? | #include <string.h>
#include <stdio.h>
#include <stdlib.h>
const char STX = '\002', ETX = '\003';
int compareStrings(const void *a, const void *b) {
char *aa = *(char **)a;
char *bb = *(char **)b;
return strcmp(aa, bb);
}
int bwt(const char *s, char r[]) {
int i, len = strlen(s) + 2;
char *ss, *s... | program BurrowsWheeler;
uses SysUtils;
const STR_BASE = 1;
type TComparison = -1..1;
procedure Encode( const input : string;
out encoded : string;
out index : integer);
var
n : integer;
perm : array of integer;
i, j, k : integer;
incr, v : integer;
... |
Transform the following C implementation into Pascal, maintaining the same output and logic. | #include <string.h>
#include <stdio.h>
#include <stdlib.h>
const char STX = '\002', ETX = '\003';
int compareStrings(const void *a, const void *b) {
char *aa = *(char **)a;
char *bb = *(char **)b;
return strcmp(aa, bb);
}
int bwt(const char *s, char r[]) {
int i, len = strlen(s) + 2;
char *ss, *s... | program BurrowsWheeler;
uses SysUtils;
const STR_BASE = 1;
type TComparison = -1..1;
procedure Encode( const input : string;
out encoded : string;
out index : integer);
var
n : integer;
perm : array of integer;
i, j, k : integer;
incr, v : integer;
... |
Translate the given C code snippet into Pascal without altering its behavior. | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int binomial(int n, int k) {
int num, denom, i;
if (n < 0 || k < 0 || n < k) return -1;
if (n == 0 || k == 0) return 1;
num = 1;
for (i = k + 1; i <= n; ++i) {
num = num * i;
}
denom = 1;
for (i =... | program FaulhaberTriangle;
uses uIntX, uEnums,
SysUtils;
function RationalToString( num, den : TIntX;
minWidth : integer) : string;
var
num1, den1, divisor : TIntX;
w : integer;
begin
divisor := TIntX.GCD( num, den);
num1 := TIntx.Divide( num, divisor, uEnums.dmClassic);
... |
Generate a Pascal translation of this C snippet without changing its computational steps. | #include <stdio.h>
#define MAX_N 33
#define BRANCH 4
typedef unsigned long long xint;
#define FMT "llu"
xint rooted[MAX_N] = {1, 1, 0};
xint unrooted[MAX_N] = {1, 1, 0};
xint choose(xint m, xint k)
{
xint i, r;
if (k == 1) return m;
for (r = m, i = 1; i < k; i++)
r = r * (m + i) / (i + 1);
return r;
}
... | Program Paraffins;
uses
gmp;
const
max_n = 500;
branch = 4;
var
rooted, unrooted: array [0 .. max_n-1] of mpz_t;
c: array [0 .. branch-1] of mpz_t;
cnt, tmp: mpz_t;
n: integer;
fmt: pchar;
sum: integer;
procedure tree(br, n, l: integer; sum: integer; cnt: mpz_t);
var
b, m: integer;
begin... |
Rewrite this program in Pascal while keeping its functionality equivalent to the C version. | #include <stdio.h>
#define MAX_N 33
#define BRANCH 4
typedef unsigned long long xint;
#define FMT "llu"
xint rooted[MAX_N] = {1, 1, 0};
xint unrooted[MAX_N] = {1, 1, 0};
xint choose(xint m, xint k)
{
xint i, r;
if (k == 1) return m;
for (r = m, i = 1; i < k; i++)
r = r * (m + i) / (i + 1);
return r;
}
... | Program Paraffins;
uses
gmp;
const
max_n = 500;
branch = 4;
var
rooted, unrooted: array [0 .. max_n-1] of mpz_t;
c: array [0 .. branch-1] of mpz_t;
cnt, tmp: mpz_t;
n: integer;
fmt: pchar;
sum: integer;
procedure tree(br, n, l: integer; sum: integer; cnt: mpz_t);
var
b, m: integer;
begin... |
Produce a language-to-language conversion: from C to Pascal, same semantics. | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
int binomial(int n, int k) {
int num, denom, i;
if (n < 0 || k < 0 || n < k) return -1;
if (n == 0 || k == 0) return 1;
num = 1;
for (i = k + 1; i <= n; ++i) {
num = num * i;
}
denom = 1;
for (i = 2; i <= n - k; ++i)... | program Faulhaber;
uses SysUtils;
type TRational = record
Num, Den : integer;
end;
const
ZERO : TRational = ( Num: 0; Den : 1);
HALF : TRational = ( Num: 1; Den : 2);
function Rational( const a, b : integer) : TRational;
var
t, x, y : integer;
begin
if b <= 0 then raise SysUtils.Exc... |
Convert this C block to Pascal, preserving its control flow and logic. | #include <assert.h>
#include <stdbool.h>
#include <stdio.h>
typedef unsigned char byte;
struct Transition {
byte a, b;
unsigned int c;
} transitions[100];
void init() {
int i, j;
for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
int idx = i * 10 + j;
transitions[id... | program primCons;
const
PrimeLimit = 2038074748 DIV 2;
type
tLimit = 0..PrimeLimit;
tCntTransition = array[0..9,0..9] of NativeInt;
tCntTransRec = record
CTR_CntTrans:tCntTransition;
CTR_primCnt,
CTR_Limit : NativeInt;
end;
tCntTr... |
Change the programming language of this snippet from C to Pascal without modifying what it does. | #include <stdio.h>
#include <limits.h>
typedef unsigned long long ull;
#define N (sizeof(ull) * CHAR_BIT)
#define B(x) (1ULL << (x))
void evolve(ull state, int rule)
{
int i, p, q, b;
for (p = 0; p < 10; p++) {
for (b = 0, q = 8; q--; ) {
ull st = state;
b |= (st&1) << q;
for (state = i = 0; i < N; i++... | Program Rule30;
uses
SysUtils;
const
maxRounds = 2*1000*1000;
rounds = 10;
var
Rule30_State : Uint64;
function GetCPU_Time: int64;
type
TCpu = record
HiCpu,
LoCpu : Dword;
end;
var
Cput : TCpu;
begin
asm
RDTSC;
MOV Dword Ptr [CpuT.LoCpu],EAX
MOV D... |
Convert this C block to Pascal, preserving its control flow and logic. |
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#define NMAX 10000000
double mean(double* values, int n)
{
int i;
double s = 0;
for ( i = 0; i < n; i++ )
s += values[i];
return s / n;
}
double stddev(double* values, int n)
{
int i;
d... | Program Example40;
Uses Math;
type
tTestData = extended;
ttstfunc = function (mean, sd: tTestData): tTestData;
tExArray = Array of tTestData;
tSolution = record
SolExArr : tExArray;
SollowVal,
SolHighVal,
SolMean,
SolStdDiv... |
Produce a language-to-language conversion: from C to Pascal, same semantics. | #include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
__int128 imax(__int128 a, __int128 b) {
if (a > b) {
return a;
}
return b;
}
__int128 ipow(__int128 b, __int128 n) {
__int128 res;
if (n == 0) {
return 1;
}
if (n == 1) {
return b;
}... | program B10_num;
uses
sysutils,gmp;
const
Limit = 256*256*8;
B10_4 = 10*10*10*10;
B10_5 = 10*B10_4;
B10_9 = B10_5*B10_4;
HexB10 : array[0..15] of NativeUint = (0000,0001,0010,0011,0100,0101,0110,0111,
1000,1001,1010,1011,1100,1101,1110,1111);
va... |
Translate the given C code snippet into Pascal without altering its behavior. | #include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
typedef enum State { READY, WAITING, REFUND, DISPENSE, COLLECT, QUIT } State;
typedef struct statechange {
const int in;
const State out;
} statechange;
#define MAXINPUTS 3
typedef struct FSM {
const State... |
program fsm1.pas;
uses sysutils;
type
state = (Null,Ready,Waiting,Refund,Dispense,Stop);
event = (Epsilon := 1,Deposit,Select,Cancel,Remove,Quit,Error);
Item = record
Name : string[12];
Stock: shortint;
price: currency;
end;
var
amountPaid, itemPrice , changeDue: currency;
I,J ... |
Can you help me rewrite this code in Pascal instead of C, keeping it the same logically? | #include <glib.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
guchar* sha256_merkle_tree(FILE* in, size_t block_size) {
gchar* buffer = g_malloc(block_size);
GPtrArray* hashes = g_ptr_array_new_with_free_func(g_free);
gssize digest_length = g_checksum_type_get_length(G_CHECKSUM_SHA256);
... | program SHA256_Merkle_tree;
uses
System.SysUtils,
System.Classes,
DCPsha256;
type
TmyByte = TArray<Byte>;
TmyHashes = TArray<TArray<byte>>;
uses
SysUtils,
Classes,
DCPsha256;
type
TmyByte = array of byte;
TmyHashes = array of TmyByte;
function SHA256(const Input: TmyByte; ... |
Produce a language-to-language conversion: from C to Pascal, same semantics. | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <locale.h>
bool *primeSieve(int limit) {
int i, p;
limit++;
bool *c = calloc(limit, sizeof(bool));
c[0] = true;
c[1] = true;
for (i = 4; i < limit; i += 2) c[i] = true;
p = 3;
while (true) {
int p2 = p *... | program UntouchableNumbers;
program UntouchableNumbers;
uses
sysutils,strutils
,Windows
;
const
MAXPRIME = 1742537;
LIMIT = 5*1000*1000;
LIMIT_mul = trunc(exp(ln(LIMIT)/3))+1;
const
SizePrDeFe = 16*8192;
type
tdigits = array [0..31] of Uint32;
tprimeFac = packed record
... |
Please provide an equivalent version of this C code in Pascal. | #include <stdio.h>
#include <stdlib.h>
int main() {
const int maxNumber = 100000000;
int *dsum = (int *)malloc((maxNumber + 1) * sizeof(int));
int *dcount = (int *)malloc((maxNumber + 1) * sizeof(int));
int i, j;
for (i = 0; i <= maxNumber; ++i) {
dsum[i] = 1;
dcount[i] = 1;
}
... | program ErdoesNumb;
uses
sysutils
,Windows
;
const
HCN_DivCnt = 4096;
type
tItem = Uint64;
tDivisors = array [0..HCN_DivCnt] of tItem;
tpDivisor = pUint64;
const
SizePrDeFe = 32768;
type
tdigits = array [0..31] of Uint32;
tprimeFac = packed record
pfSu... |
Please provide an equivalent version of this C code in Pascal. | #include <stdio.h>
#include <stdbool.h>
int digit_set(int n) {
static const int powers[] = {
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
100000000, 1000000000
};
int dset;
for (dset = 0; n; n /= 10)
dset += powers[n % 10];
return dset;
}
bool is_permuted_mult... | program euler52;
uses
sysutils;
const
BaseConvDgt :array[0..35] of char = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
MAXBASE = 12;
type
TUsedDigits = array[0..MAXBASE-1] of byte;
tDigitsInUse = set of 0..MAXBASE-1;
var
UsedDigits :tUsedDigits;
gblMaxDepth,
steps,
base,maxmul : NativeIn... |
Translate this program into Pascal but keep the logic exactly as in C. | #include <stdio.h>
#include <stdbool.h>
int digit_set(int n) {
static const int powers[] = {
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
100000000, 1000000000
};
int dset;
for (dset = 0; n; n /= 10)
dset += powers[n % 10];
return dset;
}
bool is_permuted_mult... | program euler52;
uses
sysutils;
const
BaseConvDgt :array[0..35] of char = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
MAXBASE = 12;
type
TUsedDigits = array[0..MAXBASE-1] of byte;
tDigitsInUse = set of 0..MAXBASE-1;
var
UsedDigits :tUsedDigits;
gblMaxDepth,
steps,
base,maxmul : NativeIn... |
Preserve the algorithm and functionality while converting the code from C to Pascal. | #include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
typedef uint64_t integer;
integer reverse(integer n) {
integer rev = 0;
while (n > 0) {
rev = rev * 10 + (n % 10);
n /= 10;
}
return rev;
}
typedef struct palgen_tag {
integer power;
integer next;
int digit;
b... | program PalinGap;
type
tLimits = record
LoLmt,HiLmt:Uint64;
end;
const
base = 10;
var
delta : Array[0..9] of Uint64;
deltaBase: Array[0..9] of Uint64;
deltaMod : Array[0..9] of Uint32;
deltaModBase : Array[0..9] of Uint32;
IdxCnt : Array[0..9] of Uint32;
... |
Convert this C block to Pascal, preserving its control flow and logic. | #include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
typedef uint64_t integer;
integer reverse(integer n) {
integer rev = 0;
while (n > 0) {
rev = rev * 10 + (n % 10);
n /= 10;
}
return rev;
}
typedef struct palgen_tag {
integer power;
integer next;
int digit;
b... | program PalinGap;
type
tLimits = record
LoLmt,HiLmt:Uint64;
end;
const
base = 10;
var
delta : Array[0..9] of Uint64;
deltaBase: Array[0..9] of Uint64;
deltaMod : Array[0..9] of Uint32;
deltaModBase : Array[0..9] of Uint32;
IdxCnt : Array[0..9] of Uint32;
... |
Rewrite this program in Pascal while keeping its functionality equivalent to the C version. | #include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <time.h>
bool is_prime(unsigned int n) {
assert(n < 64);
static bool isprime[] = {0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0,
0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1,
0, 0, ... | program PrimePyramid;
const
MAX = 21;
cMaxAlign32 = (((MAX-1)DIV 32)+1)*32-1;
type
tPrimeRange = set of 0..127;
var
SetOfPrimes :tPrimeRange =[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,
53,59,61,67,71,73,79,83,89,97,101,103,107,
109,113,127];
S... |
Convert this C snippet to Pascal and keep its semantics consistent. | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <locale.h>
bool *sieve(int limit) {
int i, p;
limit++;
bool *c = calloc(limit, sizeof(bool));
c[0] = true;
c[1] = true;
for (i = 4; i < limit; i += 2) c[i] = true;
p = 3;
while (true) {
... | program sphenic;
const
Limit= 1000*1000;
type
tPrimesSieve = array of boolean;
tElement = Uint32;
tarrElement = array of tElement;
tpPrimes = pBoolean;
var
PrimeSieve : tPrimesSieve;
primes : tarrElement;
sphenics : tarrElement;
procedure ClearAll;
begin
setlength(sphenics,0);
setlength(... |
Preserve the algorithm and functionality while converting the code from C to Pascal. | #include <locale.h>
#include <stdbool.h>
#include <stdio.h>
#include <time.h>
bool colorful(int n) {
if (n < 0 || n > 98765432)
return false;
int digit_count[10] = {};
int digits[8] = {};
int num_digits = 0;
for (int m = n; m > 0; m /= 10) {
int d = m % 10;
if (n > 9 &&... |
uses
sysutils;
const
EightFak = 1*2*3*4*5*6*7*8;
type
tDgt = Int8;
tpDgt = pInt8;
tDgtfield = array[0..7] of tdgt;
tpDgtfield = ^tDgtfield;
tPermfield = tDgtfield;
tAllPermDigits = array[0..EightFak] of tDgtfield;
tMarkNotColorful = array[0..EightFak-1] of byte;
tDat = Uin... |
Transform the following C implementation into Pascal, maintaining the same output and logic. | #include <locale.h>
#include <stdbool.h>
#include <stdio.h>
#include <time.h>
bool colorful(int n) {
if (n < 0 || n > 98765432)
return false;
int digit_count[10] = {};
int digits[8] = {};
int num_digits = 0;
for (int m = n; m > 0; m /= 10) {
int d = m % 10;
if (n > 9 &&... |
uses
sysutils;
const
EightFak = 1*2*3*4*5*6*7*8;
type
tDgt = Int8;
tpDgt = pInt8;
tDgtfield = array[0..7] of tdgt;
tpDgtfield = ^tDgtfield;
tPermfield = tDgtfield;
tAllPermDigits = array[0..EightFak] of tDgtfield;
tMarkNotColorful = array[0..EightFak-1] of byte;
tDat = Uin... |
Transform the following C implementation into Pascal, maintaining the same output and logic. | #include <stdio.h>
#include <locale.h>
int divisorCount(int n) {
int i, j, count = 0, k = !(n%2) ? 1 : 2;
for (i = 1; i*i <= n; i += k) {
if (!(n%i)) {
++count;
j = n/i;
if (j != i) ++count;
}
}
return count;
}
int main() {
int i, numbers50[50], ... | program Root3rd_divs_n.pas;
uses
sysutils
,Windows
;
const
limit = 110*1000 *1000;
var
sol : array [0..limit] of byte;
primes : array of Uint32;
gblCount: Uint64;
procedure SievePrimes(lmt:Uint32);
var
sieve : array of byte;
p,i,delta : NativeInt;
Begin
setlength(sieve,lmt DIV 2);
... |
Convert the following code from C to Pascal, ensuring the logic remains intact. |
csv=externstr("curl 'https:
{
for(i = 1 , #csv, tmp = Vecsmall(csv[i]);
for(j = 1 , #tmp, if(tmp[j]==92, tmp[j]=78));
csv[i] = strchr(tmp)
);
};
{
convert(csv,mat)=
write1(mat,"[");
for(i=1, #csv-1,
write1(mat,csv[i]); write1(mat,";")
);
write1(mat,csv[#csv]); wri... | program Dist_Bearing;
uses
SysUtils,Math;
const
cDegToRad = pi / 180; cRadToDeg = 180 / pi;
cOneNmInKm = (12742*pi)/360/60;
DiaEarth = 12742/cOneNmInKm;
type
tLatLon = record
lat,lon:double;
sinLat,cosLat:double;
sinLon,cosLon:double;
end... |
Write the same code in Pascal as shown below in C. |
csv=externstr("curl 'https:
{
for(i = 1 , #csv, tmp = Vecsmall(csv[i]);
for(j = 1 , #tmp, if(tmp[j]==92, tmp[j]=78));
csv[i] = strchr(tmp)
);
};
{
convert(csv,mat)=
write1(mat,"[");
for(i=1, #csv-1,
write1(mat,csv[i]); write1(mat,";")
);
write1(mat,csv[#csv]); wri... | program Dist_Bearing;
uses
SysUtils,Math;
const
cDegToRad = pi / 180; cRadToDeg = 180 / pi;
cOneNmInKm = (12742*pi)/360/60;
DiaEarth = 12742/cOneNmInKm;
type
tLatLon = record
lat,lon:double;
sinLat,cosLat:double;
sinLon,cosLon:double;
end... |
Convert this C block to Pascal, preserving its control flow and logic. | char input[] = "top1 des1 ip1 ip2\n"
"top2 des1 ip2 ip3\n"
"ip1 extra1 ip1a ipcommon\n"
"ip2 ip2a ip2b ip2c ipcommon\n"
"des1 des1a des1b des1c\n"
"des1a des1a1 des1a2\n"
"des1c des1c1 extra1\n";
...
int find_name(item base, int len, const char *name)
{
int i;
for (i = 0; i < len; i+... | program TopLevel;
uses
SysUtils, Generics.Collections;
type
TAdjList = class
InList,
OutList: THashSet<string>;
constructor Create;
destructor Destroy; override;
end;
TDigraph = class(TObjectDictionary<string, TAdjList>)
procedure AddNode(const s: string);
procedu... |
Translate the given C code snippet into Pascal without altering its behavior. | #include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
bool is_prime(uint64_t n) {
if (n < 2)
return false;
if (n % 2 == 0)
return n == 2;
if (n % 3 == 0)
return n == 3;
if (n % 5 == 0)
return n == 5;
static const uint64_t wheel[] = {4, 2, 4, 2, 4, 6, 2, 6};
... | program PanBaseNonPrime;
type
tDgts = 0..31;
tUsedDgts = set of tDgts;
tDecDigits = packed record
decdgts :array[0..20] of byte;
decmaxIdx :byte;
decmaxDgt :byte;
decUsedDgt :tUsedDgts;
end;
const
MAXLIMIT = 2500;... |
Can you help me rewrite this code in Ada instead of Java, keeping it the same logically? | import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.geometry.Point3D;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.shape.MeshView;
import javafx.scene.shape.TriangleMesh;
import javafx.... | with Ada.Numerics.Elementary_Functions;
with Ada.Numerics.Generic_Real_Arrays;
with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Video.Palettes;
with SDL.Events.Events;
procedure Death_Star is
Width : constant := 400;
Height : constant := 400;
package Float_Arrays is
new Ada... |
Ensure the translated Ada code behaves exactly like the original Java snippet. | import java.awt.*;
import static java.awt.Color.*;
import javax.swing.*;
public class ColourPinstripeDisplay extends JPanel {
final static Color[] palette = {black, red, green, blue, magenta,cyan,
yellow, white};
final int bands = 4;
public ColourPinstripeDisplay() {
setPreferredSize(new ... | with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Video.Palettes;
with SDL.Events.Events;
procedure Colour_Pinstripe_Display is
Width : constant := 1_200;
Height : constant := 800;
Window : SDL.Video.Windows.Window;
Renderer : SDL.Video.Renderers.Renderer;
Event : SDL.Ev... |
Generate a Ada translation of this Java snippet without changing its computational steps. | import static java.util.Arrays.stream;
import java.util.Random;
public class Test {
static double equalBirthdays(int nSharers, int groupSize, int nRepetitions) {
Random rand = new Random(1);
int eq = 0;
for (int i = 0; i < nRepetitions; i++) {
int[] group = new int[365];
... | with Ada.Command_Line, Ada.Text_IO, Ada.Numerics.Discrete_random;
procedure Birthday_Test is
Samples: constant Positive := Integer'Value(Ada.Command_Line.Argument(1));
subtype Day is integer range 0 .. 365;
subtype Extended_Day is Integer range 0 .. 365*4;
package ANDR is new Ada.Numerics... |
Preserve the algorithm and functionality while converting the code from Java to Ada. | import static java.util.Arrays.stream;
import java.util.Random;
public class Test {
static double equalBirthdays(int nSharers, int groupSize, int nRepetitions) {
Random rand = new Random(1);
int eq = 0;
for (int i = 0; i < nRepetitions; i++) {
int[] group = new int[365];
... | with Ada.Command_Line, Ada.Text_IO, Ada.Numerics.Discrete_random;
procedure Birthday_Test is
Samples: constant Positive := Integer'Value(Ada.Command_Line.Argument(1));
subtype Day is integer range 0 .. 365;
subtype Extended_Day is Integer range 0 .. 365*4;
package ANDR is new Ada.Numerics... |
Change the following Java code into Ada without altering its purpose. | using System;
namespace Sphere {
internal class Program {
private const string Shades = ".:!*oe%&#@";
private static readonly double[] Light = {30, 30, -50};
private static void Normalize(double[] v) {
double len = Math.Sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
v[0] ... | with Glib; use Glib;
with Cairo; use Cairo;
with Cairo.Png; use Cairo.Png;
with Cairo.Pattern; use Cairo.Pattern;
with Cairo.Image_Surface; use Cairo.Image_Surface;
with Ada.Numerics;
procedure Sphere is
subtype Dub is Glib.Gdouble;
Surface : Cairo_Surface;
Cr ... |
Transform the following Java implementation into Ada, maintaining the same output and logic. | using System;
namespace Sphere {
internal class Program {
private const string Shades = ".:!*oe%&#@";
private static readonly double[] Light = {30, 30, -50};
private static void Normalize(double[] v) {
double len = Math.Sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
v[0] ... | with Glib; use Glib;
with Cairo; use Cairo;
with Cairo.Png; use Cairo.Png;
with Cairo.Pattern; use Cairo.Pattern;
with Cairo.Image_Surface; use Cairo.Image_Surface;
with Ada.Numerics;
procedure Sphere is
subtype Dub is Glib.Gdouble;
Surface : Cairo_Surface;
Cr ... |
Generate an equivalent Ada version of this Java code. | import static java.lang.Math.*;
public class Test {
final static int N = 32;
final static int N2 = (N * (N - 1) / 2);
final static double STEP = 0.05;
static double[] xval = new double[N];
static double[] t_sin = new double[N];
static double[] t_cos = new double[N];
static double[] t_tan =... | with Ada.Numerics.Generic_Real_Arrays;
generic
type Real is digits <>;
package Thiele is
package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (Real);
subtype Real_Array is Real_Arrays.Real_Vector;
type Thiele_Interpolation (Length : Natural) is private;
function Create (X, Y : Real_Array) retur... |
Can you help me rewrite this code in Ada instead of Java, keeping it the same logically? | import java.io.File;
import java.util.Scanner;
public class LongestStringChallenge {
public static void main(String[] args) throws Exception {
String lines = "", longest = "";
try (Scanner sc = new Scanner(new File("lines.txt"))) {
while(sc.hasNext()) {
String line = sc... | with Ada.Text_IO;
procedure Longest_Strings is
use Ada.Text_IO;
function Measure_And_Print_N (O : String := "";
N : String := ""
) return Integer is
T1 : String := O;
T2 : String := N;
... |
Produce a language-to-language conversion: from Java to Ada, same semantics. | final PVector t = new PVector(20, 30, 60);
void setup() {
size(450, 400);
noLoop();
background(0, 0, 200);
stroke(-1);
sc(7, 400, -60, t);
}
PVector sc(int o, float l, final int a, final PVector s) {
if (o > 0) {
sc(--o, l *= .5, -a, s).z += a;
sc(o, l, a, s).z += a;
sc(o, l, -a, s);
} else ... | with Ada.Command_Line;
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Text_IO;
with PDF_Out;
procedure Arrowhead_Curve is
package Real_Math is
new Ada.Numerics.Generic_Elementary_Functions (PDF_Out.Real);
use Real_Math, PDF_Out, Ada.Command_Line, Ada.Text_IO;
subtype Angle_Deg is Real;
ty... |
Convert this Java snippet to Ada and keep its semantics consistent. | import java.io.FileWriter;
import java.io.IOException;
public class LinePrinter {
public static void main(String[] args) {
try {
FileWriter lp0 = new FileWriter("/dev/lp0");
lp0.write("Hello World!");
lp0.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
| with Ada.Text_IO; use Ada.Text_IO;
procedure Print_Line is
Printer : File_Type;
begin
begin
Open (Printer, Mode => Out_File, Name => "/dev/lp0");
exception
when others =>
Put_Line ("Unable to open printer.");
return;
end;
Set_Output (Printer);
Put_Line ("Hello World!");... |
Produce a language-to-language conversion: from Java to Ada, same semantics. | import java.io.FileWriter;
import java.io.IOException;
public class LinePrinter {
public static void main(String[] args) {
try {
FileWriter lp0 = new FileWriter("/dev/lp0");
lp0.write("Hello World!");
lp0.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
| with Ada.Text_IO; use Ada.Text_IO;
procedure Print_Line is
Printer : File_Type;
begin
begin
Open (Printer, Mode => Out_File, Name => "/dev/lp0");
exception
when others =>
Put_Line ("Unable to open printer.");
return;
end;
Set_Output (Printer);
Put_Line ("Hello World!");... |
Rewrite the snippet below in Ada so it works the same as the original Java code. | public class MagicSquare {
public static void main(String[] args) {
int n = 5;
for (int[] row : magicSquareOdd(n)) {
for (int x : row)
System.out.format("%2s ", x);
System.out.println();
}
System.out.printf("\nMagic constant: %d ", (n * n + 1)... | with Ada.Text_IO, Ada.Command_Line;
procedure Magic_Square is
N: constant Positive := Positive'Value(Ada.Command_Line.Argument(1));
subtype Constants is Natural range 1 .. N*N;
package CIO is new Ada.Text_IO.Integer_IO(Constants);
Undef: constant Natural := 0;
subtype Index is Natural range 0 .. N-... |
Can you help me rewrite this code in Ada instead of Java, keeping it the same logically? | public class MagicSquare {
public static void main(String[] args) {
int n = 5;
for (int[] row : magicSquareOdd(n)) {
for (int x : row)
System.out.format("%2s ", x);
System.out.println();
}
System.out.printf("\nMagic constant: %d ", (n * n + 1)... | with Ada.Text_IO, Ada.Command_Line;
procedure Magic_Square is
N: constant Positive := Positive'Value(Ada.Command_Line.Argument(1));
subtype Constants is Natural range 1 .. N*N;
package CIO is new Ada.Text_IO.Integer_IO(Constants);
Undef: constant Natural := 0;
subtype Index is Natural range 0 .. N-... |
Translate this program into Ada but keep the logic exactly as in Java. | import java.awt.*;
import java.awt.geom.Line2D;
import java.util.*;
import java.util.List;
import javax.swing.*;
public class SutherlandHodgman extends JFrame {
SutherlandHodgmanPanel panel;
public static void main(String[] args) {
JFrame f = new SutherlandHodgman();
f.setDefaultCloseOperatio... | with Ada.Containers.Doubly_Linked_Lists;
with Ada.Text_IO;
procedure Main is
package FIO is new Ada.Text_IO.Float_IO (Float);
type Point is record
X, Y : Float;
end record;
function "-" (Left, Right : Point) return Point is
begin
return (Left.X - Right.X, Left.Y - Right.Y);
end "-";
... |
Maintain the same structure and functionality when rewriting this code in Ada. | public class PancakeSort
{
int[] heap;
public String toString() {
String info = "";
for (int x: heap)
info += x + " ";
return info;
}
public void flip(int n) {
for (int i = 0; i < (n+1) / 2; ++i) {
int tmp = heap[i];
heap[i] = heap[n-i];
heap... | with Ada.Text_IO;
procedure Pancake_Sort is
generic
type Element_Type is private;
type Index_Type is range <>;
type Array_Type is array (Index_Type range <>) of Element_Type;
with function ">" (Left, Right : Element_Type) return Boolean is <>;
procedure Pancake_Sort (Data: in out Array_Typ... |
Convert the following code from Java to Ada, ensuring the logic remains intact. | public class Test {
public static void main(String[] args) {
String[] filenames = { "http:
"CharacterModel.3DS",
".desktop",
"document",
"document.txt_backup",
... | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
use Ada.Strings;
with Ada.Characters.Handling; use Ada.Characters.Handling;
procedure Main is
function extension (S : in String) return String is
P_Index : Natural;
begin
P_Index :=
Index (Source => S, Pat... |
Convert this Java snippet to Ada and keep its semantics consistent. | public class Test {
public static void main(String[] args) {
String[] filenames = { "http:
"CharacterModel.3DS",
".desktop",
"document",
"document.txt_backup",
... | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
use Ada.Strings;
with Ada.Characters.Handling; use Ada.Characters.Handling;
procedure Main is
function extension (S : in String) return String is
P_Index : Natural;
begin
P_Index :=
Index (Source => S, Pat... |
Port the following code from Java to Ada with equivalent syntax and logic. | import static java.lang.Math.abs;
import java.util.*;
import static java.util.stream.Collectors.toList;
import static java.util.stream.IntStream.range;
public class NoConnection {
static int[][] links = {
{2, 3, 4},
{3, 4, 5},
{2, 4},
{5},
{2, 3, 4},
... | With
Ada.Text_IO,
Connection_Types,
Connection_Combinations;
procedure main is
Result : Connection_Types.Partial_Board renames Connection_Combinations;
begin
Ada.Text_IO.Put_Line( Connection_Types.Image(Result) );
end;
|
Transform the following Java implementation into Ada, maintaining the same output and logic. | public class PermutationTest {
private static final int[] data = new int[]{
85, 88, 75, 66, 25, 29, 83, 39, 97,
68, 41, 10, 49, 16, 65, 32, 92, 28, 98
};
private static int pick(int at, int remain, int accu, int treat) {
if (remain == 0) return (accu > treat) ? 1 : 0;
return... | with Ada.Text_IO; with Iterate_Subsets;
procedure Permutation_Test is
type Group_Type is array(Positive range <>) of Positive;
Treat_Group: constant Group_Type := (85, 88, 75, 66, 25, 29, 83, 39, 97);
Ctrl_Group: constant Group_Type := (68, 41, 10, 49, 16, 65, 32, 92, 28, 98);
package Iter is new Itera... |
Convert this Java snippet to Ada and keep its semantics consistent. | import java.awt.image.*;
import java.io.File;
import java.io.IOException;
import javax.imageio.*;
public class ImageConvolution
{
public static class ArrayData
{
public final int[] dataArray;
public final int width;
public final int height;
public ArrayData(int width, int height)
{
t... | type Float_Luminance is new Float;
type Float_Pixel is record
R, G, B : Float_Luminance := 0.0;
end record;
function "*" (Left : Float_Pixel; Right : Float_Luminance) return Float_Pixel is
pragma Inline ("*");
begin
return (Left.R * Right, Left.G * Right, Left.B * Right);
end "*";
function "+" (Left, Right ... |
Produce a functionally identical Ada code for the snippet given in Java. | String src = "Hello";
String newAlias = src;
String strCopy = new String(src);
| Src : String := "Hello";
Dest : String := Src;
|
Convert this Java block to Ada, preserving its control flow and logic. | import java.util.*;
public class Abbreviations {
public static void main(String[] args) {
CommandList commands = new CommandList(commandTable);
String input = "riG rePEAT copies put mo rest types fup. 6 poweRin";
System.out.println(" input: " + input);
System.out.... | with Ada.Characters.Handling;
with Ada.Containers.Vectors;
with Ada.Strings.Fixed;
with Ada.Strings.Maps.Constants;
with Ada.Strings.Unbounded;
with Ada.Text_IO;
procedure Abbreviations_Simple is
use Ada.Strings.Unbounded;
subtype Ustring is Unbounded_String;
type Word_Entry is record
Word : Ustring;
... |
Port the following code from Java to Ada with equivalent syntax and logic. | import java.util.*;
public class Abbreviations {
public static void main(String[] args) {
CommandList commands = new CommandList(commandTable);
String input = "riG rePEAT copies put mo rest types fup. 6 poweRin";
System.out.println(" input: " + input);
System.out.... | with Ada.Characters.Handling;
with Ada.Containers.Vectors;
with Ada.Strings.Fixed;
with Ada.Strings.Maps.Constants;
with Ada.Strings.Unbounded;
with Ada.Text_IO;
procedure Abbreviations_Simple is
use Ada.Strings.Unbounded;
subtype Ustring is Unbounded_String;
type Word_Entry is record
Word : Ustring;
... |
Transform the following Java implementation into Ada, maintaining the same output and logic. | public class Class1 extends Class2
{
}
| with Ada.Text_IO, Another_Package; use Ada.Text_IO;
|
Produce a language-to-language conversion: from Java to Ada, same semantics. | public class Class1 extends Class2
{
}
| with Ada.Text_IO, Another_Package; use Ada.Text_IO;
|
Produce a functionally identical Ada code for the snippet given in Java. | public class Compare
{
public static void compare (String A, String B)
{
if (A.equals(B))
System.debug(A + ' and ' + B + ' are lexically equal.');
else
System.debug(A + ' and ' + B + ' are not lexically equal.');
if (A.equalsIgnoreCase(B))
Sy... | with Ada.Text_IO, Ada.Strings.Equal_Case_Insensitive;
procedure String_Compare is
procedure Print_Comparison (A, B : String) is
begin
Ada.Text_IO.Put_Line
("""" & A & """ and """ & B & """: " &
(if A = B then
"equal, "
elsif Ada.Strings.Equal_Case_Insensitive (A... |
Change the following Java code into Ada without altering its purpose. | import java.util.ArrayList;
import java.util.List;
public class HailstoneSequence {
public static void main(String[] args) {
int n = 27;
List<Long> sequence27 = hailstoneSequence(n);
System.out.printf("Hailstone sequence for %d has a length of %d:%nhailstone(%d) = %s%n", n, seque... | package Parameter is
X: Natural := 0;
Y: Natural;
end Parameter;
|
Convert this Java block to Ada, preserving its control flow and logic. | import java.util.ArrayList;
import java.util.List;
public class HailstoneSequence {
public static void main(String[] args) {
int n = 27;
List<Long> sequence27 = hailstoneSequence(n);
System.out.printf("Hailstone sequence for %d has a length of %d:%nhailstone(%d) = %s%n", n, seque... | package Parameter is
X: Natural := 0;
Y: Natural;
end Parameter;
|
Change the following Java code into Ada without altering its purpose. | import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class EntropyNarcissist {
private static final String FILE_NAME = "src/EntropyNarcissist.java";
public static void main(String[] args) {
... | with Ada.Text_Io;
with Ada.Command_Line;
with Ada.Numerics.Elementary_Functions;
procedure Entropy is
use Ada.Text_Io;
type Hist_Type is array (Character) of Natural;
function Log_2 (V : Float) return Float is
use Ada.Numerics.Elementary_Functions;
begin
return Log (V) / Log (2.0);
end Log... |
Generate a Ada translation of this Java snippet without changing its computational steps. | import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class EntropyNarcissist {
private static final String FILE_NAME = "src/EntropyNarcissist.java";
public static void main(String[] args) {
... | with Ada.Text_Io;
with Ada.Command_Line;
with Ada.Numerics.Elementary_Functions;
procedure Entropy is
use Ada.Text_Io;
type Hist_Type is array (Character) of Natural;
function Log_2 (V : Float) return Float is
use Ada.Numerics.Elementary_Functions;
begin
return Log (V) / Log (2.0);
end Log... |
Please provide an equivalent version of this Java code in Ada. | import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
public class DrawAPixel extends JFrame{
public DrawAPixel() {
super("Red Pixel");
setSize(320, 240);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
@Override
public void paint(Graphics g) {
g.setColor(new Col... | with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Events.Events;
procedure Draw_A_Pixel is
Width : constant := 320;
Height : constant := 200;
Window : SDL.Video.Windows.Window;
Renderer : SDL.Video.Renderers.Renderer;
procedure Wait is
use type SDL.Events.Event_Types... |
Rewrite this program in Ada while keeping its functionality equivalent to the Java version. | import static java.lang.Math.abs;
import java.util.*;
import java.util.function.IntSupplier;
public class Test {
static void distCheck(IntSupplier f, int nRepeats, double delta) {
Map<Integer, Integer> counts = new HashMap<>();
for (int i = 0; i < nRepeats; i++)
counts.compute(f.getAs... | with Ada.Numerics.Discrete_Random, Ada.Text_IO;
procedure Naive_Random is
type M_1000 is mod 1000;
package Rand is new Ada.Numerics.Discrete_Random(M_1000);
Gen: Rand.Generator;
procedure Perform(Modulus: Positive; Expected, Margin: Natural;
Passed: out boolean) is
Low: Natural... |
Write a version of this Java function in Ada with identical behavior. |
public class Query {
public static boolean call(byte[] data, int[] length)
throws java.io.UnsupportedEncodingException
{
String message = "Here am I";
byte[] mb = message.getBytes("utf-8");
if (length[0] < mb.length)
return false;
length[0] = mb.length;
System.arraycopy(mb, 0, data, 0, mb.length);
... | with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
package Exported is
function Query (Data : chars_ptr; Size : access size_t)
return int;
pragma Export (C, Query, "Query");
end Exported;
|
Port the provided Java code into Ada while preserving the original functionality. | public class FirstLastBits {
public static int mssb(int x) {
return Integer.highestOneBit(x);
}
public static long mssb(long x) {
return Long.highestOneBit(x);
}
public static int mssb_idx(int x) {
return Integer.SIZE - 1 - Integer.numberOfLeadingZeros(x);
}
... | with Ada.Text_IO;
with Ada.Integer_Text_IO;
with Ada.Unchecked_Conversion;
procedure Find_Last_Bit is
type My_Integer is range -2**63 .. 2**63 - 1;
procedure Find_Set_Bits (Value : in My_Integer;
MSB_Bit : out Integer;
LSB_Bit : out Integer)
... |
Write the same algorithm in Ada as shown in this Java implementation. | public class FirstLastBits {
public static int mssb(int x) {
return Integer.highestOneBit(x);
}
public static long mssb(long x) {
return Long.highestOneBit(x);
}
public static int mssb_idx(int x) {
return Integer.SIZE - 1 - Integer.numberOfLeadingZeros(x);
}
... | with Ada.Text_IO;
with Ada.Integer_Text_IO;
with Ada.Unchecked_Conversion;
procedure Find_Last_Bit is
type My_Integer is range -2**63 .. 2**63 - 1;
procedure Find_Set_Bits (Value : in My_Integer;
MSB_Bit : out Integer;
LSB_Bit : out Integer)
... |
Write a version of this Java function in Ada with identical behavior. | import java.util.Arrays;
import java.util.Random;
public class SequenceMutation {
public static void main(String[] args) {
SequenceMutation sm = new SequenceMutation();
sm.setWeight(OP_CHANGE, 3);
String sequence = sm.generateSequence(250);
System.out.println("Initial sequence:");
... | with Ada.Containers.Vectors;
with Ada.Numerics.Discrete_Random;
with Ada.Text_Io;
procedure Mutations is
Width : constant := 60;
type Nucleotide_Type is (A, C, G, T);
type Operation_Type is (Delete, Insert, Swap);
type Position_Type is new Natural;
package Position_Io is new Ada.Text_Io.Integer_Io ... |
Translate this program into Ada but keep the logic exactly as in Java. | import java.util.Arrays;
import java.util.Random;
public class SequenceMutation {
public static void main(String[] args) {
SequenceMutation sm = new SequenceMutation();
sm.setWeight(OP_CHANGE, 3);
String sequence = sm.generateSequence(250);
System.out.println("Initial sequence:");
... | with Ada.Containers.Vectors;
with Ada.Numerics.Discrete_Random;
with Ada.Text_Io;
procedure Mutations is
Width : constant := 60;
type Nucleotide_Type is (A, C, G, T);
type Operation_Type is (Delete, Insert, Swap);
type Position_Type is new Natural;
package Position_Io is new Ada.Text_Io.Integer_Io ... |
Translate this program into Ada but keep the logic exactly as in Java. | import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
public class ColorFrame extends JFrame {
public ColorFrame(int width, int height) {
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(width, height);
this.setVisible(true);
}
@Override
public void paint(Graphics g) {
Col... | with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Video.Palettes;
with SDL.Events.Events;
with SDL.Events.Keyboards;
procedure Colour_Bars_Display is
use type SDL.Events.Event_Types;
use SDL.C;
Colours : constant array (0 .. 7) of SDL.Video.Palettes.Colour :=
((0, 0, 0, 255), ... |
Generate an equivalent Ada version of this Java code. | import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
public class ColorFrame extends JFrame {
public ColorFrame(int width, int height) {
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(width, height);
this.setVisible(true);
}
@Override
public void paint(Graphics g) {
Col... | with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Video.Palettes;
with SDL.Events.Events;
with SDL.Events.Keyboards;
procedure Colour_Bars_Display is
use type SDL.Events.Event_Types;
use SDL.C;
Colours : constant array (0 .. 7) of SDL.Video.Palettes.Colour :=
((0, 0, 0, 255), ... |
Produce a language-to-language conversion: from Java to Ada, same semantics. | import static java.lang.Math.*;
public class RayCasting {
static boolean intersects(int[] A, int[] B, double[] P) {
if (A[1] > B[1])
return intersects(B, A, P);
if (P[1] == A[1] || P[1] == B[1])
P[1] += 0.0001;
if (P[1] > B[1] || P[1] < A[1] || P[0] >= max(A[0], B... | package Polygons is
type Point is record
X, Y : Float;
end record;
type Point_List is array (Positive range <>) of Point;
subtype Segment is Point_List (1 .. 2);
type Polygon is array (Positive range <>) of Segment;
function Create_Polygon (List : Point_List) return Polygon;
function Is_In... |
Please provide an equivalent version of this Java code in Ada. | package diningphilosophers;
import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
enum PhilosopherState { Get, Eat, Pon }
class Fork {
public static final int ON_TABLE = -1;
static int instances = 0;
public... | with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
with Ada.Text_IO; use Ada.Text_IO;
with Synchronization.Generic_Mutexes_Array;
procedure Test_Dining_Philosophers is
type Philosopher is (Aristotle, Kant, Spinoza, Marx, Russel);
package Fork_Arrays is new Synchronization.Generic_Mut... |
Translate the given Java code snippet into Ada without altering its behavior. | import java.util.*;
public class Game24 {
static Random r = new Random();
public static void main(String[] args) {
int[] digits = randomDigits();
Scanner in = new Scanner(System.in);
System.out.print("Make 24 using these digits: ");
System.out.println(Arrays.toString(digits))... | with Ada.Float_Text_IO;
with Ada.Text_IO;
with Ada.Numerics.Discrete_Random;
procedure Game_24 is
subtype Digit is Character range '1' .. '9';
package Random_Digit is new Ada.Numerics.Discrete_Random (Digit);
Exp_Error : exception;
Digit_Generator : Random_Digit.Generator;
Given_Digits : array (1 .. 4) o... |
Maintain the same structure and functionality when rewriting this code in Ada. | import java.util.*;
public class Game24 {
static Random r = new Random();
public static void main(String[] args) {
int[] digits = randomDigits();
Scanner in = new Scanner(System.in);
System.out.print("Make 24 using these digits: ");
System.out.println(Arrays.toString(digits))... | with Ada.Float_Text_IO;
with Ada.Text_IO;
with Ada.Numerics.Discrete_Random;
procedure Game_24 is
subtype Digit is Character range '1' .. '9';
package Random_Digit is new Ada.Numerics.Discrete_Random (Digit);
Exp_Error : exception;
Digit_Generator : Random_Digit.Generator;
Given_Digits : array (1 .. 4) o... |
Convert the following code from Java to Ada, ensuring the logic remains intact. | final int immutableInt = 4;
int mutableInt = 4;
mutableInt = 6;
immutableInt = 6;
| Foo : constant := 42;
Foo : constant Blahtype := Blahvalue;
|
Produce a language-to-language conversion: from Java to Ada, same semantics. | import java.util.LinkedList;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class StrangeNumbers {
private static List<Integer> digits(int n) {
var result = new LinkedList<Integer>();
while (n > 0) {
... | with Ada.Text_IO; use Ada.Text_IO;
procedure Strange_Numbers is
function Is_Strange (A : Natural) return Boolean is
Last : Natural := A mod 10;
Reminder : Natural := A / 10;
Current : Natural;
begin
while Reminder /= 0 loop
Current := Reminder mod 10;
exit when abs... |
Ensure the translated Ada code behaves exactly like the original Java snippet. | import java.util.LinkedList;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class StrangeNumbers {
private static List<Integer> digits(int n) {
var result = new LinkedList<Integer>();
while (n > 0) {
... | with Ada.Text_IO; use Ada.Text_IO;
procedure Strange_Numbers is
function Is_Strange (A : Natural) return Boolean is
Last : Natural := A mod 10;
Reminder : Natural := A / 10;
Current : Natural;
begin
while Reminder /= 0 loop
Current := Reminder mod 10;
exit when abs... |
Translate the given Java code snippet into Ada without altering its behavior. | import java.util.HashMap;
import java.util.Map;
public class HofQ {
private static Map<Integer, Integer> q = new HashMap<Integer, Integer>(){{
put(1, 1);
put(2, 1);
}};
private static int[] nUses = new int[100001];
public static int Q(int n){
nUses[n]++;
if(q.containsKey(n)){
return q.get(n);
}
... | with Ada.Text_IO;
procedure Hofstadter_Q_Sequence is
type Callback is access procedure(N: Positive);
procedure Q(First, Last: Positive; Q_Proc: Callback) is
Q_Store: array(1 .. Last) of Natural := (1 => 1, 2 => 1, others => 0);
function Q(N: Positive) return Positive ... |
Port the following code from Java to Ada with equivalent syntax and logic. | import java.util.HashMap;
import java.util.Map;
public class HofQ {
private static Map<Integer, Integer> q = new HashMap<Integer, Integer>(){{
put(1, 1);
put(2, 1);
}};
private static int[] nUses = new int[100001];
public static int Q(int n){
nUses[n]++;
if(q.containsKey(n)){
return q.get(n);
}
... | with Ada.Text_IO;
procedure Hofstadter_Q_Sequence is
type Callback is access procedure(N: Positive);
procedure Q(First, Last: Positive; Q_Proc: Callback) is
Q_Store: array(1 .. Last) of Natural := (1 => 1, 2 => 1, others => 0);
function Q(N: Positive) return Positive ... |
Rewrite this program in Ada while keeping its functionality equivalent to the Java version. | public class CountSubstring {
public static int countSubstring(String subStr, String str){
return (str.length() - str.replace(subStr, "").length()) / subStr.length();
}
public static void main(String[] args){
System.out.println(countSubstring("th", "the three truths"));
System.out.println(countSubstring("aba... | with Ada.Strings.Fixed, Ada.Integer_Text_IO;
procedure Substrings is
begin
Ada.Integer_Text_IO.Put (Ada.Strings.Fixed.Count (Source => "the three truths",
Pattern => "th"));
Ada.Integer_Text_IO.Put (Ada.Strings.Fixed.Count (Source => "ababababab",
... |
Convert the following code from Java to Ada, ensuring the logic remains intact. | import java.util.List;
import java.util.function.Function;
public class LogisticCurveFitting {
private static final double K = 7.8e9;
private static final int N0 = 27;
private static final List<Double> ACTUAL = List.of(
27.0, 27.0, 27.0, 44.0, 44.0, 59.0, 59.0, 59.0, 59.0, 59.0, 59.0, 59.0, 59.0, ... | with Ada.Text_Io;
with Ada.Numerics.Generic_Elementary_Functions;
procedure Curve_Fitting is
type Real is new Long_Float;
type Fuction_Access is access function (X : Real) return Real;
type Time_Type is new Natural;
package Real_Io is new Ada.Text_Io.Float_Io (Real);
package Math is new Ada.Numerics.... |
Translate this program into Ada but keep the logic exactly as in Java. | import javax.swing.*;
public class GetInputSwing {
public static void main(String[] args) throws Exception {
int number = Integer.parseInt(
JOptionPane.showInputDialog ("Enter an Integer"));
String string = JOptionPane.showInputDialog ("Enter a String");
}
}
| with Gtk.Button; use Gtk.Button;
with Gtk.GEntry; use Gtk.GEntry;
with Gtk.Label; use Gtk.Label;
with Gtk.Window; use Gtk.Window;
with Gtk.Widget; use Gtk.Widget;
with Gtk.Table; use Gtk.Table;
with Gtk.Handlers;
with Gtk.Main;
procedure Graphic_Input is
Window : Gtk_Window;
Grid : Gtk_Tnetable;
... |
Port the provided Java code into Ada while preserving the original functionality. | public class Test {
static int mod(int n, int m) {
return ((n % m) + m) % m;
}
static boolean isPrime(int n) {
if (n == 2 || n == 3)
return true;
else if (n < 2 || n % 2 == 0 || n % 3 == 0)
return false;
for (int div = 5, inc = 2; Math.pow(div, 2) <=... | with Ada.Text_IO, Miller_Rabin;
procedure Nemesis is
type Number is range 0 .. 2**40-1;
function Is_Prime(N: Number) return Boolean is
package MR is new Miller_Rabin(Number); use MR;
begin
return MR.Is_Prime(N) = Probably_Prime;
end Is_Prime;
begin
for P1 in Number(2) .. 61 loop
if... |
Translate the given Java code snippet into Ada without altering its behavior. | import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class PascalsTrianglePuzzle {
public static void main(String[] args) {
Matrix mat = new Matrix(Arrays.asList(1d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, -1d, 0d, 0d),
Arrays.asList(0d, 1d, 0d, 0d, 0d, 0... | with Ada.Text_IO; use Ada.Text_IO;
procedure Pyramid_of_Numbers is
B_X, B_Y, B_Z : Integer := 0;
type Block_Value is record
Known : Integer := 0;
X, Y, Z : Integer := 0;
end record;
X : constant Block_Value := (0, 1, 0, 0);
Y : constant Block_Value := (0, 0, 1, 0);
Z : constant Bloc... |
Please provide an equivalent version of this Java code in Ada. | import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class PascalsTrianglePuzzle {
public static void main(String[] args) {
Matrix mat = new Matrix(Arrays.asList(1d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, -1d, 0d, 0d),
Arrays.asList(0d, 1d, 0d, 0d, 0d, 0... | with Ada.Text_IO; use Ada.Text_IO;
procedure Pyramid_of_Numbers is
B_X, B_Y, B_Z : Integer := 0;
type Block_Value is record
Known : Integer := 0;
X, Y, Z : Integer := 0;
end record;
X : constant Block_Value := (0, 1, 0, 0);
Y : constant Block_Value := (0, 0, 1, 0);
Z : constant Bloc... |
Translate this program into Ada but keep the logic exactly as in Java. | import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
public class FractalTree extends JFrame {
public FractalTree() {
super("Fractal Tree");
setBounds(100, 100, 800, 600);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private void d... | with Ada.Numerics.Elementary_Functions;
with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Video.Rectangles;
with SDL.Events.Events;
procedure Fractal_Tree is
Width : constant := 600;
Height : constant := 600;
Level : constant := 13;
Length : constant := 130.0;
X_Start : co... |
Please provide an equivalent version of this Java code in Ada. | import java.util.Arrays;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Random;
public class RPS {
public enum Item{
ROCK, PAPER, SCISSORS, ;
public List<Item> losesToList;
public boolean losesTo(Item other) {
return losesToList.contains(othe... | with Ada.Text_IO; with Ada.Numerics.Float_Random;
procedure Rock_Paper_Scissors is
package Rand renames Ada.Numerics.Float_Random;
Gen: Rand.Generator;
type Choice is (Rock, Paper, Scissors);
Cnt: array (Choice) of Natural := (1, 1, 1);
function Computer_Choice return Choice is
... |
Transform the following Java implementation into Ada, maintaining the same output and logic. | import java.math.BigInteger;
import java.util.Locale;
public class BenfordsLaw {
private static BigInteger[] generateFibonacci(int n) {
BigInteger[] fib = new BigInteger[n];
fib[0] = BigInteger.ONE;
fib[1] = BigInteger.ONE;
for (int i = 2; i < fib.length; i++) {
fib[i] ... | with Ada.Text_IO, Ada.Numerics.Generic_Elementary_Functions;
procedure Benford is
subtype Nonzero_Digit is Natural range 1 .. 9;
function First_Digit(S: String) return Nonzero_Digit is
(if S(S'First) in '1' .. '9'
then Nonzero_Digit'Value(S(S'First .. S'First))
else First_Digit(S(S'... |
Convert the following code from Java to Ada, ensuring the logic remains intact. | import java.math.BigInteger;
import java.util.Locale;
public class BenfordsLaw {
private static BigInteger[] generateFibonacci(int n) {
BigInteger[] fib = new BigInteger[n];
fib[0] = BigInteger.ONE;
fib[1] = BigInteger.ONE;
for (int i = 2; i < fib.length; i++) {
fib[i] ... | with Ada.Text_IO, Ada.Numerics.Generic_Elementary_Functions;
procedure Benford is
subtype Nonzero_Digit is Natural range 1 .. 9;
function First_Digit(S: String) return Nonzero_Digit is
(if S(S'First) in '1' .. '9'
then Nonzero_Digit'Value(S(S'First .. S'First))
else First_Digit(S(S'... |
Ensure the translated Ada code behaves exactly like the original Java snippet. | import java.math.*;
public class Hickerson {
final static String LN2 = "0.693147180559945309417232121458";
public static void main(String[] args) {
for (int n = 1; n <= 17; n++)
System.out.printf("%2s is almost integer: %s%n", n, almostInteger(n));
}
static boolean almostInteger(... | with Ada.Text_IO;
with Ada.Numerics.Generic_Elementary_Functions;
procedure Almost_Integers is
type Real is new Long_Long_Float;
package Real_IO is
new Ada.Text_IO.Float_IO (Real);
package Integer_IO is
new Ada.Text_IO.Integer_IO (Integer);
function Faculty (N : in Long_Long_Integer) return ... |
Rewrite the snippet below in Ada so it works the same as the original Java code. | import java.math.*;
public class Hickerson {
final static String LN2 = "0.693147180559945309417232121458";
public static void main(String[] args) {
for (int n = 1; n <= 17; n++)
System.out.printf("%2s is almost integer: %s%n", n, almostInteger(n));
}
static boolean almostInteger(... | with Ada.Text_IO;
with Ada.Numerics.Generic_Elementary_Functions;
procedure Almost_Integers is
type Real is new Long_Long_Float;
package Real_IO is
new Ada.Text_IO.Float_IO (Real);
package Integer_IO is
new Ada.Text_IO.Integer_IO (Integer);
function Faculty (N : in Long_Long_Integer) return ... |
Preserve the algorithm and functionality while converting the code from Java to Ada. | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ConfigReader {
private static final Pattern LINE_PATTERN = Pattern.... | with Config; use Config;
with Ada.Text_IO; use Ada.Text_IO;
procedure Rosetta_Read_Cfg is
cfg: Configuration:= Init("rosetta_read.cfg", Case_Sensitive => False, Variable_Terminator => ' ');
fullname : String := cfg.Value_Of("*", "fullname");
favouritefruit : String := cfg.Value_Of("*", "favouritefruit");... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.