Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Can you help me rewrite this code in PHP instead of Fortran, keeping it the same logically?
program VectorProducts real, dimension(3) :: a, b, c a = (/ 3, 4, 5 /) b = (/ 4, 3, 5 /) c = (/ -5, -12, -13 /) print *, dot_product(a, b) print *, cross_product(a, b) print *, s3_product(a, b, c) print *, v3_product(a, b, c) contains function cross_product(a, b) real, dimension(3) :: cross_...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Convert this Groovy block to PHP, preserving its control flow and logic.
def pairwiseOperation = { x, y, Closure binaryOp -> assert x && y && x.size() == y.size() [x, y].transpose().collect(binaryOp) } def pwMult = pairwiseOperation.rcurry { it[0] * it[1] } def dotProduct = { x, y -> assert x && y && x.size() == y.size() pwMult(x, y).sum() }
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Change the programming language of this snippet from Groovy to PHP without modifying what it does.
def pairwiseOperation = { x, y, Closure binaryOp -> assert x && y && x.size() == y.size() [x, y].transpose().collect(binaryOp) } def pwMult = pairwiseOperation.rcurry { it[0] * it[1] } def dotProduct = { x, y -> assert x && y && x.size() == y.size() pwMult(x, y).sum() }
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Write the same algorithm in PHP as shown in this Haskell implementation.
import Data.Monoid ((<>)) type Vector a = [a] type Scalar a = a a, b, c, d :: Vector Int a = [3, 4, 5] b = [4, 3, 5] c = [-5, -12, -13] d = [3, 4, 5, 6] dot :: (Num t) => Vector t -> Vector t -> Scalar t dot u v | length u == length v = sum $ zipWith (*) u v | otherwise = error "Dotted Vectors must be of...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Transform the following Haskell implementation into PHP, maintaining the same output and logic.
import Data.Monoid ((<>)) type Vector a = [a] type Scalar a = a a, b, c, d :: Vector Int a = [3, 4, 5] b = [4, 3, 5] c = [-5, -12, -13] d = [3, 4, 5, 6] dot :: (Num t) => Vector t -> Vector t -> Scalar t dot u v | length u == length v = sum $ zipWith (*) u v | otherwise = error "Dotted Vectors must be of...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Produce a functionally identical PHP code for the snippet given in Icon.
record Vector3D(x, y, z) procedure toString (vector) return "(" || vector.x || ", " || vector.y || ", " || vector.z || ")" end procedure dotProduct (a, b) return a.x * b.x + a.y * b.y + a.z * b.z end procedure crossProduct (a, b) x := a.y * b.z - a.z * b.y y := a.z * b.x - a.x * b.z z := a.x * b.y - a.y ...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Write the same algorithm in PHP as shown in this Icon implementation.
record Vector3D(x, y, z) procedure toString (vector) return "(" || vector.x || ", " || vector.y || ", " || vector.z || ")" end procedure dotProduct (a, b) return a.x * b.x + a.y * b.y + a.z * b.z end procedure crossProduct (a, b) x := a.y * b.z - a.z * b.y y := a.z * b.x - a.x * b.z z := a.x * b.y - a.y ...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Change the following J code into PHP without altering its purpose.
cross=: (1&|.@[ * 2&|.@]) - 2&|.@[ * 1&|.@]
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Write a version of this J function in PHP with identical behavior.
cross=: (1&|.@[ * 2&|.@]) - 2&|.@[ * 1&|.@]
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Please provide an equivalent version of this Julia code in PHP.
using LinearAlgebra const a = [3, 4, 5] const b = [4, 3, 5] const c = [-5, -12, -13] println("Test Vectors:") @show a b c println("\nVector Products:") @show a ⋅ b @show a × b @show a ⋅ (b × c) @show a × (b × c)
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Keep all operations the same but rewrite the snippet in PHP.
using LinearAlgebra const a = [3, 4, 5] const b = [4, 3, 5] const c = [-5, -12, -13] println("Test Vectors:") @show a b c println("\nVector Products:") @show a ⋅ b @show a × b @show a ⋅ (b × c) @show a × (b × c)
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Transform the following Lua implementation into PHP, maintaining the same output and logic.
Vector = {} function Vector.new( _x, _y, _z ) return { x=_x, y=_y, z=_z } end function Vector.dot( A, B ) return A.x*B.x + A.y*B.y + A.z*B.z end function Vector.cross( A, B ) return { x = A.y*B.z - A.z*B.y, y = A.z*B.x - A.x*B.z, z = A.x*B.y - A.y*B.x } end function Vector.scal...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Translate the given Lua code snippet into PHP without altering its behavior.
Vector = {} function Vector.new( _x, _y, _z ) return { x=_x, y=_y, z=_z } end function Vector.dot( A, B ) return A.x*B.x + A.y*B.y + A.z*B.z end function Vector.cross( A, B ) return { x = A.y*B.z - A.z*B.y, y = A.z*B.x - A.x*B.z, z = A.x*B.y - A.y*B.x } end function Vector.scal...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Produce a language-to-language conversion: from Mathematica to PHP, same semantics.
a={3,4,5}; b={4,3,5}; c={-5,-12,-13}; a.b Cross[a,b] a.Cross[b,c] Cross[a,Cross[b,c]]
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Can you help me rewrite this code in PHP instead of Mathematica, keeping it the same logically?
a={3,4,5}; b={4,3,5}; c={-5,-12,-13}; a.b Cross[a,b] a.Cross[b,c] Cross[a,Cross[b,c]]
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Rewrite this program in PHP while keeping its functionality equivalent to the MATLAB version.
dot(a,b) cross(a,b) dot(a,cross(b,c)) cross(a,cross(b,c)) cross(a,b) cross(a,b) dot(a,cross(b,c)) cross(a,cross(b,c))
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Translate the given MATLAB code snippet into PHP without altering its behavior.
dot(a,b) cross(a,b) dot(a,cross(b,c)) cross(a,cross(b,c)) cross(a,b) cross(a,b) dot(a,cross(b,c)) cross(a,cross(b,c))
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Convert this Nim snippet to PHP and keep its semantics consistent.
import strformat, strutils type Vector3 = array[1..3, float] proc `$`(a: Vector3): string = result = "(" for x in a: result.addSep(", ", 1) result.add &"{x}" result.add ')' proc cross(a, b: Vector3): Vector3 = result = [a[2]*b[3] - a[3]*b[2], a[3]*b[1] - a[1]*b[3], a[1]*b[2] - a[2]*b[1]] proc dot(a,...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Produce a language-to-language conversion: from Nim to PHP, same semantics.
import strformat, strutils type Vector3 = array[1..3, float] proc `$`(a: Vector3): string = result = "(" for x in a: result.addSep(", ", 1) result.add &"{x}" result.add ')' proc cross(a, b: Vector3): Vector3 = result = [a[2]*b[3] - a[3]*b[2], a[3]*b[1] - a[1]*b[3], a[1]*b[2] - a[2]*b[1]] proc dot(a,...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Maintain the same structure and functionality when rewriting this code in PHP.
let a = (3.0, 4.0, 5.0) let b = (4.0, 3.0, 5.0) let c = (-5.0, -12.0, -13.0) let string_of_vector (x,y,z) = Printf.sprintf "(%g, %g, %g)" x y z let dot (a1, a2, a3) (b1, b2, b3) = (a1 *. b1) +. (a2 *. b2) +. (a3 *. b3) let cross (a1, a2, a3) (b1, b2, b3) = (a2 *. b3 -. a3 *. b2, a3 *. b1 -. a1 *. b3, a1 ...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Please provide an equivalent version of this OCaml code in PHP.
let a = (3.0, 4.0, 5.0) let b = (4.0, 3.0, 5.0) let c = (-5.0, -12.0, -13.0) let string_of_vector (x,y,z) = Printf.sprintf "(%g, %g, %g)" x y z let dot (a1, a2, a3) (b1, b2, b3) = (a1 *. b1) +. (a2 *. b2) +. (a3 *. b3) let cross (a1, a2, a3) (b1, b2, b3) = (a2 *. b3 -. a3 *. b2, a3 *. b1 -. a1 *. b3, a1 ...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Ensure the translated PHP code behaves exactly like the original Pascal snippet.
Program VectorProduct (output); type Tvector = record x, y, z: double end; function dotProduct(a, b: Tvector): double; begin dotProduct := a.x*b.x + a.y*b.y + a.z*b.z; end; function crossProduct(a, b: Tvector): Tvector; begin crossProduct.x := a.y*b.z - a.z*b.y; crossProduct.y := a.z*b.x - a.x*b.z; ...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Ensure the translated PHP code behaves exactly like the original Pascal snippet.
Program VectorProduct (output); type Tvector = record x, y, z: double end; function dotProduct(a, b: Tvector): double; begin dotProduct := a.x*b.x + a.y*b.y + a.z*b.z; end; function crossProduct(a, b: Tvector): Tvector; begin crossProduct.x := a.y*b.z - a.z*b.y; crossProduct.y := a.z*b.x - a.x*b.z; ...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Ensure the translated PHP code behaves exactly like the original Perl snippet.
package Vector; use List::Util 'sum'; use List::MoreUtils 'pairwise'; sub new { shift; bless [@_] } use overload ( '""' => sub { "(@{+shift})" }, '&' => sub { sum pairwise { $a * $b } @{+shift}, @{+shift} }, '^' => sub { my @a = @{+shift}; ...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Keep all operations the same but rewrite the snippet in PHP.
package Vector; use List::Util 'sum'; use List::MoreUtils 'pairwise'; sub new { shift; bless [@_] } use overload ( '""' => sub { "(@{+shift})" }, '&' => sub { sum pairwise { $a * $b } @{+shift}, @{+shift} }, '^' => sub { my @a = @{+shift}; ...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Generate a PHP translation of this PowerShell snippet without changing its computational steps.
function dot-product($a,$b) { $a[0]*$b[0] + $a[1]*$b[1] + $a[2]*$b[2] } function cross-product($a,$b) { $v1 = $a[1]*$b[2] - $a[2]*$b[1] $v2 = $a[2]*$b[0] - $a[0]*$b[2] $v3 = $a[0]*$b[1] - $a[1]*$b[0] @($v1,$v2,$v3) } function scalar-triple-product($a,$b,$c) { dot-product $a (cross-product $b...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Generate an equivalent PHP version of this PowerShell code.
function dot-product($a,$b) { $a[0]*$b[0] + $a[1]*$b[1] + $a[2]*$b[2] } function cross-product($a,$b) { $v1 = $a[1]*$b[2] - $a[2]*$b[1] $v2 = $a[2]*$b[0] - $a[0]*$b[2] $v3 = $a[0]*$b[1] - $a[1]*$b[0] @($v1,$v2,$v3) } function scalar-triple-product($a,$b,$c) { dot-product $a (cross-product $b...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Port the provided Racket code into PHP while preserving the original functionality.
#lang racket (define (dot-product X Y) (for/sum ([x (in-vector X)] [y (in-vector Y)]) (* x y))) (define (cross-product X Y) (define len (vector-length X)) (for/vector ([n len]) (define (ref V i) (vector-ref V (modulo (+ n i) len))) (- (* (ref X 1) (ref Y 2)) (* (ref X 2) (ref Y 1))))) (define (scalar-t...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Can you help me rewrite this code in PHP instead of Racket, keeping it the same logically?
#lang racket (define (dot-product X Y) (for/sum ([x (in-vector X)] [y (in-vector Y)]) (* x y))) (define (cross-product X Y) (define len (vector-length X)) (for/vector ([n len]) (define (ref V i) (vector-ref V (modulo (+ n i) len))) (- (* (ref X 1) (ref Y 2)) (* (ref X 2) (ref Y 1))))) (define (scalar-t...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Write the same algorithm in PHP as shown in this REXX implementation.
a = .vector~new(3, 4, 5); b = .vector~new(4, 3, 5); c = .vector~new(-5, -12, -13); say a~dot(b) say a~cross(b) say a~scalarTriple(b, c) say a~vectorTriple(b, c) ::class vector ::method init expose x y z use arg x, y, z ::attribute x get ::attribute y get ::attribute z get -- dot product operation ::method dot ...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Maintain the same structure and functionality when rewriting this code in PHP.
a = .vector~new(3, 4, 5); b = .vector~new(4, 3, 5); c = .vector~new(-5, -12, -13); say a~dot(b) say a~cross(b) say a~scalarTriple(b, c) say a~vectorTriple(b, c) ::class vector ::method init expose x y z use arg x, y, z ::attribute x get ::attribute y get ::attribute z get -- dot product operation ::method dot ...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Change the programming language of this snippet from Ruby to PHP without modifying what it does.
class Vector property x, y, z def initialize(@x : Int64, @y : Int64, @z : Int64) end def dot_product(other : Vector) (self.x * other.x) + (self.y * other.y) + (self.z * other.z) end def cross_product(other : Vector) Vector.new(self.y * other.z - self.z * other.y, self.z * o...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Preserve the algorithm and functionality while converting the code from Ruby to PHP.
class Vector property x, y, z def initialize(@x : Int64, @y : Int64, @z : Int64) end def dot_product(other : Vector) (self.x * other.x) + (self.y * other.y) + (self.z * other.z) end def cross_product(other : Vector) Vector.new(self.y * other.z - self.z * other.y, self.z * o...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Generate a PHP translation of this Scala snippet without changing its computational steps.
class Vector3D(val x: Double, val y: Double, val z: Double) { infix fun dot(v: Vector3D) = x * v.x + y * v.y + z * v.z infix fun cross(v: Vector3D) = Vector3D(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x) fun scalarTriple(v: Vector3D, w: Vector3D) = this dot (v cross w) fun vect...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Ensure the translated PHP code behaves exactly like the original Scala snippet.
class Vector3D(val x: Double, val y: Double, val z: Double) { infix fun dot(v: Vector3D) = x * v.x + y * v.y + z * v.z infix fun cross(v: Vector3D) = Vector3D(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x) fun scalarTriple(v: Vector3D, w: Vector3D) = this dot (v cross w) fun vect...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Port the following code from Swift to PHP with equivalent syntax and logic.
import Foundation infix operator • : MultiplicationPrecedence infix operator × : MultiplicationPrecedence public struct Vector { public var x = 0.0 public var y = 0.0 public var z = 0.0 public init(x: Double, y: Double, z: Double) { (self.x, self.y, self.z) = (x, y, z) } public static func • (lhs: V...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Convert this Swift block to PHP, preserving its control flow and logic.
import Foundation infix operator • : MultiplicationPrecedence infix operator × : MultiplicationPrecedence public struct Vector { public var x = 0.0 public var y = 0.0 public var z = 0.0 public init(x: Double, y: Double, z: Double) { (self.x, self.y, self.z) = (x, y, z) } public static func • (lhs: V...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Ensure the translated PHP code behaves exactly like the original Tcl snippet.
proc dot {A B} { lassign $A a1 a2 a3 lassign $B b1 b2 b3 expr {$a1*$b1 + $a2*$b2 + $a3*$b3} } proc cross {A B} { lassign $A a1 a2 a3 lassign $B b1 b2 b3 list [expr {$a2*$b3 - $a3*$b2}] \ [expr {$a3*$b1 - $a1*$b3}] \ [expr {$a1*$b2 - $a2*$b1}] } proc scalarTriple {A B C} { dot $A [cross $...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Rewrite the snippet below in PHP so it works the same as the original Tcl code.
proc dot {A B} { lassign $A a1 a2 a3 lassign $B b1 b2 b3 expr {$a1*$b1 + $a2*$b2 + $a3*$b3} } proc cross {A B} { lassign $A a1 a2 a3 lassign $B b1 b2 b3 list [expr {$a2*$b3 - $a3*$b2}] \ [expr {$a3*$b1 - $a1*$b3}] \ [expr {$a1*$b2 - $a2*$b1}] } proc scalarTriple {A B C} { dot $A [cross $...
<?php class Vector { private $values; public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'...
Produce a language-to-language conversion: from C to Rust, same semantics.
#include<stdio.h> typedef struct{ float i,j,k; }Vector; Vector a = {3, 4, 5},b = {4, 3, 5},c = {-5, -12, -13}; float dotProduct(Vector a, Vector b) { return a.i*b.i+a.j*b.j+a.k*b.k; } Vector crossProduct(Vector a,Vector b) { Vector c = {a.j*b.k - a.k*b.j, a.k*b.i - a.i*b.k, a.i*b.j - a.j*b.i}; return c; } f...
#[derive(Debug)] struct Vector { x: f64, y: f64, z: f64, } impl Vector { fn new(x: f64, y: f64, z: f64) -> Self { Vector { x: x, y: y, z: z, } } fn dot_product(&self, other: &Vector) -> f64 { (self.x * other.x) + (self.y * other.y) + ...
Write the same code in Rust as shown below in C++.
#include <iostream> template< class T > class D3Vector { template< class U > friend std::ostream & operator<<( std::ostream & , const D3Vector<U> & ) ; public : D3Vector( T a , T b , T c ) { x = a ; y = b ; z = c ; } T dotproduct ( const D3Vector & rhs ) { T scalar = x * rhs.x + ...
#[derive(Debug)] struct Vector { x: f64, y: f64, z: f64, } impl Vector { fn new(x: f64, y: f64, z: f64) -> Self { Vector { x: x, y: y, z: z, } } fn dot_product(&self, other: &Vector) -> f64 { (self.x * other.x) + (self.y * other.y) + ...
Port the following code from C# to Rust with equivalent syntax and logic.
using System; using System.Windows.Media.Media3D; class VectorProducts { static double ScalarTripleProduct(Vector3D a, Vector3D b, Vector3D c) { return Vector3D.DotProduct(a, Vector3D.CrossProduct(b, c)); } static Vector3D VectorTripleProduct(Vector3D a, Vector3D b, Vector3D c) { r...
#[derive(Debug)] struct Vector { x: f64, y: f64, z: f64, } impl Vector { fn new(x: f64, y: f64, z: f64) -> Self { Vector { x: x, y: y, z: z, } } fn dot_product(&self, other: &Vector) -> f64 { (self.x * other.x) + (self.y * other.y) + ...
Transform the following C# implementation into Rust, maintaining the same output and logic.
using System; using System.Windows.Media.Media3D; class VectorProducts { static double ScalarTripleProduct(Vector3D a, Vector3D b, Vector3D c) { return Vector3D.DotProduct(a, Vector3D.CrossProduct(b, c)); } static Vector3D VectorTripleProduct(Vector3D a, Vector3D b, Vector3D c) { r...
#[derive(Debug)] struct Vector { x: f64, y: f64, z: f64, } impl Vector { fn new(x: f64, y: f64, z: f64) -> Self { Vector { x: x, y: y, z: z, } } fn dot_product(&self, other: &Vector) -> f64 { (self.x * other.x) + (self.y * other.y) + ...
Translate this program into Rust but keep the logic exactly as in Go.
package main import "fmt" type vector struct { x, y, z float64 } var ( a = vector{3, 4, 5} b = vector{4, 3, 5} c = vector{-5, -12, -13} ) func dot(a, b vector) float64 { return a.x*b.x + a.y*b.y + a.z*b.z } func cross(a, b vector) vector { return vector{a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z,...
#[derive(Debug)] struct Vector { x: f64, y: f64, z: f64, } impl Vector { fn new(x: f64, y: f64, z: f64) -> Self { Vector { x: x, y: y, z: z, } } fn dot_product(&self, other: &Vector) -> f64 { (self.x * other.x) + (self.y * other.y) + ...
Transform the following Go implementation into Rust, maintaining the same output and logic.
package main import "fmt" type vector struct { x, y, z float64 } var ( a = vector{3, 4, 5} b = vector{4, 3, 5} c = vector{-5, -12, -13} ) func dot(a, b vector) float64 { return a.x*b.x + a.y*b.y + a.z*b.z } func cross(a, b vector) vector { return vector{a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z,...
#[derive(Debug)] struct Vector { x: f64, y: f64, z: f64, } impl Vector { fn new(x: f64, y: f64, z: f64) -> Self { Vector { x: x, y: y, z: z, } } fn dot_product(&self, other: &Vector) -> f64 { (self.x * other.x) + (self.y * other.y) + ...
Translate the given Rust code snippet into Python without altering its behavior.
#[derive(Debug)] struct Vector { x: f64, y: f64, z: f64, } impl Vector { fn new(x: f64, y: f64, z: f64) -> Self { Vector { x: x, y: y, z: z, } } fn dot_product(&self, other: &Vector) -> f64 { (self.x * other.x) + (self.y * other.y) + ...
def crossp(a, b): assert len(a) == len(b) == 3, 'For 3D vectors only' a1, a2, a3 = a b1, b2, b3 = b return (a2*b3 - a3*b2, a3*b1 - a1*b3, a1*b2 - a2*b1) def dotp(a,b): assert len(a) == len(b), 'Vector sizes must match' return sum(aterm * bterm for aterm,bterm in zip(a, b)) def scal...
Rewrite this program in Python while keeping its functionality equivalent to the Rust version.
#[derive(Debug)] struct Vector { x: f64, y: f64, z: f64, } impl Vector { fn new(x: f64, y: f64, z: f64) -> Self { Vector { x: x, y: y, z: z, } } fn dot_product(&self, other: &Vector) -> f64 { (self.x * other.x) + (self.y * other.y) + ...
def crossp(a, b): assert len(a) == len(b) == 3, 'For 3D vectors only' a1, a2, a3 = a b1, b2, b3 = b return (a2*b3 - a3*b2, a3*b1 - a1*b3, a1*b2 - a2*b1) def dotp(a,b): assert len(a) == len(b), 'Vector sizes must match' return sum(aterm * bterm for aterm,bterm in zip(a, b)) def scal...
Generate an equivalent VB version of this Rust code.
#[derive(Debug)] struct Vector { x: f64, y: f64, z: f64, } impl Vector { fn new(x: f64, y: f64, z: f64) -> Self { Vector { x: x, y: y, z: z, } } fn dot_product(&self, other: &Vector) -> f64 { (self.x * other.x) + (self.y * other.y) + ...
Option Base 1 Function dot_product(a As Variant, b As Variant) As Variant dot_product = WorksheetFunction.SumProduct(a, b) End Function Function cross_product(a As Variant, b As Variant) As Variant cross_product = Array(a(2) * b(3) - a(3) * b(2), a(3) * b(1) - a(1) * b(3), a(1) * b(2) - a(2) * b(1)) End Funct...
Convert the following code from Rust to VB, ensuring the logic remains intact.
#[derive(Debug)] struct Vector { x: f64, y: f64, z: f64, } impl Vector { fn new(x: f64, y: f64, z: f64) -> Self { Vector { x: x, y: y, z: z, } } fn dot_product(&self, other: &Vector) -> f64 { (self.x * other.x) + (self.y * other.y) + ...
Option Base 1 Function dot_product(a As Variant, b As Variant) As Variant dot_product = WorksheetFunction.SumProduct(a, b) End Function Function cross_product(a As Variant, b As Variant) As Variant cross_product = Array(a(2) * b(3) - a(3) * b(2), a(3) * b(1) - a(1) * b(3), a(1) * b(2) - a(2) * b(1)) End Funct...
Convert this C block to Rust, preserving its control flow and logic.
#include<stdio.h> typedef struct{ float i,j,k; }Vector; Vector a = {3, 4, 5},b = {4, 3, 5},c = {-5, -12, -13}; float dotProduct(Vector a, Vector b) { return a.i*b.i+a.j*b.j+a.k*b.k; } Vector crossProduct(Vector a,Vector b) { Vector c = {a.j*b.k - a.k*b.j, a.k*b.i - a.i*b.k, a.i*b.j - a.j*b.i}; return c; } f...
#[derive(Debug)] struct Vector { x: f64, y: f64, z: f64, } impl Vector { fn new(x: f64, y: f64, z: f64) -> Self { Vector { x: x, y: y, z: z, } } fn dot_product(&self, other: &Vector) -> f64 { (self.x * other.x) + (self.y * other.y) + ...
Transform the following C++ implementation into Rust, maintaining the same output and logic.
#include <iostream> template< class T > class D3Vector { template< class U > friend std::ostream & operator<<( std::ostream & , const D3Vector<U> & ) ; public : D3Vector( T a , T b , T c ) { x = a ; y = b ; z = c ; } T dotproduct ( const D3Vector & rhs ) { T scalar = x * rhs.x + ...
#[derive(Debug)] struct Vector { x: f64, y: f64, z: f64, } impl Vector { fn new(x: f64, y: f64, z: f64) -> Self { Vector { x: x, y: y, z: z, } } fn dot_product(&self, other: &Vector) -> f64 { (self.x * other.x) + (self.y * other.y) + ...
Generate an equivalent Rust version of this Java code.
public class VectorProds{ public static class Vector3D<T extends Number>{ private T a, b, c; public Vector3D(T a, T b, T c){ this.a = a; this.b = b; this.c = c; } public double dot(Vector3D<?> vec){ return (a.doubleValue() * vec.a.dou...
#[derive(Debug)] struct Vector { x: f64, y: f64, z: f64, } impl Vector { fn new(x: f64, y: f64, z: f64) -> Self { Vector { x: x, y: y, z: z, } } fn dot_product(&self, other: &Vector) -> f64 { (self.x * other.x) + (self.y * other.y) + ...
Write a version of this Java function in Rust with identical behavior.
public class VectorProds{ public static class Vector3D<T extends Number>{ private T a, b, c; public Vector3D(T a, T b, T c){ this.a = a; this.b = b; this.c = c; } public double dot(Vector3D<?> vec){ return (a.doubleValue() * vec.a.dou...
#[derive(Debug)] struct Vector { x: f64, y: f64, z: f64, } impl Vector { fn new(x: f64, y: f64, z: f64) -> Self { Vector { x: x, y: y, z: z, } } fn dot_product(&self, other: &Vector) -> f64 { (self.x * other.x) + (self.y * other.y) + ...
Translate the given Ada code snippet into C# without altering its behavior.
with Ada.Text_IO; use Ada.Text_IO; procedure Goodbye_World is begin Put_Line (Standard_Error, "Goodbye, World!"); end Goodbye_World;
static class StdErr { static void Main(string[] args) { Console.Error.WriteLine("Goodbye, World!"); } }
Change the programming language of this snippet from Ada to C without modifying what it does.
with Ada.Text_IO; use Ada.Text_IO; procedure Goodbye_World is begin Put_Line (Standard_Error, "Goodbye, World!"); end Goodbye_World;
#include <stdio.h> int main() { fprintf(stderr, "Goodbye, "); fputs("World!\n", stderr); return 0; }
Write the same algorithm in C++ as shown in this Ada implementation.
with Ada.Text_IO; use Ada.Text_IO; procedure Goodbye_World is begin Put_Line (Standard_Error, "Goodbye, World!"); end Goodbye_World;
#include <iostream> int main() { std::cerr << "Goodbye, World!\n"; }
Rewrite the snippet below in Go so it works the same as the original Ada code.
with Ada.Text_IO; use Ada.Text_IO; procedure Goodbye_World is begin Put_Line (Standard_Error, "Goodbye, World!"); end Goodbye_World;
package main func main() { println("Goodbye, World!") }
Translate this program into Java but keep the logic exactly as in Ada.
with Ada.Text_IO; use Ada.Text_IO; procedure Goodbye_World is begin Put_Line (Standard_Error, "Goodbye, World!"); end Goodbye_World;
public class Err{ public static void main(String[] args){ System.err.println("Goodbye, World!"); } }
Write the same algorithm in Python as shown in this Ada implementation.
with Ada.Text_IO; use Ada.Text_IO; procedure Goodbye_World is begin Put_Line (Standard_Error, "Goodbye, World!"); end Goodbye_World;
import sys print >> sys.stderr, "Goodbye, World!"
Convert the following code from Ada to VB, ensuring the logic remains intact.
with Ada.Text_IO; use Ada.Text_IO; procedure Goodbye_World is begin Put_Line (Standard_Error, "Goodbye, World!"); end Goodbye_World;
Sub StandardError() Debug.Print "Goodbye World!" End Sub
Rewrite this program in C while keeping its functionality equivalent to the AutoHotKey version.
FileAppend, Goodbye`, World!, stderr  
#include <stdio.h> int main() { fprintf(stderr, "Goodbye, "); fputs("World!\n", stderr); return 0; }
Rewrite the snippet below in C# so it works the same as the original AutoHotKey code.
FileAppend, Goodbye`, World!, stderr  
static class StdErr { static void Main(string[] args) { Console.Error.WriteLine("Goodbye, World!"); } }
Generate a C++ translation of this AutoHotKey snippet without changing its computational steps.
FileAppend, Goodbye`, World!, stderr  
#include <iostream> int main() { std::cerr << "Goodbye, World!\n"; }
Write the same code in Java as shown below in AutoHotKey.
FileAppend, Goodbye`, World!, stderr  
public class Err{ public static void main(String[] args){ System.err.println("Goodbye, World!"); } }
Transform the following AWK implementation into C, maintaining the same output and logic.
BEGIN { print "Goodbye, World!"| "cat 1>&2" }
#include <stdio.h> int main() { fprintf(stderr, "Goodbye, "); fputs("World!\n", stderr); return 0; }
Maintain the same structure and functionality when rewriting this code in C#.
BEGIN { print "Goodbye, World!"| "cat 1>&2" }
static class StdErr { static void Main(string[] args) { Console.Error.WriteLine("Goodbye, World!"); } }
Maintain the same structure and functionality when rewriting this code in C++.
BEGIN { print "Goodbye, World!"| "cat 1>&2" }
#include <iostream> int main() { std::cerr << "Goodbye, World!\n"; }
Can you help me rewrite this code in Java instead of AWK, keeping it the same logically?
BEGIN { print "Goodbye, World!"| "cat 1>&2" }
public class Err{ public static void main(String[] args){ System.err.println("Goodbye, World!"); } }
Keep all operations the same but rewrite the snippet in Python.
BEGIN { print "Goodbye, World!"| "cat 1>&2" }
import sys print >> sys.stderr, "Goodbye, World!"
Generate a VB translation of this AWK snippet without changing its computational steps.
BEGIN { print "Goodbye, World!"| "cat 1>&2" }
Sub StandardError() Debug.Print "Goodbye World!" End Sub
Produce a language-to-language conversion: from AWK to Go, same semantics.
BEGIN { print "Goodbye, World!"| "cat 1>&2" }
package main func main() { println("Goodbye, World!") }
Change the following BBC_Basic code into C without altering its purpose.
STD_ERROR_HANDLE = -12 SYS "GetStdHandle", STD_ERROR_HANDLE TO @hfile%(1) PRINT #13, "Goodbye, World!" QUIT
#include <stdio.h> int main() { fprintf(stderr, "Goodbye, "); fputs("World!\n", stderr); return 0; }
Generate an equivalent C# version of this BBC_Basic code.
STD_ERROR_HANDLE = -12 SYS "GetStdHandle", STD_ERROR_HANDLE TO @hfile%(1) PRINT #13, "Goodbye, World!" QUIT
static class StdErr { static void Main(string[] args) { Console.Error.WriteLine("Goodbye, World!"); } }
Write the same code in C++ as shown below in BBC_Basic.
STD_ERROR_HANDLE = -12 SYS "GetStdHandle", STD_ERROR_HANDLE TO @hfile%(1) PRINT #13, "Goodbye, World!" QUIT
#include <iostream> int main() { std::cerr << "Goodbye, World!\n"; }
Keep all operations the same but rewrite the snippet in Java.
STD_ERROR_HANDLE = -12 SYS "GetStdHandle", STD_ERROR_HANDLE TO @hfile%(1) PRINT #13, "Goodbye, World!" QUIT
public class Err{ public static void main(String[] args){ System.err.println("Goodbye, World!"); } }
Convert this BBC_Basic snippet to Python and keep its semantics consistent.
STD_ERROR_HANDLE = -12 SYS "GetStdHandle", STD_ERROR_HANDLE TO @hfile%(1) PRINT #13, "Goodbye, World!" QUIT
import sys print >> sys.stderr, "Goodbye, World!"
Maintain the same structure and functionality when rewriting this code in VB.
STD_ERROR_HANDLE = -12 SYS "GetStdHandle", STD_ERROR_HANDLE TO @hfile%(1) PRINT #13, "Goodbye, World!" QUIT
Sub StandardError() Debug.Print "Goodbye World!" End Sub
Port the provided BBC_Basic code into Go while preserving the original functionality.
STD_ERROR_HANDLE = -12 SYS "GetStdHandle", STD_ERROR_HANDLE TO @hfile%(1) PRINT #13, "Goodbye, World!" QUIT
package main func main() { println("Goodbye, World!") }
Generate a C translation of this Common_Lisp snippet without changing its computational steps.
(binding [*out* *err*] (println "Goodbye, world!"))
#include <stdio.h> int main() { fprintf(stderr, "Goodbye, "); fputs("World!\n", stderr); return 0; }
Generate a C# translation of this Common_Lisp snippet without changing its computational steps.
(binding [*out* *err*] (println "Goodbye, world!"))
static class StdErr { static void Main(string[] args) { Console.Error.WriteLine("Goodbye, World!"); } }
Translate the given Common_Lisp code snippet into C++ without altering its behavior.
(binding [*out* *err*] (println "Goodbye, world!"))
#include <iostream> int main() { std::cerr << "Goodbye, World!\n"; }
Write the same code in Java as shown below in Common_Lisp.
(binding [*out* *err*] (println "Goodbye, world!"))
public class Err{ public static void main(String[] args){ System.err.println("Goodbye, World!"); } }
Translate this program into Python but keep the logic exactly as in Common_Lisp.
(binding [*out* *err*] (println "Goodbye, world!"))
import sys print >> sys.stderr, "Goodbye, World!"
Produce a functionally identical VB code for the snippet given in Common_Lisp.
(binding [*out* *err*] (println "Goodbye, world!"))
Sub StandardError() Debug.Print "Goodbye World!" End Sub
Write a version of this Common_Lisp function in Go with identical behavior.
(binding [*out* *err*] (println "Goodbye, world!"))
package main func main() { println("Goodbye, World!") }
Please provide an equivalent version of this D code in C.
import std.stdio; void main () { stderr.writeln("Goodbye, World!"); }
#include <stdio.h> int main() { fprintf(stderr, "Goodbye, "); fputs("World!\n", stderr); return 0; }
Ensure the translated C# code behaves exactly like the original D snippet.
import std.stdio; void main () { stderr.writeln("Goodbye, World!"); }
static class StdErr { static void Main(string[] args) { Console.Error.WriteLine("Goodbye, World!"); } }
Change the programming language of this snippet from D to C++ without modifying what it does.
import std.stdio; void main () { stderr.writeln("Goodbye, World!"); }
#include <iostream> int main() { std::cerr << "Goodbye, World!\n"; }
Ensure the translated Java code behaves exactly like the original D snippet.
import std.stdio; void main () { stderr.writeln("Goodbye, World!"); }
public class Err{ public static void main(String[] args){ System.err.println("Goodbye, World!"); } }
Port the following code from D to Python with equivalent syntax and logic.
import std.stdio; void main () { stderr.writeln("Goodbye, World!"); }
import sys print >> sys.stderr, "Goodbye, World!"
Please provide an equivalent version of this D code in VB.
import std.stdio; void main () { stderr.writeln("Goodbye, World!"); }
Sub StandardError() Debug.Print "Goodbye World!" End Sub
Write the same code in Go as shown below in D.
import std.stdio; void main () { stderr.writeln("Goodbye, World!"); }
package main func main() { println("Goodbye, World!") }
Convert the following code from Delphi to C, ensuring the logic remains intact.
program Project1; begin WriteLn(ErrOutput, 'Goodbye, World!'); end.
#include <stdio.h> int main() { fprintf(stderr, "Goodbye, "); fputs("World!\n", stderr); return 0; }
Please provide an equivalent version of this Delphi code in C#.
program Project1; begin WriteLn(ErrOutput, 'Goodbye, World!'); end.
static class StdErr { static void Main(string[] args) { Console.Error.WriteLine("Goodbye, World!"); } }
Please provide an equivalent version of this Delphi code in C++.
program Project1; begin WriteLn(ErrOutput, 'Goodbye, World!'); end.
#include <iostream> int main() { std::cerr << "Goodbye, World!\n"; }
Convert the following code from Delphi to Java, ensuring the logic remains intact.
program Project1; begin WriteLn(ErrOutput, 'Goodbye, World!'); end.
public class Err{ public static void main(String[] args){ System.err.println("Goodbye, World!"); } }
Convert this Delphi block to Python, preserving its control flow and logic.
program Project1; begin WriteLn(ErrOutput, 'Goodbye, World!'); end.
import sys print >> sys.stderr, "Goodbye, World!"
Port the provided Delphi code into VB while preserving the original functionality.
program Project1; begin WriteLn(ErrOutput, 'Goodbye, World!'); end.
Sub StandardError() Debug.Print "Goodbye World!" End Sub
Generate an equivalent Go version of this Delphi code.
program Project1; begin WriteLn(ErrOutput, 'Goodbye, World!'); end.
package main func main() { println("Goodbye, World!") }
Rewrite this program in C while keeping its functionality equivalent to the Elixir version.
IO.puts :stderr, "Goodbye, World!"
#include <stdio.h> int main() { fprintf(stderr, "Goodbye, "); fputs("World!\n", stderr); return 0; }