Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Ensure the translated Pascal code behaves exactly like the original C snippet. | #include <stdio.h>
#include <stdbool.h>
bool isPrime(int n) {
int d;
if (n < 2) return false;
if (!(n%2)) return n == 2;
if (!(n%3)) return n == 3;
d = 5;
while (d*d <= n) {
if (!(n%d)) return false;
d += 2;
if (!(n%d)) return false;
d += 4;
}
return tru... | program NextSpecialprimes;
uses
sysutils,
primTrial;
procedure GetIncreasingGaps;
var
Gap,LastPrime,p : NativeUInt;
Begin
InitPrime;
Writeln('next increasing prime gap');
writeln('Prime1':8,'Prime2':8,'Gap':4);
Gap := 0;
LastPrime := actPrime;
repeat
p := NextPrime;
if p-LastPrime > Gap the... |
Keep all operations the same but rewrite the snippet in Pascal. | #include <stdio.h>
#include <stdbool.h>
bool isPrime(int n) {
int d;
if (n < 2) return false;
if (!(n%2)) return n == 2;
if (!(n%3)) return n == 3;
d = 5;
while (d*d <= n) {
if (!(n%d)) return false;
d += 2;
if (!(n%d)) return false;
d += 4;
}
return tru... | program NextSpecialprimes;
uses
sysutils,
primTrial;
procedure GetIncreasingGaps;
var
Gap,LastPrime,p : NativeUInt;
Begin
InitPrime;
Writeln('next increasing prime gap');
writeln('Prime1':8,'Prime2':8,'Gap':4);
Gap := 0;
LastPrime := actPrime;
repeat
p := NextPrime;
if p-LastPrime > Gap the... |
Write a version of this C function in Pascal with identical behavior. | #include <stdio.h>
unsigned modpow(unsigned b, unsigned e, unsigned m)
{
unsigned p;
for (p = 1; e; e >>= 1) {
if (e & 1)
p = p * b % m;
b = b * b % m;
}
return p;
}
int is_deceptive(unsigned n)
{
unsigned x;
if (n & 1 && n % 3 && n % 5) {
for (x = 7; x * x ... | program DeceptiveNumbers;
uses
sysutils;
const
LIMIT = 100000;
RepInitLen = 13;
DecimalDigits = 10*1000*1000*1000*1000;
RepLimit = (DecimalDigits-1)DIV 9;
type
tmyUint64 = array[0..Limit DIV RepInitLen+1] of Uint64;
var
K: tmyUint64;
MaxKIdx : Int32;
procedure OutK(const K:tmyUint64);
var... |
Convert the following code from C to Pascal, ensuring the logic remains intact. | #include <stdio.h>
unsigned modpow(unsigned b, unsigned e, unsigned m)
{
unsigned p;
for (p = 1; e; e >>= 1) {
if (e & 1)
p = p * b % m;
b = b * b % m;
}
return p;
}
int is_deceptive(unsigned n)
{
unsigned x;
if (n & 1 && n % 3 && n % 5) {
for (x = 7; x * x ... | program DeceptiveNumbers;
uses
sysutils;
const
LIMIT = 100000;
RepInitLen = 13;
DecimalDigits = 10*1000*1000*1000*1000;
RepLimit = (DecimalDigits-1)DIV 9;
type
tmyUint64 = array[0..Limit DIV RepInitLen+1] of Uint64;
var
K: tmyUint64;
MaxKIdx : Int32;
procedure OutK(const K:tmyUint64);
var... |
Port the provided C code into Pascal while preserving the original functionality. | #include<stdlib.h>
#include<stdio.h>
#include<time.h>
void sattoloCycle(void** arr,int count){
int i,j;
void* temp;
if(count<2)
return;
for(i=count-1;i>=1;i--){
j = rand()%i;
temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
int main(int argC,char* argV[])
{
int i;
if(argC==1)
printf("Usage : ... | program sattolocycle;
uses math;
var
a:Array of cardinal = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19];
i,j:integer;
t:cardinal;
begin
randomize;
i := length(a);
while i > 1 do
begin
dec(i);
j :=randomrange(0,i);
t:=a[i];a[i]:=a[j];a[j]:=t;
write(a[i]:4);
end;
writeln;
end.... |
Write the same code in Pascal as shown below in C. | #include<stdlib.h>
#include<stdio.h>
#include<time.h>
void sattoloCycle(void** arr,int count){
int i,j;
void* temp;
if(count<2)
return;
for(i=count-1;i>=1;i--){
j = rand()%i;
temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
int main(int argC,char* argV[])
{
int i;
if(argC==1)
printf("Usage : ... | program sattolocycle;
uses math;
var
a:Array of cardinal = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19];
i,j:integer;
t:cardinal;
begin
randomize;
i := length(a);
while i > 1 do
begin
dec(i);
j :=randomrange(0,i);
t:=a[i];a[i]:=a[j];a[j]:=t;
write(a[i]:4);
end;
writeln;
end.... |
Port the provided C code into Pascal while preserving the original functionality. | #include <stdio.h>
typedef char bool;
#define TRUE 1
#define FALSE 0
bool same_digits(int n, int b) {
int f = n % b;
n /= b;
while (n > 0) {
if (n % b != f) return FALSE;
n /= b;
}
return TRUE;
}
bool is_brazilian(int n) {
int b;
if (n < 7) return FALSE;
if (!(n % 2) ... | program brazilianNumbers;
uses
SysUtils;
const
PrimeMarker = 0;
SquareMarker = PrimeMarker + 1;
MAX = 1053421821;
var
isprime: array of word;
procedure MarkSmallestFactor;
var
i, j, lmt: NativeUint;
begin
lmt := High(isPrime);
fillWord(isPrime[0], lmt + 1... |
Generate an equivalent Pascal version of this C code. | #include <stdio.h>
typedef char bool;
#define TRUE 1
#define FALSE 0
bool same_digits(int n, int b) {
int f = n % b;
n /= b;
while (n > 0) {
if (n % b != f) return FALSE;
n /= b;
}
return TRUE;
}
bool is_brazilian(int n) {
int b;
if (n < 7) return FALSE;
if (!(n % 2) ... | program brazilianNumbers;
uses
SysUtils;
const
PrimeMarker = 0;
SquareMarker = PrimeMarker + 1;
MAX = 1053421821;
var
isprime: array of word;
procedure MarkSmallestFactor;
var
i, j, lmt: NativeUint;
begin
lmt := High(isPrime);
fillWord(isPrime[0], lmt + 1... |
Ensure the translated Pascal code behaves exactly like the original C snippet. | #include <stdio.h>
int main() {
int n, b, d;
unsigned long long i, j, sum, fact[12];
fact[0] = 1;
for (n = 1; n < 12; ++n) {
fact[n] = fact[n-1] * n;
}
for (b = 9; b <= 12; ++b) {
printf("The factorions for base %d are:\n", b);
for (i = 1; i < 1500000; ++i) {
... | program munchhausennumber;
uses
sysutils;
type
tdigit = byte;
const
MAXBASE = 17;
var
DgtPotDgt : array[0..MAXBASE-1] of NativeUint;
dgtCnt : array[0..MAXBASE-1] of NativeInt;
cnt: NativeUint;
function convertToString(n:NativeUint;base:byte):AnsiString;
const
cBASEDIGITS = '0123456789ABCDEFGHIJKLMNOPQ... |
Convert this C block to Pascal, preserving its control flow and logic. | #include <stdio.h>
int main() {
int n, b, d;
unsigned long long i, j, sum, fact[12];
fact[0] = 1;
for (n = 1; n < 12; ++n) {
fact[n] = fact[n-1] * n;
}
for (b = 9; b <= 12; ++b) {
printf("The factorions for base %d are:\n", b);
for (i = 1; i < 1500000; ++i) {
... | program munchhausennumber;
uses
sysutils;
type
tdigit = byte;
const
MAXBASE = 17;
var
DgtPotDgt : array[0..MAXBASE-1] of NativeUint;
dgtCnt : array[0..MAXBASE-1] of NativeInt;
cnt: NativeUint;
function convertToString(n:NativeUint;base:byte):AnsiString;
const
cBASEDIGITS = '0123456789ABCDEFGHIJKLMNOPQ... |
Change the programming language of this snippet from C to Pascal without modifying what it does. | #include <stdio.h>
unsigned int divisor_sum(unsigned int n) {
unsigned int total = 1, power = 2;
unsigned int p;
for (; (n & 1) == 0; power <<= 1, n >>= 1) {
total += power;
}
for (p = 3; p * p <= n; p += 2) {
unsigned int sum = 1;
for (power = p; n % p == 0; powe... | program Sum_of_divisors;
}
uses
System.SysUtils;
function DivisorSum(n: Cardinal): Cardinal;
var
i,quot,total: Cardinal;
begin
total :=n+1;
i := 2;
repeat
quot := n div i;
if quot <= i then
BREAK;
if quot*i = n then
inc(total,i+quot);
inc(i);
until false;
if i... |
Rewrite this program in Pascal while keeping its functionality equivalent to the C version. | #include <stdio.h>
unsigned int divisor_sum(unsigned int n) {
unsigned int total = 1, power = 2;
unsigned int p;
for (; (n & 1) == 0; power <<= 1, n >>= 1) {
total += power;
}
for (p = 3; p * p <= n; p += 2) {
unsigned int sum = 1;
for (power = p; n % p == 0; powe... | program Sum_of_divisors;
}
uses
System.SysUtils;
function DivisorSum(n: Cardinal): Cardinal;
var
i,quot,total: Cardinal;
begin
total :=n+1;
i := 2;
repeat
quot := n div i;
if quot <= i then
BREAK;
if quot*i = n then
inc(total,i+quot);
inc(i);
until false;
if i... |
Write the same code in Pascal as shown below in C. | #include <stdio.h>
#include <stdlib.h>
void bead_sort(int *a, int len)
{
int i, j, max, sum;
unsigned char *beads;
# define BEAD(i, j) beads[i * max + j]
for (i = 1, max = a[0]; i < len; i++)
if (a[i] > max) max = a[i];
beads = calloc(1, max * len);
for (i = 0; i < len; i++)
for (j = 0; j < a[i]; j++)
... | program BDS;
const MAX = 1000;
type
type_matrix = record
lin,col:integer;
matrix: array [1..MAX,1..MAX] of boolean;
end;
type_vector = record
size:integer;
vector: array[1..MAX] of integer;
end;
procedure BeadSort(var v:type_vector);
var
i,j,k,sum:integer;
m:type_matrix;
begin
m.lin:=... |
Write the same code in Pascal as shown below in C. | #include <stdio.h>
#include <math.h>
int main() {
const int N = 2;
int base = 10;
int c1 = 0;
int c2 = 0;
int k;
for (k = 1; k < pow(base, N); k++) {
c1++;
if (k % (base - 1) == (k * k) % (base - 1)) {
c2++;
printf("%d ", k);
}
}
printf(... | program castout9;
uses generics.collections;
type
TIntegerList = TSortedList<integer>;
procedure co9(const start,base,lim:integer;kaprekars:array of integer);
var
C1:integer = 0;
C2:integer = 0;
S:TIntegerlist;
k,i:integer;
begin
S:=TIntegerlist.Create;
for k := start to lim do
begin
inc(C1);
... |
Maintain the same structure and functionality when rewriting this code in Pascal. | #include <stdio.h>
#include <math.h>
int main() {
const int N = 2;
int base = 10;
int c1 = 0;
int c2 = 0;
int k;
for (k = 1; k < pow(base, N); k++) {
c1++;
if (k % (base - 1) == (k * k) % (base - 1)) {
c2++;
printf("%d ", k);
}
}
printf(... | program castout9;
uses generics.collections;
type
TIntegerList = TSortedList<integer>;
procedure co9(const start,base,lim:integer;kaprekars:array of integer);
var
C1:integer = 0;
C2:integer = 0;
S:TIntegerlist;
k,i:integer;
begin
S:=TIntegerlist.Create;
for k := start to lim do
begin
inc(C1);
... |
Keep all operations the same but rewrite the snippet in Pascal. | void runCode(const char *code)
{
int c_len = strlen(code);
int i, bottles;
unsigned accumulator=0;
for(i=0;i<c_len;i++)
{
switch(code[i])
{
case 'Q':
printf("%s\n", code);
break;
case 'H':
printf("Hello, world!\... | program HQ9;
procedure runCode(code: string);
var
c_len, i, bottles: Integer;
accumulator: Cardinal;
begin
c_len := Length(code);
accumulator := 0;
for i := 1 to c_len do
begin
case code[i] of
'Q','q':
writeln(code);
'H','h':
Writeln('Hello, world!');
'9':
begi... |
Produce a language-to-language conversion: from C to Pascal, same semantics. | #include <stdio.h>
unsigned int divisor_count(unsigned int n) {
unsigned int total = 1;
for (; (n & 1) == 0; n >>= 1) {
++total;
}
for (unsigned int p = 3; p * p <= n; p += 2) {
unsigned int count = 1;
for (; n % p == 0; n /= p) {
++count;
}
... | begin % find the count of the divisors of the first 100 positive integers %
% calculates the number of divisors of v %
integer procedure divisor_count( integer value v ) ; begin
integer total, n, p;
total := 1; n := v;
% Deal with powers of 2 first %
... |
Please provide an equivalent version of this C code in Pascal. | #include <stdio.h>
unsigned int divisor_count(unsigned int n) {
unsigned int total = 1;
for (; (n & 1) == 0; n >>= 1) {
++total;
}
for (unsigned int p = 3; p * p <= n; p += 2) {
unsigned int count = 1;
for (; n % p == 0; n /= p) {
++count;
}
... | begin % find the count of the divisors of the first 100 positive integers %
% calculates the number of divisors of v %
integer procedure divisor_count( integer value v ) ; begin
integer total, n, p;
total := 1; n := v;
% Deal with powers of 2 first %
... |
Ensure the translated Pascal code behaves exactly like the original C snippet. | #include <stdio.h>
int main(){
int ptr=0, i=0, cell[7];
for( i=0; i<7; ++i) cell[i]=0;
ptr+= 1;
if(ptr>=7) perror("Program pointer overflow");
cell[ptr]+= 8;
while(cell[ptr])
{
ptr-= 1;
if(ptr<0) perror("Program pointer underflow");
cell[ptr]+= 9;
... | program rcExceuteBrainF;
uses
Crt;
Const
DataSize= 1024;
MaxNest= 1000;
procedure ExecuteBF(Source: string);
var
Dp: pByte;
DataSeg: Pointer;
Ip: pChar;
Las... |
Write the same algorithm in Pascal as shown in this C implementation. | #include <stdio.h>
int main(){
int ptr=0, i=0, cell[7];
for( i=0; i<7; ++i) cell[i]=0;
ptr+= 1;
if(ptr>=7) perror("Program pointer overflow");
cell[ptr]+= 8;
while(cell[ptr])
{
ptr-= 1;
if(ptr<0) perror("Program pointer underflow");
cell[ptr]+= 9;
... | program rcExceuteBrainF;
uses
Crt;
Const
DataSize= 1024;
MaxNest= 1000;
procedure ExecuteBF(Source: string);
var
Dp: pByte;
DataSeg: Pointer;
Ip: pChar;
Las... |
Convert this C snippet to Pascal and keep its semantics consistent. | #include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <locale.h>
uint64_t modPow(uint64_t base, uint64_t exp, uint64_t mod) {
if (mod == 1) return 0;
uint64_t result = 1;
base %= mod;
for (; exp > 0; exp >>= 1) {
if ((exp & 1) == 1) result = (result * base) % mod;
base = ... | program CurzonNumbers;
uses SysUtils;
const
MAX_CURZON_MEG = 100;
RC_LINE_LENGTH = 66;
procedure ListCurzonNumbers( base : integer);
var
k, n, m, x, testBit, maxCurzon : uint64;
nrHits : integer;
lineOut : string;
begin
maxCurzon := 1000000*MAX_CURZON_MEG;
k := uint64( base);
nrHits := 0;
n := 0;
W... |
Convert this C snippet to Pascal and keep its semantics consistent. | #include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <locale.h>
uint64_t modPow(uint64_t base, uint64_t exp, uint64_t mod) {
if (mod == 1) return 0;
uint64_t result = 1;
base %= mod;
for (; exp > 0; exp >>= 1) {
if ((exp & 1) == 1) result = (result * base) % mod;
base = ... | program CurzonNumbers;
uses SysUtils;
const
MAX_CURZON_MEG = 100;
RC_LINE_LENGTH = 66;
procedure ListCurzonNumbers( base : integer);
var
k, n, m, x, testBit, maxCurzon : uint64;
nrHits : integer;
lineOut : string;
begin
maxCurzon := 1000000*MAX_CURZON_MEG;
k := uint64( base);
nrHits := 0;
n := 0;
W... |
Rewrite this program in Pascal while keeping its functionality equivalent to the C version. | #include <stdio.h>
#include <stdlib.h>
int* mertens_numbers(int max) {
int* m = malloc((max + 1) * sizeof(int));
if (m == NULL)
return m;
m[1] = 1;
for (int n = 2; n <= max; ++n) {
m[n] = 1;
for (int k = 2; k <= n; ++k)
m[n] -= m[n/k];
}
return m;
}
int main... | program Merten;
uses
sysutils;
const
BigLimit = 10*1000*1000*1000;
type
tSieveElement = Int8;
tpSieve = pInt8;
tMoebVal = array[-1..1] of Int64;
var
MertensValues : array[-40000..50500] of NativeInt;
primes : array of byte;
sieve : array of tSieveElement;
procedure CompactPrimes;
var
... |
Write a version of this C function in Pascal with identical behavior. | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <locale.h>
#define LIMIT 1000000
#define LOWER_LIMIT 2500
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 = ... | var p, c, z, k, isprime, factk, iskchecked;
procedure checkprimality;
var i, isichecked;
begin
isprime := 0;
if z = 2 then isprime := 1;
if z >= 3 then
begin
i := 2; isichecked := 0;
while isichecked = 0 do
begin
if (z / i) * i = z then isichecked := 1;
if isichecked = 0 then
if... |
Convert the following code from C to Pascal, ensuring the logic remains intact. | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <locale.h>
#define LIMIT 1000000
#define LOWER_LIMIT 2500
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 = ... | var p, c, z, k, isprime, factk, iskchecked;
procedure checkprimality;
var i, isichecked;
begin
isprime := 0;
if z = 2 then isprime := 1;
if z >= 3 then
begin
i := 2; isichecked := 0;
while isichecked = 0 do
begin
if (z / i) * i = z then isichecked := 1;
if isichecked = 0 then
if... |
Port the provided C code into Pascal while preserving the original functionality. | main(){printf("Code Golf");}
| var a:QWord=$006F472065646F43;b:DWord=$0000666C;BEGIN write(pChar(@a),pChar(@b));END.
|
Change the programming language of this snippet from C to Pascal without modifying what it does. | main(){printf("Code Golf");}
| var a:QWord=$006F472065646F43;b:DWord=$0000666C;BEGIN write(pChar(@a),pChar(@b));END.
|
Produce a functionally identical Pascal code for the snippet given in C. | #include<stdlib.h>
#include<stdio.h>
long totient(long n){
long tot = n,i;
for(i=2;i*i<=n;i+=2){
if(n%i==0){
while(n%i==0)
n/=i;
tot-=tot/i;
}
if(i==2)
i=1;
}
if(n>1)
tot-=tot/n;
return tot;
}
long* perfectTotients(long n){
long *ptList = (long*)malloc(n*sizeof(long)), m,count=0,su... | program Perftotient;
uses
sysutils;
const
cLimit = 57395631;
var
TotientList : array of LongWord;
Sieve : Array of byte;
SolList : array of LongWord;
T1,T0 : INt64;
procedure SieveInit(svLimit:NativeUint);
var
pSieve:pByte;
i,j,pr :NativeUint;
Begin
svlimit := (svLimit+1) DIV 2;
setlength(si... |
Preserve the algorithm and functionality while converting the code from C to Pascal. | #include<stdlib.h>
#include<stdio.h>
long totient(long n){
long tot = n,i;
for(i=2;i*i<=n;i+=2){
if(n%i==0){
while(n%i==0)
n/=i;
tot-=tot/i;
}
if(i==2)
i=1;
}
if(n>1)
tot-=tot/n;
return tot;
}
long* perfectTotients(long n){
long *ptList = (long*)malloc(n*sizeof(long)), m,count=0,su... | program Perftotient;
uses
sysutils;
const
cLimit = 57395631;
var
TotientList : array of LongWord;
Sieve : Array of byte;
SolList : array of LongWord;
T1,T0 : INt64;
procedure SieveInit(svLimit:NativeUint);
var
pSieve:pByte;
i,j,pr :NativeUint;
Begin
svlimit := (svLimit+1) DIV 2;
setlength(si... |
Produce a language-to-language conversion: from C to Pascal, same semantics. | #include<stdio.h>
int main()
{
int arr[5] = {0, 2, 11, 19, 90},sum = 21,i,j,check = 0;
for(i=0;i<4;i++){
for(j=i+1;j<5;j++){
if(arr[i]+arr[j]==sum){
printf("[%d,%d]",i,j);
check = 1;
break;
}
}
}
if(check==0)
printf("[]");
return 0;
}
| program twosum;
uses
sysutils;
type
tSolRec = record
SolRecI,
SolRecJ : NativeInt;
end;
tMyArray = array of NativeInt;
const
ConstArray :array[-17..-13] of NativeInt = (0, 2, 11, 19, 90);
function Check2SumUnSorted(const A :tMyArray;
... |
Generate an equivalent Pascal version of this C code. | #include<stdio.h>
int main()
{
int arr[5] = {0, 2, 11, 19, 90},sum = 21,i,j,check = 0;
for(i=0;i<4;i++){
for(j=i+1;j<5;j++){
if(arr[i]+arr[j]==sum){
printf("[%d,%d]",i,j);
check = 1;
break;
}
}
}
if(check==0)
printf("[]");
return 0;
}
| program twosum;
uses
sysutils;
type
tSolRec = record
SolRecI,
SolRecJ : NativeInt;
end;
tMyArray = array of NativeInt;
const
ConstArray :array[-17..-13] of NativeInt = (0, 2, 11, 19, 90);
function Check2SumUnSorted(const A :tMyArray;
... |
Convert this C block to Pascal, preserving its control flow and logic. | #include <assert.h>
#include <locale.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct bit_array_tag {
uint32_t size;
uint32_t* array;
} bit_array;
bool bit_array_create(bit_array* b, uint32_t size) {
uint32_t* array = calloc((size + 31)/32, sizeof(uint32_t)... | program unprimable;
const
base = 10;
type
TNumVal = array[0..base-1] of NativeUint;
TConvNum = record
NumRest : TNumVal;
LowDgt,
MaxIdx : NativeUint;
end;
var
PotBase,
EndDgtFound : TNumVal;
TotalCnt,
EndDgtCnt :NativeUint;
procedure Init... |
Translate this program into Pascal but keep the logic exactly as in C. | #include <stdio.h>
unsigned int divisor_count(unsigned int n) {
unsigned int total = 1;
unsigned int p;
for (; (n & 1) == 0; n >>= 1) {
++total;
}
for (p = 3; p * p <= n; p += 2) {
unsigned int count = 1;
for (; n % p == 0; n /= p) {
++count;
}... | program Tau_number;
function CountDivisors(n: NativeUint): integer;
var
q, p, cnt, divcnt: NativeUint;
begin
divCnt := 1;
if n > 1 then
begin
cnt := 1;
while not (Odd(n)) do
begin
n := n shr 1;
divCnt+= cnt;
end;
p := 3;
while p * p <= n d... |
Change the following C code into Pascal without altering its purpose. | #include <stdbool.h>
#include <stdio.h>
bool is_prime(int n) {
int i = 5;
if (n < 2) {
return false;
}
if (n % 2 == 0) {
return n == 2;
}
if (n % 3 == 0) {
return n == 3;
}
while (i * i <= n) {
if (n % i == 0) {
return false;
}
... | program Perm5aus8;
uses
sysutils,
gmp;
const
cTotalSum = 31;
cMaxCardsOnDeck = cTotalSum;
CMaxCardsUsed = cTotalSum;
type
tDeckIndex = 0..cMaxCardsOnDeck-1;
tSequenceIndex = 0..CMaxCardsUsed-1;
tDiffCardCount = 0..9;
tSetElem = record
Elem : tDiffCardC... |
Write the same algorithm in Pascal as shown in this C implementation. | #include <stdbool.h>
#include <stdio.h>
bool is_prime(int n) {
int i = 5;
if (n < 2) {
return false;
}
if (n % 2 == 0) {
return n == 2;
}
if (n % 3 == 0) {
return n == 3;
}
while (i * i <= n) {
if (n % i == 0) {
return false;
}
... | program Perm5aus8;
uses
sysutils,
gmp;
const
cTotalSum = 31;
cMaxCardsOnDeck = cTotalSum;
CMaxCardsUsed = cTotalSum;
type
tDeckIndex = 0..cMaxCardsOnDeck-1;
tSequenceIndex = 0..CMaxCardsUsed-1;
tDiffCardCount = 0..9;
tSetElem = record
Elem : tDiffCardC... |
Port the following code from C to Pascal with equivalent syntax and logic. | #include <stdbool.h>
#include <stdio.h>
bool primeDigitsSum13(int n) {
int sum = 0;
while (n > 0) {
int r = n % 10;
switch (r) {
case 2:
case 3:
case 5:
case 7:
break;
default:
return false;
}
n /= 10;
sum +... | program PrimSumUpTo13;
uses
sysutils;
type
tDigits = array[0..3] of Uint32;
const
MAXNUM = 113;
var
gblPrimDgtCnt :tDigits;
gblCount: NativeUint;
function isPrime(n: NativeUint):boolean;
var
i : NativeUInt;
Begin
result := (n>1);
if n<4 then
EXIT;
result := false;
if n AND 1 = 0 then
... |
Can you help me rewrite this code in Pascal instead of C, keeping it the same logically? | #include <stdbool.h>
#include <stdio.h>
bool primeDigitsSum13(int n) {
int sum = 0;
while (n > 0) {
int r = n % 10;
switch (r) {
case 2:
case 3:
case 5:
case 7:
break;
default:
return false;
}
n /= 10;
sum +... | program PrimSumUpTo13;
uses
sysutils;
type
tDigits = array[0..3] of Uint32;
const
MAXNUM = 113;
var
gblPrimDgtCnt :tDigits;
gblCount: NativeUint;
function isPrime(n: NativeUint):boolean;
var
i : NativeUInt;
Begin
result := (n>1);
if n<4 then
EXIT;
result := false;
if n AND 1 = 0 then
... |
Ensure the translated Pascal code behaves exactly like the original C snippet. | #include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gmp.h>
bool is_prime(uint32_t n) {
if (n == 2)
return true;
if (n < 2 || n % 2 == 0)
return false;
for (uint32_t p = 3; p * p <= n; p += 2) {
if (n % p == 0)
ret... | program CircularPrimes;
uses
Sysutils,gmp;
uses
System.Sysutils,?gmp?;
const
MAXCNTOFDIGITS = 14;
MAXDGTVAL = 3;
conv : array[0..MAXDGTVAL+1] of byte = (9,7,3,1,0);
type
tDigits = array[0..23] of byte;
tUint64 = NativeUint;
var
mpz : mpz_t;
digits,
revDigits : tDigits;
C... |
Transform the following C implementation into Pascal, maintaining the same output and logic. | int meaning_of_life();
|
program ScriptedMain;
unit ScriptedMain;
interface
function MeaningOfLife () : integer;
implementation
function MeaningOfLife () : integer;
begin
MeaningOfLife := 42
end;
begin
write('Main: The meaning of life is: ');
writeln(MeaningOfLife())
end.
|
Can you help me rewrite this code in Pascal instead of C, keeping it the same logically? | int meaning_of_life();
|
program ScriptedMain;
unit ScriptedMain;
interface
function MeaningOfLife () : integer;
implementation
function MeaningOfLife () : integer;
begin
MeaningOfLife := 42
end;
begin
write('Main: The meaning of life is: ');
writeln(MeaningOfLife())
end.
|
Generate an equivalent Pascal version of this C code. | #include <stdbool.h>
#include <stdio.h>
bool is_prime(unsigned int n) {
if (n < 2) {
return false;
}
if (n % 2 == 0) {
return n == 2;
}
if (n % 3 == 0) {
return n == 3;
}
for (unsigned int p = 5; p * p <= n; p += 4) {
if (n % p == 0) {
return fals... | var n, sum, prime, i;
procedure sumdigitsofn;
var v, vover10;
begin
sum := 0;
v := n;
while v > 0 do begin
vover10 := v / 10;
sum := sum + ( v - ( vover10 * 10 ) );
v := vover10
end
end;
procedure isnprime;
var p;
begin
... |
Produce a functionally identical Pascal code for the snippet given in C. | #include <stdbool.h>
#include <stdio.h>
bool is_prime(unsigned int n) {
if (n < 2) {
return false;
}
if (n % 2 == 0) {
return n == 2;
}
if (n % 3 == 0) {
return n == 3;
}
for (unsigned int p = 5; p * p <= n; p += 4) {
if (n % p == 0) {
return fals... | var n, sum, prime, i;
procedure sumdigitsofn;
var v, vover10;
begin
sum := 0;
v := n;
while v > 0 do begin
vover10 := v / 10;
sum := sum + ( v - ( vover10 * 10 ) );
v := vover10
end
end;
procedure isnprime;
var p;
begin
... |
Port the provided C code into Pascal while preserving the original functionality. | #include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int days[] = {31,29,31,30,31,30,31,31,30,31,30,31};
int m, y, w;
if (argc < 2 || (y = atoi(argv[1])) <= 1752) return 1;
days[1] -= (y % 4) || (!(y % 100) && (y % 400));
w = y * 365 + 97 * (y - 1) / 400 + ... | program sundays;
Uses sysutils;
type
MonthLength = Array[1..13] of Integer;
procedure sund(y : Integer);
var
dt : TDateTime;
m,mm : Integer;
len : MonthLength;
begin
len[1] := 31; len[2] := 28; len[3] := 31; len[4] := 30;
len[5] := 31; len[6] := 30; len[7] := 31; len[8] := 31;
len[9] := 30; len[10] ... |
Preserve the algorithm and functionality while converting the code from C to Pascal. | #include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int days[] = {31,29,31,30,31,30,31,31,30,31,30,31};
int m, y, w;
if (argc < 2 || (y = atoi(argv[1])) <= 1752) return 1;
days[1] -= (y % 4) || (!(y % 100) && (y % 400));
w = y * 365 + 97 * (y - 1) / 400 + ... | program sundays;
Uses sysutils;
type
MonthLength = Array[1..13] of Integer;
procedure sund(y : Integer);
var
dt : TDateTime;
m,mm : Integer;
len : MonthLength;
begin
len[1] := 31; len[2] := 28; len[3] := 31; len[4] := 30;
len[5] := 31; len[6] := 30; len[7] := 31; len[8] := 31;
len[9] := 30; len[10] ... |
Write the same code in Pascal as shown below in C. | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int randInt(int low, int high) {
return (rand() % (high - low)) + low;
}
void shuffle(int *const array, const int n) {
if (n > 1) {
int i;
for (i = 0; i < n - 1; i++) {
int j = randI... |
const
Alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
Type
IncidenceCube = Array of Array Of Array of Integer;
Var
Cube : IncidenceCube;
DIM : Integer;
Procedure InitIncidenceCube(Var c:IncidenceCube; const Size:Integer);
var i, j, k : integer;
begin
DIM := Size;
SetLength(c,DIM,DIM,DIM);
for i := 0 to DIM-1 do
for j :... |
Produce a functionally identical Pascal code for the snippet given in C. | #include <stdio.h>
#include <string.h>
#include <locale.h>
typedef int bool;
typedef unsigned long long ull;
#define TRUE 1
#define FALSE 0
char as_digit(int d) {
return (d >= 0 && d <= 9) ? d + '0' : d - 10 + 'a';
}
void revstr(char *str) {
int i, len = strlen(str);
char t;
for (i = 0; i < le... | program Esthetic;
uses
sysutils,
strutils;
const
ConvBase :array[0..15] of char= '0123456789ABCDEF';
maxBase = 16;
type
tErg = string[63];
tCnt = array[0..maxBase-1] of UInt64;
tDgtcnt = array[0..64] of tCnt;
var
Dgtcnt :tDgtcnt;
procedure CalcDgtCnt(base:NativeInt;var Dgtcnt :tDgtcnt);
v... |
Transform the following C implementation into Pascal, maintaining the same output and logic. | #include <stdio.h>
#include <stdlib.h>
#include <time.h>
int compareInts(const void *i1, const void *i2) {
int a = *((int *)i1);
int b = *((int *)i2);
return a - b;
}
int main() {
int i, j, nsum, vsum, vcount, values[6], numbers[4];
srand(time(NULL));
for (;;) {
vsum = 0;
for (... | program attributes;
var
total, roll,score, count: integer;
atribs : array [1..6] of integer;
begin
randomize;
repeat
count:=0;
total:=0;
for score :=1 to 6 do begin
for diceroll:=1 to 4 do dice[diceroll]:=random(6)+1;
lowroll:=... |
Maintain the same structure and functionality when rewriting this code in Pascal. | #include <stdio.h>
#include <stdlib.h>
struct node {
int val, len;
struct node *next;
};
void lis(int *v, int len)
{
int i;
struct node *p, *n = calloc(len, sizeof *n);
for (i = 0; i < len; i++)
n[i].val = v[i];
for (i = len; i--; ) {
for (p = n + i; p++ < n + len; ) {
if (p->val > n[i].val && p->len... | program LisDemo;
uses
SysUtils;
function Lis(const A: array of Integer): specialize TArray<Integer>;
var
TailIndex: array of Integer;
function CeilIndex(Value, R: Integer): Integer;
var
L, M: Integer;
begin
L := 0;
while L < R do begin
M := (L + R) shr 1;
if A[TailIndex[M]] < Value t... |
Write the same code in Pascal as shown below in C. | #include <stdio.h>
#include <stdbool.h>
int digit_sum(int n) {
int sum;
for (sum = 0; n; n /= 10) sum += n % 10;
return sum;
}
bool prime(int n) {
if (n<4) return n>=2;
for (int d=2; d*d <= n; d++)
if (n%d == 0) return false;
return true;
}
int main() {
for (int i=1; i<100; i++)
... | const maxnumber = 99;
var n, sum, prime, i, i2, i3;
procedure sumdigitsofn;
var v, vover10;
begin
sum := 0;
v := n;
while v > 0 do begin
vover10 := v / 10;
sum := sum + ( v - ( vover10 * 10 ) );
v := vover10
end
end;
procedure isnprime;... |
Write a version of this C function in Pascal with identical behavior. | #include <stdio.h>
#include <wchar.h>
#include <stdlib.h>
#include <locale.h>
int main(void)
{
char *locale = setlocale(LC_ALL, "");
FILE *in = fopen("input.txt", "r");
wint_t c;
while ((c = fgetwc(in)) != WEOF)
putwchar(c);
fclose(in);
return EXIT_SUCCESS;
}
|
program ReadFileByChar;
var
InputFile,OutputFile: file of char;
InputChar: char;
begin
Assign(InputFile, 'testin.txt');
Reset(InputFile);
Assign(OutputFile, 'testout.txt');
Rewrite(OutputFile);
while not Eof(InputFile) do
begin
Read(InputFile, InputChar... |
Convert the following code from C to Pascal, ensuring the logic remains intact. | #include <stdio.h>
int circle_sort_inner(int *start, int *end)
{
int *p, *q, t, swapped;
if (start == end) return 0;
for (swapped = 0, p = start, q = end; p<q || (p==q && ++q); p++, q--)
if (*p > *q)
t = *p, *p = *q, *q = t, swapped = 1;
return swapped | circle_sort_inner(start, q) | circle_sort_inner(... |
program sort;
var
a : array[0..999] of integer;
i : integer;
procedure circle_sort(var a : array of integer; left : integer; right : integer);
var swaps : integer;
procedure csinternal(var a : array of integer; left : integer; right : integer; var swaps : integer);
var
lo, hi, mid : integer;
... |
Please provide an equivalent version of this C code in Pascal. | #include <stdbool.h>
#include <stdio.h>
#define MAX_WORD 80
#define LETTERS 26
bool is_letter(char c) { return c >= 'a' && c <= 'z'; }
int index(char c) { return c - 'a'; }
void word_wheel(const char* letters, char central, int min_length, FILE* dict) {
int max_count[LETTERS] = { 0 };
for (const char* p = l... | program WordWheel;
uses
SysUtils;
const
WheelSize = 9;
MinLength = 3;
WordListFN = 'unixdict.txt';
procedure search(Wheel : string);
var
Allowed, Required, Available, w : string;
Len, i, p : integer;
WordFile : TextFile;
Match : boolean;
begin
AssignFile(WordFile, WordListFN);
try
Reset(Wor... |
Produce a functionally identical Pascal code for the snippet given in C. | #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SEQLEN 3
int getseq(char *s)
{
int r = 0;
int i = 1 << (SEQLEN - 1);
while (*s && i) {
switch (*s++) {
case 'H':
case 'h':
r |= i;
break;
case 'T':
case... | PROGRAM Penney;
TYPE
CoinToss = (heads, tails);
Sequence = array [1..3] of CoinToss;
Player = record
bet: Sequence;
score: integer;
end;
VAR
Human, Computer: Player;
Rounds, Count: integer;
Function TossCoin: CoinToss;
Begin
if random(2) = 1 then TossCoin := Heads
els... |
Maintain the same structure and functionality when rewriting this code in Pascal. | #include <stdio.h>
#include <string.h>
void nb(int cells, int total_block_size, int* blocks, int block_count,
char* output, int offset, int* count) {
if (block_count == 0) {
printf("%2d %s\n", ++*count, output);
return;
}
int block_size = blocks[0];
int max_pos = cells - (total... | program Nonoblock;
uses SysUtils;
function GetFirstSolution( var z : array of integer;
s : integer) : boolean;
var
j : integer;
begin
result := (s >= 0) and (High(z) >= 0);
if result then begin
j := High(z); z[j] := s;
while (j > 0) do begin
dec(j); z[j] :... |
Convert this C snippet to Pascal and keep its semantics consistent. | #include <stdio.h>
#include <string.h>
void nb(int cells, int total_block_size, int* blocks, int block_count,
char* output, int offset, int* count) {
if (block_count == 0) {
printf("%2d %s\n", ++*count, output);
return;
}
int block_size = blocks[0];
int max_pos = cells - (total... | program Nonoblock;
uses SysUtils;
function GetFirstSolution( var z : array of integer;
s : integer) : boolean;
var
j : integer;
begin
result := (s >= 0) and (High(z) >= 0);
if result then begin
j := High(z); z[j] := s;
while (j > 0) do begin
dec(j); z[j] :... |
Port the provided C code into Pascal while preserving the original functionality. | #include<stdio.h>
#include<conio.h>
#include<math.h>
#include<dos.h>
typedef struct{
char str[3];
int key;
}note;
note sequence[] = {{"Do",0},{"Re",2},{"Mi",4},{"Fa",5},{"So",7},{"La",9},{"Ti",11},{"Do",12}};
int main(void)
{
int i=0;
while(!kbhit())
{
printf("\t%s",sequence[i].str);
sound(261.63*pow(2,... |
uses windows,math;
var
Interval:Double = 1.0594630943592953;
i:integer;
begin
for i:= 0 to 11 do
beep(Round(440.0*interval**i),500);
end.
|
Change the programming language of this snippet from C to Pascal without modifying what it does. | #include<stdio.h>
#include<conio.h>
#include<math.h>
#include<dos.h>
typedef struct{
char str[3];
int key;
}note;
note sequence[] = {{"Do",0},{"Re",2},{"Mi",4},{"Fa",5},{"So",7},{"La",9},{"Ti",11},{"Do",12}};
int main(void)
{
int i=0;
while(!kbhit())
{
printf("\t%s",sequence[i].str);
sound(261.63*pow(2,... |
uses windows,math;
var
Interval:Double = 1.0594630943592953;
i:integer;
begin
for i:= 0 to 11 do
beep(Round(440.0*interval**i),500);
end.
|
Transform the following C implementation into Pascal, maintaining the same output and logic. | #include <stdio.h>
#include <stdlib.h>
typedef struct {
char *name;
int weight;
int value;
int count;
} item_t;
item_t items[] = {
{"map", 9, 150, 1},
{"compass", 13, 35, 1},
{"water", 153, 200, 2},
{"sandwich", ... | program KnapsackBounded;
uses
SysUtils, Math;
type
TItem = record
Name: string;
Weight, Value, Count: Integer;
end;
const
NUM_ITEMS = 22;
ITEMS: array[0..NUM_ITEMS-1] of TItem = (
(Name: 'map'; Weight: 9; Value: 150; Count: 1),
(Name: 'compass'; Weight: ... |
Convert this C block to Pascal, preserving its control flow and logic. | #include <stdio.h>
typedef struct node_t *node, node_t;
struct node_t { int v; node next; };
typedef struct { node head, tail; } slist;
void push(slist *l, node e) {
if (!l->head) l->head = e;
if (l->tail) l->tail->next = e;
l->tail = e;
}
node removehead(slist *l) {
node e = l->head;
if (e) {
l->head = e->n... | program StrandSortDemo;
type
TIntArray = array of integer;
function merge(left: TIntArray; right: TIntArray): TIntArray;
var
i, j, k: integer;
begin
setlength(merge, length(left) + length(right));
i := low(merge);
j := low(left);
k := low(right);
repeat
if ((left[j] <= right[k]) a... |
Produce a language-to-language conversion: from C to Pascal, same semantics. | #include<stdlib.h>
#include<string.h>
#include<stdio.h>
int main(int argc, char** argv)
{
int i,j,sandPileEdge, centerPileHeight, processAgain = 1,top,down,left,right;
int** sandPile;
char* fileName;
static unsigned char colour[3];
if(argc!=3){
printf("Usage: %s <Sand pile side> <Center pile height>",argv[0])... | program Abelian2;
uses
SysUtils;
type
Tlimit = record
lmtLow,LmtHigh : LongWord;
end;
TRowlimits = array of Tlimit;
tOneRow = pLongWord;
tGrid = array of LongWord;
var
Grid: tGrid;
Rowlimits:TRowlimits;
s : AnsiString;
maxval,maxCoor : NativeUint;
function CalcMax... |
Preserve the algorithm and functionality while converting the code from C to Pascal. | #include<stdlib.h>
#include<string.h>
#include<stdio.h>
int main(int argc, char** argv)
{
int i,j,sandPileEdge, centerPileHeight, processAgain = 1,top,down,left,right;
int** sandPile;
char* fileName;
static unsigned char colour[3];
if(argc!=3){
printf("Usage: %s <Sand pile side> <Center pile height>",argv[0])... | program Abelian2;
uses
SysUtils;
type
Tlimit = record
lmtLow,LmtHigh : LongWord;
end;
TRowlimits = array of Tlimit;
tOneRow = pLongWord;
tGrid = array of LongWord;
var
Grid: tGrid;
Rowlimits:TRowlimits;
s : AnsiString;
maxval,maxCoor : NativeUint;
function CalcMax... |
Write a version of this C function in Pascal with identical behavior. | void draw_line_antialias(
image img,
unsigned int x0, unsigned int y0,
unsigned int x1, unsigned int y1,
color_component r,
color_component g,
color_component b );
| program wu;
uses
SDL2,
math;
const
FPS = 1000 div 60;
SCALE = 6;
var
win: PSDL_Window;
ren: PSDL_Renderer;
mouse_x, mouse_y: longint;
origin: TSDL_Point;
event: TSDL_Event;
line_alpha: byte = 255;
procedure SDL_RenderDrawWuLine(renderer: PSDL_Renderer; x1, y1, x2, y2: longint);
var
r, g, b, a, ... |
Can you help me rewrite this code in Pascal instead of C, keeping it the same logically? | #include <stdio.h>
#include <sys/mman.h>
#include <string.h>
int test (int a, int b)
{
char code[] = {0x8B, 0x44, 0x24, 0x4, 0x3, 0x44, 0x24, 0x8, 0xC3};
void *buf;
int c;
buf = mmap (0,sizeof(code),PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_PRIVATE|MAP_ANON,-1,0);
memcpy (buf, code, sizeof(code... | Program Example66;
Uses
BaseUnix,Unix;
const
code : array[0..9] of byte = ($8B, $44, $24, $4, $3, $44, $24, $8, $C3, $00);
a :longInt= 12;
b :longInt= 7;
type
tDummyFunc = function(a,b:LongInt):LongInt;cdecl;
Var
Len,k : cint;
P : Pointer;
begin
len := sizeof(code);
P:= fpmmap(nil,
... |
Convert the following code from C to Pascal, ensuring the logic remains intact. | #include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
int trial, secs_tot=0, steps_tot=0;
int sbeh, slen, wiz, secs;
time_t t;
srand((unsigned) time(&t));
printf( "Seconds steps behind steps ahead\n" );
for( trial=1;trial<=10000;trial++ ... | program WizardStaircase;
const
StartStairLength = 100;
StairsPerSpell = 5;
rounds = 10000;
procedure OutActual(trials,behind,infront:longword);
begin
writeln(trials:5,infront+behind:12,behind:10,inFront:9);
end;
function OneRun(StairsPerSpell:Cardinal;WithOutput:boolean):longword;
var
inFront,behind,total,i... |
Transform the following C implementation into Pascal, maintaining the same output and logic. | #include<stdio.h>
#include<stdlib.h>
#define min(a, b) (a<=b?a:b)
void minab( unsigned int n ) {
int i, j;
for(i=0;i<n;i++) {
for(j=0;j<n;j++) {
printf( "%2d ", min( min(i, n-1-i), min(j, n-1-j) ));
}
printf( "\n" );
}
return;
}
int main(void) {
minab(10);
... | program mindistance;
uses
sysutils
,Windows
;
type
tMinDist = array of Uint32;
tpMinDist= pUint32;
var
dgtwidth : NativeUint;
OneRowElems : tMinDist;
function CalcDigitWidth(n: NativeUint):NativeUint;
begin
result:= 2;
while n>= 10 do
Begin
inc(result);
n := n DIV 10;
end;
en... |
Port the provided C code into Pascal while preserving the original functionality. | #include <stdio.h>
#include <math.h>
typedef struct {
double x;
double y;
} pair;
int main() {
double list[17] = {1, 8, 2, -3, 0, 1, 1, -2.3, 0, 5.5, 8,6, 2, 9, 11, 10, 3};
double diff, maxDiff = -1;
pair maxPairs[5];
int i, count = 0;
for (i = 1; i < 17; ++i) {
diff = fabs(list[i-... | program maximumDifferenceBetweenAdjacentElementsOfList(output);
type
tmyReal = extended;
tmyList = array of tmyReal;
const
input: tmyList = (1, 8, 2, -3, 0, 1, 1, -2.3, 0, 5.5, 8, 6, 2, 9, 11, 10, 3);
procedure OutSameDistanceInList(Dist:tmyReal;const list: tmyList);
var
currentDistance : tmyReal;
i ... |
Port the provided C code into Pascal while preserving the original functionality. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
void farey(int n)
{
typedef struct { int d, n; } frac;
frac f1 = {0, 1}, f2 = {1, n}, t;
int k;
printf("%d/%d %d/%d", 0, 1, 1, n);
while (f2.n > 1) {
k = (n + f1.n) / f2.n;
t = f1, f1 = f2, f2 = (frac) { f2.d * k - t.d, f2.n * k - t.n };
printf(" %... | program Farey;
uses
sysutils;
type
tNextFarey= record
nom,dom,n,c,d: longInt;
end;
function InitFarey(maxdom:longINt):tNextFarey;
Begin
with result do
Begin
nom := 0; dom := 1; n := maxdom;
c := 1; d := maxdom;
end;
end;
function NextFar... |
Generate a Pascal translation of this C snippet without changing its computational steps. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
void farey(int n)
{
typedef struct { int d, n; } frac;
frac f1 = {0, 1}, f2 = {1, n}, t;
int k;
printf("%d/%d %d/%d", 0, 1, 1, n);
while (f2.n > 1) {
k = (n + f1.n) / f2.n;
t = f1, f1 = f2, f2 = (frac) { f2.d * k - t.d, f2.n * k - t.n };
printf(" %... | program Farey;
uses
sysutils;
type
tNextFarey= record
nom,dom,n,c,d: longInt;
end;
function InitFarey(maxdom:longINt):tNextFarey;
Begin
with result do
Begin
nom := 0; dom := 1; n := maxdom;
c := 1; d := maxdom;
end;
end;
function NextFar... |
Change the following C code into Pascal without altering its purpose. | #include <stdio.h>
main(){
unsigned char uc; char c;
enum{e1, e2, e3}e123;
short si; int i; long li;
unsigned short su; unsigned u; unsigned long lu;
float sf; float f; double lf; long double llf;
union {char c; unsigned u; int i; float f; }ucuif;
struct {char c; unsigned u; int i; float ... | program implicitTypeConversion;
var
i: integer;
r: real;
begin
i := 42;
r := i
end.
|
Can you help me rewrite this code in Pascal instead of C, keeping it the same logically? | #include <stdio.h>
main(){
unsigned char uc; char c;
enum{e1, e2, e3}e123;
short si; int i; long li;
unsigned short su; unsigned u; unsigned long lu;
float sf; float f; double lf; long double llf;
union {char c; unsigned u; int i; float f; }ucuif;
struct {char c; unsigned u; int i; float ... | program implicitTypeConversion;
var
i: integer;
r: real;
begin
i := 42;
r := i
end.
|
Convert this C snippet to Pascal and keep its semantics consistent. | #include <stdio.h>
#include <string.h>
typedef int bool;
typedef unsigned long long ull;
#define TRUE 1
#define FALSE 0
bool is_prime(ull n) {
ull d;
if (n < 2) return FALSE;
if (!(n % 2)) return n == 2;
if (!(n % 3)) return n == 3;
d = 5;
while (d * d <= n) {
if (!(n % d)) return F... | program Magnanimous;
uses
gmp,
SysUtils;
const
MaxLimit = 10*1000*1000 +10;
MAXHIGHIDX = 10;
type
tprimes = array of byte;
tBaseType = Byte;
tpBaseType = pByte;
tBase =array[0..15] of tBaseType;
tNumType = NativeUint;
tSplitNum = array[0..15] of tNumType;
tMagList =... |
Port the provided C code into Pascal while preserving the original functionality. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#define TRUE 1
#define FALSE 0
typedef unsigned char bool;
void sieve(bool *c, int limit) {
int i, p = 3, p2;
c[0] = TRUE;
c[1] = TRUE;
for (;;) {
p2 = p * p;
if (p2 >= limit) {
break;... | program SexyPrimes;
uses
SysUtils
,windows
const
ctext: array[0..5] of string = ('Primes',
'sexy prime pairs',
'sexy prime triplets',
'sexy prime quadruplets',
'sexy prime quintuplet',
'sexy prime sextuplet');
primeLmt = 1000 * 1000 + 35;
type
sxPrtpl = record
spCnt,
splast5Id... |
Translate this program into Pascal but keep the logic exactly as in C. | #include <stdio.h>
#include <stdlib.h>
typedef unsigned long long xint;
typedef unsigned uint;
typedef struct {
uint x, y;
xint value;
} sum_t;
xint *cube;
uint n_cubes;
sum_t *pq;
uint pq_len, pq_cap;
void add_cube(void)
{
uint x = n_cubes++;
cube = realloc(cube, sizeof(xint) * (n_cubes + 1));
cube[n_cubes] ... | program taxiCabNo;
uses
sysutils;
type
tPot3 = Uint32;
tPot3Sol = record
p3Sum : tPot3;
i1,j1,
i2,j2 : Word;
end;
tpPot3 = ^tPot3;
tpPot3Sol = ^tPot3Sol;
var
pot3 : array[0..1190] of tPot3;
AllSol : array[0..3000] of tpot3Sol;
AllSolHigh :... |
Produce a language-to-language conversion: from C to Pascal, same semantics. | #include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
const int PRIMES[] = {
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, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211... | program WeakPrim;
const
PrimeLimit = 1000*1000*1000;
type
tLimit = 0..(PrimeLimit-1) DIV 2;
tPrimCnt = 0..51*1000*1000;
tWeakStrong = record
strong,
balanced,
weak : NativeUint;
end;
var
primes: array [tLimit] of byte;
delta... |
Keep all operations the same but rewrite the snippet in Pascal. | #include <stdbool.h>
#include <stdio.h>
#include <string.h>
#define LIMIT 3000
void init_sieve(unsigned char sieve[], int limit) {
int i, j;
for (i = 0; i < limit; i++) {
sieve[i] = 1;
}
sieve[0] = 0;
sieve[1] = 0;
for (i = 2; i < limit; i++) {
if (sieve[i]) {
for... | program PrimeTriplets;
const
MAXZAHL = 100000;
MAXSUM = 3*MAXZAHL;
CountOfPrimes = trunc(MAXZAHL/(ln(MAXZAHL)-1.08))+100;
type
tChkprimes = array[0..MAXSUM] of byte;
var
Chkprimes:tChkprimes;
primes : array[0..CountOfPrimes]of Uint32;
count,primeCount:NativeInt;
procedure Init... |
Port the following code from C to Pascal with equivalent syntax and logic. | #include <stdbool.h>
#include <stdio.h>
#include <string.h>
#define LIMIT 3000
void init_sieve(unsigned char sieve[], int limit) {
int i, j;
for (i = 0; i < limit; i++) {
sieve[i] = 1;
}
sieve[0] = 0;
sieve[1] = 0;
for (i = 2; i < limit; i++) {
if (sieve[i]) {
for... | program PrimeTriplets;
const
MAXZAHL = 100000;
MAXSUM = 3*MAXZAHL;
CountOfPrimes = trunc(MAXZAHL/(ln(MAXZAHL)-1.08))+100;
type
tChkprimes = array[0..MAXSUM] of byte;
var
Chkprimes:tChkprimes;
primes : array[0..CountOfPrimes]of Uint32;
count,primeCount:NativeInt;
procedure Init... |
Write the same algorithm in Pascal as shown in this C implementation. | #include<stdio.h>
#include<stdlib.h>
int isprime( int p ) {
int i;
if(p==2) return 1;
if(!(p%2)) return 0;
for(i=3; i*i<=p; i+=2) {
if(!(p%i)) return 0;
}
return 1;
}
int nextprime( int p ) {
int i=0;
if(p==0) return 2;
if(p<3) return p+1;
while(!isprime(++i + p));
r... | var n, p1, p2, prime;
procedure isnprime;
var p;
begin
prime := 1;
if n < 2 then prime := 0;
if n > 2 then begin
prime := 0;
if odd( n ) then prime := 1;
p := 3;
while p * p <= n * prime do begin
if n - ( ( n / p ) * p ) = ... |
Rewrite the snippet below in Pascal so it works the same as the original C code. | #include<stdio.h>
#include<stdlib.h>
int isprime( int p ) {
int i;
if(p==2) return 1;
if(!(p%2)) return 0;
for(i=3; i*i<=p; i+=2) {
if(!(p%i)) return 0;
}
return 1;
}
int nextprime( int p ) {
int i=0;
if(p==0) return 2;
if(p<3) return p+1;
while(!isprime(++i + p));
r... | var n, p1, p2, prime;
procedure isnprime;
var p;
begin
prime := 1;
if n < 2 then prime := 0;
if n > 2 then begin
prime := 0;
if odd( n ) then prime := 1;
p := 3;
while p * p <= n * prime do begin
if n - ( ( n / p ) * p ) = ... |
Produce a language-to-language conversion: from C to Pascal, same semantics. | #include <stdio.h>
static int p[19] = {0, 0, 1, 1, 0, 1, 0, 1, 0, 0,
0, 1, 0, 1, 0, 0, 0, 1, 0};
int isstrange(long n) {
if (n < 10) return 0;
for (; n >= 10; n /= 10) {
if (!p[n%10 + (n/10)%10]) return 0;
}
return 1;
}
int main(void) {
long n;
int k = 0;
for ... | begin % find numbers where the sum of the first 2 digits is prime and also %
% the sum of the second 2 digits is prime %
% considers numbers n where 100 < n < 500 %
logical procedure isSmallPrime ( integer value n ); n = 2 or ( odd( n ) and n n... |
Maintain the same structure and functionality when rewriting this code in Pascal. | #include <stdio.h>
static int p[19] = {0, 0, 1, 1, 0, 1, 0, 1, 0, 0,
0, 1, 0, 1, 0, 0, 0, 1, 0};
int isstrange(long n) {
if (n < 10) return 0;
for (; n >= 10; n /= 10) {
if (!p[n%10 + (n/10)%10]) return 0;
}
return 1;
}
int main(void) {
long n;
int k = 0;
for ... | begin % find numbers where the sum of the first 2 digits is prime and also %
% the sum of the second 2 digits is prime %
% considers numbers n where 100 < n < 500 %
logical procedure isSmallPrime ( integer value n ); n = 2 or ( odd( n ) and n n... |
Transform the following C implementation into Pascal, maintaining the same output and logic. | #include <locale.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
typedef uint32_t integer;
integer next_prime_digit_number(integer n) {
if (n == 0)
return 2;
switch (n % 10) {
case 2:
return n + 1;
case 3:
case 5:
return n + 2;
default:
return 2 +... | program Smarandache;
uses
sysutils,primsieve;
const
Digits : array[0..3] of Uint32 = (2,3,5,7);
var
i,j,pot10,DgtLimit,n,DgtCnt,v,cnt,LastPrime,Limit : NativeUint;
procedure Check(n:NativeUint);
var
p : NativeUint;
Begin
p := LastPrime;
while p< n do
p := nextprime;
if p = n then
begin
inc(cnt... |
Can you help me rewrite this code in Pascal instead of C, keeping it the same logically? | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define TRUE 1
#define FALSE 0
#define TRILLION 1000000000000
typedef unsigned char bool;
typedef unsigned long long uint64;
void sieve(uint64 limit, uint64 *primes, uint64 *length) {
uint64 i, count, p, p2;
bool *c = calloc(limit + 1, sizeof(bool)); ... | program SquareFree;
const
BigLimit = 10*1000*1000*1000;
TRILLION = 1000*1000*1000*1000;
primeLmt = trunc(sqrt(TRILLION+150));
var
primes : array of byte;
sieve : array of byte;
procedure initPrimes;
var
i,lmt,dp :NativeInt;
Begin
setlength(primes,80000);
setlength(sieve,primeLmt);
sie... |
Transform the following C implementation into Pascal, maintaining the same output and logic. | #include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef unsigned char bool;
#define TRUE 1
#define FALSE 0
#define MILLION 1000000
#define BILLION 1000 * MILLION
#define MAX_COUNT 2*BILLION + 9*9 + 1
void sieve(bool *sv) {
int n = 0, s[8], a, b, c, d, e, f, g, h, i, j;
for (a = 0; a < 2; ++a) {
... | program selfnumb;
uses
sysutils;
const
MAXCOUNT =103*10000*10000+11*9+ 1;
type
tDigitSum9999 = array[0..9999] of Uint8;
tpDigitSum9999 = ^tDigitSum9999;
var
DigitSum9999 : tDigitSum9999;
sieve : array of boolean;
procedure dosieve;
var
pSieve : pBoolean;
pDigitSum :tpDigitSum9999;
n,c,b,a,... |
Ensure the translated Pascal code behaves exactly like the original C snippet. | #include <locale.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
uint64_t digit_sum(uint64_t n, uint64_t sum) {
++sum;
while (n > 0 && n % 10 == 0) {
sum -= 9;
n /= 10;
}
return sum;
}
inline bool divisible(uint64_t n, uint64_t d) {
if ((d & 1) == 0 && (n & 1) == 1... | program NivenGaps;
uses
sysutils,
strutils;
const
base = 10;
type
tNum = Uint64;
const
cntbasedigits = ((trunc(ln(High(tNum))/ln(base))+1) DIV 8 +1) *8;
type
tSumDigit = record
sdDigits : array[0..cntbasedigits-1] of byte;
sdNumber,
sdNivCoun... |
Write the same algorithm in Pascal as shown in this C implementation. | #include <stdio.h>
unsigned digit_sum(unsigned n) {
unsigned sum = 0;
do { sum += n % 10; }
while(n /= 10);
return sum;
}
unsigned a131382(unsigned n) {
unsigned m;
for (m = 1; n != digit_sum(m*n); m++);
return m;
}
int main() {
unsigned n;
for (n = 1; n <= 70; n++) {
prin... | program m_by_n_sumofdgts_m;
uses
sysutils;
const
BASE = 10;
BASE4 = BASE*BASE*BASE*BASE;
MAXDGTSUM4 = 4*(BASE-1);
var
SoD: array[0..BASE4-1] of byte;
DtgBase4 :array[0..7] of Uint32;
DtgPartSums :array[0..7] of Uint32;
DgtSumBefore :array[0..7] of Uint32;
procedure Init_SoD;
var
d0,d... |
Keep all operations the same but rewrite the snippet in Pascal. | #include <stdio.h>
#include <math.h>
#include <string.h>
#define N 2200
int main(int argc, char **argv){
int a,b,c,d;
int r[N+1];
memset(r,0,sizeof(r));
for(a=1; a<=N; a++){
for(b=a; b<=N; b++){
int aabb;
if(a&1 && b&1) continue;
aabb=a*a + b*b;
for(c=b; c<=N; c++){
int aabbcc=aabb +... | program pythQuad;
const
MaxFactor =2200;
limit = MaxFactor*MaxFactor;
type
tIdx = NativeUint;
tSum = NativeUint;
var
check : array[0..MaxFactor] of boolean;
checkCnt : LongWord;
procedure Find2(s:tSum;idx:tSum);
var
s1 : tSum;
d : tSum;
begin
d := trunc(sqrt(s+idx*idx));
For idx := idx to M... |
Ensure the translated Pascal code behaves exactly like the original C snippet. | #include <stdio.h>
#include <complex.h>
#include <math.h>
#define FMTSPEC(arg) _Generic((arg), \
float: "%f", double: "%f", \
long double: "%Lf", unsigned int: "%u", \
unsigned long: "%lu", unsigned long long: "%llu", \
int: "%d", long: "%ld", long long: "%lld", \
default: "(invalid type (%p)")
#... | program integerness(output);
function isRealIntegral(protected x: complex): Boolean;
begin
isRealIntegral := (im(x) = 0.0) and_then
(abs(re(x)) <= maxInt * 1.0) and_then
(trunc(re(x)) * 1.0 = re(x))
end;
function isIntegral(protected x: real): Boolean;
begin
isIntegral := isRealIntegral(cmplx(x * 1.0, 0.0... |
Rewrite this program in Pascal while keeping its functionality equivalent to the C version. | #include<stdio.h>
#include<stdlib.h>
int isprime( int p ) {
int i;
if(p==2) return 1;
if(!(p%2)) return 0;
for(i=3; i*i<=p; i+=2) {
if(!(p%i)) return 0;
}
return 1;
}
int nextprime( int p ) {
int i=0;
if(p==0) return 2;
if(p<3) return p+1;
while(!isprime(++i + p));
r... | program primesieve;
uses
sysutils;
const
smlPrimes :array [0..10] of Byte = (2,3,5,7,11,13,17,19,23,29,31);
maxPreSievePrime = 17;
sieveSize = 1 shl 15;
type
tSievePrim = record
svdeltaPrime:word;
svSivOfs:word;
svSivNum:LongWord;
... |
Produce a language-to-language conversion: from C to Pascal, same semantics. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
void fatal(const char* message) {
fprintf(stderr, "%s\n", message);
exit(1);
}
void* xmalloc(size_t n) {
void* ptr = malloc(n);
if (ptr == NULL)
fatal("Out of memory");
return ptr;
}
void* xrealloc(void* p, size_... | program UlamNumbers;
uses
sysutils;
const
maxUlam = 100000;
Limit = 1351223+4000;
type
tCheck = Uint16;
tpCheck = pUint16;
var
Ulams : array of Uint32;
Check0 : array of tCheck;
Ulam_idx :NativeInt;
procedure init;
begin
setlength(Ulams,maxUlam);
Ulams[0] := 1;
Ulams[1] := 2;
Ulam_idx... |
Convert this C snippet to Pascal and keep its semantics consistent. | #include <stdio.h>
#include <string.h>
#include <gmp.h>
char *power_of_six(unsigned int n, char *buf) {
mpz_t p;
mpz_init(p);
mpz_ui_pow_ui(p, 6, n);
mpz_get_str(buf, 10, p);
mpz_clear(p);
return buf;
}
char *smallest_six(unsigned int n) {
static char nbuf[32], powbuf[1024];
unsigned i... | program PotOf6;
uses
sysutils;
const
calcDigits = 8;
PowerBase = 6;
DIGITS = 7;decLimit= 10*1000*1000;POT_LIMIT = 32804;STRCOUNT = 24960;
type
tMulElem = Uint32;
tMul = array of tMulElem;
tpMul = pUint32;
tPotArrN = array[0..1] of tMul;
tFound = record
foun... |
Maintain the same structure and functionality when rewriting this code in Pascal. | #include<stdio.h>
#include<ctype.h>
void typeDetector(char* str){
if(isalnum(str[0])!=0)
printf("\n%c is alphanumeric",str[0]);
if(isalpha(str[0])!=0)
printf("\n%c is alphabetic",str[0]);
if(iscntrl(str[0])!=0)
printf("\n%c is a control character",str[0]);
if(isdigit(str[0])!=0)
printf("\n%c is a digit",s... | program typedetectiondemo (input, output);
type
sourcetype = record case kind : (builtintext, filetext) of
builtintext : (i : integer);
filetext : (f : file of char);
end;
var
source : sourcetype;
input : file of char;
c : char;
procedure printt... |
Please provide an equivalent version of this C code in Pascal. | #include<stdio.h>
#include<stdlib.h>
int isprime( int p ) {
int i;
if(p==2) return 1;
if(!(p%2)) return 0;
for(i=3; i*i<=p; i+=2) {
if(!(p%i)) return 0;
}
return 1;
}
int main( void ) {
int p;
long int s = 2;
for(p=3;p<2000000;p+=2) {
if(isprime(p)) s+=p;
}
p... | program SumPrimes;
uses
SysUtils,primTrial;
var
p,sum : NativeInt;
begin
sum := actPrime;
repeat inc(sum,p); p := NextPrime until p >= 2*1000*1000;
writeln(sum);
readln;
end.
|
Translate this program into Pascal but keep the logic exactly as in C. | #include <stdio.h>
#include <stdbool.h>
bool steady(int n)
{
int mask = 1;
for (int d = n; d != 0; d /= 10)
mask *= 10;
return (n * n) % mask == n;
}
int main()
{
for (int i = 1; i < 10000; i++)
if (steady(i))
printf("%4d^2 = %8d\n", i, i * i);
return 0;
}
| const maxnumber = 10000;
var p10, n, d, nd, n2;
begin
p10 := 10;
n := 0;
while n <= maxnumber do begin
if n = p10 then p10 := p10 * 10;
d := 0;
while d < 6 do begin
if d = 5 then d := 6;
if d = 1 then d := 5;
if d = 0 then d := 1;
... |
Preserve the algorithm and functionality while converting the code from C to Pascal. | #include <stdbool.h>
#include <stdio.h>
int primes[] = {
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, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
211, 223, 227, 229, 233, 239, 241, 251, 257, 263,... | program Sophie;
uses
mp_prime,sysutils;
var
pS0,pS1:TSieve;
procedure SafeOrNoSavePrimeOut(totCnt:NativeInt;CntSafe:boolean);
var
cnt,pr,pSG,testPr : NativeUint;
begin
prime_sieve_reset(pS0,1);
prime_sieve_reset(pS1,1);
cnt := 0;
testPr := prime_sieve_next(pS1);
IF CntSafe then
Begin
writel... |
Translate the given C code snippet into Pascal without altering its behavior. | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define STACK_SIZE 80
#define BUFFER_SIZE 100
typedef int bool;
typedef struct {
char name;
bool val;
} var;
typedef struct {
int top;
bool els[STACK_SIZE];
} stack_of_bool;
char expr[BUFFER_SIZE];
int expr_le... | program TruthTables;
const
StackSize = 80;
type
TVariable = record
Name: Char;
Value: Boolean;
end;
TStackOfBool = record
Top: Integer;
Elements: array [0 .. StackSize - 1] of Boolean;
end;
var
Expression: string;
Variables: array [0 .. 23] of TVariable;
VariablesLength: Integer;
i:... |
Convert this C block to Pascal, preserving its control flow and logic. | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define STACK_SIZE 80
#define BUFFER_SIZE 100
typedef int bool;
typedef struct {
char name;
bool val;
} var;
typedef struct {
int top;
bool els[STACK_SIZE];
} stack_of_bool;
char expr[BUFFER_SIZE];
int expr_le... | program TruthTables;
const
StackSize = 80;
type
TVariable = record
Name: Char;
Value: Boolean;
end;
TStackOfBool = record
Top: Integer;
Elements: array [0 .. StackSize - 1] of Boolean;
end;
var
Expression: string;
Variables: array [0 .. 23] of TVariable;
VariablesLength: Integer;
i:... |
Ensure the translated Pascal code behaves exactly like the original C snippet. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gmp.h>
int main() {
for (unsigned int d = 2; d <= 9; ++d) {
printf("First 10 super-%u numbers:\n", d);
char digits[16] = { 0 };
memset(digits, '0' + d, d);
mpz_t bignum;
mpz_init(bignum);
for (unsig... | program Super_D;
uses
sysutils,gmp;
var
s :ansistring;
s_comp : ansistring;
test : mpz_t;
i,j,dgt,cnt : NativeUint;
Begin
mpz_init(test);
for dgt := 2 to 9 do
Begin
i := dgt;
For j := 2 to dgt do
i := i*10+dgt;
s_comp := IntToStr(i);
writeln('Finding ',s_comp,' in ',dgt,'*i*... |
Change the programming language of this snippet from C to Pascal without modifying what it does. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gmp.h>
int main() {
for (unsigned int d = 2; d <= 9; ++d) {
printf("First 10 super-%u numbers:\n", d);
char digits[16] = { 0 };
memset(digits, '0' + d, d);
mpz_t bignum;
mpz_init(bignum);
for (unsig... | program Super_D;
uses
sysutils,gmp;
var
s :ansistring;
s_comp : ansistring;
test : mpz_t;
i,j,dgt,cnt : NativeUint;
Begin
mpz_init(test);
for dgt := 2 to 9 do
Begin
i := dgt;
For j := 2 to dgt do
i := i*10+dgt;
s_comp := IntToStr(i);
writeln('Finding ',s_comp,' in ',dgt,'*i*... |
Port the following code from C to Pascal with equivalent syntax and logic. | #include "gmp.h"
void agm (const mpf_t in1, const mpf_t in2, mpf_t out1, mpf_t out2) {
mpf_add (out1, in1, in2);
mpf_div_ui (out1, out1, 2);
mpf_mul (out2, in1, in2);
mpf_sqrt (out2, out2);
}
int main (void) {
mpf_set_default_prec (300000);
mpf_t x0, y0, resA, resB, Z, var;
mpf_init_set_ui (x0, 1);
mpf_init_... | program AgmForPi;
uses
SysUtils, Math, GMP;
const
MIN_DIGITS = 32;
MAX_DIGITS = 1000000;
var
Digits: Cardinal = 256;
procedure ReadInput;
var
UserDigits: Cardinal;
begin
if (ParamCount > 0) and TryStrToDWord(ParamStr(1), UserDigits) then
Digits := Min(MAX_DIGITS, Max(UserDigits, MIN_DIGITS));
f_se... |
Port the following code from C to Pascal with equivalent syntax and logic. | #include "gmp.h"
void agm (const mpf_t in1, const mpf_t in2, mpf_t out1, mpf_t out2) {
mpf_add (out1, in1, in2);
mpf_div_ui (out1, out1, 2);
mpf_mul (out2, in1, in2);
mpf_sqrt (out2, out2);
}
int main (void) {
mpf_set_default_prec (300000);
mpf_t x0, y0, resA, resB, Z, var;
mpf_init_set_ui (x0, 1);
mpf_init_... | program AgmForPi;
uses
SysUtils, Math, GMP;
const
MIN_DIGITS = 32;
MAX_DIGITS = 1000000;
var
Digits: Cardinal = 256;
procedure ReadInput;
var
UserDigits: Cardinal;
begin
if (ParamCount > 0) and TryStrToDWord(ParamStr(1), UserDigits) then
Digits := Min(MAX_DIGITS, Max(UserDigits, MIN_DIGITS));
f_se... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.