Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Transform the following Nim implementation into Go, maintaining the same output and logic. | type
Point = tuple
x: float
y: float
func shoelace(points: openArray[Point]): float =
var leftSum, rightSum = 0.0
for i in 0..<len(points):
var j = (i + 1) mod len(points)
leftSum += points[i].x * points[j].y
rightSum += points[j].x * points[i].y
0.5 * abs(leftSum - rightSum)
var points =... | package main
import "fmt"
type point struct{ x, y float64 }
func shoelace(pts []point) float64 {
sum := 0.
p0 := pts[len(pts)-1]
for _, p1 := range pts {
sum += p0.y*p1.x - p0.x*p1.y
p0 = p1
}
return sum / 2
}
func main() {
fmt.Println(shoelace([]point{{3, 4}, {5, 11}, {12, 8... |
Please provide an equivalent version of this Perl code in C. | use strict;
use warnings;
use feature 'say';
sub area_by_shoelace {
my $area;
our @p;
$
$area += $p[$_][0] * $p[($_+1)%@p][1] for 0 .. @p-1;
$area -= $p[$_][1] * $p[($_+1)%@p][0] for 0 .. @p-1;
return abs $area/2;
}
my @poly = ( [3,4], [5,11], [12,8], [9,5], [5,6] );
say area_by_shoelace( [... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
double x,y;
}point;
double shoelace(char* inputFile){
int i,numPoints;
double leftSum = 0,rightSum = 0;
point* pointSet;
FILE* fp = fopen(inputFile,"r");
fscanf(fp,"%d",&numPoints);
pointSet = (point*)malloc((numPoints + 1)*sizeof(poin... |
Generate an equivalent C version of this Perl code. | use strict;
use warnings;
use feature 'say';
sub area_by_shoelace {
my $area;
our @p;
$
$area += $p[$_][0] * $p[($_+1)%@p][1] for 0 .. @p-1;
$area -= $p[$_][1] * $p[($_+1)%@p][0] for 0 .. @p-1;
return abs $area/2;
}
my @poly = ( [3,4], [5,11], [12,8], [9,5], [5,6] );
say area_by_shoelace( [... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
double x,y;
}point;
double shoelace(char* inputFile){
int i,numPoints;
double leftSum = 0,rightSum = 0;
point* pointSet;
FILE* fp = fopen(inputFile,"r");
fscanf(fp,"%d",&numPoints);
pointSet = (point*)malloc((numPoints + 1)*sizeof(poin... |
Produce a language-to-language conversion: from Perl to C#, same semantics. | use strict;
use warnings;
use feature 'say';
sub area_by_shoelace {
my $area;
our @p;
$
$area += $p[$_][0] * $p[($_+1)%@p][1] for 0 .. @p-1;
$area -= $p[$_][1] * $p[($_+1)%@p][0] for 0 .. @p-1;
return abs $area/2;
}
my @poly = ( [3,4], [5,11], [12,8], [9,5], [5,6] );
say area_by_shoelace( [... | using System;
using System.Collections.Generic;
namespace ShoelaceFormula {
using Point = Tuple<double, double>;
class Program {
static double ShoelaceArea(List<Point> v) {
int n = v.Count;
double a = 0.0;
for (int i = 0; i < n - 1; i++) {
a += v[i].... |
Translate the given Perl code snippet into C# without altering its behavior. | use strict;
use warnings;
use feature 'say';
sub area_by_shoelace {
my $area;
our @p;
$
$area += $p[$_][0] * $p[($_+1)%@p][1] for 0 .. @p-1;
$area -= $p[$_][1] * $p[($_+1)%@p][0] for 0 .. @p-1;
return abs $area/2;
}
my @poly = ( [3,4], [5,11], [12,8], [9,5], [5,6] );
say area_by_shoelace( [... | using System;
using System.Collections.Generic;
namespace ShoelaceFormula {
using Point = Tuple<double, double>;
class Program {
static double ShoelaceArea(List<Point> v) {
int n = v.Count;
double a = 0.0;
for (int i = 0; i < n - 1; i++) {
a += v[i].... |
Keep all operations the same but rewrite the snippet in C++. | use strict;
use warnings;
use feature 'say';
sub area_by_shoelace {
my $area;
our @p;
$
$area += $p[$_][0] * $p[($_+1)%@p][1] for 0 .. @p-1;
$area -= $p[$_][1] * $p[($_+1)%@p][0] for 0 .. @p-1;
return abs $area/2;
}
my @poly = ( [3,4], [5,11], [12,8], [9,5], [5,6] );
say area_by_shoelace( [... | #include <iostream>
#include <tuple>
#include <vector>
using namespace std;
double shoelace(vector<pair<double, double>> points) {
double leftSum = 0.0;
double rightSum = 0.0;
for (int i = 0; i < points.size(); ++i) {
int j = (i + 1) % points.size();
leftSum += points[i].first * points[j].second;
rightSum ... |
Convert this Perl block to C++, preserving its control flow and logic. | use strict;
use warnings;
use feature 'say';
sub area_by_shoelace {
my $area;
our @p;
$
$area += $p[$_][0] * $p[($_+1)%@p][1] for 0 .. @p-1;
$area -= $p[$_][1] * $p[($_+1)%@p][0] for 0 .. @p-1;
return abs $area/2;
}
my @poly = ( [3,4], [5,11], [12,8], [9,5], [5,6] );
say area_by_shoelace( [... | #include <iostream>
#include <tuple>
#include <vector>
using namespace std;
double shoelace(vector<pair<double, double>> points) {
double leftSum = 0.0;
double rightSum = 0.0;
for (int i = 0; i < points.size(); ++i) {
int j = (i + 1) % points.size();
leftSum += points[i].first * points[j].second;
rightSum ... |
Translate this program into Java but keep the logic exactly as in Perl. | use strict;
use warnings;
use feature 'say';
sub area_by_shoelace {
my $area;
our @p;
$
$area += $p[$_][0] * $p[($_+1)%@p][1] for 0 .. @p-1;
$area -= $p[$_][1] * $p[($_+1)%@p][0] for 0 .. @p-1;
return abs $area/2;
}
my @poly = ( [3,4], [5,11], [12,8], [9,5], [5,6] );
say area_by_shoelace( [... | import java.util.List;
public class ShoelaceFormula {
private static class Point {
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return String.format("(%d, %d)", x, y);
}
}
... |
Rewrite the snippet below in Java so it works the same as the original Perl code. | use strict;
use warnings;
use feature 'say';
sub area_by_shoelace {
my $area;
our @p;
$
$area += $p[$_][0] * $p[($_+1)%@p][1] for 0 .. @p-1;
$area -= $p[$_][1] * $p[($_+1)%@p][0] for 0 .. @p-1;
return abs $area/2;
}
my @poly = ( [3,4], [5,11], [12,8], [9,5], [5,6] );
say area_by_shoelace( [... | import java.util.List;
public class ShoelaceFormula {
private static class Point {
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return String.format("(%d, %d)", x, y);
}
}
... |
Keep all operations the same but rewrite the snippet in Python. | use strict;
use warnings;
use feature 'say';
sub area_by_shoelace {
my $area;
our @p;
$
$area += $p[$_][0] * $p[($_+1)%@p][1] for 0 .. @p-1;
$area -= $p[$_][1] * $p[($_+1)%@p][0] for 0 .. @p-1;
return abs $area/2;
}
my @poly = ( [3,4], [5,11], [12,8], [9,5], [5,6] );
say area_by_shoelace( [... | >>> def area_by_shoelace(x, y):
"Assumes x,y points go around the polygon in one direction"
return abs( sum(i * j for i, j in zip(x, y[1:] + y[:1]))
-sum(i * j for i, j in zip(x[1:] + x[:1], y ))) / 2
>>> points = [(3,4), (5,11), (12,8), (9,5), (5,6)]
>>> x, y = zip(*point... |
Change the programming language of this snippet from Perl to Python without modifying what it does. | use strict;
use warnings;
use feature 'say';
sub area_by_shoelace {
my $area;
our @p;
$
$area += $p[$_][0] * $p[($_+1)%@p][1] for 0 .. @p-1;
$area -= $p[$_][1] * $p[($_+1)%@p][0] for 0 .. @p-1;
return abs $area/2;
}
my @poly = ( [3,4], [5,11], [12,8], [9,5], [5,6] );
say area_by_shoelace( [... | >>> def area_by_shoelace(x, y):
"Assumes x,y points go around the polygon in one direction"
return abs( sum(i * j for i, j in zip(x, y[1:] + y[:1]))
-sum(i * j for i, j in zip(x[1:] + x[:1], y ))) / 2
>>> points = [(3,4), (5,11), (12,8), (9,5), (5,6)]
>>> x, y = zip(*point... |
Change the programming language of this snippet from Perl to VB without modifying what it does. | use strict;
use warnings;
use feature 'say';
sub area_by_shoelace {
my $area;
our @p;
$
$area += $p[$_][0] * $p[($_+1)%@p][1] for 0 .. @p-1;
$area -= $p[$_][1] * $p[($_+1)%@p][0] for 0 .. @p-1;
return abs $area/2;
}
my @poly = ( [3,4], [5,11], [12,8], [9,5], [5,6] );
say area_by_shoelace( [... | Option Base 1
Public Enum axes
u = 1
v
End Enum
Private Function shoelace(s As Collection) As Double
Dim t As Double
If s.Count > 2 Then
s.Add s(1)
For i = 1 To s.Count - 1
t = t + s(i)(u) * s(i + 1)(v) - s(i + 1)(u) * s(i)(v)
Next i
End If
shoelace = Abs(t) /... |
Change the following Perl code into VB without altering its purpose. | use strict;
use warnings;
use feature 'say';
sub area_by_shoelace {
my $area;
our @p;
$
$area += $p[$_][0] * $p[($_+1)%@p][1] for 0 .. @p-1;
$area -= $p[$_][1] * $p[($_+1)%@p][0] for 0 .. @p-1;
return abs $area/2;
}
my @poly = ( [3,4], [5,11], [12,8], [9,5], [5,6] );
say area_by_shoelace( [... | Option Base 1
Public Enum axes
u = 1
v
End Enum
Private Function shoelace(s As Collection) As Double
Dim t As Double
If s.Count > 2 Then
s.Add s(1)
For i = 1 To s.Count - 1
t = t + s(i)(u) * s(i + 1)(v) - s(i + 1)(u) * s(i)(v)
Next i
End If
shoelace = Abs(t) /... |
Maintain the same structure and functionality when rewriting this code in Go. | use strict;
use warnings;
use feature 'say';
sub area_by_shoelace {
my $area;
our @p;
$
$area += $p[$_][0] * $p[($_+1)%@p][1] for 0 .. @p-1;
$area -= $p[$_][1] * $p[($_+1)%@p][0] for 0 .. @p-1;
return abs $area/2;
}
my @poly = ( [3,4], [5,11], [12,8], [9,5], [5,6] );
say area_by_shoelace( [... | package main
import "fmt"
type point struct{ x, y float64 }
func shoelace(pts []point) float64 {
sum := 0.
p0 := pts[len(pts)-1]
for _, p1 := range pts {
sum += p0.y*p1.x - p0.x*p1.y
p0 = p1
}
return sum / 2
}
func main() {
fmt.Println(shoelace([]point{{3, 4}, {5, 11}, {12, 8... |
Port the provided Perl code into Go while preserving the original functionality. | use strict;
use warnings;
use feature 'say';
sub area_by_shoelace {
my $area;
our @p;
$
$area += $p[$_][0] * $p[($_+1)%@p][1] for 0 .. @p-1;
$area -= $p[$_][1] * $p[($_+1)%@p][0] for 0 .. @p-1;
return abs $area/2;
}
my @poly = ( [3,4], [5,11], [12,8], [9,5], [5,6] );
say area_by_shoelace( [... | package main
import "fmt"
type point struct{ x, y float64 }
func shoelace(pts []point) float64 {
sum := 0.
p0 := pts[len(pts)-1]
for _, p1 := range pts {
sum += p0.y*p1.x - p0.x*p1.y
p0 = p1
}
return sum / 2
}
func main() {
fmt.Println(shoelace([]point{{3, 4}, {5, 11}, {12, 8... |
Produce a language-to-language conversion: from Racket to C, same semantics. | #lang racket/base
(struct P (x y))
(define (area . Ps)
(define (A P-a P-b)
(+ (for/sum ((p_i Ps)
(p_i+1 (in-sequences (cdr Ps)
(in-value (car Ps)))))
(* (P-a p_i) (P-b p_i+1)))))
(/ (abs (- (A P-x P-y) (A P-y P-x))) 2))
(module+ main
(area (P ... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
double x,y;
}point;
double shoelace(char* inputFile){
int i,numPoints;
double leftSum = 0,rightSum = 0;
point* pointSet;
FILE* fp = fopen(inputFile,"r");
fscanf(fp,"%d",&numPoints);
pointSet = (point*)malloc((numPoints + 1)*sizeof(poin... |
Write the same code in C as shown below in Racket. | #lang racket/base
(struct P (x y))
(define (area . Ps)
(define (A P-a P-b)
(+ (for/sum ((p_i Ps)
(p_i+1 (in-sequences (cdr Ps)
(in-value (car Ps)))))
(* (P-a p_i) (P-b p_i+1)))))
(/ (abs (- (A P-x P-y) (A P-y P-x))) 2))
(module+ main
(area (P ... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
double x,y;
}point;
double shoelace(char* inputFile){
int i,numPoints;
double leftSum = 0,rightSum = 0;
point* pointSet;
FILE* fp = fopen(inputFile,"r");
fscanf(fp,"%d",&numPoints);
pointSet = (point*)malloc((numPoints + 1)*sizeof(poin... |
Translate this program into C# but keep the logic exactly as in Racket. | #lang racket/base
(struct P (x y))
(define (area . Ps)
(define (A P-a P-b)
(+ (for/sum ((p_i Ps)
(p_i+1 (in-sequences (cdr Ps)
(in-value (car Ps)))))
(* (P-a p_i) (P-b p_i+1)))))
(/ (abs (- (A P-x P-y) (A P-y P-x))) 2))
(module+ main
(area (P ... | using System;
using System.Collections.Generic;
namespace ShoelaceFormula {
using Point = Tuple<double, double>;
class Program {
static double ShoelaceArea(List<Point> v) {
int n = v.Count;
double a = 0.0;
for (int i = 0; i < n - 1; i++) {
a += v[i].... |
Keep all operations the same but rewrite the snippet in C#. | #lang racket/base
(struct P (x y))
(define (area . Ps)
(define (A P-a P-b)
(+ (for/sum ((p_i Ps)
(p_i+1 (in-sequences (cdr Ps)
(in-value (car Ps)))))
(* (P-a p_i) (P-b p_i+1)))))
(/ (abs (- (A P-x P-y) (A P-y P-x))) 2))
(module+ main
(area (P ... | using System;
using System.Collections.Generic;
namespace ShoelaceFormula {
using Point = Tuple<double, double>;
class Program {
static double ShoelaceArea(List<Point> v) {
int n = v.Count;
double a = 0.0;
for (int i = 0; i < n - 1; i++) {
a += v[i].... |
Please provide an equivalent version of this Racket code in C++. | #lang racket/base
(struct P (x y))
(define (area . Ps)
(define (A P-a P-b)
(+ (for/sum ((p_i Ps)
(p_i+1 (in-sequences (cdr Ps)
(in-value (car Ps)))))
(* (P-a p_i) (P-b p_i+1)))))
(/ (abs (- (A P-x P-y) (A P-y P-x))) 2))
(module+ main
(area (P ... | #include <iostream>
#include <tuple>
#include <vector>
using namespace std;
double shoelace(vector<pair<double, double>> points) {
double leftSum = 0.0;
double rightSum = 0.0;
for (int i = 0; i < points.size(); ++i) {
int j = (i + 1) % points.size();
leftSum += points[i].first * points[j].second;
rightSum ... |
Change the programming language of this snippet from Racket to C++ without modifying what it does. | #lang racket/base
(struct P (x y))
(define (area . Ps)
(define (A P-a P-b)
(+ (for/sum ((p_i Ps)
(p_i+1 (in-sequences (cdr Ps)
(in-value (car Ps)))))
(* (P-a p_i) (P-b p_i+1)))))
(/ (abs (- (A P-x P-y) (A P-y P-x))) 2))
(module+ main
(area (P ... | #include <iostream>
#include <tuple>
#include <vector>
using namespace std;
double shoelace(vector<pair<double, double>> points) {
double leftSum = 0.0;
double rightSum = 0.0;
for (int i = 0; i < points.size(); ++i) {
int j = (i + 1) % points.size();
leftSum += points[i].first * points[j].second;
rightSum ... |
Write the same algorithm in Java as shown in this Racket implementation. | #lang racket/base
(struct P (x y))
(define (area . Ps)
(define (A P-a P-b)
(+ (for/sum ((p_i Ps)
(p_i+1 (in-sequences (cdr Ps)
(in-value (car Ps)))))
(* (P-a p_i) (P-b p_i+1)))))
(/ (abs (- (A P-x P-y) (A P-y P-x))) 2))
(module+ main
(area (P ... | import java.util.List;
public class ShoelaceFormula {
private static class Point {
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return String.format("(%d, %d)", x, y);
}
}
... |
Port the following code from Racket to Java with equivalent syntax and logic. | #lang racket/base
(struct P (x y))
(define (area . Ps)
(define (A P-a P-b)
(+ (for/sum ((p_i Ps)
(p_i+1 (in-sequences (cdr Ps)
(in-value (car Ps)))))
(* (P-a p_i) (P-b p_i+1)))))
(/ (abs (- (A P-x P-y) (A P-y P-x))) 2))
(module+ main
(area (P ... | import java.util.List;
public class ShoelaceFormula {
private static class Point {
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return String.format("(%d, %d)", x, y);
}
}
... |
Convert this Racket block to Python, preserving its control flow and logic. | #lang racket/base
(struct P (x y))
(define (area . Ps)
(define (A P-a P-b)
(+ (for/sum ((p_i Ps)
(p_i+1 (in-sequences (cdr Ps)
(in-value (car Ps)))))
(* (P-a p_i) (P-b p_i+1)))))
(/ (abs (- (A P-x P-y) (A P-y P-x))) 2))
(module+ main
(area (P ... | >>> def area_by_shoelace(x, y):
"Assumes x,y points go around the polygon in one direction"
return abs( sum(i * j for i, j in zip(x, y[1:] + y[:1]))
-sum(i * j for i, j in zip(x[1:] + x[:1], y ))) / 2
>>> points = [(3,4), (5,11), (12,8), (9,5), (5,6)]
>>> x, y = zip(*point... |
Rewrite this program in Python while keeping its functionality equivalent to the Racket version. | #lang racket/base
(struct P (x y))
(define (area . Ps)
(define (A P-a P-b)
(+ (for/sum ((p_i Ps)
(p_i+1 (in-sequences (cdr Ps)
(in-value (car Ps)))))
(* (P-a p_i) (P-b p_i+1)))))
(/ (abs (- (A P-x P-y) (A P-y P-x))) 2))
(module+ main
(area (P ... | >>> def area_by_shoelace(x, y):
"Assumes x,y points go around the polygon in one direction"
return abs( sum(i * j for i, j in zip(x, y[1:] + y[:1]))
-sum(i * j for i, j in zip(x[1:] + x[:1], y ))) / 2
>>> points = [(3,4), (5,11), (12,8), (9,5), (5,6)]
>>> x, y = zip(*point... |
Transform the following Racket implementation into VB, maintaining the same output and logic. | #lang racket/base
(struct P (x y))
(define (area . Ps)
(define (A P-a P-b)
(+ (for/sum ((p_i Ps)
(p_i+1 (in-sequences (cdr Ps)
(in-value (car Ps)))))
(* (P-a p_i) (P-b p_i+1)))))
(/ (abs (- (A P-x P-y) (A P-y P-x))) 2))
(module+ main
(area (P ... | Option Base 1
Public Enum axes
u = 1
v
End Enum
Private Function shoelace(s As Collection) As Double
Dim t As Double
If s.Count > 2 Then
s.Add s(1)
For i = 1 To s.Count - 1
t = t + s(i)(u) * s(i + 1)(v) - s(i + 1)(u) * s(i)(v)
Next i
End If
shoelace = Abs(t) /... |
Translate the given Racket code snippet into VB without altering its behavior. | #lang racket/base
(struct P (x y))
(define (area . Ps)
(define (A P-a P-b)
(+ (for/sum ((p_i Ps)
(p_i+1 (in-sequences (cdr Ps)
(in-value (car Ps)))))
(* (P-a p_i) (P-b p_i+1)))))
(/ (abs (- (A P-x P-y) (A P-y P-x))) 2))
(module+ main
(area (P ... | Option Base 1
Public Enum axes
u = 1
v
End Enum
Private Function shoelace(s As Collection) As Double
Dim t As Double
If s.Count > 2 Then
s.Add s(1)
For i = 1 To s.Count - 1
t = t + s(i)(u) * s(i + 1)(v) - s(i + 1)(u) * s(i)(v)
Next i
End If
shoelace = Abs(t) /... |
Write the same algorithm in Go as shown in this Racket implementation. | #lang racket/base
(struct P (x y))
(define (area . Ps)
(define (A P-a P-b)
(+ (for/sum ((p_i Ps)
(p_i+1 (in-sequences (cdr Ps)
(in-value (car Ps)))))
(* (P-a p_i) (P-b p_i+1)))))
(/ (abs (- (A P-x P-y) (A P-y P-x))) 2))
(module+ main
(area (P ... | package main
import "fmt"
type point struct{ x, y float64 }
func shoelace(pts []point) float64 {
sum := 0.
p0 := pts[len(pts)-1]
for _, p1 := range pts {
sum += p0.y*p1.x - p0.x*p1.y
p0 = p1
}
return sum / 2
}
func main() {
fmt.Println(shoelace([]point{{3, 4}, {5, 11}, {12, 8... |
Translate this program into Go but keep the logic exactly as in Racket. | #lang racket/base
(struct P (x y))
(define (area . Ps)
(define (A P-a P-b)
(+ (for/sum ((p_i Ps)
(p_i+1 (in-sequences (cdr Ps)
(in-value (car Ps)))))
(* (P-a p_i) (P-b p_i+1)))))
(/ (abs (- (A P-x P-y) (A P-y P-x))) 2))
(module+ main
(area (P ... | package main
import "fmt"
type point struct{ x, y float64 }
func shoelace(pts []point) float64 {
sum := 0.
p0 := pts[len(pts)-1]
for _, p1 := range pts {
sum += p0.y*p1.x - p0.x*p1.y
p0 = p1
}
return sum / 2
}
func main() {
fmt.Println(shoelace([]point{{3, 4}, {5, 11}, {12, 8... |
Convert the following code from REXX to C, ensuring the logic remains intact. |
parse arg $; if $='' then $= "(3,4),(5,11),(12,8),(9,5),(5,6)"
A= 0; @= space($, 0)
do #=1 until @==''; parse var @ '(' x.# "," y.# ')' "," @
end
z= #+1; y.0= y.#; y.z= y.1
do j=1 for #; jm= ... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
double x,y;
}point;
double shoelace(char* inputFile){
int i,numPoints;
double leftSum = 0,rightSum = 0;
point* pointSet;
FILE* fp = fopen(inputFile,"r");
fscanf(fp,"%d",&numPoints);
pointSet = (point*)malloc((numPoints + 1)*sizeof(poin... |
Transform the following REXX implementation into C, maintaining the same output and logic. |
parse arg $; if $='' then $= "(3,4),(5,11),(12,8),(9,5),(5,6)"
A= 0; @= space($, 0)
do #=1 until @==''; parse var @ '(' x.# "," y.# ')' "," @
end
z= #+1; y.0= y.#; y.z= y.1
do j=1 for #; jm= ... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
double x,y;
}point;
double shoelace(char* inputFile){
int i,numPoints;
double leftSum = 0,rightSum = 0;
point* pointSet;
FILE* fp = fopen(inputFile,"r");
fscanf(fp,"%d",&numPoints);
pointSet = (point*)malloc((numPoints + 1)*sizeof(poin... |
Produce a functionally identical C# code for the snippet given in REXX. |
parse arg $; if $='' then $= "(3,4),(5,11),(12,8),(9,5),(5,6)"
A= 0; @= space($, 0)
do #=1 until @==''; parse var @ '(' x.# "," y.# ')' "," @
end
z= #+1; y.0= y.#; y.z= y.1
do j=1 for #; jm= ... | using System;
using System.Collections.Generic;
namespace ShoelaceFormula {
using Point = Tuple<double, double>;
class Program {
static double ShoelaceArea(List<Point> v) {
int n = v.Count;
double a = 0.0;
for (int i = 0; i < n - 1; i++) {
a += v[i].... |
Can you help me rewrite this code in C# instead of REXX, keeping it the same logically? |
parse arg $; if $='' then $= "(3,4),(5,11),(12,8),(9,5),(5,6)"
A= 0; @= space($, 0)
do #=1 until @==''; parse var @ '(' x.# "," y.# ')' "," @
end
z= #+1; y.0= y.#; y.z= y.1
do j=1 for #; jm= ... | using System;
using System.Collections.Generic;
namespace ShoelaceFormula {
using Point = Tuple<double, double>;
class Program {
static double ShoelaceArea(List<Point> v) {
int n = v.Count;
double a = 0.0;
for (int i = 0; i < n - 1; i++) {
a += v[i].... |
Rewrite this program in C++ while keeping its functionality equivalent to the REXX version. |
parse arg $; if $='' then $= "(3,4),(5,11),(12,8),(9,5),(5,6)"
A= 0; @= space($, 0)
do #=1 until @==''; parse var @ '(' x.# "," y.# ')' "," @
end
z= #+1; y.0= y.#; y.z= y.1
do j=1 for #; jm= ... | #include <iostream>
#include <tuple>
#include <vector>
using namespace std;
double shoelace(vector<pair<double, double>> points) {
double leftSum = 0.0;
double rightSum = 0.0;
for (int i = 0; i < points.size(); ++i) {
int j = (i + 1) % points.size();
leftSum += points[i].first * points[j].second;
rightSum ... |
Can you help me rewrite this code in C++ instead of REXX, keeping it the same logically? |
parse arg $; if $='' then $= "(3,4),(5,11),(12,8),(9,5),(5,6)"
A= 0; @= space($, 0)
do #=1 until @==''; parse var @ '(' x.# "," y.# ')' "," @
end
z= #+1; y.0= y.#; y.z= y.1
do j=1 for #; jm= ... | #include <iostream>
#include <tuple>
#include <vector>
using namespace std;
double shoelace(vector<pair<double, double>> points) {
double leftSum = 0.0;
double rightSum = 0.0;
for (int i = 0; i < points.size(); ++i) {
int j = (i + 1) % points.size();
leftSum += points[i].first * points[j].second;
rightSum ... |
Keep all operations the same but rewrite the snippet in Java. |
parse arg $; if $='' then $= "(3,4),(5,11),(12,8),(9,5),(5,6)"
A= 0; @= space($, 0)
do #=1 until @==''; parse var @ '(' x.# "," y.# ')' "," @
end
z= #+1; y.0= y.#; y.z= y.1
do j=1 for #; jm= ... | import java.util.List;
public class ShoelaceFormula {
private static class Point {
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return String.format("(%d, %d)", x, y);
}
}
... |
Port the following code from REXX to Java with equivalent syntax and logic. |
parse arg $; if $='' then $= "(3,4),(5,11),(12,8),(9,5),(5,6)"
A= 0; @= space($, 0)
do #=1 until @==''; parse var @ '(' x.# "," y.# ')' "," @
end
z= #+1; y.0= y.#; y.z= y.1
do j=1 for #; jm= ... | import java.util.List;
public class ShoelaceFormula {
private static class Point {
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return String.format("(%d, %d)", x, y);
}
}
... |
Keep all operations the same but rewrite the snippet in Python. |
parse arg $; if $='' then $= "(3,4),(5,11),(12,8),(9,5),(5,6)"
A= 0; @= space($, 0)
do #=1 until @==''; parse var @ '(' x.# "," y.# ')' "," @
end
z= #+1; y.0= y.#; y.z= y.1
do j=1 for #; jm= ... | >>> def area_by_shoelace(x, y):
"Assumes x,y points go around the polygon in one direction"
return abs( sum(i * j for i, j in zip(x, y[1:] + y[:1]))
-sum(i * j for i, j in zip(x[1:] + x[:1], y ))) / 2
>>> points = [(3,4), (5,11), (12,8), (9,5), (5,6)]
>>> x, y = zip(*point... |
Convert the following code from REXX to Python, ensuring the logic remains intact. |
parse arg $; if $='' then $= "(3,4),(5,11),(12,8),(9,5),(5,6)"
A= 0; @= space($, 0)
do #=1 until @==''; parse var @ '(' x.# "," y.# ')' "," @
end
z= #+1; y.0= y.#; y.z= y.1
do j=1 for #; jm= ... | >>> def area_by_shoelace(x, y):
"Assumes x,y points go around the polygon in one direction"
return abs( sum(i * j for i, j in zip(x, y[1:] + y[:1]))
-sum(i * j for i, j in zip(x[1:] + x[:1], y ))) / 2
>>> points = [(3,4), (5,11), (12,8), (9,5), (5,6)]
>>> x, y = zip(*point... |
Write the same algorithm in VB as shown in this REXX implementation. |
parse arg $; if $='' then $= "(3,4),(5,11),(12,8),(9,5),(5,6)"
A= 0; @= space($, 0)
do #=1 until @==''; parse var @ '(' x.# "," y.# ')' "," @
end
z= #+1; y.0= y.#; y.z= y.1
do j=1 for #; jm= ... | Option Base 1
Public Enum axes
u = 1
v
End Enum
Private Function shoelace(s As Collection) As Double
Dim t As Double
If s.Count > 2 Then
s.Add s(1)
For i = 1 To s.Count - 1
t = t + s(i)(u) * s(i + 1)(v) - s(i + 1)(u) * s(i)(v)
Next i
End If
shoelace = Abs(t) /... |
Keep all operations the same but rewrite the snippet in VB. |
parse arg $; if $='' then $= "(3,4),(5,11),(12,8),(9,5),(5,6)"
A= 0; @= space($, 0)
do #=1 until @==''; parse var @ '(' x.# "," y.# ')' "," @
end
z= #+1; y.0= y.#; y.z= y.1
do j=1 for #; jm= ... | Option Base 1
Public Enum axes
u = 1
v
End Enum
Private Function shoelace(s As Collection) As Double
Dim t As Double
If s.Count > 2 Then
s.Add s(1)
For i = 1 To s.Count - 1
t = t + s(i)(u) * s(i + 1)(v) - s(i + 1)(u) * s(i)(v)
Next i
End If
shoelace = Abs(t) /... |
Transform the following REXX implementation into Go, maintaining the same output and logic. |
parse arg $; if $='' then $= "(3,4),(5,11),(12,8),(9,5),(5,6)"
A= 0; @= space($, 0)
do #=1 until @==''; parse var @ '(' x.# "," y.# ')' "," @
end
z= #+1; y.0= y.#; y.z= y.1
do j=1 for #; jm= ... | package main
import "fmt"
type point struct{ x, y float64 }
func shoelace(pts []point) float64 {
sum := 0.
p0 := pts[len(pts)-1]
for _, p1 := range pts {
sum += p0.y*p1.x - p0.x*p1.y
p0 = p1
}
return sum / 2
}
func main() {
fmt.Println(shoelace([]point{{3, 4}, {5, 11}, {12, 8... |
Change the programming language of this snippet from REXX to Go without modifying what it does. |
parse arg $; if $='' then $= "(3,4),(5,11),(12,8),(9,5),(5,6)"
A= 0; @= space($, 0)
do #=1 until @==''; parse var @ '(' x.# "," y.# ')' "," @
end
z= #+1; y.0= y.#; y.z= y.1
do j=1 for #; jm= ... | package main
import "fmt"
type point struct{ x, y float64 }
func shoelace(pts []point) float64 {
sum := 0.
p0 := pts[len(pts)-1]
for _, p1 := range pts {
sum += p0.y*p1.x - p0.x*p1.y
p0 = p1
}
return sum / 2
}
func main() {
fmt.Println(shoelace([]point{{3, 4}, {5, 11}, {12, 8... |
Port the provided Ruby code into C while preserving the original functionality. | Point = Struct.new(:x,:y) do
def shoelace(other)
x * other.y - y * other.x
end
end
class Polygon
def initialize(*coords)
@points = coords.map{|c| Point.new(*c) }
end
def area
points = @points + [@points.first]
points.each_cons(2).sum{|p1,p2| p1.shoelace(p2) }.abs.fdiv(2)
end
end
puts... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
double x,y;
}point;
double shoelace(char* inputFile){
int i,numPoints;
double leftSum = 0,rightSum = 0;
point* pointSet;
FILE* fp = fopen(inputFile,"r");
fscanf(fp,"%d",&numPoints);
pointSet = (point*)malloc((numPoints + 1)*sizeof(poin... |
Translate the given Ruby code snippet into C without altering its behavior. | Point = Struct.new(:x,:y) do
def shoelace(other)
x * other.y - y * other.x
end
end
class Polygon
def initialize(*coords)
@points = coords.map{|c| Point.new(*c) }
end
def area
points = @points + [@points.first]
points.each_cons(2).sum{|p1,p2| p1.shoelace(p2) }.abs.fdiv(2)
end
end
puts... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
double x,y;
}point;
double shoelace(char* inputFile){
int i,numPoints;
double leftSum = 0,rightSum = 0;
point* pointSet;
FILE* fp = fopen(inputFile,"r");
fscanf(fp,"%d",&numPoints);
pointSet = (point*)malloc((numPoints + 1)*sizeof(poin... |
Change the following Ruby code into C# without altering its purpose. | Point = Struct.new(:x,:y) do
def shoelace(other)
x * other.y - y * other.x
end
end
class Polygon
def initialize(*coords)
@points = coords.map{|c| Point.new(*c) }
end
def area
points = @points + [@points.first]
points.each_cons(2).sum{|p1,p2| p1.shoelace(p2) }.abs.fdiv(2)
end
end
puts... | using System;
using System.Collections.Generic;
namespace ShoelaceFormula {
using Point = Tuple<double, double>;
class Program {
static double ShoelaceArea(List<Point> v) {
int n = v.Count;
double a = 0.0;
for (int i = 0; i < n - 1; i++) {
a += v[i].... |
Produce a functionally identical C# code for the snippet given in Ruby. | Point = Struct.new(:x,:y) do
def shoelace(other)
x * other.y - y * other.x
end
end
class Polygon
def initialize(*coords)
@points = coords.map{|c| Point.new(*c) }
end
def area
points = @points + [@points.first]
points.each_cons(2).sum{|p1,p2| p1.shoelace(p2) }.abs.fdiv(2)
end
end
puts... | using System;
using System.Collections.Generic;
namespace ShoelaceFormula {
using Point = Tuple<double, double>;
class Program {
static double ShoelaceArea(List<Point> v) {
int n = v.Count;
double a = 0.0;
for (int i = 0; i < n - 1; i++) {
a += v[i].... |
Transform the following Ruby implementation into C++, maintaining the same output and logic. | Point = Struct.new(:x,:y) do
def shoelace(other)
x * other.y - y * other.x
end
end
class Polygon
def initialize(*coords)
@points = coords.map{|c| Point.new(*c) }
end
def area
points = @points + [@points.first]
points.each_cons(2).sum{|p1,p2| p1.shoelace(p2) }.abs.fdiv(2)
end
end
puts... | #include <iostream>
#include <tuple>
#include <vector>
using namespace std;
double shoelace(vector<pair<double, double>> points) {
double leftSum = 0.0;
double rightSum = 0.0;
for (int i = 0; i < points.size(); ++i) {
int j = (i + 1) % points.size();
leftSum += points[i].first * points[j].second;
rightSum ... |
Generate a C++ translation of this Ruby snippet without changing its computational steps. | Point = Struct.new(:x,:y) do
def shoelace(other)
x * other.y - y * other.x
end
end
class Polygon
def initialize(*coords)
@points = coords.map{|c| Point.new(*c) }
end
def area
points = @points + [@points.first]
points.each_cons(2).sum{|p1,p2| p1.shoelace(p2) }.abs.fdiv(2)
end
end
puts... | #include <iostream>
#include <tuple>
#include <vector>
using namespace std;
double shoelace(vector<pair<double, double>> points) {
double leftSum = 0.0;
double rightSum = 0.0;
for (int i = 0; i < points.size(); ++i) {
int j = (i + 1) % points.size();
leftSum += points[i].first * points[j].second;
rightSum ... |
Translate the given Ruby code snippet into Java without altering its behavior. | Point = Struct.new(:x,:y) do
def shoelace(other)
x * other.y - y * other.x
end
end
class Polygon
def initialize(*coords)
@points = coords.map{|c| Point.new(*c) }
end
def area
points = @points + [@points.first]
points.each_cons(2).sum{|p1,p2| p1.shoelace(p2) }.abs.fdiv(2)
end
end
puts... | import java.util.List;
public class ShoelaceFormula {
private static class Point {
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return String.format("(%d, %d)", x, y);
}
}
... |
Transform the following Ruby implementation into Python, maintaining the same output and logic. | Point = Struct.new(:x,:y) do
def shoelace(other)
x * other.y - y * other.x
end
end
class Polygon
def initialize(*coords)
@points = coords.map{|c| Point.new(*c) }
end
def area
points = @points + [@points.first]
points.each_cons(2).sum{|p1,p2| p1.shoelace(p2) }.abs.fdiv(2)
end
end
puts... | >>> def area_by_shoelace(x, y):
"Assumes x,y points go around the polygon in one direction"
return abs( sum(i * j for i, j in zip(x, y[1:] + y[:1]))
-sum(i * j for i, j in zip(x[1:] + x[:1], y ))) / 2
>>> points = [(3,4), (5,11), (12,8), (9,5), (5,6)]
>>> x, y = zip(*point... |
Rewrite the snippet below in Python so it works the same as the original Ruby code. | Point = Struct.new(:x,:y) do
def shoelace(other)
x * other.y - y * other.x
end
end
class Polygon
def initialize(*coords)
@points = coords.map{|c| Point.new(*c) }
end
def area
points = @points + [@points.first]
points.each_cons(2).sum{|p1,p2| p1.shoelace(p2) }.abs.fdiv(2)
end
end
puts... | >>> def area_by_shoelace(x, y):
"Assumes x,y points go around the polygon in one direction"
return abs( sum(i * j for i, j in zip(x, y[1:] + y[:1]))
-sum(i * j for i, j in zip(x[1:] + x[:1], y ))) / 2
>>> points = [(3,4), (5,11), (12,8), (9,5), (5,6)]
>>> x, y = zip(*point... |
Please provide an equivalent version of this Ruby code in VB. | Point = Struct.new(:x,:y) do
def shoelace(other)
x * other.y - y * other.x
end
end
class Polygon
def initialize(*coords)
@points = coords.map{|c| Point.new(*c) }
end
def area
points = @points + [@points.first]
points.each_cons(2).sum{|p1,p2| p1.shoelace(p2) }.abs.fdiv(2)
end
end
puts... | Option Base 1
Public Enum axes
u = 1
v
End Enum
Private Function shoelace(s As Collection) As Double
Dim t As Double
If s.Count > 2 Then
s.Add s(1)
For i = 1 To s.Count - 1
t = t + s(i)(u) * s(i + 1)(v) - s(i + 1)(u) * s(i)(v)
Next i
End If
shoelace = Abs(t) /... |
Write a version of this Ruby function in VB with identical behavior. | Point = Struct.new(:x,:y) do
def shoelace(other)
x * other.y - y * other.x
end
end
class Polygon
def initialize(*coords)
@points = coords.map{|c| Point.new(*c) }
end
def area
points = @points + [@points.first]
points.each_cons(2).sum{|p1,p2| p1.shoelace(p2) }.abs.fdiv(2)
end
end
puts... | Option Base 1
Public Enum axes
u = 1
v
End Enum
Private Function shoelace(s As Collection) As Double
Dim t As Double
If s.Count > 2 Then
s.Add s(1)
For i = 1 To s.Count - 1
t = t + s(i)(u) * s(i + 1)(v) - s(i + 1)(u) * s(i)(v)
Next i
End If
shoelace = Abs(t) /... |
Convert this Ruby snippet to Go and keep its semantics consistent. | Point = Struct.new(:x,:y) do
def shoelace(other)
x * other.y - y * other.x
end
end
class Polygon
def initialize(*coords)
@points = coords.map{|c| Point.new(*c) }
end
def area
points = @points + [@points.first]
points.each_cons(2).sum{|p1,p2| p1.shoelace(p2) }.abs.fdiv(2)
end
end
puts... | package main
import "fmt"
type point struct{ x, y float64 }
func shoelace(pts []point) float64 {
sum := 0.
p0 := pts[len(pts)-1]
for _, p1 := range pts {
sum += p0.y*p1.x - p0.x*p1.y
p0 = p1
}
return sum / 2
}
func main() {
fmt.Println(shoelace([]point{{3, 4}, {5, 11}, {12, 8... |
Produce a language-to-language conversion: from Ruby to Go, same semantics. | Point = Struct.new(:x,:y) do
def shoelace(other)
x * other.y - y * other.x
end
end
class Polygon
def initialize(*coords)
@points = coords.map{|c| Point.new(*c) }
end
def area
points = @points + [@points.first]
points.each_cons(2).sum{|p1,p2| p1.shoelace(p2) }.abs.fdiv(2)
end
end
puts... | package main
import "fmt"
type point struct{ x, y float64 }
func shoelace(pts []point) float64 {
sum := 0.
p0 := pts[len(pts)-1]
for _, p1 := range pts {
sum += p0.y*p1.x - p0.x*p1.y
p0 = p1
}
return sum / 2
}
func main() {
fmt.Println(shoelace([]point{{3, 4}, {5, 11}, {12, 8... |
Produce a functionally identical C code for the snippet given in Scala. |
class Point(val x: Int, val y: Int) {
override fun toString() = "($x, $y)"
}
fun shoelaceArea(v: List<Point>): Double {
val n = v.size
var a = 0.0
for (i in 0 until n - 1) {
a += v[i].x * v[i + 1].y - v[i + 1].x * v[i].y
}
return Math.abs(a + v[n - 1].x * v[0].y - v[0].x * v[n -1].y... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
double x,y;
}point;
double shoelace(char* inputFile){
int i,numPoints;
double leftSum = 0,rightSum = 0;
point* pointSet;
FILE* fp = fopen(inputFile,"r");
fscanf(fp,"%d",&numPoints);
pointSet = (point*)malloc((numPoints + 1)*sizeof(poin... |
Port the provided Scala code into C while preserving the original functionality. |
class Point(val x: Int, val y: Int) {
override fun toString() = "($x, $y)"
}
fun shoelaceArea(v: List<Point>): Double {
val n = v.size
var a = 0.0
for (i in 0 until n - 1) {
a += v[i].x * v[i + 1].y - v[i + 1].x * v[i].y
}
return Math.abs(a + v[n - 1].x * v[0].y - v[0].x * v[n -1].y... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
double x,y;
}point;
double shoelace(char* inputFile){
int i,numPoints;
double leftSum = 0,rightSum = 0;
point* pointSet;
FILE* fp = fopen(inputFile,"r");
fscanf(fp,"%d",&numPoints);
pointSet = (point*)malloc((numPoints + 1)*sizeof(poin... |
Ensure the translated C# code behaves exactly like the original Scala snippet. |
class Point(val x: Int, val y: Int) {
override fun toString() = "($x, $y)"
}
fun shoelaceArea(v: List<Point>): Double {
val n = v.size
var a = 0.0
for (i in 0 until n - 1) {
a += v[i].x * v[i + 1].y - v[i + 1].x * v[i].y
}
return Math.abs(a + v[n - 1].x * v[0].y - v[0].x * v[n -1].y... | using System;
using System.Collections.Generic;
namespace ShoelaceFormula {
using Point = Tuple<double, double>;
class Program {
static double ShoelaceArea(List<Point> v) {
int n = v.Count;
double a = 0.0;
for (int i = 0; i < n - 1; i++) {
a += v[i].... |
Preserve the algorithm and functionality while converting the code from Scala to C#. |
class Point(val x: Int, val y: Int) {
override fun toString() = "($x, $y)"
}
fun shoelaceArea(v: List<Point>): Double {
val n = v.size
var a = 0.0
for (i in 0 until n - 1) {
a += v[i].x * v[i + 1].y - v[i + 1].x * v[i].y
}
return Math.abs(a + v[n - 1].x * v[0].y - v[0].x * v[n -1].y... | using System;
using System.Collections.Generic;
namespace ShoelaceFormula {
using Point = Tuple<double, double>;
class Program {
static double ShoelaceArea(List<Point> v) {
int n = v.Count;
double a = 0.0;
for (int i = 0; i < n - 1; i++) {
a += v[i].... |
Please provide an equivalent version of this Scala code in C++. |
class Point(val x: Int, val y: Int) {
override fun toString() = "($x, $y)"
}
fun shoelaceArea(v: List<Point>): Double {
val n = v.size
var a = 0.0
for (i in 0 until n - 1) {
a += v[i].x * v[i + 1].y - v[i + 1].x * v[i].y
}
return Math.abs(a + v[n - 1].x * v[0].y - v[0].x * v[n -1].y... | #include <iostream>
#include <tuple>
#include <vector>
using namespace std;
double shoelace(vector<pair<double, double>> points) {
double leftSum = 0.0;
double rightSum = 0.0;
for (int i = 0; i < points.size(); ++i) {
int j = (i + 1) % points.size();
leftSum += points[i].first * points[j].second;
rightSum ... |
Port the following code from Scala to C++ with equivalent syntax and logic. |
class Point(val x: Int, val y: Int) {
override fun toString() = "($x, $y)"
}
fun shoelaceArea(v: List<Point>): Double {
val n = v.size
var a = 0.0
for (i in 0 until n - 1) {
a += v[i].x * v[i + 1].y - v[i + 1].x * v[i].y
}
return Math.abs(a + v[n - 1].x * v[0].y - v[0].x * v[n -1].y... | #include <iostream>
#include <tuple>
#include <vector>
using namespace std;
double shoelace(vector<pair<double, double>> points) {
double leftSum = 0.0;
double rightSum = 0.0;
for (int i = 0; i < points.size(); ++i) {
int j = (i + 1) % points.size();
leftSum += points[i].first * points[j].second;
rightSum ... |
Translate the given Scala code snippet into Java without altering its behavior. |
class Point(val x: Int, val y: Int) {
override fun toString() = "($x, $y)"
}
fun shoelaceArea(v: List<Point>): Double {
val n = v.size
var a = 0.0
for (i in 0 until n - 1) {
a += v[i].x * v[i + 1].y - v[i + 1].x * v[i].y
}
return Math.abs(a + v[n - 1].x * v[0].y - v[0].x * v[n -1].y... | import java.util.List;
public class ShoelaceFormula {
private static class Point {
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return String.format("(%d, %d)", x, y);
}
}
... |
Convert the following code from Scala to Java, ensuring the logic remains intact. |
class Point(val x: Int, val y: Int) {
override fun toString() = "($x, $y)"
}
fun shoelaceArea(v: List<Point>): Double {
val n = v.size
var a = 0.0
for (i in 0 until n - 1) {
a += v[i].x * v[i + 1].y - v[i + 1].x * v[i].y
}
return Math.abs(a + v[n - 1].x * v[0].y - v[0].x * v[n -1].y... | import java.util.List;
public class ShoelaceFormula {
private static class Point {
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return String.format("(%d, %d)", x, y);
}
}
... |
Keep all operations the same but rewrite the snippet in Python. |
class Point(val x: Int, val y: Int) {
override fun toString() = "($x, $y)"
}
fun shoelaceArea(v: List<Point>): Double {
val n = v.size
var a = 0.0
for (i in 0 until n - 1) {
a += v[i].x * v[i + 1].y - v[i + 1].x * v[i].y
}
return Math.abs(a + v[n - 1].x * v[0].y - v[0].x * v[n -1].y... | >>> def area_by_shoelace(x, y):
"Assumes x,y points go around the polygon in one direction"
return abs( sum(i * j for i, j in zip(x, y[1:] + y[:1]))
-sum(i * j for i, j in zip(x[1:] + x[:1], y ))) / 2
>>> points = [(3,4), (5,11), (12,8), (9,5), (5,6)]
>>> x, y = zip(*point... |
Port the provided Scala code into Python while preserving the original functionality. |
class Point(val x: Int, val y: Int) {
override fun toString() = "($x, $y)"
}
fun shoelaceArea(v: List<Point>): Double {
val n = v.size
var a = 0.0
for (i in 0 until n - 1) {
a += v[i].x * v[i + 1].y - v[i + 1].x * v[i].y
}
return Math.abs(a + v[n - 1].x * v[0].y - v[0].x * v[n -1].y... | >>> def area_by_shoelace(x, y):
"Assumes x,y points go around the polygon in one direction"
return abs( sum(i * j for i, j in zip(x, y[1:] + y[:1]))
-sum(i * j for i, j in zip(x[1:] + x[:1], y ))) / 2
>>> points = [(3,4), (5,11), (12,8), (9,5), (5,6)]
>>> x, y = zip(*point... |
Preserve the algorithm and functionality while converting the code from Scala to VB. |
class Point(val x: Int, val y: Int) {
override fun toString() = "($x, $y)"
}
fun shoelaceArea(v: List<Point>): Double {
val n = v.size
var a = 0.0
for (i in 0 until n - 1) {
a += v[i].x * v[i + 1].y - v[i + 1].x * v[i].y
}
return Math.abs(a + v[n - 1].x * v[0].y - v[0].x * v[n -1].y... | Option Base 1
Public Enum axes
u = 1
v
End Enum
Private Function shoelace(s As Collection) As Double
Dim t As Double
If s.Count > 2 Then
s.Add s(1)
For i = 1 To s.Count - 1
t = t + s(i)(u) * s(i + 1)(v) - s(i + 1)(u) * s(i)(v)
Next i
End If
shoelace = Abs(t) /... |
Produce a functionally identical VB code for the snippet given in Scala. |
class Point(val x: Int, val y: Int) {
override fun toString() = "($x, $y)"
}
fun shoelaceArea(v: List<Point>): Double {
val n = v.size
var a = 0.0
for (i in 0 until n - 1) {
a += v[i].x * v[i + 1].y - v[i + 1].x * v[i].y
}
return Math.abs(a + v[n - 1].x * v[0].y - v[0].x * v[n -1].y... | Option Base 1
Public Enum axes
u = 1
v
End Enum
Private Function shoelace(s As Collection) As Double
Dim t As Double
If s.Count > 2 Then
s.Add s(1)
For i = 1 To s.Count - 1
t = t + s(i)(u) * s(i + 1)(v) - s(i + 1)(u) * s(i)(v)
Next i
End If
shoelace = Abs(t) /... |
Preserve the algorithm and functionality while converting the code from Scala to Go. |
class Point(val x: Int, val y: Int) {
override fun toString() = "($x, $y)"
}
fun shoelaceArea(v: List<Point>): Double {
val n = v.size
var a = 0.0
for (i in 0 until n - 1) {
a += v[i].x * v[i + 1].y - v[i + 1].x * v[i].y
}
return Math.abs(a + v[n - 1].x * v[0].y - v[0].x * v[n -1].y... | package main
import "fmt"
type point struct{ x, y float64 }
func shoelace(pts []point) float64 {
sum := 0.
p0 := pts[len(pts)-1]
for _, p1 := range pts {
sum += p0.y*p1.x - p0.x*p1.y
p0 = p1
}
return sum / 2
}
func main() {
fmt.Println(shoelace([]point{{3, 4}, {5, 11}, {12, 8... |
Generate an equivalent Go version of this Scala code. |
class Point(val x: Int, val y: Int) {
override fun toString() = "($x, $y)"
}
fun shoelaceArea(v: List<Point>): Double {
val n = v.size
var a = 0.0
for (i in 0 until n - 1) {
a += v[i].x * v[i + 1].y - v[i + 1].x * v[i].y
}
return Math.abs(a + v[n - 1].x * v[0].y - v[0].x * v[n -1].y... | package main
import "fmt"
type point struct{ x, y float64 }
func shoelace(pts []point) float64 {
sum := 0.
p0 := pts[len(pts)-1]
for _, p1 := range pts {
sum += p0.y*p1.x - p0.x*p1.y
p0 = p1
}
return sum / 2
}
func main() {
fmt.Println(shoelace([]point{{3, 4}, {5, 11}, {12, 8... |
Translate this program into C but keep the logic exactly as in Swift. | import Foundation
struct Point {
var x: Double
var y: Double
}
extension Point: CustomStringConvertible {
var description: String {
return "Point(x: \(x), y: \(y))"
}
}
struct Polygon {
var points: [Point]
var area: Double {
let xx = points.map({ $0.x })
let yy = points.map({ $0.y })
let... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
double x,y;
}point;
double shoelace(char* inputFile){
int i,numPoints;
double leftSum = 0,rightSum = 0;
point* pointSet;
FILE* fp = fopen(inputFile,"r");
fscanf(fp,"%d",&numPoints);
pointSet = (point*)malloc((numPoints + 1)*sizeof(poin... |
Translate this program into C but keep the logic exactly as in Swift. | import Foundation
struct Point {
var x: Double
var y: Double
}
extension Point: CustomStringConvertible {
var description: String {
return "Point(x: \(x), y: \(y))"
}
}
struct Polygon {
var points: [Point]
var area: Double {
let xx = points.map({ $0.x })
let yy = points.map({ $0.y })
let... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
double x,y;
}point;
double shoelace(char* inputFile){
int i,numPoints;
double leftSum = 0,rightSum = 0;
point* pointSet;
FILE* fp = fopen(inputFile,"r");
fscanf(fp,"%d",&numPoints);
pointSet = (point*)malloc((numPoints + 1)*sizeof(poin... |
Transform the following Swift implementation into C#, maintaining the same output and logic. | import Foundation
struct Point {
var x: Double
var y: Double
}
extension Point: CustomStringConvertible {
var description: String {
return "Point(x: \(x), y: \(y))"
}
}
struct Polygon {
var points: [Point]
var area: Double {
let xx = points.map({ $0.x })
let yy = points.map({ $0.y })
let... | using System;
using System.Collections.Generic;
namespace ShoelaceFormula {
using Point = Tuple<double, double>;
class Program {
static double ShoelaceArea(List<Point> v) {
int n = v.Count;
double a = 0.0;
for (int i = 0; i < n - 1; i++) {
a += v[i].... |
Convert this Swift block to C#, preserving its control flow and logic. | import Foundation
struct Point {
var x: Double
var y: Double
}
extension Point: CustomStringConvertible {
var description: String {
return "Point(x: \(x), y: \(y))"
}
}
struct Polygon {
var points: [Point]
var area: Double {
let xx = points.map({ $0.x })
let yy = points.map({ $0.y })
let... | using System;
using System.Collections.Generic;
namespace ShoelaceFormula {
using Point = Tuple<double, double>;
class Program {
static double ShoelaceArea(List<Point> v) {
int n = v.Count;
double a = 0.0;
for (int i = 0; i < n - 1; i++) {
a += v[i].... |
Produce a functionally identical C++ code for the snippet given in Swift. | import Foundation
struct Point {
var x: Double
var y: Double
}
extension Point: CustomStringConvertible {
var description: String {
return "Point(x: \(x), y: \(y))"
}
}
struct Polygon {
var points: [Point]
var area: Double {
let xx = points.map({ $0.x })
let yy = points.map({ $0.y })
let... | #include <iostream>
#include <tuple>
#include <vector>
using namespace std;
double shoelace(vector<pair<double, double>> points) {
double leftSum = 0.0;
double rightSum = 0.0;
for (int i = 0; i < points.size(); ++i) {
int j = (i + 1) % points.size();
leftSum += points[i].first * points[j].second;
rightSum ... |
Write a version of this Swift function in C++ with identical behavior. | import Foundation
struct Point {
var x: Double
var y: Double
}
extension Point: CustomStringConvertible {
var description: String {
return "Point(x: \(x), y: \(y))"
}
}
struct Polygon {
var points: [Point]
var area: Double {
let xx = points.map({ $0.x })
let yy = points.map({ $0.y })
let... | #include <iostream>
#include <tuple>
#include <vector>
using namespace std;
double shoelace(vector<pair<double, double>> points) {
double leftSum = 0.0;
double rightSum = 0.0;
for (int i = 0; i < points.size(); ++i) {
int j = (i + 1) % points.size();
leftSum += points[i].first * points[j].second;
rightSum ... |
Port the provided Swift code into Java while preserving the original functionality. | import Foundation
struct Point {
var x: Double
var y: Double
}
extension Point: CustomStringConvertible {
var description: String {
return "Point(x: \(x), y: \(y))"
}
}
struct Polygon {
var points: [Point]
var area: Double {
let xx = points.map({ $0.x })
let yy = points.map({ $0.y })
let... | import java.util.List;
public class ShoelaceFormula {
private static class Point {
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return String.format("(%d, %d)", x, y);
}
}
... |
Preserve the algorithm and functionality while converting the code from Swift to Java. | import Foundation
struct Point {
var x: Double
var y: Double
}
extension Point: CustomStringConvertible {
var description: String {
return "Point(x: \(x), y: \(y))"
}
}
struct Polygon {
var points: [Point]
var area: Double {
let xx = points.map({ $0.x })
let yy = points.map({ $0.y })
let... | import java.util.List;
public class ShoelaceFormula {
private static class Point {
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return String.format("(%d, %d)", x, y);
}
}
... |
Produce a functionally identical Python code for the snippet given in Swift. | import Foundation
struct Point {
var x: Double
var y: Double
}
extension Point: CustomStringConvertible {
var description: String {
return "Point(x: \(x), y: \(y))"
}
}
struct Polygon {
var points: [Point]
var area: Double {
let xx = points.map({ $0.x })
let yy = points.map({ $0.y })
let... | >>> def area_by_shoelace(x, y):
"Assumes x,y points go around the polygon in one direction"
return abs( sum(i * j for i, j in zip(x, y[1:] + y[:1]))
-sum(i * j for i, j in zip(x[1:] + x[:1], y ))) / 2
>>> points = [(3,4), (5,11), (12,8), (9,5), (5,6)]
>>> x, y = zip(*point... |
Produce a functionally identical Python code for the snippet given in Swift. | import Foundation
struct Point {
var x: Double
var y: Double
}
extension Point: CustomStringConvertible {
var description: String {
return "Point(x: \(x), y: \(y))"
}
}
struct Polygon {
var points: [Point]
var area: Double {
let xx = points.map({ $0.x })
let yy = points.map({ $0.y })
let... | >>> def area_by_shoelace(x, y):
"Assumes x,y points go around the polygon in one direction"
return abs( sum(i * j for i, j in zip(x, y[1:] + y[:1]))
-sum(i * j for i, j in zip(x[1:] + x[:1], y ))) / 2
>>> points = [(3,4), (5,11), (12,8), (9,5), (5,6)]
>>> x, y = zip(*point... |
Convert this Swift block to VB, preserving its control flow and logic. | import Foundation
struct Point {
var x: Double
var y: Double
}
extension Point: CustomStringConvertible {
var description: String {
return "Point(x: \(x), y: \(y))"
}
}
struct Polygon {
var points: [Point]
var area: Double {
let xx = points.map({ $0.x })
let yy = points.map({ $0.y })
let... | Option Base 1
Public Enum axes
u = 1
v
End Enum
Private Function shoelace(s As Collection) As Double
Dim t As Double
If s.Count > 2 Then
s.Add s(1)
For i = 1 To s.Count - 1
t = t + s(i)(u) * s(i + 1)(v) - s(i + 1)(u) * s(i)(v)
Next i
End If
shoelace = Abs(t) /... |
Can you help me rewrite this code in VB instead of Swift, keeping it the same logically? | import Foundation
struct Point {
var x: Double
var y: Double
}
extension Point: CustomStringConvertible {
var description: String {
return "Point(x: \(x), y: \(y))"
}
}
struct Polygon {
var points: [Point]
var area: Double {
let xx = points.map({ $0.x })
let yy = points.map({ $0.y })
let... | Option Base 1
Public Enum axes
u = 1
v
End Enum
Private Function shoelace(s As Collection) As Double
Dim t As Double
If s.Count > 2 Then
s.Add s(1)
For i = 1 To s.Count - 1
t = t + s(i)(u) * s(i + 1)(v) - s(i + 1)(u) * s(i)(v)
Next i
End If
shoelace = Abs(t) /... |
Translate the given Swift code snippet into Go without altering its behavior. | import Foundation
struct Point {
var x: Double
var y: Double
}
extension Point: CustomStringConvertible {
var description: String {
return "Point(x: \(x), y: \(y))"
}
}
struct Polygon {
var points: [Point]
var area: Double {
let xx = points.map({ $0.x })
let yy = points.map({ $0.y })
let... | package main
import "fmt"
type point struct{ x, y float64 }
func shoelace(pts []point) float64 {
sum := 0.
p0 := pts[len(pts)-1]
for _, p1 := range pts {
sum += p0.y*p1.x - p0.x*p1.y
p0 = p1
}
return sum / 2
}
func main() {
fmt.Println(shoelace([]point{{3, 4}, {5, 11}, {12, 8... |
Change the programming language of this snippet from Swift to Go without modifying what it does. | import Foundation
struct Point {
var x: Double
var y: Double
}
extension Point: CustomStringConvertible {
var description: String {
return "Point(x: \(x), y: \(y))"
}
}
struct Polygon {
var points: [Point]
var area: Double {
let xx = points.map({ $0.x })
let yy = points.map({ $0.y })
let... | package main
import "fmt"
type point struct{ x, y float64 }
func shoelace(pts []point) float64 {
sum := 0.
p0 := pts[len(pts)-1]
for _, p1 := range pts {
sum += p0.y*p1.x - p0.x*p1.y
p0 = p1
}
return sum / 2
}
func main() {
fmt.Println(shoelace([]point{{3, 4}, {5, 11}, {12, 8... |
Convert this Ada snippet to C# and keep its semantics consistent. | WITH Ada.Text_IO; USE Ada.Text_IO;
PROCEDURE Main IS
TYPE Vertex IS MOD 3;
TYPE Point IS ARRAY (0 .. 1) OF Float;
TYPE Triangle IS ARRAY (Vertex) OF Point;
TYPE Triangle_Vertices IS ARRAY (0 .. 5) OF Float;
FUNCTION Same_Side (A, B, M, N : Point) RETURN Boolean IS
FUNCTION Aff (U : Point) RETU... | using System;
using System.Collections.Generic;
namespace TriangleOverlap {
class Triangle {
public Tuple<double, double> P1 { get; set; }
public Tuple<double, double> P2 { get; set; }
public Tuple<double, double> P3 { get; set; }
public Triangle(Tuple<double, double> p1, Tuple<dou... |
Generate an equivalent C# version of this Ada code. | WITH Ada.Text_IO; USE Ada.Text_IO;
PROCEDURE Main IS
TYPE Vertex IS MOD 3;
TYPE Point IS ARRAY (0 .. 1) OF Float;
TYPE Triangle IS ARRAY (Vertex) OF Point;
TYPE Triangle_Vertices IS ARRAY (0 .. 5) OF Float;
FUNCTION Same_Side (A, B, M, N : Point) RETURN Boolean IS
FUNCTION Aff (U : Point) RETU... | using System;
using System.Collections.Generic;
namespace TriangleOverlap {
class Triangle {
public Tuple<double, double> P1 { get; set; }
public Tuple<double, double> P2 { get; set; }
public Tuple<double, double> P3 { get; set; }
public Triangle(Tuple<double, double> p1, Tuple<dou... |
Generate an equivalent C version of this Ada code. | WITH Ada.Text_IO; USE Ada.Text_IO;
PROCEDURE Main IS
TYPE Vertex IS MOD 3;
TYPE Point IS ARRAY (0 .. 1) OF Float;
TYPE Triangle IS ARRAY (Vertex) OF Point;
TYPE Triangle_Vertices IS ARRAY (0 .. 5) OF Float;
FUNCTION Same_Side (A, B, M, N : Point) RETURN Boolean IS
FUNCTION Aff (U : Point) RETU... | #include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct {
double x, y;
} Point;
double det2D(const Point * const p1, const Point * const p2, const Point * const p3) {
return p1->x * (p2->y - p3->y)
+ p2->x * (p3->y - p1->y)
+ p3->x * (p1->y - p2->y);
}
vo... |
Write the same code in C as shown below in Ada. | WITH Ada.Text_IO; USE Ada.Text_IO;
PROCEDURE Main IS
TYPE Vertex IS MOD 3;
TYPE Point IS ARRAY (0 .. 1) OF Float;
TYPE Triangle IS ARRAY (Vertex) OF Point;
TYPE Triangle_Vertices IS ARRAY (0 .. 5) OF Float;
FUNCTION Same_Side (A, B, M, N : Point) RETURN Boolean IS
FUNCTION Aff (U : Point) RETU... | #include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct {
double x, y;
} Point;
double det2D(const Point * const p1, const Point * const p2, const Point * const p3) {
return p1->x * (p2->y - p3->y)
+ p2->x * (p3->y - p1->y)
+ p3->x * (p1->y - p2->y);
}
vo... |
Can you help me rewrite this code in C++ instead of Ada, keeping it the same logically? | WITH Ada.Text_IO; USE Ada.Text_IO;
PROCEDURE Main IS
TYPE Vertex IS MOD 3;
TYPE Point IS ARRAY (0 .. 1) OF Float;
TYPE Triangle IS ARRAY (Vertex) OF Point;
TYPE Triangle_Vertices IS ARRAY (0 .. 5) OF Float;
FUNCTION Same_Side (A, B, M, N : Point) RETURN Boolean IS
FUNCTION Aff (U : Point) RETU... | #include <vector>
#include <iostream>
#include <stdexcept>
using namespace std;
typedef std::pair<double, double> TriPoint;
inline double Det2D(TriPoint &p1, TriPoint &p2, TriPoint &p3)
{
return +p1.first*(p2.second-p3.second)
+p2.first*(p3.second-p1.second)
+p3.first*(p1.second-p2.second);
}
void CheckTriWind... |
Produce a functionally identical C++ code for the snippet given in Ada. | WITH Ada.Text_IO; USE Ada.Text_IO;
PROCEDURE Main IS
TYPE Vertex IS MOD 3;
TYPE Point IS ARRAY (0 .. 1) OF Float;
TYPE Triangle IS ARRAY (Vertex) OF Point;
TYPE Triangle_Vertices IS ARRAY (0 .. 5) OF Float;
FUNCTION Same_Side (A, B, M, N : Point) RETURN Boolean IS
FUNCTION Aff (U : Point) RETU... | #include <vector>
#include <iostream>
#include <stdexcept>
using namespace std;
typedef std::pair<double, double> TriPoint;
inline double Det2D(TriPoint &p1, TriPoint &p2, TriPoint &p3)
{
return +p1.first*(p2.second-p3.second)
+p2.first*(p3.second-p1.second)
+p3.first*(p1.second-p2.second);
}
void CheckTriWind... |
Convert the following code from Ada to Go, ensuring the logic remains intact. | WITH Ada.Text_IO; USE Ada.Text_IO;
PROCEDURE Main IS
TYPE Vertex IS MOD 3;
TYPE Point IS ARRAY (0 .. 1) OF Float;
TYPE Triangle IS ARRAY (Vertex) OF Point;
TYPE Triangle_Vertices IS ARRAY (0 .. 5) OF Float;
FUNCTION Same_Side (A, B, M, N : Point) RETURN Boolean IS
FUNCTION Aff (U : Point) RETU... | package main
import "fmt"
type point struct {
x, y float64
}
func (p point) String() string {
return fmt.Sprintf("(%.1f, %.1f)", p.x, p.y)
}
type triangle struct {
p1, p2, p3 point
}
func (t *triangle) String() string {
return fmt.Sprintf("Triangle %s, %s, %s", t.p1, t.p2, t.p3)
}
func (t *triangl... |
Rewrite this program in Go while keeping its functionality equivalent to the Ada version. | WITH Ada.Text_IO; USE Ada.Text_IO;
PROCEDURE Main IS
TYPE Vertex IS MOD 3;
TYPE Point IS ARRAY (0 .. 1) OF Float;
TYPE Triangle IS ARRAY (Vertex) OF Point;
TYPE Triangle_Vertices IS ARRAY (0 .. 5) OF Float;
FUNCTION Same_Side (A, B, M, N : Point) RETURN Boolean IS
FUNCTION Aff (U : Point) RETU... | package main
import "fmt"
type point struct {
x, y float64
}
func (p point) String() string {
return fmt.Sprintf("(%.1f, %.1f)", p.x, p.y)
}
type triangle struct {
p1, p2, p3 point
}
func (t *triangle) String() string {
return fmt.Sprintf("Triangle %s, %s, %s", t.p1, t.p2, t.p3)
}
func (t *triangl... |
Preserve the algorithm and functionality while converting the code from Ada to Java. | WITH Ada.Text_IO; USE Ada.Text_IO;
PROCEDURE Main IS
TYPE Vertex IS MOD 3;
TYPE Point IS ARRAY (0 .. 1) OF Float;
TYPE Triangle IS ARRAY (Vertex) OF Point;
TYPE Triangle_Vertices IS ARRAY (0 .. 5) OF Float;
FUNCTION Same_Side (A, B, M, N : Point) RETURN Boolean IS
FUNCTION Aff (U : Point) RETU... | import java.util.function.BiFunction;
public class TriangleOverlap {
private static class Pair {
double first;
double second;
Pair(double first, double second) {
this.first = first;
this.second = second;
}
@Override
public String toString() ... |
Port the provided Ada code into Java while preserving the original functionality. | WITH Ada.Text_IO; USE Ada.Text_IO;
PROCEDURE Main IS
TYPE Vertex IS MOD 3;
TYPE Point IS ARRAY (0 .. 1) OF Float;
TYPE Triangle IS ARRAY (Vertex) OF Point;
TYPE Triangle_Vertices IS ARRAY (0 .. 5) OF Float;
FUNCTION Same_Side (A, B, M, N : Point) RETURN Boolean IS
FUNCTION Aff (U : Point) RETU... | import java.util.function.BiFunction;
public class TriangleOverlap {
private static class Pair {
double first;
double second;
Pair(double first, double second) {
this.first = first;
this.second = second;
}
@Override
public String toString() ... |
Transform the following Ada implementation into Python, maintaining the same output and logic. | WITH Ada.Text_IO; USE Ada.Text_IO;
PROCEDURE Main IS
TYPE Vertex IS MOD 3;
TYPE Point IS ARRAY (0 .. 1) OF Float;
TYPE Triangle IS ARRAY (Vertex) OF Point;
TYPE Triangle_Vertices IS ARRAY (0 .. 5) OF Float;
FUNCTION Same_Side (A, B, M, N : Point) RETURN Boolean IS
FUNCTION Aff (U : Point) RETU... | from __future__ import print_function
import numpy as np
def CheckTriWinding(tri, allowReversed):
trisq = np.ones((3,3))
trisq[:,0:2] = np.array(tri)
detTri = np.linalg.det(trisq)
if detTri < 0.0:
if allowReversed:
a = trisq[2,:].copy()
trisq[2,:] = trisq[1,:]
trisq[1,:] = a
else: raise ValueError("tr... |
Ensure the translated Python code behaves exactly like the original Ada snippet. | WITH Ada.Text_IO; USE Ada.Text_IO;
PROCEDURE Main IS
TYPE Vertex IS MOD 3;
TYPE Point IS ARRAY (0 .. 1) OF Float;
TYPE Triangle IS ARRAY (Vertex) OF Point;
TYPE Triangle_Vertices IS ARRAY (0 .. 5) OF Float;
FUNCTION Same_Side (A, B, M, N : Point) RETURN Boolean IS
FUNCTION Aff (U : Point) RETU... | from __future__ import print_function
import numpy as np
def CheckTriWinding(tri, allowReversed):
trisq = np.ones((3,3))
trisq[:,0:2] = np.array(tri)
detTri = np.linalg.det(trisq)
if detTri < 0.0:
if allowReversed:
a = trisq[2,:].copy()
trisq[2,:] = trisq[1,:]
trisq[1,:] = a
else: raise ValueError("tr... |
Please provide an equivalent version of this Ada code in VB. | WITH Ada.Text_IO; USE Ada.Text_IO;
PROCEDURE Main IS
TYPE Vertex IS MOD 3;
TYPE Point IS ARRAY (0 .. 1) OF Float;
TYPE Triangle IS ARRAY (Vertex) OF Point;
TYPE Triangle_Vertices IS ARRAY (0 .. 5) OF Float;
FUNCTION Same_Side (A, B, M, N : Point) RETURN Boolean IS
FUNCTION Aff (U : Point) RETU... | Module Module1
Class Triangle
Property P1 As Tuple(Of Double, Double)
Property P2 As Tuple(Of Double, Double)
Property P3 As Tuple(Of Double, Double)
Sub New(p1 As Tuple(Of Double, Double), p2 As Tuple(Of Double, Double), p3 As Tuple(Of Double, Double))
Me.P1 = p1
... |
Rewrite the snippet below in VB so it works the same as the original Ada code. | WITH Ada.Text_IO; USE Ada.Text_IO;
PROCEDURE Main IS
TYPE Vertex IS MOD 3;
TYPE Point IS ARRAY (0 .. 1) OF Float;
TYPE Triangle IS ARRAY (Vertex) OF Point;
TYPE Triangle_Vertices IS ARRAY (0 .. 5) OF Float;
FUNCTION Same_Side (A, B, M, N : Point) RETURN Boolean IS
FUNCTION Aff (U : Point) RETU... | Module Module1
Class Triangle
Property P1 As Tuple(Of Double, Double)
Property P2 As Tuple(Of Double, Double)
Property P3 As Tuple(Of Double, Double)
Sub New(p1 As Tuple(Of Double, Double), p2 As Tuple(Of Double, Double), p3 As Tuple(Of Double, Double))
Me.P1 = p1
... |
Write a version of this AutoHotKey function in C with identical behavior. | TrianglesIntersect(T1, T2){
counter := 0
for i, Pt in T1
counter += PointInTriangle(Pt, T2)
for i, Pt in T2
counter += PointInTriangle(Pt, T1)
counter += LinesIntersect([t1.1,t1.2],[t2.1,t2.2]) ? 1 : 0
counter += LinesIntersect([t1.1,t1.3],[t2.1,t2.2]) ? 1 : 0
counter += LinesIntersect([t1.2,t1.3],[t2.1... | #include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct {
double x, y;
} Point;
double det2D(const Point * const p1, const Point * const p2, const Point * const p3) {
return p1->x * (p2->y - p3->y)
+ p2->x * (p3->y - p1->y)
+ p3->x * (p1->y - p2->y);
}
vo... |
Change the programming language of this snippet from AutoHotKey to C without modifying what it does. | TrianglesIntersect(T1, T2){
counter := 0
for i, Pt in T1
counter += PointInTriangle(Pt, T2)
for i, Pt in T2
counter += PointInTriangle(Pt, T1)
counter += LinesIntersect([t1.1,t1.2],[t2.1,t2.2]) ? 1 : 0
counter += LinesIntersect([t1.1,t1.3],[t2.1,t2.2]) ? 1 : 0
counter += LinesIntersect([t1.2,t1.3],[t2.1... | #include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct {
double x, y;
} Point;
double det2D(const Point * const p1, const Point * const p2, const Point * const p3) {
return p1->x * (p2->y - p3->y)
+ p2->x * (p3->y - p1->y)
+ p3->x * (p1->y - p2->y);
}
vo... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.