Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Translate the given Go code snippet into Pascal without altering its behavior. | package main
import (
"fmt"
"strconv"
)
func isPrime(n int) bool {
switch {
case n < 2:
return false
case n%2 == 0:
return n == 2
case n%3 == 0:
return n == 3
default:
d := 5
for d*d <= n {
if n%d == 0 {
return false
... | 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... |
Write a version of this Go function in Pascal with identical behavior. | package main
import "fmt"
func countDivisors(n int) int {
count := 0
i := 1
k := 2
if n%2 == 0 {
k = 1
}
for i*i <= n {
if n%i == 0 {
count++
j := n / i
if j != i {
count++
}
}
i += k
}
retu... | 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 programming language of this snippet from Go to Pascal without modifying what it does. | package main
import (
"fmt"
big "github.com/ncw/gmp"
"time"
)
func sieve(limit int) []bool {
limit++
c := make([]bool, limit)
c[0] = true
c[1] = true
p := 3
for {
p2 := p * p
if p2 >= limit {
break
}
for i := p2; i < limit; i... | 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... |
Can you help me rewrite this code in Pascal instead of Go, keeping it the same logically? | package main
import (
"fmt"
"sort"
"strconv"
)
func combrep(n int, lst []byte) [][]byte {
if n == 0 {
return [][]byte{nil}
}
if len(lst) == 0 {
return nil
}
r := combrep(n, lst[1:])
for _, x := range combrep(n-1, lst) {
r = append(r, append(x, lst[0]))
}... | 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
... |
Port the provided Go code into Pascal while preserving the original functionality. | package main
import (
"fmt"
"sort"
"strconv"
)
func combrep(n int, lst []byte) [][]byte {
if n == 0 {
return [][]byte{nil}
}
if len(lst) == 0 {
return nil
}
r := combrep(n, lst[1:])
for _, x := range combrep(n-1, lst) {
r = append(r, append(x, lst[0]))
}... | 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
... |
Rewrite this program in Pascal while keeping its functionality equivalent to the Go version. | package main
import (
"fmt"
big "github.com/ncw/gmp"
"strings"
)
func isPrime(n int) bool {
switch {
case n < 2:
return false
case n%2 == 0:
return n == 2
case n%3 == 0:
return n == 3
default:
d := 5
for d*d <= n {
if n%d == 0 {
... | 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... |
Rewrite this program in Pascal while keeping its functionality equivalent to the Go version. |
package main
import "fmt"
func MeaningOfLife() int {
return 42
}
func libMain() {
fmt.Println("The meaning of life is", MeaningOfLife())
}
|
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.
|
Rewrite this program in Pascal while keeping its functionality equivalent to the Go version. |
package main
import "fmt"
func MeaningOfLife() int {
return 42
}
func libMain() {
fmt.Println("The meaning of life is", MeaningOfLife())
}
|
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.
|
Port the following code from Go to Pascal with equivalent syntax and logic. | package main
import "fmt"
func isPrime(n int) bool {
switch {
case n < 2:
return false
case n%2 == 0:
return n == 2
case n%3 == 0:
return n == 3
default:
d := 5
for d*d <= n {
if n%d == 0 {
return false
}
d... | 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
... |
Generate a Pascal translation of this Go snippet without changing its computational steps. | package main
import "fmt"
func isPrime(n int) bool {
switch {
case n < 2:
return false
case n%2 == 0:
return n == 2
case n%3 == 0:
return n == 3
default:
d := 5
for d*d <= n {
if n%d == 0 {
return false
}
d... | 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
... |
Convert the following code from Go to Pascal, ensuring the logic remains intact. | package main
import (
"fmt"
"time"
)
func main() {
var year int
var t time.Time
var lastDay = [12]int { 31,29,31,30,31,30,31,31,30,31,30,31 }
for {
fmt.Print("Please select a year: ")
_, err := fmt.Scanf("%d", &year)
if err != nil {
fmt.Println(err)
continue
} else {
break
}
}
fmt.Prin... | 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] ... |
Produce a language-to-language conversion: from Go to Pascal, same semantics. | package main
import (
"fmt"
"time"
)
func main() {
var year int
var t time.Time
var lastDay = [12]int { 31,29,31,30,31,30,31,31,30,31,30,31 }
for {
fmt.Print("Please select a year: ")
_, err := fmt.Scanf("%d", &year)
if err != nil {
fmt.Println(err)
continue
} else {
break
}
}
fmt.Prin... | 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 Go to Pascal. | package main
import (
"fmt"
"math/rand"
"time"
)
type matrix [][]int
func shuffle(row []int, n int) {
rand.Shuffle(n, func(i, j int) {
row[i], row[j] = row[j], row[i]
})
}
func latinSquare(n int) {
if n <= 0 {
fmt.Println("[]\n")
return
}
latin := make(matrix,... |
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 :... |
Convert this Go block to Pascal, preserving its control flow and logic. | package main
import (
"fmt"
"strconv"
)
func uabs(a, b uint64) uint64 {
if a > b {
return a - b
}
return b - a
}
func isEsthetic(n, b uint64) bool {
if n == 0 {
return false
}
i := n % b
n /= b
for n > 0 {
j := n % b
if uabs(i, j) != 1 {
... | 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... |
Convert this Go snippet to Pascal and keep its semantics consistent. | package main
import (
"fmt"
"math/rand"
"sort"
"time"
)
func main() {
s := rand.NewSource(time.Now().UnixNano())
r := rand.New(s)
for {
var values [6]int
vsum := 0
for i := range values {
var numbers [4]int
for j := range numbers {
... | 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:=... |
Convert this Go snippet to Pascal and keep its semantics consistent. | package main
import (
"fmt"
"sort"
)
type Node struct {
val int
back *Node
}
func lis (n []int) (result []int) {
var pileTops []*Node
for _, x := range n {
j := sort.Search(len(pileTops), func (i int) bool { return pileTops[i].val >= x })
node := &Node{ x, nil }
if j != 0 { node.back =... | 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... |
Transform the following Go implementation into Pascal, maintaining the same output and logic. | package main
import (
"fmt"
"rcu"
)
func main() {
for i := 1; i < 100; i++ {
if !rcu.IsPrime(rcu.DigitSum(i*i, 10)) {
continue
}
if rcu.IsPrime(rcu.DigitSum(i*i*i, 10)) {
fmt.Printf("%d ", i)
}
}
fmt.Println()
}
| 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;... |
Change the following Go code into Pascal without altering its purpose. | package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
"strings"
)
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
scanner := bufio.NewScanner(os.Stdin)
n := 0
for n < 1 || n > 5 {
fmt.Print("How many integer variables do you want... | PROGRAM ExDynVar;
USES
Generics.Collections,
SysUtils,
Variants;
TYPE
Tdict =
specialize
TDictionary < ansistring, variant > ;
VAR
VarName: ansistring;
strValue: ansistring;
VarValue: variant;
D: Tdict;
FUNCTION SetType ( strVal... |
Transform the following Go implementation into Pascal, maintaining the same output and logic. | package main
import (
"fmt"
"math"
"math/big"
"strconv"
"strings"
)
func calkinWilf(n int) []*big.Rat {
cw := make([]*big.Rat, n+1)
cw[0] = big.NewRat(1, 1)
one := big.NewRat(1, 1)
two := big.NewRat(2, 1)
for i := 1; i < n; i++ {
t := new(big.Rat).Set(cw[i-1])
f... | program CWTerms;
uses SysUtils;
type TRational = record
Num, Den : integer;
end;
var
terms : array of TRational;
max_index, k : integer;
procedure CalcTerms_algo_1();
var
j, k : integer;
begin
SetLength( terms, max_index + 1);
j := 1;
k := 1;
terms[1].Num := 1;
terms[1].De... |
Translate this program into Pascal but keep the logic exactly as in Go. | package main
import (
"fmt"
"math"
"math/big"
"strconv"
"strings"
)
func calkinWilf(n int) []*big.Rat {
cw := make([]*big.Rat, n+1)
cw[0] = big.NewRat(1, 1)
one := big.NewRat(1, 1)
two := big.NewRat(2, 1)
for i := 1; i < n; i++ {
t := new(big.Rat).Set(cw[i-1])
f... | program CWTerms;
uses SysUtils;
type TRational = record
Num, Den : integer;
end;
var
terms : array of TRational;
max_index, k : integer;
procedure CalcTerms_algo_1();
var
j, k : integer;
begin
SetLength( terms, max_index + 1);
j := 1;
k := 1;
terms[1].Num := 1;
terms[1].De... |
Please provide an equivalent version of this Go code in Pascal. | package main
import (
"fmt"
"rcu"
)
func main() {
c := rcu.PrimeSieve(5505, false)
var triples [][3]int
fmt.Println("Prime triplets: p, p + 2, p + 6 where p < 5,500:")
for i := 3; i < 5500; i += 2 {
if !c[i] && !c[i+2] && !c[i+6] {
triples = append(triples, [3]int{i, i + 2,... | var n, a, 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 ) = 0 the... |
Transform the following Go implementation into Pascal, maintaining the same output and logic. | package main
import (
"fmt"
"rcu"
)
func main() {
c := rcu.PrimeSieve(5505, false)
var triples [][3]int
fmt.Println("Prime triplets: p, p + 2, p + 6 where p < 5,500:")
for i := 3; i < 5500; i += 2 {
if !c[i] && !c[i+2] && !c[i+6] {
triples = append(triples, [3]int{i, i + 2,... | var n, a, 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 ) = 0 the... |
Port the following code from Go to Pascal with equivalent syntax and logic. | package main
import (
"fmt"
"rcu"
)
func main() {
primes := rcu.Primes(504)
var nprimes []int
fmt.Println("Neighbour primes < 500:")
for i := 0; i < len(primes)-1; i++ {
p := primes[i]*primes[i+1] + 2
if rcu.IsPrime(p) {
nprimes = append(nprimes, primes[i])
... | 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 ) = ... |
Change the following Go code into Pascal without altering its purpose. | package main
import (
"fmt"
"rcu"
)
func main() {
primes := rcu.Primes(504)
var nprimes []int
fmt.Println("Neighbour primes < 500:")
for i := 0; i < len(primes)-1; i++ {
p := primes[i]*primes[i+1] + 2
if rcu.IsPrime(p) {
nprimes = append(nprimes, primes[i])
... | 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 ) = ... |
Write a version of this Go function in Pascal with identical behavior. | package main
import (
"fmt"
"rcu"
"strconv"
"strings"
)
func main() {
count := 0
k := 11 * 11
var res []int
for count < 20 {
if k%3 == 0 || k%5 == 0 || k%7 == 0 {
k += 2
continue
}
factors := rcu.PrimeFactors(k)
if len(factors) > ... | program FacOfInt;
uses
sysutils,
strutils
,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
... |
Ensure the translated Pascal code behaves exactly like the original Go snippet. | package main
import (
"fmt"
"rcu"
"strconv"
"strings"
)
func main() {
count := 0
k := 11 * 11
var res []int
for count < 20 {
if k%3 == 0 || k%5 == 0 || k%7 == 0 {
k += 2
continue
}
factors := rcu.PrimeFactors(k)
if len(factors) > ... | program FacOfInt;
uses
sysutils,
strutils
,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
... |
Port the provided Go code into Pascal while preserving the original functionality. | package main
import (
"fmt"
"regexp"
"strings"
)
var elements = `
hydrogen helium lithium beryllium
boron carbon nitrogen oxygen
fluorine neon sodium magnesium
aluminum silicon phosphorous sulfur
chlorine argon ... | program longStringLiteralDemo(output);
uses
sysUtils,
strUtils;
const
elementString = 'hydrogen helium lithium beryllium boron carbon nitrogen oxy' +
'gen fluorine neon sodium magnesium aluminum silicon phosphorous sulfur chl' +
'orine argon potassium calcium scandium titanium vanadium chromium manganes... |
Generate an equivalent Pascal version of this Go code. | package main
import (
"bufio"
"fmt"
"io"
"os"
)
func Runer(r io.RuneReader) func() (rune, error) {
return func() (r rune, err error) {
r, _, err = r.ReadRune()
return
}
}
func main() {
runes := Runer(bufio.NewReader(os.Stdin))
for r, err := runes(); err != nil; r,err =... |
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... |
Please provide an equivalent version of this Go code in Pascal. | package main
import "fmt"
func circleSort(a []int, lo, hi, swaps int) int {
if lo == hi {
return swaps
}
high, low := hi, lo
mid := (hi - lo) / 2
for lo < hi {
if a[lo] > a[hi] {
a[lo], a[hi] = a[hi], a[lo]
swaps++
}
lo++
hi--
}
... |
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;
... |
Change the following Go code into Pascal without altering its purpose. | package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"sort"
"strings"
)
func main() {
b, err := ioutil.ReadFile("unixdict.txt")
if err != nil {
log.Fatal("Error reading file")
}
letters := "deegklnow"
wordsAll := bytes.Split(b, []byte{'\n'})
var words [][]... | 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... |
Translate this program into Pascal but keep the logic exactly as in Go. | package main
import "fmt"
import "math/rand"
func main(){
var a1,a2,a3,y,match,j,k int
var inp string
y=1
for y==1{
fmt.Println("Enter your sequence:")
fmt.Scanln(&inp)
var Ai [3] int
var user [3] int
for j=0;j<3;j++{
if(inp[j]==104){
user[j]=1
}else{
user[j]=0
}
}
for k=0;k<3;k++{
Ai[k]=rand.Intn(2)
}
for user[0]==Ai[... | 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... |
Please provide an equivalent version of this Go code in Pascal. | package main
import (
"fmt"
"strings"
)
func printBlock(data string, le int) {
a := []byte(data)
sumBytes := 0
for _, b := range a {
sumBytes += int(b - 48)
}
fmt.Printf("\nblocks %c, cells %d\n", a, le)
if le-sumBytes <= 0 {
fmt.Println("No solution")
return
... | 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] :... |
Rewrite this program in Pascal while keeping its functionality equivalent to the Go version. | package main
import (
"fmt"
"strings"
)
func printBlock(data string, le int) {
a := []byte(data)
sumBytes := 0
for _, b := range a {
sumBytes += int(b - 48)
}
fmt.Printf("\nblocks %c, cells %d\n", a, le)
if le-sumBytes <= 0 {
fmt.Println("No solution")
return
... | 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] :... |
Change the following Go code into Pascal without altering its purpose. | package main
import (
"encoding/binary"
"log"
"math"
"os"
"strings"
)
func main() {
const (
sampleRate = 44100
duration = 8
dataLength = sampleRate * duration
hdrSize = 44
fileLen = dataLength + hdrSize - 8
)
buf1 := make([]byte, 1)... |
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.
|
Please provide an equivalent version of this Go code in Pascal. | package main
import (
"encoding/binary"
"log"
"math"
"os"
"strings"
)
func main() {
const (
sampleRate = 44100
duration = 8
dataLength = sampleRate * duration
hdrSize = 44
fileLen = dataLength + hdrSize - 8
)
buf1 := make([]byte, 1)... |
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.
|
Produce a language-to-language conversion: from Go to Pascal, same semantics. | package main
import "fmt"
type Item struct {
name string
weight, value, qty int
}
var items = []Item{
{"map", 9, 150, 1},
{"compass", 13, 35, 1},
{"water", 153, 200, 2},
{"sandwich", 50, 60, 2},
{"glucose", 15, 60, 2},
{"tin", 68, 45, 3},
{"banana", 27, 60, 3},
{"apple", 39, 40, 3},... | 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: ... |
Rewrite the snippet below in Pascal so it works the same as the original Go code. | package main
import "fmt"
type link struct {
int
next *link
}
func linkInts(s []int) *link {
if len(s) == 0 {
return nil
}
return &link{s[0], linkInts(s[1:])}
}
func (l *link) String() string {
if l == nil {
return "nil"
}
r := fmt.Sprintf("[%d", l.int)
for l = l.... | 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... |
Translate the given Go code snippet into Pascal without altering its behavior. | package main
import (
"fmt"
"log"
"os"
"strings"
)
const dim = 16
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func drawPile(pile [][]uint) {
chars:= []rune(" ░▓█")
for _, row := range pile {
line := make([]rune, len(row))
for i, elem := range ... | 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... |
Change the programming language of this snippet from Go to Pascal without modifying what it does. | package main
import (
"fmt"
"log"
"os"
"strings"
)
const dim = 16
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func drawPile(pile [][]uint) {
chars:= []rune(" ░▓█")
for _, row := range pile {
line := make([]rune, len(row))
for i, elem := range ... | 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... |
Convert this Go block to Pascal, preserving its control flow and logic. | package raster
import "math"
func ipart(x float64) float64 {
return math.Floor(x)
}
func round(x float64) float64 {
return ipart(x + .5)
}
func fpart(x float64) float64 {
return x - ipart(x)
}
func rfpart(x float64) float64 {
return 1 - fpart(x)
}
func (g *Grmap) AaLine(x1, y1, x2, y2 float64) {
... | 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, ... |
Convert this Go snippet to Pascal and keep its semantics consistent. | package main
import "fmt"
import "C"
func main() {
code := []byte{
0x55, 0x48, 0x89, 0xe5, 0x89, 0x7d,
0xfc, 0x89, 0x75, 0xf8, 0x8b, 0x75,
0xfc, 0x03, 0x75, 0xf8, 0x89, 0x75,
0xf4, 0x8b, 0x45, 0xf4, 0x5d, 0xc3,
}
le := len(code)
buf := C.mmap(nil, C.size_t(le), C.PROT... | 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,
... |
Generate a Pascal translation of this Go snippet without changing its computational steps. | package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
rand.Seed(time.Now().UnixNano())
totalSecs := 0
totalSteps := 0
fmt.Println("Seconds steps behind steps ahead")
fmt.Println("------- ------------ -----------")
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... |
Rewrite this program in Pascal while keeping its functionality equivalent to the Go version. | package main
import "fmt"
func printMinCells(n int) {
fmt.Printf("Minimum number of cells after, before, above and below %d x %d square:\n", n, n)
p := 1
if n > 20 {
p = 2
}
for r := 0; r < n; r++ {
cells := make([]int, n)
for c := 0; c < n; c++ {
nums := []int{... | 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... |
Ensure the translated Pascal code behaves exactly like the original Go snippet. | package main
import (
"fmt"
"math"
)
func main() {
list := []float64{1, 8, 2, -3, 0, 1, 1, -2.3, 0, 5.5, 8, 6, 2, 9, 11, 10, 3}
maxDiff := -1.0
var maxPairs [][2]float64
for i := 1; i < len(list); i++ {
diff := math.Abs(list[i-1] - list[i])
if diff > maxDiff {
maxDi... | 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 ... |
Translate the given Go code snippet into Pascal without altering its behavior. | package main
import (
"fmt"
"reflect"
)
type example struct{}
func (example) Foo() int {
return 42
}
func (e example) CallMethod(n string) int {
if m := reflect.ValueOf(e).MethodByName(n); m.IsValid() {
return int(m.Call(nil)[0].Int())
}
fmt.Println("Unknown method:", ... | unit MyObjDef;
interface
uses
SysUtils, Variants;
function MyObjCreate: Variant;
implementation
var
MyObjType: TInvokeableVariantType;
type
TMyObjType = class(TInvokeableVariantType)
procedure Clear(var V: TVarData); override;
procedure Copy(var aDst: TVarData; const aSrc: TVarData; const Indir: B... |
Translate the given Go code snippet into Pascal without altering its behavior. | package main
import (
"fmt"
"math/big"
"rcu"
)
func lcm(n int) *big.Int {
lcm := big.NewInt(1)
t := new(big.Int)
for _, p := range rcu.Primes(n) {
f := p
for f*p <= n {
f *= p
}
lcm.Mul(lcm, t.SetUint64(uint64(f)))
}
return lcm
}
func main()... |
const
smallprimes : array[0..10] of Uint32 = (2,3,5,7,11,13,17,19,23,29,31);
MAX = 20;
function getmaxfac(pr: Uint32): Uint32;
var
i,fac : integer;
Begin
result := pr;
while pr*result <= MAX do
result *= pr;
end;
var
n,pr,prIdx : Uint32;
BEGIN
n := 1;
prIdx := 0;
pr := smallprimes[prIdx]... |
Produce a functionally identical Pascal code for the snippet given in Go. | package main
import "fmt"
type frac struct{ num, den int }
func (f frac) String() string {
return fmt.Sprintf("%d/%d", f.num, f.den)
}
func f(l, r frac, n int) {
m := frac{l.num + r.num, l.den + r.den}
if m.den <= n {
f(l, m, n)
fmt.Print(m, " ")
f(m, r, n)
}
}
func main() {... | 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... |
Write the same code in Pascal as shown below in Go. | package main
import "fmt"
type frac struct{ num, den int }
func (f frac) String() string {
return fmt.Sprintf("%d/%d", f.num, f.den)
}
func f(l, r frac, n int) {
m := frac{l.num + r.num, l.den + r.den}
if m.den <= n {
f(l, m, n)
fmt.Print(m, " ")
f(m, r, n)
}
}
func main() {... | 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... |
Transform the following Go implementation into Pascal, maintaining the same output and logic. | package main
import "fmt"
func main() {
var i int32 = 1
fmt.Printf("i : type %-7T value %d\n", i, i)
j := 2
fmt.Printf("j : type %-7T value %d\n", j, j)
var k int64 = int64(i) + int64(j)
fmt.Printf("k : type %-7T value %d\n", k, k)
... | program implicitTypeConversion;
var
i: integer;
r: real;
begin
i := 42;
r := i
end.
|
Preserve the algorithm and functionality while converting the code from Go to Pascal. | package main
import "fmt"
func main() {
var i int32 = 1
fmt.Printf("i : type %-7T value %d\n", i, i)
j := 2
fmt.Printf("j : type %-7T value %d\n", j, j)
var k int64 = int64(i) + int64(j)
fmt.Printf("k : type %-7T value %d\n", k, k)
... | program implicitTypeConversion;
var
i: integer;
r: real;
begin
i := 42;
r := i
end.
|
Ensure the translated Pascal code behaves exactly like the original Go snippet. | package main
import "fmt"
func isPrime(n uint64) bool {
switch {
case n < 2:
return false
case n%2 == 0:
return n == 2
case n%3 == 0:
return n == 3
default:
d := uint64(5)
for d*d <= n {
if n%d == 0 {
return false
}
... | 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 =... |
Write a version of this Go function in Pascal with identical behavior. | package main
import "fmt"
func sieve(limit int) []bool {
limit++
c := make([]bool, limit)
c[0] = true
c[1] = true
p := 3
for {
p2 := p * p
if p2 >= limit {
break
}
for i := p2; i < limit; i += 2 * p {
c[i] = true
}
... | 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... |
Change the programming language of this snippet from Go to Pascal without modifying what it does. | package main
import (
"container/heap"
"fmt"
"strings"
)
type CubeSum struct {
x, y uint16
value uint64
}
func (c *CubeSum) fixvalue() { c.value = cubes[c.x] + cubes[c.y] }
type CubeSumHeap []*CubeSum
func (h CubeSumHeap) Len() int { return len(h) }
func (h CubeSumHeap) Less(i, j int) bool { retu... | 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 :... |
Change the programming language of this snippet from Go to Pascal without modifying what it does. | package main
import "fmt"
func sieve(limit int) []bool {
limit++
c := make([]bool, limit)
c[0] = true
c[1] = true
p := 3
for {
p2 := p * p
if p2 >= limit {
break
}
for i := p2; i < limit; i += 2 * p {
c[i] = true
}
... | 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... |
Transform the following Go implementation into Pascal, maintaining the same output and logic. | package main
import "fmt"
func isPrime(n int) bool {
switch {
case n < 2:
return false
case n%2 == 0:
return n == 2
case n%3 == 0:
return n == 3
default:
d := 5
for d*d <= n {
if n%d == 0 {
return false
}
d... | 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... |
Keep all operations the same but rewrite the snippet in Pascal. | package main
import "fmt"
func isPrime(n int) bool {
switch {
case n < 2:
return false
case n%2 == 0:
return n == 2
case n%3 == 0:
return n == 3
default:
d := 5
for d*d <= n {
if n%d == 0 {
return false
}
d... | 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... |
Translate this program into Pascal but keep the logic exactly as in Go. | package main
import (
"fmt"
"rcu"
)
const MAX = 1e7 - 1
var primes = rcu.Primes(MAX)
func specialNP(limit int, showAll bool) {
if showAll {
fmt.Println("Neighbor primes, p1 and p2, where p1 + p2 - 1 is prime:")
}
count := 0
for i := 1; i < len(primes); i++ {
p2 := primes[i]
... | 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 Go to Pascal, same semantics. | package main
import (
"fmt"
"rcu"
)
const MAX = 1e7 - 1
var primes = rcu.Primes(MAX)
func specialNP(limit int, showAll bool) {
if showAll {
fmt.Println("Neighbor primes, p1 and p2, where p1 + p2 - 1 is prime:")
}
count := 0
for i := 1; i < len(primes); i++ {
p2 := primes[i]
... | 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 ) = ... |
Can you help me rewrite this code in Pascal instead of Go, keeping it the same logically? | package main
import "fmt"
func isPrime(n int) bool {
return n == 2 || n == 3 || n == 5 || n == 7 || n == 11 || n == 13 || n == 17
}
func main() {
count := 0
var d []int
fmt.Println("Strange plus numbers in the open interval (100, 500) are:\n")
for i := 101; i < 500; i++ {
d = d[:0]
... | 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... |
Write the same algorithm in Pascal as shown in this Go implementation. | package main
import "fmt"
func isPrime(n int) bool {
return n == 2 || n == 3 || n == 5 || n == 7 || n == 11 || n == 13 || n == 17
}
func main() {
count := 0
var d []int
fmt.Println("Strange plus numbers in the open interval (100, 500) are:\n")
for i := 101; i < 500; i++ {
d = d[:0]
... | 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... |
Produce a functionally identical Pascal code for the snippet given in Go. | package main
import (
"fmt"
"math/big"
)
var b = new(big.Int)
func isSPDSPrime(n uint64) bool {
nn := n
for nn > 0 {
r := nn % 10
if r != 2 && r != 3 && r != 5 && r != 7 {
return false
}
nn /= 10
}
b.SetUint64(n)
if b.ProbablyPrime(0) {
... | 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... |
Port the following code from Go to Pascal with equivalent syntax and logic. | package main
import (
"fmt"
"math"
)
func sieve(limit uint64) []uint64 {
primes := []uint64{2}
c := make([]bool, limit+1)
p := uint64(3)
for {
p2 := p * p
if p2 > limit {
break
}
for i := p2; i <= limit; i += 2 * p {
c[i] = true
... | 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... |
Translate this program into Pascal but keep the logic exactly as in Go. | package main
import (
"fmt"
"time"
)
func sumDigits(n int) int {
sum := 0
for n > 0 {
sum += n % 10
n /= 10
}
return sum
}
func max(x, y int) int {
if x > y {
return x
}
return y
}
func main() {
st := time.Now()
count := 0
var selfs []int
i... | 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 Go snippet. | package main
import "fmt"
type is func() uint64
func newSum() is {
var ms is
ms = func() uint64 {
ms = newSum()
return ms()
}
var msd, d uint64
return func() uint64 {
if d < 9 {
d++
} else {
d = 0
msd = ms()
}
ret... | 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... |
Convert the following code from Go to Pascal, ensuring the logic remains intact. | package main
import "rcu"
func main() {
var res []int
for n := 1; n <= 70; n++ {
m := 1
for rcu.DigitSum(m*n, 10) != n {
m++
}
res = append(res, m)
}
rcu.PrintTable(res, 7, 10, true)
}
| 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... |
Generate an equivalent Pascal version of this Go code. | package main
import "fmt"
const (
N = 2200
N2 = N * N * 2
)
func main() {
s := 3
var s1, s2 int
var r [N + 1]bool
var ab [N2 + 1]bool
for a := 1; a <= N; a++ {
a2 := a * a
for b := a; b <= N; b++ {
ab[a2 + b * b] = true
}
}
for c := 1; ... | 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... |
Generate a Pascal translation of this Go snippet without changing its computational steps. | package main
import (
"fmt"
"math"
"math/big"
"reflect"
"strings"
"unsafe"
)
func Float64IsInt(f float64) bool {
_, frac := math.Modf(f)
return frac == 0
}
func Float32IsInt(f float32) bool {
return Float64IsInt(float64(f))
}
func Complex128IsInt(c complex128) bool {
return imag(c) == 0 && Float6... | 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... |
Port the following code from Go to Pascal with equivalent syntax and logic. | package main
import (
"fmt"
"rcu"
)
func main() {
limit := int(1e10 - 1)
primes := rcu.Primes(limit)
maxI := 0
maxDiff := 0
nextStop := 10
fmt.Println("The largest differences between adjacent primes under the following limits is:")
for i := 1; i < len(primes); i++ {
diff :... | 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;
... |
Convert this Go snippet to Pascal and keep its semantics consistent. | package main
import "fmt"
func ulam(n int) int {
ulams := []int{1, 2}
set := map[int]bool{1: true, 2: true}
i := 3
for {
count := 0
for j := 0; j < len(ulams); j++ {
_, ok := set[i-ulams[j]]
if ok && ulams[j] != (i-ulams[j]) {
count++
... | 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... |
Please provide an equivalent version of this Go code in Pascal. | package main
import (
"fmt"
"math/big"
"strconv"
"strings"
)
func commatize(s string) string {
neg := false
if strings.HasPrefix(s, "-") {
s = s[1:]
neg = true
}
le := len(s)
for i := le - 3; i >= 1; i -= 3 {
s = s[0:i] + "," + s[i:]
}
if !neg {
... | 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... |
Can you help me rewrite this code in Pascal instead of Go, keeping it the same logically? | package main
import "fmt"
type any = interface{}
func showType(a any) {
switch a.(type) {
case rune:
fmt.Printf("The type of '%c' is %T\n", a, a)
default:
fmt.Printf("The type of '%v' is %T\n", a, a)
}
}
func main() {
values := []any{5, 7.5, 2 + 3i, 'd', true, "Rosetta"}
for ... | 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... |
Write the same code in Pascal as shown below in Go. | package main
import (
"fmt"
"rcu"
)
func main() {
sum := 0
for _, p := range rcu.Primes(2e6 - 1) {
sum += p
}
fmt.Printf("The sum of all primes below 2 million is %s.\n", rcu.Commatize(sum))
}
| 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.
|
Generate a Pascal translation of this Go snippet without changing its computational steps. | package main
import (
"fmt"
"rcu"
"strconv"
"strings"
)
func contains(list []int, s int) bool {
for _, e := range list {
if e == s {
return true
}
}
return false
}
func main() {
fmt.Println("Steady squares under 10,000:")
finalDigits := []int{1, 5, 6}
... | 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;
... |
Transform the following Go implementation into Pascal, maintaining the same output and logic. | package main
import "fmt"
func sieve(limit uint64) []bool {
limit++
c := make([]bool, limit)
c[0] = true
c[1] = true
for i := uint64(4); i < limit; i += 2 {
c[i] = true
}
p := uint64(3)
for {
p2 := p * p
if p2 >= limit {
break
}
... | 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... |
Port the provided Go code into Pascal while preserving the original functionality. | package main
import (
"fmt"
"rcu"
)
func countDivisors(n int) int {
count := 0
i := 1
k := 1
if n%2 == 1 {
k = 2
}
for ; i*i <= n; i += k {
if n%i == 0 {
count++
j := n / i
if j != i {
count++
}
}
... | program FacOfInteger;
uses
sysutils;
type
tPot = record
potSoD : Uint64;
potPrim,
potMax :Uint32;
end;
tprimeFac = record
pfPrims : array[0..13] of tPot;
pfSumOfDivs : Uint64;
pfCnt,
pfNu... |
Write a version of this Go function in Pascal with identical behavior. | package main
import "fmt"
var factors []int
var inc = []int{4, 2, 4, 2, 4, 6, 2, 6}
func primeFactors(n int) {
factors = factors[:0]
factors = append(factors, 2)
last := 2
n /= 2
for n%3 == 0 {
if last == 3 {
factors = factors[:0]
return
}
last = ... | program Giuga;
uses
sysutils
,Windows
;
type
tprimeFac = packed record
pfpotPrimIdx : array[0..9] of Uint64;
pfMaxIdx : Uint32;
end;
tpPrimeFac = ^tprimeFac;
tPrimes = array[0..65535] of Uint32;
var
SmallPrimes: tPrimes;
procedure In... |
Convert this Go block to Pascal, preserving its control flow and logic. | package main
import "fmt"
var (
n = 3
values = []string{"A", "B", "C", "D"}
k = len(values)
decide = func(p []string) bool {
return p[0] == "B" && p[1] == "C"
}
)
func main() {
pn := make([]int, n)
p := make([]string, n)
for {
for i, x := range pn {
... | program PermuWithRep;
uses
sysutils;
type
tPermData = record
mdTup_n,
mdTup_k:NativeInt;
mdTup :array of integer;
end;
function InitTuple(k,n:nativeInt):tPermData;
begin
with result do
Begin
IF k> 0 then
Begin
mdTup... |
Change the following Go code into Pascal without altering its purpose. | package main
import "fmt"
var (
n = 3
values = []string{"A", "B", "C", "D"}
k = len(values)
decide = func(p []string) bool {
return p[0] == "B" && p[1] == "C"
}
)
func main() {
pn := make([]int, n)
p := make([]string, n)
for {
for i, x := range pn {
... | program PermuWithRep;
uses
sysutils;
type
tPermData = record
mdTup_n,
mdTup_k:NativeInt;
mdTup :array of integer;
end;
function InitTuple(k,n:nativeInt):tPermData;
begin
with result do
Begin
IF k> 0 then
Begin
mdTup... |
Transform the following Go implementation into Pascal, maintaining the same output and logic. | package main
import (
"bufio"
"errors"
"fmt"
"go/ast"
"go/parser"
"go/token"
"os"
"reflect"
)
func main() {
in := bufio.NewScanner(os.Stdin)
for {
fmt.Print("Expr: ")
in.Scan()
if err := in.Err(); err != nil {
fmt.Println(err)
re... | 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:... |
Transform the following Go implementation into Pascal, maintaining the same output and logic. | package main
import (
"bufio"
"errors"
"fmt"
"go/ast"
"go/parser"
"go/token"
"os"
"reflect"
)
func main() {
in := bufio.NewScanner(os.Stdin)
for {
fmt.Print("Expr: ")
in.Scan()
if err := in.Err(); err != nil {
fmt.Println(err)
re... | 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:... |
Can you help me rewrite this code in Pascal instead of Go, keeping it the same logically? | package main
import (
"fmt"
"math/big"
"strings"
"time"
)
func main() {
start := time.Now()
rd := []string{"22", "333", "4444", "55555", "666666", "7777777", "88888888", "999999999"}
one := big.NewInt(1)
nine := big.NewInt(9)
for i := big.NewInt(2); i.Cmp(nine) <= 0; i.Add(i, one) ... | 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 Go to Pascal without modifying what it does. | package main
import (
"fmt"
"math/big"
"strings"
"time"
)
func main() {
start := time.Now()
rd := []string{"22", "333", "4444", "55555", "666666", "7777777", "88888888", "999999999"}
one := big.NewInt(1)
nine := big.NewInt(9)
for i := big.NewInt(2); i.Cmp(nine) <= 0; i.Add(i, one) ... | 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*... |
Write a version of this Go function in Pascal with identical behavior. | package main
import (
"fmt"
"reflect"
)
type example struct{}
func (example) Foo() int {
return 42
}
func main() {
var e example
m := reflect.ValueOf(e).MethodByName("Foo")
r := m.Call(nil)
fmt.Println(r[0].Int())
}
| program Test;
uses
SysUtils;
type
TProc = procedure of object;
TMyObj = class
strict private
FName: string;
public
constructor Create(const aName: string);
property Name: string read FName;
published
procedure Foo;
procedure Bar;
end;
constructor TMyObj.Create(const aName: string... |
Preserve the algorithm and functionality while converting the code from Go to Pascal. | package main
import (
"fmt"
"math/big"
)
func main() {
one := big.NewFloat(1)
two := big.NewFloat(2)
four := big.NewFloat(4)
prec := uint(768)
a := big.NewFloat(1).SetPrec(prec)
g := new(big.Float).SetPrec(prec)
t := new(big.Float).SetPrec(prec)
u := new(big.Float).SetP... | 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... |
Convert this Go snippet to Pascal and keep its semantics consistent. | package main
import (
"fmt"
"math/big"
)
func main() {
one := big.NewFloat(1)
two := big.NewFloat(2)
four := big.NewFloat(4)
prec := uint(768)
a := big.NewFloat(1).SetPrec(prec)
g := new(big.Float).SetPrec(prec)
t := new(big.Float).SetPrec(prec)
u := new(big.Float).SetP... | 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... |
Change the following Go code into Pascal without altering its purpose. | package main
import (
"log"
"github.com/jezek/xgb"
"github.com/jezek/xgb/xproto"
)
func main() {
X, err := xgb.NewConn()
if err != nil {
log.Fatal(err)
}
points := []xproto.Point{
{10, 10},
{10, 20},
{20, 10},
{20, 20}};
... | 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 Go snippet. | package main
import (
"fmt"
"math/big"
"time"
"github.com/jbarham/primegen.go"
)
func main() {
start := time.Now()
pg := primegen.New()
var i uint64
p := big.NewInt(1)
tmp := new(big.Int)
for i <= 9 {
fmt.Printf("primorial(%v) = %v\n", i, p)
i++
p = p.Mul(p, tmp.SetUint64(pg.Next()))
}
for _, j := ... |
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 ... |
Keep all operations the same but rewrite the snippet in Pascal. | package main
import (
"fmt"
"math"
)
type cFunc func(float64) float64
func main() {
fmt.Println("integral:", glq(math.Exp, -3, 3, 5))
}
func glq(f cFunc, a, b float64, n int) float64 {
x, w := glqNodes(n, f)
show := func(label string, vs []float64) {
fmt.Printf("%8s: ", label)
... | 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... |
Produce a functionally identical Pascal code for the snippet given in Go. | package main
import (
"fmt"
"math/big"
)
func commatize(n uint64) string {
s := fmt.Sprintf("%d", n)
le := len(s)
for i := le - 3; i >= 1; i -= 3 {
s = s[0:i] + "," + s[i:]
}
return s
}
func main() {
var z big.Int
var cube1, cube2, cube100k, diff uint64
cubans := make(... | 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 := ... |
Rewrite this program in Pascal while keeping its functionality equivalent to the Go version. | package main
import (
"fmt"
"image"
"image/color"
"image/draw"
"image/gif"
"log"
"math"
"math/rand"
"os"
"time"
)
var bwPalette = color.Palette{
color.Transparent,
color.White,
color.RGBA{R: 0xff, A: 0xff},
color.RGBA{G: 0xff, A: 0xff},
color.RGBA{B: 0xff, A: 0xff},
}
func main() {
const (
width ... | 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... |
Port the following code from Go to Pascal with equivalent syntax and logic. | package main
import (
"fmt"
"image"
"image/color"
"image/draw"
"image/gif"
"log"
"math"
"math/rand"
"os"
"time"
)
var bwPalette = color.Palette{
color.Transparent,
color.White,
color.RGBA{R: 0xff, A: 0xff},
color.RGBA{G: 0xff, A: 0xff},
color.RGBA{B: 0xff, A: 0xff},
}
func main() {
const (
width ... | 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... |
Change the programming language of this snippet from Go to Pascal without modifying what it does. | package main
import (
"fmt"
"math"
)
func main() {
fmt.Println(noise(3.14, 42, 7))
}
func noise(x, y, z float64) float64 {
X := int(math.Floor(x)) & 255
Y := int(math.Floor(y)) & 255
Z := int(math.Floor(z)) & 255
x -= math.Floor(x)
y -= math.Floor(y)
z -= math.Floor(z)
u := fa... | 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,... |
Convert the following code from Go to Pascal, ensuring the logic remains intact. | package main
import (
"flag"
"fmt"
"math"
"math/big"
"os"
)
var maxRev = big.NewInt(math.MaxUint64 / 10)
var ten = big.NewInt(10)
func reverseInt(v *big.Int, result *big.Int) *big.Int {
if v.Cmp(maxRev) <= 0 {
result.SetUint64(reverseUint64(v.Uint64()))
} else {
if true {
s := reverseString(... | program p196;
uses
SysUtils,classes;
const
cMAXNUM = 100*1000*1000;
cMaxCycle = 1500;
cChkDigit = 10;
MaxLen = 256;
cMaxDigit = MAXLEN-1;
type
TDigit = byte;
tpDigit =^TDigit;
tDigitArr = array[0..0] of tDigit;
tpDigitArr = ^tDigitArr;
TNumber = record
... |
Ensure the translated Pascal code behaves exactly like the original Go snippet. | package main
import (
"flag"
"fmt"
"math"
"math/big"
"os"
)
var maxRev = big.NewInt(math.MaxUint64 / 10)
var ten = big.NewInt(10)
func reverseInt(v *big.Int, result *big.Int) *big.Int {
if v.Cmp(maxRev) <= 0 {
result.SetUint64(reverseUint64(v.Uint64()))
} else {
if true {
s := reverseString(... | program p196;
uses
SysUtils,classes;
const
cMAXNUM = 100*1000*1000;
cMaxCycle = 1500;
cChkDigit = 10;
MaxLen = 256;
cMaxDigit = MAXLEN-1;
type
TDigit = byte;
tpDigit =^TDigit;
tDigitArr = array[0..0] of tDigit;
tpDigitArr = ^tDigitArr;
TNumber = record
... |
Generate a Pascal translation of this Go snippet without changing its computational steps. | package main
import "fmt"
const (
msg = "a Top Secret secret"
key = "this is my secret key"
)
func main() {
var z state
z.seed(key)
fmt.Println("Message: ", msg)
fmt.Println("Key : ", key)
fmt.Println("XOR : ", z.vernam(msg))
}
type state struct {
aa, bb, cc uint32
mm ... | PROGRAM RosettaIsaac;
USES
StrUtils;
TYPE
iMode = (iEncrypt, iDecrypt);
VAR
msg : String = 'a Top Secret secret';
key : String = 'this is my secret key';
xctx: String = '';
mctx: String = '';
xptx: String = '';
mptx: String = '';
VAR
randrsl: ARRAY[0 .. 255] OF Cardinal;
randcnt: Cardina... |
Translate the given Go code snippet into Pascal without altering its behavior. | package main
import "fmt"
const (
msg = "a Top Secret secret"
key = "this is my secret key"
)
func main() {
var z state
z.seed(key)
fmt.Println("Message: ", msg)
fmt.Println("Key : ", key)
fmt.Println("XOR : ", z.vernam(msg))
}
type state struct {
aa, bb, cc uint32
mm ... | PROGRAM RosettaIsaac;
USES
StrUtils;
TYPE
iMode = (iEncrypt, iDecrypt);
VAR
msg : String = 'a Top Secret secret';
key : String = 'this is my secret key';
xctx: String = '';
mctx: String = '';
xptx: String = '';
mptx: String = '';
VAR
randrsl: ARRAY[0 .. 255] OF Cardinal;
randcnt: Cardina... |
Preserve the algorithm and functionality while converting the code from Go to Pascal. | package main
import (
"fmt"
"math"
"time"
)
const ld10 = math.Ln2 / math.Ln10
func commatize(n uint64) string {
s := fmt.Sprintf("%d", n)
le := len(s)
for i := le - 3; i >= 1; i -= 3 {
s = s[0:i] + "," + s[i:]
}
return s
}
func p(L, n uint64) uint64 {
i := L
digits :=... | 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 a version of this Go function in Pascal with identical behavior. | package main
import (
"fmt"
"math"
"time"
)
const ld10 = math.Ln2 / math.Ln10
func commatize(n uint64) string {
s := fmt.Sprintf("%d", n)
le := len(s)
for i := le - 3; i >= 1; i -= 3 {
s = s[0:i] + "," + s[i:]
}
return s
}
func p(L, n uint64) uint64 {
i := L
digits :=... | 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 + ... |
Convert this Go block to Pascal, preserving its control flow and logic. | package main
import (
"fmt"
"log"
"math/big"
)
var (
primes []*big.Int
smallPrimes []int
)
func init() {
two := big.NewInt(2)
three := big.NewInt(3)
p521 := big.NewInt(521)
p29 := big.NewInt(29)
primes = append(primes, two)
smallPrimes = append(smallPrimes, 2)
fo... | 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... |
Keep all operations the same but rewrite the snippet in Pascal. | package main
import (
"fmt"
"sort"
"strings"
)
const stx = "\002"
const etx = "\003"
func bwt(s string) (string, error) {
if strings.Index(s, stx) >= 0 || strings.Index(s, etx) >= 0 {
return "", fmt.Errorf("String can't contain STX or ETX")
}
s = stx + s + etx
le := len(s)
tab... | 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;
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.