Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Please provide an equivalent version of this Go code in REXX. | package main
import (
"fmt"
"math"
)
type F = func(float64) float64
func quadSimpsonsMem(f F, a, fa, b, fb float64) (m, fm, simp float64) {
m = (a + b) / 2
fm = f(m)
simp = math.Abs(b-a) / 6 * (fa + 4*fm + fb)
return
}
func quadAsrRec(f F, a, fa, b, fb, eps, whole, m, fm float64) float... |
numeric digits length( pi() ) - length(.)
a= 0; b= 1; f= 'SIN'
sinx= quadAsr('SIN',a,b,"1e" || (-digits() + 1) )
say "Simpson's integration of sine from " a ' to ' b ' = ' sinx
exit
pi: pi= 3.1415926535897... |
Change the following Go code into REXX without altering its purpose. | package main
import (
"fmt"
"math"
)
type F = func(float64) float64
func quadSimpsonsMem(f F, a, fa, b, fb float64) (m, fm, simp float64) {
m = (a + b) / 2
fm = f(m)
simp = math.Abs(b-a) / 6 * (fa + 4*fm + fb)
return
}
func quadAsrRec(f F, a, fa, b, fb, eps, whole, m, fm float64) float... |
numeric digits length( pi() ) - length(.)
a= 0; b= 1; f= 'SIN'
sinx= quadAsr('SIN',a,b,"1e" || (-digits() + 1) )
say "Simpson's integration of sine from " a ' to ' b ' = ' sinx
exit
pi: pi= 3.1415926535897... |
Convert the following code from Go to REXX, ensuring the logic remains intact. | package main
import (
"fmt"
"math/rand"
"strconv"
"strings"
"time"
)
var grid [8][8]byte
func abs(i int) int {
if i >= 0 {
return i
} else {
return -i
}
}
func createFen() string {
placeKings()
placePieces("PPPPPPPP", true)
placePieces("pppppppp", true)
... |
parse arg seed CBs .
if datatype(seed,'W') then call random ,,seed
if CBs=='' | CBs=="," then CBs=1
do boards=1 for abs(CBs)
if sign(CBs)\==CBs then do; say; say center(' board' board... |
Produce a language-to-language conversion: from Go to REXX, same semantics. | package main
import (
"fmt"
"math/big"
)
func sf(n int) *big.Int {
if n < 2 {
return big.NewInt(1)
}
sfact := big.NewInt(1)
fact := big.NewInt(1)
for i := 2; i <= n; i++ {
fact.Mul(fact, big.NewInt(int64(i)))
sfact.Mul(sfact, fact)
}
return sfact
}
func H(n... |
numeric digits 1000
call hdr 'super'; do j=0 to 9; $= $ sf(j); end; call tell
call hdr 'hyper'; do j=0 to 9; $= $ hf(j); end; call tell
call hdr 'alternating '; do j=0 to 9; $= $ af(j); end; call tell
call hdr 'exp... |
Write a version of this Go function in REXX with identical behavior. | package main
import (
"fmt"
"rcu"
)
func factorial(n int) int {
fact := 1
for i := 2; i <= n; i++ {
fact *= i
}
return fact
}
func permutations(input []int) [][]int {
perms := [][]int{input}
a := make([]int, len(input))
copy(a, input)
var n = len(input) - 1
for c... |
pand = reverse(123456789)
gp= 0
do j=9 by -1 for 9; $= right(pand, j)
if sumDigs($)//3==0 then iterate
if \gp then do
call genP iSqrt($)
e... |
Translate this program into REXX but keep the logic exactly as in Go. | package main
import (
"fmt"
"rcu"
)
func factorial(n int) int {
fact := 1
for i := 2; i <= n; i++ {
fact *= i
}
return fact
}
func permutations(input []int) [][]int {
perms := [][]int{input}
a := make([]int, len(input))
copy(a, input)
var n = len(input) - 1
for c... |
pand = reverse(123456789)
gp= 0
do j=9 by -1 for 9; $= right(pand, j)
if sumDigs($)//3==0 then iterate
if \gp then do
call genP iSqrt($)
e... |
Transform the following Go implementation into REXX, maintaining the same output and logic. | package main
import (
"fmt"
"github.com/nsf/termbox-go"
"log"
"math/rand"
"strconv"
"time"
)
type coord struct{ x, y int }
const (
width = 79
height = 22
nCount = float64(width * height)
)
var (
board [width * height]int
score = 0
bold = termbox.AttrBold
curs... |
parse arg sw sd @ b ?r .
if sw=='' | sw=="," then sw= 79
if sd=='' | sd=="," then sd= 22
if @=='' | @=="," then @= '@'
if b=='' | b=="," then b= ' '
if datatype(?r, 'W') then call random ,,?r
if length(@)==2 & d... |
Write a version of this Go function in REXX with identical behavior. | package main
import (
"fmt"
"github.com/nsf/termbox-go"
"log"
"math/rand"
"strconv"
"time"
)
type coord struct{ x, y int }
const (
width = 79
height = 22
nCount = float64(width * height)
)
var (
board [width * height]int
score = 0
bold = termbox.AttrBold
curs... |
parse arg sw sd @ b ?r .
if sw=='' | sw=="," then sw= 79
if sd=='' | sd=="," then sd= 22
if @=='' | @=="," then @= '@'
if b=='' | b=="," then b= ' '
if datatype(?r, 'W') then call random ,,?r
if length(@)==2 & d... |
Please provide an equivalent version of this Go code in REXX. | package main
import (
"fmt"
"log"
"math"
)
var MinusInf = math.Inf(-1)
type MaxTropical struct{ r float64 }
func newMaxTropical(r float64) MaxTropical {
if math.IsInf(r, 1) || math.IsNaN(r) {
log.Fatal("Argument must be a real number or negative infinity.")
}
return MaxTropical{r}
}
... |
call negInf; @x= '(x)'; @a= '(+)'; @h= '(^)'; @e= 'expression'; @c= 'comparison'
numeric digits 1000
x= 2 ; y= -2 ; say is(@x) LS(x) RS(y) $Mul(x,y)
x= -0.001 ; y= nInf ; say is(@a) LS(x) RS(y) $Add(x,y)
... |
Generate an equivalent REXX version of this Go code. | package main
import "fmt"
func shouldSwap(s []byte, start, curr int) bool {
for i := start; i < curr; i++ {
if s[i] == s[curr] {
return false
}
}
return true
}
func findPerms(s []byte, index, n int, res *[]string) {
if index >= n {
*res = append(*res, string(s))
... |
parse arg g
if g='' | g="," then g= 2 3 1
#= words(g)
@= left('ABCDEFGHIJKLMNOPQRSTUVWXYZ', #)
LO=
HI=
do i=1 for #... |
Change the programming language of this snippet from Go to REXX without modifying what it does. | package main
import "fmt"
func gcd(a, b uint) uint {
if b == 0 {
return a
}
return gcd(b, a%b)
}
func lcm(a, b uint) uint {
return a / gcd(a, b) * b
}
func ipow(x, p uint) uint {
prod := uint(1)
for p > 0 {
if p&1 != 0 {
prod *= x
}
p >>= 1
... |
numeric digits 500
parse arg lim.1 lim.2 lim.3 .
if lim.1=='' | lim.1=="," then lim.1= 15 - 1
if lim.2=='' | lim.2=="," then lim.2= 180 - 1
if lim.3=='' | lim.3=="," then lim.3= 180
call Fib
do i=1 fo... |
Maintain the same structure and functionality when rewriting this code in REXX. | package main
import (
"fmt"
"math"
"math/big"
"strconv"
"strings"
)
type minmult struct {
min int
mult float64
}
var abbrevs = map[string]minmult{
"PAIRs": {4, 2}, "SCOres": {3, 20}, "DOZens": {3, 12},
"GRoss": {2, 144}, "GREATGRoss": {7, 1728}, "GOOGOLs": {6, 1e100},
}
var metr... |
numeric digits 2000
@.=; @.1= '2greatGRo 24Gros 288Doz 1,728pairs 172.8SCOre'
@.2= '1,567 +1.567k 0.1567e-2m'
@.3= '25.123kK 25.123m 2.5123e-00002G'
@.4= '25.123kiKI 25.123Mi 2.5123e-00002Gi +.25123E-7Ei'
@.5= '-.25123e-34Vikki 2e-77gooGols'
... |
Change the programming language of this snippet from Go to REXX without modifying what it does. | package main
import (
"fmt"
"math"
"math/big"
"strconv"
"strings"
)
type minmult struct {
min int
mult float64
}
var abbrevs = map[string]minmult{
"PAIRs": {4, 2}, "SCOres": {3, 20}, "DOZens": {3, 12},
"GRoss": {2, 144}, "GREATGRoss": {7, 1728}, "GOOGOLs": {6, 1e100},
}
var metr... |
numeric digits 2000
@.=; @.1= '2greatGRo 24Gros 288Doz 1,728pairs 172.8SCOre'
@.2= '1,567 +1.567k 0.1567e-2m'
@.3= '25.123kK 25.123m 2.5123e-00002G'
@.4= '25.123kiKI 25.123Mi 2.5123e-00002Gi +.25123E-7Ei'
@.5= '-.25123e-34Vikki 2e-77gooGols'
... |
Ensure the translated REXX code behaves exactly like the original Go snippet. | package main
import (
"fmt"
"math"
)
const MAXITER = 151
func minkowski(x float64) float64 {
if x > 1 || x < 0 {
return math.Floor(x) + minkowski(x-math.Floor(x))
}
p := uint64(x)
q := uint64(1)
r := p + 1
s := uint64(1)
d := 1.0
y := float64(p)
for {
d = d... |
numeric digits 40
say fmt( mink( 0.5 * (1+sqrt(5) ) ) ) fmt( 5/3 )
say fmt( minkI(-5/9) ) fmt( (sqrt(13) - 7) / 6)
say fmt( mink( minkI(0.718281828) ) ) fmt( mink( minkI(.1213141516171819) ) )
exit 0
floor: proc... |
Transform the following Go implementation into REXX, maintaining the same output and logic. | package main
import (
"fmt"
"math/big"
"rcu"
"sort"
)
var zero = new(big.Int)
var one = big.NewInt(1)
var two = big.NewInt(2)
var three = big.NewInt(3)
var four = big.NewInt(4)
var five = big.NewInt(5)
var six = big.NewInt(6)
func primeFactorsWheel(m *big.Int) []*big.Int {
n := new(big.Int).Set(... |
numeric digits 20
parse arg LO HI .
if LO=='' | LO=="," then LO= 2
if HI=='' | HI=="," then HI= 20
@hpc= 'home prime chain for '
w= length(HI)
do j=max(2, ... |
Port the following code from Go to REXX with equivalent syntax and logic. | package main
import (
"fmt"
"strings"
"unicode"
)
func main() {
f := NewFourIsSeq()
fmt.Print("The lengths of the first 201 words are:")
for i := 1; i <= 201; i++ {
if i%25 == 1 {
fmt.Printf("\n%3d: ", i)
}
_, n := f.WordLen(i)
fmt.Printf(" %2d", n)
}
fmt.Println()
fmt.Println("Length of sentence ... |
@= 'Four is the number of letters in the first word of this sentence,'
parse arg N M
if N='' | N="," then N= 201
if M='' | M="," then M=1000 10000 100000 1000000
@abcU= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'... |
Change the programming language of this snippet from Go to REXX without modifying what it does. | package main
import (
"fmt"
"github.com/ALTree/bigfloat"
"math/big"
)
const (
prec = 256
ps = "3.1415926535897932384626433832795028841971693993751058209749445923078164"
)
func q(d int64) *big.Float {
pi, _ := new(big.Float).SetPrec(prec).SetString(ps)
t := new(big.Float).SetPrec(prec).... |
d= min( length(pi()), length(e()) ) - length(.)
parse arg digs sDigs . 1 . . $
if digs=='' | digs=="," then digs= d
if sDigs=='' | sDigs=="," then sDigs= d % 2
if $='' | $="," then $= 19 43 67 163
digs= min( digs, d)
sDigs= min(sDigs, d... |
Write the same algorithm in REXX as shown in this Go implementation. | package main
import (
"fmt"
"github.com/ALTree/bigfloat"
"math/big"
)
const (
prec = 256
ps = "3.1415926535897932384626433832795028841971693993751058209749445923078164"
)
func q(d int64) *big.Float {
pi, _ := new(big.Float).SetPrec(prec).SetString(ps)
t := new(big.Float).SetPrec(prec).... |
d= min( length(pi()), length(e()) ) - length(.)
parse arg digs sDigs . 1 . . $
if digs=='' | digs=="," then digs= d
if sDigs=='' | sDigs=="," then sDigs= d % 2
if $='' | $="," then $= 19 43 67 163
digs= min( digs, d)
sDigs= min(sDigs, d... |
Convert this Go snippet to REXX and keep its semantics consistent. | package main
import (
"fmt"
"strings"
)
var data = `
FILE FILE DEPENDENCIES
==== =================
top1 des1 ip1 ip2
top2 des1 ip2 ip3
ip1 extra1 ip1a ipcommon
ip2 ip2a ip2b ip2c ipcommon
des1 des1a des1b des1c
des1a des1a1 des1a2
des1c des1c1 extra1`
func main() {
g, dep, err ... |
parse arg job
jobL.=; stage.=; #.=0; @.=; JL=
tree.=; tree.1= ' top1 des1 ip1 ip2 '
tree.2= ' top2 des1 ip2 ip3 '
tree.3= ... |
Keep all operations the same but rewrite the snippet in REXX. | package main
import (
"fmt"
"strings"
)
var data = `
FILE FILE DEPENDENCIES
==== =================
top1 des1 ip1 ip2
top2 des1 ip2 ip3
ip1 extra1 ip1a ipcommon
ip2 ip2a ip2b ip2c ipcommon
des1 des1a des1b des1c
des1a des1a1 des1a2
des1c des1c1 extra1`
func main() {
g, dep, err ... |
parse arg job
jobL.=; stage.=; #.=0; @.=; JL=
tree.=; tree.1= ' top1 des1 ip1 ip2 '
tree.2= ' top2 des1 ip2 ip3 '
tree.3= ... |
Translate the given Go code snippet into REXX without altering its behavior. | package main
import (
"fmt"
"math"
)
func isqrt(x uint64) uint64 {
x0 := x >> 1
x1 := (x0 + x/x0) >> 1
for x1 < x0 {
x0 = x1
x1 = (x0 + x/x0) >> 1
}
return x0
}
func gcd(x, y uint64) uint64 {
for y != 0 {
x, y = y, x%y
}
return x
}
var multiplier = []u... |
numeric digits 100
call dMults 1,3,5,7,11,3*5,3*7,3*11,5*7,5*11,7*11, 3*5*7, 3*5*11, 3*7*11, 5*7*11, 3*5*7*11
call dTests 2501, 12851, 13289, 75301, 120787, 967009, 997417, 7091569, 13290059, ,
42854447, 223553581, 2027651281, 11111111111, 100895598169, 10027... |
Can you help me rewrite this code in REXX instead of Go, keeping it the same logically? | package main
import (
"fmt"
"io"
"log"
"math"
"math/rand"
"os"
"time"
)
type MinHeapNode struct{ element, index int }
type MinHeap struct{ nodes []MinHeapNode }
func left(i int) int {
return (2*i + 1)
}
func right(i int) int {
return (2*i + 2)
}
func newMinHeap(nodes []MinHeapN... |
parse arg FID n lim seed .
if FID=='' | FID=="," then FID= 'SORT_EXT.OUT'
if n=='' | n=="," then n= 500
if lim=='' | lim=="," then lim= 10
if datatype(seed, 'W') then call random ,,seed
sWork = 'SORTWORK.'
call gen n,lim ... |
Change the programming language of this snippet from Go to REXX without modifying what it does. | package main
import (
"fmt"
"io"
"log"
"math"
"math/rand"
"os"
"time"
)
type MinHeapNode struct{ element, index int }
type MinHeap struct{ nodes []MinHeapNode }
func left(i int) int {
return (2*i + 1)
}
func right(i int) int {
return (2*i + 2)
}
func newMinHeap(nodes []MinHeapN... |
parse arg FID n lim seed .
if FID=='' | FID=="," then FID= 'SORT_EXT.OUT'
if n=='' | n=="," then n= 500
if lim=='' | lim=="," then lim= 10
if datatype(seed, 'W') then call random ,,seed
sWork = 'SORTWORK.'
call gen n,lim ... |
Transform the following Go implementation into REXX, maintaining the same output and logic. | package main
import (
"fmt"
"math/big"
)
func repeatedAdd(bf *big.Float, times int) *big.Float {
if times < 2 {
return bf
}
var sum big.Float
for i := 0; i < times; i++ {
sum.Add(&sum, bf)
}
return &sum
}
func main() {
s := "12345679"
t := "123456790"
e := ... |
maxW= linesize() - 1
_123= 012345679; reps= 0; mult= 63
say ' # addend uncompressed (zoned) BCD number'
say left('ββ ββββββ β', maxW, 'β')
do j=-7 to 21 ... |
Transform the following Go implementation into REXX, maintaining the same output and logic. | package main
import (
"fmt"
"math/big"
)
func repeatedAdd(bf *big.Float, times int) *big.Float {
if times < 2 {
return bf
}
var sum big.Float
for i := 0; i < times; i++ {
sum.Add(&sum, bf)
}
return &sum
}
func main() {
s := "12345679"
t := "123456790"
e := ... |
maxW= linesize() - 1
_123= 012345679; reps= 0; mult= 63
say ' # addend uncompressed (zoned) BCD number'
say left('ββ ββββββ β', maxW, 'β')
do j=-7 to 21 ... |
Ensure the translated REXX code behaves exactly like the original Go snippet. | package main
import (
"fmt"
"os"
"regexp"
"strconv"
)
var (
rl1 = 'a'
rl2 = '\''
)
var (
is1 = "abc"
is2 = "\"ab\tc\""
)
var (
rs1 = `
first"
second'
third"
`
rs2 = `This is one way of including a ` + "`" + ` in a raw string literal.`
rs3 = `\d+`
)
func... |
a= 'This is one method of including a '' (an apostrophe) within a string.'
b= "This is one method of including a ' (an apostrophe) within a string."
c= "This is one method of including a "" (a double quote) within a s... |
Change the following Go code into REXX without altering its purpose. | package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"path"
)
func main() {
self := path.Base(os.Args[0]) + ".go"
bytes, err := ioutil.ReadFile(self)
if err != nil {
log.Fatal(err)
}
fmt.Print(string(bytes))
}
|
do j=1 for sourceline()
call lineout , sourceline(j)
end
|
Produce a language-to-language conversion: from Go to REXX, same semantics. | package main
import (
"bufio"
"fmt"
"log"
"math/rand"
"os"
"strings"
"time"
)
const (
easy = 1
hard = 4
)
var n [16]int
func initGrid() {
for i := 0; i < 16; i++ {
n[i] = i + 1
}
}
func setDiff(level int) {
moves := 3
if level == hard {
moves = 12... |
sep= copies("β",8); pad=left('',1+length(sep) )
parse arg N hard seed .
er= '***error***'
if N=='' | N=="," then N= 4
if hard=='' | hard=="," then hard= 2
if \isInt(N) then do; say sep er "grid size isn't an integer: " ... |
Convert this Go snippet to REXX and keep its semantics consistent. | package main
import (
"bufio"
"fmt"
"log"
"math/rand"
"os"
"strconv"
"time"
)
const (
esc = "\033"
test = true
)
var scanner = bufio.NewScanner(os.Stdin)
func indexOf(s []int, el int) int {
for i, v := range s {
if v == el {
return i
}
}
... |
parse arg seed .; if datatype(seed, 'W') then call random ,,seed
__= copies('β', 9)
do forever
do until $pot+3<$g; $pot = random(0, 3)
$g = random(0, 6)
end
say
say copies('β', 55); ... |
Rewrite this program in REXX while keeping its functionality equivalent to the Go version. | package main
import (
"bufio"
"fmt"
"log"
"math/rand"
"os"
"strconv"
"time"
)
const (
esc = "\033"
test = true
)
var scanner = bufio.NewScanner(os.Stdin)
func indexOf(s []int, el int) int {
for i, v := range s {
if v == el {
return i
}
}
... |
parse arg seed .; if datatype(seed, 'W') then call random ,,seed
__= copies('β', 9)
do forever
do until $pot+3<$g; $pot = random(0, 3)
$g = random(0, 6)
end
say
say copies('β', 55); ... |
Can you help me rewrite this code in REXX instead of Go, keeping it the same logically? | package main
import (
"fmt"
"io/ioutil"
"net/http"
"regexp"
"sort"
"strconv"
)
type Result struct {
lang string
users int
}
func main() {
const minimum = 25
ex := `"Category:(.+?)( User)?"(\}|,"categoryinfo":\{"size":(\d+),)`
re := regexp.MustCompile(ex)
page := "http... |
parse arg catFID lanFID outFID .
call init
call get
call eSort #,0
call tSort
call eSort #,1
call out ... |
Translate this program into REXX but keep the logic exactly as in Go. | package main
import (
"fmt"
"io/ioutil"
"net/http"
"regexp"
"sort"
"strconv"
)
type Result struct {
lang string
users int
}
func main() {
const minimum = 25
ex := `"Category:(.+?)( User)?"(\}|,"categoryinfo":\{"size":(\d+),)`
re := regexp.MustCompile(ex)
page := "http... |
parse arg catFID lanFID outFID .
call init
call get
call eSort #,0
call tSort
call eSort #,1
call out ... |
Rewrite the snippet below in REXX so it works the same as the original Go code. | package main
import (
"fmt"
"math/big"
)
var g = [][]int{
0: {1},
2: {0},
5: {2, 6},
6: {5},
1: {2},
3: {1, 2, 4},
4: {5, 3},
7: {4, 7, 6},
}
func main() {
tarjan(g, func(c []int) { fmt.Println(c) })
}
func tarjan(g [][]int, emit func([]int)) {
var indexed, stacked... |
g='[2] [3] [1] [2 3 5] [4 6] [3 7] [6] [5 7 8]'
gg=g
Do i=1 By 1 While gg>''
Parse Var gg '[' g.i ']' gg
name.i=i-1
End
g.0=i-1
index.=0
lowlink.=0
stacked.=0
stack.=0
x=1
Do n=1 To g.0
If index.n=0 Then
If strong_connect(n)=0 Then
Return
End
Exit
strong_connect: Procedure Expose x g. index. lowl... |
Convert this Go block to REXX, preserving its control flow and logic. | package main
import (
"fmt"
big "github.com/ncw/gmp"
"rcu"
)
func main() {
fact := big.NewInt(1)
sum := 0.0
first := int64(0)
firstRatio := 0.0
fmt.Println("The mean proportion of zero digits in factorials up to the following are:")
for n := int64(1); n <= 50000; n++ {
... |
parse arg $
if $='' | $="," then $= 100 1000 10000
#= words($)
numeric digits 100
big= word($, #); != 1
do i=1 for big
... |
Write a version of this Go function in REXX with identical behavior. | package main
import (
"fmt"
"math/big"
"strconv"
"strings"
)
var suffixes = " KMGTPEZYXWVU"
var ggl = googol()
func googol() *big.Float {
g1 := new(big.Float).SetPrec(500)
g1.SetInt64(10000000000)
g := new(big.Float)
g.Set(g1)
for i := 2; i <= 10; i++ {
g.Mul(g, g1)
}
... |
@.=
parse arg @.1
if @.1=='' then do; @.1= ' 87,654,321 '
@.2= ' -998,877,665,544,332,211,000 3 '
@.3= ' +112,233 0 ... |
Can you help me rewrite this code in REXX instead of Go, keeping it the same logically? | package main
import (
"fmt"
"math/big"
"strconv"
"strings"
)
var suffixes = " KMGTPEZYXWVU"
var ggl = googol()
func googol() *big.Float {
g1 := new(big.Float).SetPrec(500)
g1.SetInt64(10000000000)
g := new(big.Float)
g.Set(g1)
for i := 2; i <= 10; i++ {
g.Mul(g, g1)
}
... |
@.=
parse arg @.1
if @.1=='' then do; @.1= ' 87,654,321 '
@.2= ' -998,877,665,544,332,211,000 3 '
@.3= ' +112,233 0 ... |
Convert this Go snippet to REXX and keep its semantics consistent. | package main
import (
"fmt"
"time"
)
const rocket = `
/\
( )
( )
/|/\|\
/_||||_\
`
func printRocket(above int) {
fmt.Print(rocket)
for i := 1; i <= above; i++ {
fmt.Println(" ||")
}
}
func cls() {
fmt.Print("\x1B[2J")
}
func main() {
for n := 5; n >= 1; n-... |
parse arg cntDown .
if cntDown=='' | cntDown=="," then cntDown= 5
@. =
@.1= ' /\ '
@.2= ' | | '
@.3= ' | | '
@.4= ' | | '
@.5= ' /|/\|\ '
@.6= '/_||||_\'
do rs=1 while @.rs\==''
... |
Write the same algorithm in REXX as shown in this Go implementation. | package main
import (
"fmt"
"reflect"
"unsafe"
)
func main() {
bs := []byte("Hello world!")
fmt.Println(string(bs))
g := "globe"
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&bs))
for i := 0; i < 5; i++ {
data := (*byte)(unsafe.Pointer(hdr.Data + uintptr(i) + 6))
*data ... | ADDRESS SYSTEM 'cat cat.rexx'
|
Preserve the algorithm and functionality while converting the code from Java to Pascal. | import java.util.List;
import java.util.Arrays;
import java.util.Collections;
public class RotateLeft {
public static void main(String[] args) {
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
System.out.println("original: " + list);
Collections.rotate(list, -3);
Syst... | begin
% increments a and returns the new value %
integer procedure inc ( integer value result a ) ; begin a := a + 1; a end;
% shifts in place the elements of a left by n, a must have bounds lb::ub %
procedure rotateLeft ( integer array a ( * ); integer value lb, ub, n ) ;
if n < ( ub - lb ) a... |
Convert this Java block to Pascal, preserving its control flow and logic. | package example.diagdiag;
public class Program {
public static void main(String[] args) {
DiagonalDiagonalMatrix A = new DiagonalDiagonalMatrix(7);
System.out.println(A);
}
}
class DiagonalDiagonalMatrix {
final int n;
private double[][] a = null;
public Matrix(int n) {
... | program diagonaldiagonal;
const N = 7;
type
index = 1..N;
var
a : array[index, index] of real;
i, j, j1, j2 : index;
begin
for i := 1 to N do
begin
for j := 1 to N do
a[i, j] := 0.0;
j1 := i;
j2 := N - i + 1;
a[i, j1] := 1.0;
a[i, j2] := 1.0;
... |
Port the following code from Java to Pascal with equivalent syntax and logic. | public class NumericSeparatorSyntax {
public static void main(String[] args) {
runTask("Underscore allowed as seperator", 1_000);
runTask("Multiple consecutive underscores allowed:", 1__0_0_0);
runTask("Many multiple consecutive underscores allowed:", 1________________________00);
r... | program test;
begin
WriteLn(%1001_1001);
WriteLn(&121_102);
WriteLn(-1_123_123);
WriteLn($1_123_123);
WriteLn(-1_123___123.000_000);
WriteLn(1_123_123.000_000e1_2);
end.
|
Change the following Java code into Pascal without altering its purpose. | import java.io.*;
import java.util.*;
public class MazeSolver
{
private static String[] readLines (InputStream f) throws IOException
{
BufferedReader r =
new BufferedReader (new InputStreamReader (f, "US-ASCII"));
ArrayList<String> lines = new ArrayList<String>();
Strin... | procedure SolveMaze(var AMaze: TMaze; const S, E: TPoint);
var
Route : TRoute;
Position : TPoint;
V : TPoint;
begin
ClearVisited(AMaze);
Position := S;
Route := TStack<TPoint>.Create;
with Position do
try
AMaze[x, y].Visited := True;
repeat
if (y > 0) and not AMaze[x,... |
Write a version of this Java function in Pascal with identical behavior. | module MultiplyExample
{
static <Value extends Number> Value multiply(Value n1, Value n2)
{
return n1 * n2;
}
void run()
{
(Int i1, Int i2) = (7, 3);
Int i3 = multiply(i1, i2);
(Double d1, Double d2) = (2.7182818, 3.1415);
Double d3 = multiply... | function multiply(a, b: real): real;
begin
multiply := a * b
end;
|
Can you help me rewrite this code in Pascal instead of Java, keeping it the same logically? | class SpecialPrimes {
private static boolean isPrime(int n) {
if (n < 2) return false;
if (n%2 == 0) return n == 2;
if (n%3 == 0) return n == 3;
int d = 5;
while (d*d <= n) {
if (n%d == 0) return false;
d += 2;
if (n%d == 0) return false;
... | 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... |
Preserve the algorithm and functionality while converting the code from Java to Pascal. | class SpecialPrimes {
private static boolean isPrime(int n) {
if (n < 2) return false;
if (n%2 == 0) return n == 2;
if (n%3 == 0) return n == 3;
int d = 5;
while (d*d <= n) {
if (n%d == 0) return false;
d += 2;
if (n%d == 0) return false;
... | 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. | private static final Random rng = new Random();
void sattoloCycle(Object[] items) {
for (int i = items.length-1; i > 0; i--) {
int j = rng.nextInt(i);
Object tmp = items[i];
items[i] = items[j];
items[j] = tmp;
}
}
| 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.... |
Rewrite the snippet below in Pascal so it works the same as the original Java code. | private static final Random rng = new Random();
void sattoloCycle(Object[] items) {
for (int i = items.length-1; i > 0; i--) {
int j = rng.nextInt(i);
Object tmp = items[i];
items[i] = items[j];
items[j] = tmp;
}
}
| 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.... |
Translate the given Java code snippet into Pascal without altering its behavior. | import java.math.BigInteger;
import java.util.List;
public class Brazilian {
private static final List<Integer> primeList = List.of(
2, 3, 5, 7, 9, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,
97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 16... | 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... |
Maintain the same structure and functionality when rewriting this code in Pascal. | import java.math.BigInteger;
import java.util.List;
public class Brazilian {
private static final List<Integer> primeList = List.of(
2, 3, 5, 7, 9, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,
97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 16... | 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... |
Convert the following code from Java to Pascal, ensuring the logic remains intact. | public class Factorion {
public static void main(String [] args){
System.out.println("Base 9:");
for(int i = 1; i <= 1499999; i++){
String iStri = String.valueOf(i);
int multiplied = operate(iStri,9);
if(multiplied == i){
System.out.print(i + "\t")... | 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... |
Write a version of this Java function in Pascal with identical behavior. | public class Factorion {
public static void main(String [] args){
System.out.println("Base 9:");
for(int i = 1; i <= 1499999; i++){
String iStri = String.valueOf(i);
int multiplied = operate(iStri,9);
if(multiplied == i){
System.out.print(i + "\t")... | 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... |
Produce a language-to-language conversion: from Java to Pascal, same semantics. | public class DivisorSum {
private static long divisorSum(long n) {
var total = 1L;
var power = 2L;
for (; (n & 1) == 0; power <<= 1, n >>= 1) {
total += power;
}
for (long p = 3; p * p <= n; p += 2) {
long sum = 1;
for (po... | 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... |
Produce a language-to-language conversion: from Java to Pascal, same semantics. | public class DivisorSum {
private static long divisorSum(long n) {
var total = 1L;
var power = 2L;
for (; (n & 1) == 0; power <<= 1, n >>= 1) {
total += power;
}
for (long p = 3; p * p <= n; p += 2) {
long sum = 1;
for (po... | 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 Java version. | public class BeadSort
{
public static void main(String[] args)
{
BeadSort now=new BeadSort();
int[] arr=new int[(int)(Math.random()*11)+5];
for(int i=0;i<arr.length;i++)
arr[i]=(int)(Math.random()*10);
System.out.print("Unsorted: ");
now.display1D(arr);
int[] sort=now.beadSort(arr);
System.out.pr... | 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:=... |
Produce a language-to-language conversion: from Java to Pascal, same semantics. | import java.util.*;
import java.util.stream.IntStream;
public class CastingOutNines {
public static void main(String[] args) {
System.out.println(castOut(16, 1, 255));
System.out.println(castOut(10, 1, 99));
System.out.println(castOut(17, 1, 288));
}
static List<Integer> castOut(i... | 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);
... |
Translate this program into Pascal but keep the logic exactly as in Java. | import java.util.*;
import java.util.stream.IntStream;
public class CastingOutNines {
public static void main(String[] args) {
System.out.println(castOut(16, 1, 255));
System.out.println(castOut(10, 1, 99));
System.out.println(castOut(17, 1, 288));
}
static List<Integer> castOut(i... | 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);
... |
Write the same code in Pascal as shown below in Java. | public class TauFunction {
private static long divisorCount(long n) {
long total = 1;
for (; (n & 1) == 0; n >>= 1) {
++total;
}
for (long p = 3; p * p <= n; p += 2) {
long count = 1;
for (; n % p == 0; n /= p) {
+... | 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 %
... |
Write the same code in Pascal as shown below in Java. | public class TauFunction {
private static long divisorCount(long n) {
long total = 1;
for (; (n & 1) == 0; n >>= 1) {
++total;
}
for (long p = 3; p * p <= n; p += 2) {
long count = 1;
for (; n % p == 0; n /= p) {
+... | 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 %
... |
Write the same algorithm in Pascal as shown in this Java implementation. | import java.io.IOException;
public class Interpreter {
public final static int MEMORY_SIZE = 65536;
private final char[] memory = new char[MEMORY_SIZE];
private int dp;
private int ip;
private int border;
private void reset() {
for (int i = 0; i < MEMORY_SIZE; i++) {
mem... | program rcExceuteBrainF;
uses
Crt;
Const
DataSize= 1024;
MaxNest= 1000;
procedure ExecuteBF(Source: string);
var
Dp: pByte;
DataSeg: Pointer;
Ip: pChar;
Las... |
Change the following Java code into Pascal without altering its purpose. | import java.io.IOException;
public class Interpreter {
public final static int MEMORY_SIZE = 65536;
private final char[] memory = new char[MEMORY_SIZE];
private int dp;
private int ip;
private int border;
private void reset() {
for (int i = 0; i < MEMORY_SIZE; i++) {
mem... | program rcExceuteBrainF;
uses
Crt;
Const
DataSize= 1024;
MaxNest= 1000;
procedure ExecuteBF(Source: string);
var
Dp: pByte;
DataSeg: Pointer;
Ip: pChar;
Las... |
Write a version of this Java function in Pascal with identical behavior. | public class MertensFunction {
public static void main(String[] args) {
System.out.printf("First 199 terms of the merten function are as follows:%n ");
for ( int n = 1 ; n < 200 ; n++ ) {
System.out.printf("%2d ", mertenFunction(n));
if ( (n+1) % 20 == 0 ) {
... | 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
... |
Please provide an equivalent version of this Java code in Pascal. | import java.util.*;
public class ErdosPrimes {
public static void main(String[] args) {
boolean[] sieve = primeSieve(1000000);
int maxPrint = 2500;
int maxCount = 7875;
System.out.printf("Erd\u0151s primes less than %d:\n", maxPrint);
for (int count = 0, prime = 1; count < m... | 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... |
Please provide an equivalent version of this Java code in Pascal. | import java.util.*;
public class ErdosPrimes {
public static void main(String[] args) {
boolean[] sieve = primeSieve(1000000);
int maxPrint = 2500;
int maxCount = 7875;
System.out.printf("Erd\u0151s primes less than %d:\n", maxPrint);
for (int count = 0, prime = 1; count < m... | 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... |
Produce a functionally identical Pascal code for the snippet given in Java. | import java.util.ArrayList;
import java.util.List;
public class PerfectTotientNumbers {
public static void main(String[] args) {
computePhi();
int n = 20;
System.out.printf("The first %d perfect totient numbers:%n%s%n", n, perfectTotient(n));
}
private static final List<Intege... | 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... |
Transform the following Java implementation into Pascal, maintaining the same output and logic. | import java.util.ArrayList;
import java.util.List;
public class PerfectTotientNumbers {
public static void main(String[] args) {
computePhi();
int n = 20;
System.out.printf("The first %d perfect totient numbers:%n%s%n", n, perfectTotient(n));
}
private static final List<Intege... | 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... |
Write the same code in Pascal as shown below in Java. | import java.util.Arrays;
public class TwoSum {
public static void main(String[] args) {
long sum = 21;
int[] arr = {0, 2, 11, 19, 90};
System.out.println(Arrays.toString(twoSum(arr, sum)));
}
public static int[] twoSum(int[] a, long target) {
int i = 0, j = a.length - 1;
... | 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;
... |
Produce a functionally identical Pascal code for the snippet given in Java. | import java.util.Arrays;
public class TwoSum {
public static void main(String[] args) {
long sum = 21;
int[] arr = {0, 2, 11, 19, 90};
System.out.println(Arrays.toString(twoSum(arr, sum)));
}
public static int[] twoSum(int[] a, long target) {
int i = 0, j = a.length - 1;
... | 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 Java block to Pascal, preserving its control flow and logic. | public class UnprimeableNumbers {
private static int MAX = 10_000_000;
private static boolean[] primes = new boolean[MAX];
public static void main(String[] args) {
sieve();
System.out.println("First 35 unprimeable numbers:");
displayUnprimeableNumbers(35);
int n = 600;
... | 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 the given Java code snippet into Pascal without altering its behavior. | public class Tau {
private static long divisorCount(long n) {
long total = 1;
for (; (n & 1) == 0; n >>= 1) {
++total;
}
for (long p = 3; p * p <= n; p += 2) {
long count = 1;
for (; n % p == 0; n /= p) {
++count;
... | 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... |
Port the following code from Java to Pascal with equivalent syntax and logic. | import java.math.BigInteger;
public class PrimeSum {
private static int digitSum(BigInteger bi) {
int sum = 0;
while (bi.compareTo(BigInteger.ZERO) > 0) {
BigInteger[] dr = bi.divideAndRemainder(BigInteger.TEN);
sum += dr[1].intValue();
bi = dr[0];
}
... | 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... |
Translate this program into Pascal but keep the logic exactly as in Java. | import java.math.BigInteger;
public class PrimeSum {
private static int digitSum(BigInteger bi) {
int sum = 0;
while (bi.compareTo(BigInteger.ZERO) > 0) {
BigInteger[] dr = bi.divideAndRemainder(BigInteger.TEN);
sum += dr[1].intValue();
bi = dr[0];
}
... | 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... |
Rewrite this program in Pascal while keeping its functionality equivalent to the Java version. | public class PrimeDigits {
private static boolean primeDigitsSum13(int n) {
int sum = 0;
while (n > 0) {
int r = n % 10;
if (r != 2 && r != 3 && r != 5 && r != 7) {
return false;
}
n /= 10;
sum += r;
}
return... | 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
... |
Change the programming language of this snippet from Java to Pascal without modifying what it does. | public class PrimeDigits {
private static boolean primeDigitsSum13(int n) {
int sum = 0;
while (n > 0) {
int r = n % 10;
if (r != 2 && r != 3 && r != 5 && r != 7) {
return false;
}
n /= 10;
sum += r;
}
return... | 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
... |
Write the same algorithm in Pascal as shown in this Java implementation. | import java.math.BigInteger;
import java.util.Arrays;
public class CircularPrimes {
public static void main(String[] args) {
System.out.println("First 19 circular primes:");
int p = 2;
for (int count = 0; count < 19; ++p) {
if (isCircularPrime(p)) {
if (count > 0... | 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... |
Generate an equivalent Pascal version of this Java code. | public class ScriptedMain {
public static int meaningOfLife() {
return 42;
}
public static void main(String[] args) {
System.out.println("Main: 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.
|
Change the programming language of this snippet from Java to Pascal without modifying what it does. | public class ScriptedMain {
public static int meaningOfLife() {
return 42;
}
public static void main(String[] args) {
System.out.println("Main: 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.
|
Transform the following Java implementation into Pascal, maintaining the same output and logic. | public class NicePrimes {
private static boolean isPrime(long n) {
if (n < 2) {
return false;
}
if (n % 2 == 0L) {
return n == 2L;
}
if (n % 3 == 0L) {
return n == 3L;
}
var p = 5L;
while (p * p <= n) {
... | 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
... |
Write a version of this Java function in Pascal with identical behavior. | public class NicePrimes {
private static boolean isPrime(long n) {
if (n < 2) {
return false;
}
if (n % 2 == 0L) {
return n == 2L;
}
if (n % 3 == 0L) {
return n == 3L;
}
var p = 5L;
while (p * p <= n) {
... | 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
... |
Ensure the translated Pascal code behaves exactly like the original Java snippet. | import java.util.Scanner;
public class LastSunday
{
static final String[] months={"January","February","March","April","May","June","July","August","September","October","November","December"};
public static int[] findLastSunday(int year)
{
boolean isLeap = isLeapYear(year);
int[] days={31,isLeap?29:28,31... | 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 Java to Pascal, same semantics. | import java.util.Scanner;
public class LastSunday
{
static final String[] months={"January","February","March","April","May","June","July","August","September","October","November","December"};
public static int[] findLastSunday(int year)
{
boolean isLeap = isLeapYear(year);
int[] days={31,isLeap?29:28,31... | 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 Java to Pascal, same semantics. | import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
public class RandomLatinSquares {
private static void printSquare(List<List<Integer>> latin) {
for (List<Integer> row : latin) {
Iterator<Integer> it = row.itera... |
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 :... |
Translate this program into Pascal but keep the logic exactly as in Java. | import java.util.ArrayList;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
public class EstheticNumbers {
interface RecTriConsumer<A, B, C> {
void accept(RecTriConsumer<A, B, C> f, A a, B b, C c);
}
private static boolean isEsthetic(long n, long b) {
if (n == 0) {
... | 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... |
Translate this program into Pascal but keep the logic exactly as in Java. | import java.util.List;
import java.util.Random;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
public class Rpg {
private static final Random random = new Random();
public static int genAttribute() {
return random.ints(1, 6 + 1)
.limit(4)
... | 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 Java snippet to Pascal and keep its semantics consistent. | import java.util.*;
public class LIS {
public static <E extends Comparable<? super E>> List<E> lis(List<E> n) {
List<Node<E>> pileTops = new ArrayList<Node<E>>();
for (E x : n) {
Node<E> node = new Node<E>();
node.value = x;
int i = Collections.binarySearch(pileTops, ... | 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... |
Generate a Pascal translation of this Java snippet without changing its computational steps. | public static void main(String... args){
HashMap<String, Integer> vars = new HashMap<String, Integer>();
vars.put("Variable name", 3);
vars.put("Next variable name", 5);
Scanner sc = new Scanner(System.in);
String str = sc.next();
vars.put(str,... | 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... |
Translate the given Java code snippet into Pascal without altering its behavior. | import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class Main {
public static void main(String[] args) throws IOException {
final int endOfFile = -1;
try ( FileReader reader = new FileReader("input.txt", StandardCharsets.UTF_8) ) {
while (... |
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... |
Write the same algorithm in Pascal as shown in this Java implementation. | import java.util.Arrays;
public class CircleSort {
public static void main(String[] args) {
circleSort(new int[]{2, 14, 4, 6, 8, 1, 3, 5, 7, 11, 0, 13, 12, -1});
}
public static void circleSort(int[] arr) {
if (arr.length > 0)
do {
System.out.println(Arrays.toS... |
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;
... |
Can you help me rewrite this code in Pascal instead of Java, keeping it the same logically? | import java.util.*;
public class PenneysGame {
public static void main(String[] args) {
Random rand = new Random();
String compChoice = "", playerChoice;
if (rand.nextBoolean()) {
for (int i = 0; i < 3; i++)
compChoice += "HT".charAt(rand.nextInt(2));
... | 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... |
Port the provided Java code into Pascal while preserving the original functionality. | import java.util.*;
import static java.util.Arrays.stream;
import static java.util.stream.Collectors.toList;
public class Nonoblock {
public static void main(String[] args) {
printBlock("21", 5);
printBlock("", 5);
printBlock("8", 10);
printBlock("2323", 15);
printBlock("23... | 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 the following code from Java to Pascal, ensuring the logic remains intact. | import java.util.*;
import static java.util.Arrays.stream;
import static java.util.stream.Collectors.toList;
public class Nonoblock {
public static void main(String[] args) {
printBlock("21", 5);
printBlock("", 5);
printBlock("8", 10);
printBlock("2323", 15);
printBlock("23... | 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] :... |
Produce a language-to-language conversion: from Java to Pascal, same semantics. |
import processing.sound.*;
float[] frequencies = {261.63, 293.66, 329.63, 349.23, 392.00, 440.00, 493.88, 523.25};
SinOsc sine;
size(500,500);
sine = new SinOsc(this);
for(int i=0;i<frequencies.length;i++){
sine.freq(frequencies[i]);
sine.play();
delay(500);
}
|
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 Java code in Pascal. |
import processing.sound.*;
float[] frequencies = {261.63, 293.66, 329.63, 349.23, 392.00, 440.00, 493.88, 523.25};
SinOsc sine;
size(500,500);
sine = new SinOsc(this);
for(int i=0;i<frequencies.length;i++){
sine.freq(frequencies[i]);
sine.play();
delay(500);
}
|
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.
|
Write the same algorithm in Pascal as shown in this Java implementation. | package hu.pj.alg.test;
import hu.pj.alg.BoundedKnapsack;
import hu.pj.obj.Item;
import java.util.*;
import java.text.*;
public class BoundedKnapsackForTourists {
public BoundedKnapsackForTourists() {
BoundedKnapsack bok = new BoundedKnapsack(400);
bok.add("map", 9, 150, 1);
bok... | 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 Java code. | import java.util.Arrays;
import java.util.LinkedList;
public class Strand{
public static <E extends Comparable<? super E>>
LinkedList<E> strandSort(LinkedList<E> list){
if(list.size() <= 1) return list;
LinkedList<E> result = new LinkedList<E>();
while(list.size() > 0){
LinkedList<E> sorted = new Linked... | 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... |
Please provide an equivalent version of this Java code in Pascal. | import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class AbelianSandpile {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Frame frame = new Frame();
frame.setVisible(true);
... | 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... |
Please provide an equivalent version of this Java code in Pascal. | import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class AbelianSandpile {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Frame frame = new Frame();
frame.setVisible(true);
... | 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... |
Produce a language-to-language conversion: from Java to Pascal, same semantics. | import java.awt.*;
import static java.lang.Math.*;
import javax.swing.*;
public class XiaolinWu extends JPanel {
public XiaolinWu() {
Dimension dim = new Dimension(640, 640);
setPreferredSize(dim);
setBackground(Color.white);
}
void plot(Graphics2D g, double x, double y, double c)... | 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, ... |
Generate an equivalent Pascal version of this Java code. | import java.util.TreeSet;
public class Farey{
private static class Frac implements Comparable<Frac>{
int num;
int den;
public Frac(int num, int den){
this.num = num;
this.den = den;
}
@Override
public String toString(){
return num + "/" + den;
}
@Override
public int compareTo(Frac o){
... | 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... |
Port the provided Java code into Pascal while preserving the original functionality. | import java.util.TreeSet;
public class Farey{
private static class Frac implements Comparable<Frac>{
int num;
int den;
public Frac(int num, int den){
this.num = num;
this.den = den;
}
@Override
public String toString(){
return num + "/" + den;
}
@Override
public int compareTo(Frac o){
... | 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 Java code into Pascal without altering its purpose. | public class ImplicitTypeConversion{
public static void main(String...args){
System.out.println( "Primitive conversions" );
byte by = -1;
short sh = by;
int in = sh;
long lo = in;
System.out.println( "byte value -1 to 3 integral types: " + lo );
float fl = ... | program implicitTypeConversion;
var
i: integer;
r: real;
begin
i := 42;
r := i
end.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.