Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Write the same code in C# as shown below in Mathematica. | freq = 8; length = freq^(-1/2);
Animate[Graphics[
List[{Line[{{0, 0}, length {Sin[T], -Cos[T]}} /. {T -> (Pi/6) Cos[2 Pi freq t]}], PointSize[Large],
Point[{length {Sin[T], -Cos[T]}} /. {T -> (Pi/6) Cos[2 Pi freq t]}]}],
PlotRange -> {{-0.3, 0.3}, {-0.5, 0}}], {t, 0, 1}, AnimationRate -> 0.07]
| using System;
using System.Drawing;
using System.Windows.Forms;
class CSharpPendulum
{
Form _form;
Timer _timer;
double _angle = Math.PI / 2,
_angleAccel,
_angleVelocity = 0,
_dt = 0.1;
int _length = 50;
[STAThread]
static void Main()
{
... |
Port the provided Mathematica code into C++ while preserving the original functionality. | freq = 8; length = freq^(-1/2);
Animate[Graphics[
List[{Line[{{0, 0}, length {Sin[T], -Cos[T]}} /. {T -> (Pi/6) Cos[2 Pi freq t]}], PointSize[Large],
Point[{length {Sin[T], -Cos[T]}} /. {T -> (Pi/6) Cos[2 Pi freq t]}]}],
PlotRange -> {{-0.3, 0.3}, {-0.5, 0}}], {t, 0, 1}, AnimationRate -> 0.07]
| #ifndef __wxPendulumDlg_h__
#define __wxPendulumDlg_h__
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#include <wx/dialog.h>
#else
#include <wx/wxprec.h>
#endif
#include <wx/timer.h>
#include <wx/dcbuffer.h>
#include <cmath>
class wxPendulumDlgApp : public wxApp
{
public:
... |
Change the following Mathematica code into Java without altering its purpose. | freq = 8; length = freq^(-1/2);
Animate[Graphics[
List[{Line[{{0, 0}, length {Sin[T], -Cos[T]}} /. {T -> (Pi/6) Cos[2 Pi freq t]}], PointSize[Large],
Point[{length {Sin[T], -Cos[T]}} /. {T -> (Pi/6) Cos[2 Pi freq t]}]}],
PlotRange -> {{-0.3, 0.3}, {-0.5, 0}}], {t, 0, 1}, AnimationRate -> 0.07]
| import java.awt.*;
import javax.swing.*;
public class Pendulum extends JPanel implements Runnable {
private double angle = Math.PI / 2;
private int length;
public Pendulum(int length) {
this.length = length;
setDoubleBuffered(true);
}
@Override
public void paint(Graphics g) {... |
Generate an equivalent Python version of this Mathematica code. | freq = 8; length = freq^(-1/2);
Animate[Graphics[
List[{Line[{{0, 0}, length {Sin[T], -Cos[T]}} /. {T -> (Pi/6) Cos[2 Pi freq t]}], PointSize[Large],
Point[{length {Sin[T], -Cos[T]}} /. {T -> (Pi/6) Cos[2 Pi freq t]}]}],
PlotRange -> {{-0.3, 0.3}, {-0.5, 0}}], {t, 0, 1}, AnimationRate -> 0.07]
| import pygame, sys
from pygame.locals import *
from math import sin, cos, radians
pygame.init()
WINDOWSIZE = 250
TIMETICK = 100
BOBSIZE = 15
window = pygame.display.set_mode((WINDOWSIZE, WINDOWSIZE))
pygame.display.set_caption("Pendulum")
screen = pygame.display.get_surface()
screen.fill((255,255,255))
PIVOT = (WI... |
Change the programming language of this snippet from Mathematica to VB without modifying what it does. | freq = 8; length = freq^(-1/2);
Animate[Graphics[
List[{Line[{{0, 0}, length {Sin[T], -Cos[T]}} /. {T -> (Pi/6) Cos[2 Pi freq t]}], PointSize[Large],
Point[{length {Sin[T], -Cos[T]}} /. {T -> (Pi/6) Cos[2 Pi freq t]}]}],
PlotRange -> {{-0.3, 0.3}, {-0.5, 0}}], {t, 0, 1}, AnimationRate -> 0.07]
| option explicit
const dt = 0.15
const length=23
dim ans0:ans0=chr(27)&"["
dim Veloc,Accel,angle,olr,olc,r,c
const r0=1
const c0=40
cls
angle=0.7
while 1
wscript.sleep(50)
Accel = -.9 * sin(Angle)
Veloc = Veloc + Accel * dt
Angle = Angle + Veloc * dt
r = r0 + int(cos(Angle) * Length)
... |
Translate the given Mathematica code snippet into Go without altering its behavior. | freq = 8; length = freq^(-1/2);
Animate[Graphics[
List[{Line[{{0, 0}, length {Sin[T], -Cos[T]}} /. {T -> (Pi/6) Cos[2 Pi freq t]}], PointSize[Large],
Point[{length {Sin[T], -Cos[T]}} /. {T -> (Pi/6) Cos[2 Pi freq t]}]}],
PlotRange -> {{-0.3, 0.3}, {-0.5, 0}}], {t, 0, 1}, AnimationRate -> 0.07]
| package main
import (
"github.com/google/gxui"
"github.com/google/gxui/drivers/gl"
"github.com/google/gxui/math"
"github.com/google/gxui/themes/dark"
omath "math"
"time"
)
const (
ANIMATION_WIDTH int = 480
ANIMATION_HEIGHT int = 320
BALL_RADIUS float32 = 25.0
METER_PER_PIXEL float64 = 1.0... |
Generate a C translation of this MATLAB snippet without changing its computational steps. |
g = -9.8;
deltaTime = 1/50;
endTime = 16;
rodPivotPoint = [2 2];
rodLength = 1;
mass = 1;
radius = .2;
theta = 45;
velocity = [0 0];
assert(radius < rodLength,'Pendulum bob radius must be less than the length of the rod.');
position = rodPivotPoint - (rodLength*[-sind(theta) cosd(theta... | #include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <sys/time.h>
#define length 5
#define g 9.8
double alpha, accl, omega = 0, E;
struct timeval tv;
double elappsed() {
struct timeval now;
gettimeofday(&now, 0);
int ret = (now.tv_sec - tv.tv_sec) * 1000000
+ now.tv_usec - tv.tv... |
Generate an equivalent C# version of this MATLAB code. |
g = -9.8;
deltaTime = 1/50;
endTime = 16;
rodPivotPoint = [2 2];
rodLength = 1;
mass = 1;
radius = .2;
theta = 45;
velocity = [0 0];
assert(radius < rodLength,'Pendulum bob radius must be less than the length of the rod.');
position = rodPivotPoint - (rodLength*[-sind(theta) cosd(theta... | using System;
using System.Drawing;
using System.Windows.Forms;
class CSharpPendulum
{
Form _form;
Timer _timer;
double _angle = Math.PI / 2,
_angleAccel,
_angleVelocity = 0,
_dt = 0.1;
int _length = 50;
[STAThread]
static void Main()
{
... |
Port the provided MATLAB code into C++ while preserving the original functionality. |
g = -9.8;
deltaTime = 1/50;
endTime = 16;
rodPivotPoint = [2 2];
rodLength = 1;
mass = 1;
radius = .2;
theta = 45;
velocity = [0 0];
assert(radius < rodLength,'Pendulum bob radius must be less than the length of the rod.');
position = rodPivotPoint - (rodLength*[-sind(theta) cosd(theta... | #ifndef __wxPendulumDlg_h__
#define __wxPendulumDlg_h__
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#include <wx/dialog.h>
#else
#include <wx/wxprec.h>
#endif
#include <wx/timer.h>
#include <wx/dcbuffer.h>
#include <cmath>
class wxPendulumDlgApp : public wxApp
{
public:
... |
Rewrite this program in Java while keeping its functionality equivalent to the MATLAB version. |
g = -9.8;
deltaTime = 1/50;
endTime = 16;
rodPivotPoint = [2 2];
rodLength = 1;
mass = 1;
radius = .2;
theta = 45;
velocity = [0 0];
assert(radius < rodLength,'Pendulum bob radius must be less than the length of the rod.');
position = rodPivotPoint - (rodLength*[-sind(theta) cosd(theta... | import java.awt.*;
import javax.swing.*;
public class Pendulum extends JPanel implements Runnable {
private double angle = Math.PI / 2;
private int length;
public Pendulum(int length) {
this.length = length;
setDoubleBuffered(true);
}
@Override
public void paint(Graphics g) {... |
Maintain the same structure and functionality when rewriting this code in Python. |
g = -9.8;
deltaTime = 1/50;
endTime = 16;
rodPivotPoint = [2 2];
rodLength = 1;
mass = 1;
radius = .2;
theta = 45;
velocity = [0 0];
assert(radius < rodLength,'Pendulum bob radius must be less than the length of the rod.');
position = rodPivotPoint - (rodLength*[-sind(theta) cosd(theta... | import pygame, sys
from pygame.locals import *
from math import sin, cos, radians
pygame.init()
WINDOWSIZE = 250
TIMETICK = 100
BOBSIZE = 15
window = pygame.display.set_mode((WINDOWSIZE, WINDOWSIZE))
pygame.display.set_caption("Pendulum")
screen = pygame.display.get_surface()
screen.fill((255,255,255))
PIVOT = (WI... |
Convert the following code from MATLAB to VB, ensuring the logic remains intact. |
g = -9.8;
deltaTime = 1/50;
endTime = 16;
rodPivotPoint = [2 2];
rodLength = 1;
mass = 1;
radius = .2;
theta = 45;
velocity = [0 0];
assert(radius < rodLength,'Pendulum bob radius must be less than the length of the rod.');
position = rodPivotPoint - (rodLength*[-sind(theta) cosd(theta... | option explicit
const dt = 0.15
const length=23
dim ans0:ans0=chr(27)&"["
dim Veloc,Accel,angle,olr,olc,r,c
const r0=1
const c0=40
cls
angle=0.7
while 1
wscript.sleep(50)
Accel = -.9 * sin(Angle)
Veloc = Veloc + Accel * dt
Angle = Angle + Veloc * dt
r = r0 + int(cos(Angle) * Length)
... |
Maintain the same structure and functionality when rewriting this code in Go. |
g = -9.8;
deltaTime = 1/50;
endTime = 16;
rodPivotPoint = [2 2];
rodLength = 1;
mass = 1;
radius = .2;
theta = 45;
velocity = [0 0];
assert(radius < rodLength,'Pendulum bob radius must be less than the length of the rod.');
position = rodPivotPoint - (rodLength*[-sind(theta) cosd(theta... | package main
import (
"github.com/google/gxui"
"github.com/google/gxui/drivers/gl"
"github.com/google/gxui/math"
"github.com/google/gxui/themes/dark"
omath "math"
"time"
)
const (
ANIMATION_WIDTH int = 480
ANIMATION_HEIGHT int = 320
BALL_RADIUS float32 = 25.0
METER_PER_PIXEL float64 = 1.0... |
Produce a functionally identical C code for the snippet given in Nim. |
import math
import times
import opengl
import opengl/glut
var
lg: float
g: float
currTime: Time
theta0: float
theta: float
omega: float
accel: float
e: float
proc initSimulation(length, gravitation, start: float) =
lg = length
g =... | #include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <sys/time.h>
#define length 5
#define g 9.8
double alpha, accl, omega = 0, E;
struct timeval tv;
double elappsed() {
struct timeval now;
gettimeofday(&now, 0);
int ret = (now.tv_sec - tv.tv_sec) * 1000000
+ now.tv_usec - tv.tv... |
Rewrite the snippet below in C# so it works the same as the original Nim code. |
import math
import times
import opengl
import opengl/glut
var
lg: float
g: float
currTime: Time
theta0: float
theta: float
omega: float
accel: float
e: float
proc initSimulation(length, gravitation, start: float) =
lg = length
g =... | using System;
using System.Drawing;
using System.Windows.Forms;
class CSharpPendulum
{
Form _form;
Timer _timer;
double _angle = Math.PI / 2,
_angleAccel,
_angleVelocity = 0,
_dt = 0.1;
int _length = 50;
[STAThread]
static void Main()
{
... |
Write the same algorithm in C++ as shown in this Nim implementation. |
import math
import times
import opengl
import opengl/glut
var
lg: float
g: float
currTime: Time
theta0: float
theta: float
omega: float
accel: float
e: float
proc initSimulation(length, gravitation, start: float) =
lg = length
g =... | #ifndef __wxPendulumDlg_h__
#define __wxPendulumDlg_h__
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#include <wx/dialog.h>
#else
#include <wx/wxprec.h>
#endif
#include <wx/timer.h>
#include <wx/dcbuffer.h>
#include <cmath>
class wxPendulumDlgApp : public wxApp
{
public:
... |
Translate the given Nim code snippet into Java without altering its behavior. |
import math
import times
import opengl
import opengl/glut
var
lg: float
g: float
currTime: Time
theta0: float
theta: float
omega: float
accel: float
e: float
proc initSimulation(length, gravitation, start: float) =
lg = length
g =... | import java.awt.*;
import javax.swing.*;
public class Pendulum extends JPanel implements Runnable {
private double angle = Math.PI / 2;
private int length;
public Pendulum(int length) {
this.length = length;
setDoubleBuffered(true);
}
@Override
public void paint(Graphics g) {... |
Convert this Nim block to Python, preserving its control flow and logic. |
import math
import times
import opengl
import opengl/glut
var
lg: float
g: float
currTime: Time
theta0: float
theta: float
omega: float
accel: float
e: float
proc initSimulation(length, gravitation, start: float) =
lg = length
g =... | import pygame, sys
from pygame.locals import *
from math import sin, cos, radians
pygame.init()
WINDOWSIZE = 250
TIMETICK = 100
BOBSIZE = 15
window = pygame.display.set_mode((WINDOWSIZE, WINDOWSIZE))
pygame.display.set_caption("Pendulum")
screen = pygame.display.get_surface()
screen.fill((255,255,255))
PIVOT = (WI... |
Convert this Nim snippet to VB and keep its semantics consistent. |
import math
import times
import opengl
import opengl/glut
var
lg: float
g: float
currTime: Time
theta0: float
theta: float
omega: float
accel: float
e: float
proc initSimulation(length, gravitation, start: float) =
lg = length
g =... | option explicit
const dt = 0.15
const length=23
dim ans0:ans0=chr(27)&"["
dim Veloc,Accel,angle,olr,olc,r,c
const r0=1
const c0=40
cls
angle=0.7
while 1
wscript.sleep(50)
Accel = -.9 * sin(Angle)
Veloc = Veloc + Accel * dt
Angle = Angle + Veloc * dt
r = r0 + int(cos(Angle) * Length)
... |
Can you help me rewrite this code in Go instead of Nim, keeping it the same logically? |
import math
import times
import opengl
import opengl/glut
var
lg: float
g: float
currTime: Time
theta0: float
theta: float
omega: float
accel: float
e: float
proc initSimulation(length, gravitation, start: float) =
lg = length
g =... | package main
import (
"github.com/google/gxui"
"github.com/google/gxui/drivers/gl"
"github.com/google/gxui/math"
"github.com/google/gxui/themes/dark"
omath "math"
"time"
)
const (
ANIMATION_WIDTH int = 480
ANIMATION_HEIGHT int = 320
BALL_RADIUS float32 = 25.0
METER_PER_PIXEL float64 = 1.0... |
Change the following Perl code into C without altering its purpose. | use strict;
use warnings;
use Tk;
use Math::Trig qw/:pi/;
my $root = new MainWindow( -title => 'Pendulum Animation' );
my $canvas = $root->Canvas(-width => 320, -height => 200);
my $after_id;
for ($canvas) {
$_->createLine( 0, 25, 320, 25, -tags => [qw/plate/], -width => 2, -fill => 'grey50' );
$_->createOval... | #include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <sys/time.h>
#define length 5
#define g 9.8
double alpha, accl, omega = 0, E;
struct timeval tv;
double elappsed() {
struct timeval now;
gettimeofday(&now, 0);
int ret = (now.tv_sec - tv.tv_sec) * 1000000
+ now.tv_usec - tv.tv... |
Change the following Perl code into C# without altering its purpose. | use strict;
use warnings;
use Tk;
use Math::Trig qw/:pi/;
my $root = new MainWindow( -title => 'Pendulum Animation' );
my $canvas = $root->Canvas(-width => 320, -height => 200);
my $after_id;
for ($canvas) {
$_->createLine( 0, 25, 320, 25, -tags => [qw/plate/], -width => 2, -fill => 'grey50' );
$_->createOval... | using System;
using System.Drawing;
using System.Windows.Forms;
class CSharpPendulum
{
Form _form;
Timer _timer;
double _angle = Math.PI / 2,
_angleAccel,
_angleVelocity = 0,
_dt = 0.1;
int _length = 50;
[STAThread]
static void Main()
{
... |
Write the same algorithm in C++ as shown in this Perl implementation. | use strict;
use warnings;
use Tk;
use Math::Trig qw/:pi/;
my $root = new MainWindow( -title => 'Pendulum Animation' );
my $canvas = $root->Canvas(-width => 320, -height => 200);
my $after_id;
for ($canvas) {
$_->createLine( 0, 25, 320, 25, -tags => [qw/plate/], -width => 2, -fill => 'grey50' );
$_->createOval... | #ifndef __wxPendulumDlg_h__
#define __wxPendulumDlg_h__
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#include <wx/dialog.h>
#else
#include <wx/wxprec.h>
#endif
#include <wx/timer.h>
#include <wx/dcbuffer.h>
#include <cmath>
class wxPendulumDlgApp : public wxApp
{
public:
... |
Change the programming language of this snippet from Perl to Java without modifying what it does. | use strict;
use warnings;
use Tk;
use Math::Trig qw/:pi/;
my $root = new MainWindow( -title => 'Pendulum Animation' );
my $canvas = $root->Canvas(-width => 320, -height => 200);
my $after_id;
for ($canvas) {
$_->createLine( 0, 25, 320, 25, -tags => [qw/plate/], -width => 2, -fill => 'grey50' );
$_->createOval... | import java.awt.*;
import javax.swing.*;
public class Pendulum extends JPanel implements Runnable {
private double angle = Math.PI / 2;
private int length;
public Pendulum(int length) {
this.length = length;
setDoubleBuffered(true);
}
@Override
public void paint(Graphics g) {... |
Generate an equivalent Python version of this Perl code. | use strict;
use warnings;
use Tk;
use Math::Trig qw/:pi/;
my $root = new MainWindow( -title => 'Pendulum Animation' );
my $canvas = $root->Canvas(-width => 320, -height => 200);
my $after_id;
for ($canvas) {
$_->createLine( 0, 25, 320, 25, -tags => [qw/plate/], -width => 2, -fill => 'grey50' );
$_->createOval... | import pygame, sys
from pygame.locals import *
from math import sin, cos, radians
pygame.init()
WINDOWSIZE = 250
TIMETICK = 100
BOBSIZE = 15
window = pygame.display.set_mode((WINDOWSIZE, WINDOWSIZE))
pygame.display.set_caption("Pendulum")
screen = pygame.display.get_surface()
screen.fill((255,255,255))
PIVOT = (WI... |
Rewrite the snippet below in VB so it works the same as the original Perl code. | use strict;
use warnings;
use Tk;
use Math::Trig qw/:pi/;
my $root = new MainWindow( -title => 'Pendulum Animation' );
my $canvas = $root->Canvas(-width => 320, -height => 200);
my $after_id;
for ($canvas) {
$_->createLine( 0, 25, 320, 25, -tags => [qw/plate/], -width => 2, -fill => 'grey50' );
$_->createOval... | option explicit
const dt = 0.15
const length=23
dim ans0:ans0=chr(27)&"["
dim Veloc,Accel,angle,olr,olc,r,c
const r0=1
const c0=40
cls
angle=0.7
while 1
wscript.sleep(50)
Accel = -.9 * sin(Angle)
Veloc = Veloc + Accel * dt
Angle = Angle + Veloc * dt
r = r0 + int(cos(Angle) * Length)
... |
Produce a language-to-language conversion: from Perl to Go, same semantics. | use strict;
use warnings;
use Tk;
use Math::Trig qw/:pi/;
my $root = new MainWindow( -title => 'Pendulum Animation' );
my $canvas = $root->Canvas(-width => 320, -height => 200);
my $after_id;
for ($canvas) {
$_->createLine( 0, 25, 320, 25, -tags => [qw/plate/], -width => 2, -fill => 'grey50' );
$_->createOval... | package main
import (
"github.com/google/gxui"
"github.com/google/gxui/drivers/gl"
"github.com/google/gxui/math"
"github.com/google/gxui/themes/dark"
omath "math"
"time"
)
const (
ANIMATION_WIDTH int = 480
ANIMATION_HEIGHT int = 320
BALL_RADIUS float32 = 25.0
METER_PER_PIXEL float64 = 1.0... |
Generate an equivalent C version of this R code. | library(DescTools)
pendulum<-function(length=5,radius=1,circle.color="white",bg.color="white"){
tseq = c(seq(0,pi,by=.1),seq(pi,0,by=-.1))
slow=.27;fast=.07
sseq = c(seq(slow,fast,length.out = length(tseq)/4),seq(fast,slow,length.out = length(tseq)/4),seq(slow,fast,length.out = length(tseq)/4),seq(fast,slow,leng... | #include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <sys/time.h>
#define length 5
#define g 9.8
double alpha, accl, omega = 0, E;
struct timeval tv;
double elappsed() {
struct timeval now;
gettimeofday(&now, 0);
int ret = (now.tv_sec - tv.tv_sec) * 1000000
+ now.tv_usec - tv.tv... |
Ensure the translated C# code behaves exactly like the original R snippet. | library(DescTools)
pendulum<-function(length=5,radius=1,circle.color="white",bg.color="white"){
tseq = c(seq(0,pi,by=.1),seq(pi,0,by=-.1))
slow=.27;fast=.07
sseq = c(seq(slow,fast,length.out = length(tseq)/4),seq(fast,slow,length.out = length(tseq)/4),seq(slow,fast,length.out = length(tseq)/4),seq(fast,slow,leng... | using System;
using System.Drawing;
using System.Windows.Forms;
class CSharpPendulum
{
Form _form;
Timer _timer;
double _angle = Math.PI / 2,
_angleAccel,
_angleVelocity = 0,
_dt = 0.1;
int _length = 50;
[STAThread]
static void Main()
{
... |
Produce a language-to-language conversion: from R to C++, same semantics. | library(DescTools)
pendulum<-function(length=5,radius=1,circle.color="white",bg.color="white"){
tseq = c(seq(0,pi,by=.1),seq(pi,0,by=-.1))
slow=.27;fast=.07
sseq = c(seq(slow,fast,length.out = length(tseq)/4),seq(fast,slow,length.out = length(tseq)/4),seq(slow,fast,length.out = length(tseq)/4),seq(fast,slow,leng... | #ifndef __wxPendulumDlg_h__
#define __wxPendulumDlg_h__
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#include <wx/dialog.h>
#else
#include <wx/wxprec.h>
#endif
#include <wx/timer.h>
#include <wx/dcbuffer.h>
#include <cmath>
class wxPendulumDlgApp : public wxApp
{
public:
... |
Write the same algorithm in Java as shown in this R implementation. | library(DescTools)
pendulum<-function(length=5,radius=1,circle.color="white",bg.color="white"){
tseq = c(seq(0,pi,by=.1),seq(pi,0,by=-.1))
slow=.27;fast=.07
sseq = c(seq(slow,fast,length.out = length(tseq)/4),seq(fast,slow,length.out = length(tseq)/4),seq(slow,fast,length.out = length(tseq)/4),seq(fast,slow,leng... | import java.awt.*;
import javax.swing.*;
public class Pendulum extends JPanel implements Runnable {
private double angle = Math.PI / 2;
private int length;
public Pendulum(int length) {
this.length = length;
setDoubleBuffered(true);
}
@Override
public void paint(Graphics g) {... |
Rewrite this program in Python while keeping its functionality equivalent to the R version. | library(DescTools)
pendulum<-function(length=5,radius=1,circle.color="white",bg.color="white"){
tseq = c(seq(0,pi,by=.1),seq(pi,0,by=-.1))
slow=.27;fast=.07
sseq = c(seq(slow,fast,length.out = length(tseq)/4),seq(fast,slow,length.out = length(tseq)/4),seq(slow,fast,length.out = length(tseq)/4),seq(fast,slow,leng... | import pygame, sys
from pygame.locals import *
from math import sin, cos, radians
pygame.init()
WINDOWSIZE = 250
TIMETICK = 100
BOBSIZE = 15
window = pygame.display.set_mode((WINDOWSIZE, WINDOWSIZE))
pygame.display.set_caption("Pendulum")
screen = pygame.display.get_surface()
screen.fill((255,255,255))
PIVOT = (WI... |
Convert this R snippet to VB and keep its semantics consistent. | library(DescTools)
pendulum<-function(length=5,radius=1,circle.color="white",bg.color="white"){
tseq = c(seq(0,pi,by=.1),seq(pi,0,by=-.1))
slow=.27;fast=.07
sseq = c(seq(slow,fast,length.out = length(tseq)/4),seq(fast,slow,length.out = length(tseq)/4),seq(slow,fast,length.out = length(tseq)/4),seq(fast,slow,leng... | option explicit
const dt = 0.15
const length=23
dim ans0:ans0=chr(27)&"["
dim Veloc,Accel,angle,olr,olc,r,c
const r0=1
const c0=40
cls
angle=0.7
while 1
wscript.sleep(50)
Accel = -.9 * sin(Angle)
Veloc = Veloc + Accel * dt
Angle = Angle + Veloc * dt
r = r0 + int(cos(Angle) * Length)
... |
Write a version of this R function in Go with identical behavior. | library(DescTools)
pendulum<-function(length=5,radius=1,circle.color="white",bg.color="white"){
tseq = c(seq(0,pi,by=.1),seq(pi,0,by=-.1))
slow=.27;fast=.07
sseq = c(seq(slow,fast,length.out = length(tseq)/4),seq(fast,slow,length.out = length(tseq)/4),seq(slow,fast,length.out = length(tseq)/4),seq(fast,slow,leng... | package main
import (
"github.com/google/gxui"
"github.com/google/gxui/drivers/gl"
"github.com/google/gxui/math"
"github.com/google/gxui/themes/dark"
omath "math"
"time"
)
const (
ANIMATION_WIDTH int = 480
ANIMATION_HEIGHT int = 320
BALL_RADIUS float32 = 25.0
METER_PER_PIXEL float64 = 1.0... |
Maintain the same structure and functionality when rewriting this code in C. | #lang racket
(require 2htdp/image 2htdp/universe)
(define (pendulum)
(define (accel θ) (- (sin θ)))
(define θ (/ pi 2.5))
(define θ′ 0)
(define θ′′ (accel (/ pi 2.5)))
(define (x θ) (+ 200 (* 150 (sin θ))))
(define (y θ) (* 150 (cos θ)))
(λ (n)
(define p-image (underlay/xy (add-line (empty-scene 400... | #include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <sys/time.h>
#define length 5
#define g 9.8
double alpha, accl, omega = 0, E;
struct timeval tv;
double elappsed() {
struct timeval now;
gettimeofday(&now, 0);
int ret = (now.tv_sec - tv.tv_sec) * 1000000
+ now.tv_usec - tv.tv... |
Produce a functionally identical C# code for the snippet given in Racket. | #lang racket
(require 2htdp/image 2htdp/universe)
(define (pendulum)
(define (accel θ) (- (sin θ)))
(define θ (/ pi 2.5))
(define θ′ 0)
(define θ′′ (accel (/ pi 2.5)))
(define (x θ) (+ 200 (* 150 (sin θ))))
(define (y θ) (* 150 (cos θ)))
(λ (n)
(define p-image (underlay/xy (add-line (empty-scene 400... | using System;
using System.Drawing;
using System.Windows.Forms;
class CSharpPendulum
{
Form _form;
Timer _timer;
double _angle = Math.PI / 2,
_angleAccel,
_angleVelocity = 0,
_dt = 0.1;
int _length = 50;
[STAThread]
static void Main()
{
... |
Maintain the same structure and functionality when rewriting this code in C++. | #lang racket
(require 2htdp/image 2htdp/universe)
(define (pendulum)
(define (accel θ) (- (sin θ)))
(define θ (/ pi 2.5))
(define θ′ 0)
(define θ′′ (accel (/ pi 2.5)))
(define (x θ) (+ 200 (* 150 (sin θ))))
(define (y θ) (* 150 (cos θ)))
(λ (n)
(define p-image (underlay/xy (add-line (empty-scene 400... | #ifndef __wxPendulumDlg_h__
#define __wxPendulumDlg_h__
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#include <wx/dialog.h>
#else
#include <wx/wxprec.h>
#endif
#include <wx/timer.h>
#include <wx/dcbuffer.h>
#include <cmath>
class wxPendulumDlgApp : public wxApp
{
public:
... |
Port the following code from Racket to Java with equivalent syntax and logic. | #lang racket
(require 2htdp/image 2htdp/universe)
(define (pendulum)
(define (accel θ) (- (sin θ)))
(define θ (/ pi 2.5))
(define θ′ 0)
(define θ′′ (accel (/ pi 2.5)))
(define (x θ) (+ 200 (* 150 (sin θ))))
(define (y θ) (* 150 (cos θ)))
(λ (n)
(define p-image (underlay/xy (add-line (empty-scene 400... | import java.awt.*;
import javax.swing.*;
public class Pendulum extends JPanel implements Runnable {
private double angle = Math.PI / 2;
private int length;
public Pendulum(int length) {
this.length = length;
setDoubleBuffered(true);
}
@Override
public void paint(Graphics g) {... |
Rewrite the snippet below in Python so it works the same as the original Racket code. | #lang racket
(require 2htdp/image 2htdp/universe)
(define (pendulum)
(define (accel θ) (- (sin θ)))
(define θ (/ pi 2.5))
(define θ′ 0)
(define θ′′ (accel (/ pi 2.5)))
(define (x θ) (+ 200 (* 150 (sin θ))))
(define (y θ) (* 150 (cos θ)))
(λ (n)
(define p-image (underlay/xy (add-line (empty-scene 400... | import pygame, sys
from pygame.locals import *
from math import sin, cos, radians
pygame.init()
WINDOWSIZE = 250
TIMETICK = 100
BOBSIZE = 15
window = pygame.display.set_mode((WINDOWSIZE, WINDOWSIZE))
pygame.display.set_caption("Pendulum")
screen = pygame.display.get_surface()
screen.fill((255,255,255))
PIVOT = (WI... |
Produce a functionally identical VB code for the snippet given in Racket. | #lang racket
(require 2htdp/image 2htdp/universe)
(define (pendulum)
(define (accel θ) (- (sin θ)))
(define θ (/ pi 2.5))
(define θ′ 0)
(define θ′′ (accel (/ pi 2.5)))
(define (x θ) (+ 200 (* 150 (sin θ))))
(define (y θ) (* 150 (cos θ)))
(λ (n)
(define p-image (underlay/xy (add-line (empty-scene 400... | option explicit
const dt = 0.15
const length=23
dim ans0:ans0=chr(27)&"["
dim Veloc,Accel,angle,olr,olc,r,c
const r0=1
const c0=40
cls
angle=0.7
while 1
wscript.sleep(50)
Accel = -.9 * sin(Angle)
Veloc = Veloc + Accel * dt
Angle = Angle + Veloc * dt
r = r0 + int(cos(Angle) * Length)
... |
Port the following code from Racket to Go with equivalent syntax and logic. | #lang racket
(require 2htdp/image 2htdp/universe)
(define (pendulum)
(define (accel θ) (- (sin θ)))
(define θ (/ pi 2.5))
(define θ′ 0)
(define θ′′ (accel (/ pi 2.5)))
(define (x θ) (+ 200 (* 150 (sin θ))))
(define (y θ) (* 150 (cos θ)))
(λ (n)
(define p-image (underlay/xy (add-line (empty-scene 400... | package main
import (
"github.com/google/gxui"
"github.com/google/gxui/drivers/gl"
"github.com/google/gxui/math"
"github.com/google/gxui/themes/dark"
omath "math"
"time"
)
const (
ANIMATION_WIDTH int = 480
ANIMATION_HEIGHT int = 320
BALL_RADIUS float32 = 25.0
METER_PER_PIXEL float64 = 1.0... |
Write a version of this REXX function in C with identical behavior. | pendulum = .pendulum~new(10, 30)
before = .datetime~new
do 100 -- somewhat arbitrary loop count
call syssleep .2
now = .datetime~new
pendulum~update(now - before)
before = now
say " X:" pendulum~x " Y:" pendulum~y
end
::class pendulum
::method init
expose length theta x y velocity
use arg length... | #include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <sys/time.h>
#define length 5
#define g 9.8
double alpha, accl, omega = 0, E;
struct timeval tv;
double elappsed() {
struct timeval now;
gettimeofday(&now, 0);
int ret = (now.tv_sec - tv.tv_sec) * 1000000
+ now.tv_usec - tv.tv... |
Change the following REXX code into C# without altering its purpose. | pendulum = .pendulum~new(10, 30)
before = .datetime~new
do 100 -- somewhat arbitrary loop count
call syssleep .2
now = .datetime~new
pendulum~update(now - before)
before = now
say " X:" pendulum~x " Y:" pendulum~y
end
::class pendulum
::method init
expose length theta x y velocity
use arg length... | using System;
using System.Drawing;
using System.Windows.Forms;
class CSharpPendulum
{
Form _form;
Timer _timer;
double _angle = Math.PI / 2,
_angleAccel,
_angleVelocity = 0,
_dt = 0.1;
int _length = 50;
[STAThread]
static void Main()
{
... |
Preserve the algorithm and functionality while converting the code from REXX to C++. | pendulum = .pendulum~new(10, 30)
before = .datetime~new
do 100 -- somewhat arbitrary loop count
call syssleep .2
now = .datetime~new
pendulum~update(now - before)
before = now
say " X:" pendulum~x " Y:" pendulum~y
end
::class pendulum
::method init
expose length theta x y velocity
use arg length... | #ifndef __wxPendulumDlg_h__
#define __wxPendulumDlg_h__
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#include <wx/dialog.h>
#else
#include <wx/wxprec.h>
#endif
#include <wx/timer.h>
#include <wx/dcbuffer.h>
#include <cmath>
class wxPendulumDlgApp : public wxApp
{
public:
... |
Maintain the same structure and functionality when rewriting this code in Java. | pendulum = .pendulum~new(10, 30)
before = .datetime~new
do 100 -- somewhat arbitrary loop count
call syssleep .2
now = .datetime~new
pendulum~update(now - before)
before = now
say " X:" pendulum~x " Y:" pendulum~y
end
::class pendulum
::method init
expose length theta x y velocity
use arg length... | import java.awt.*;
import javax.swing.*;
public class Pendulum extends JPanel implements Runnable {
private double angle = Math.PI / 2;
private int length;
public Pendulum(int length) {
this.length = length;
setDoubleBuffered(true);
}
@Override
public void paint(Graphics g) {... |
Preserve the algorithm and functionality while converting the code from REXX to Python. | pendulum = .pendulum~new(10, 30)
before = .datetime~new
do 100 -- somewhat arbitrary loop count
call syssleep .2
now = .datetime~new
pendulum~update(now - before)
before = now
say " X:" pendulum~x " Y:" pendulum~y
end
::class pendulum
::method init
expose length theta x y velocity
use arg length... | import pygame, sys
from pygame.locals import *
from math import sin, cos, radians
pygame.init()
WINDOWSIZE = 250
TIMETICK = 100
BOBSIZE = 15
window = pygame.display.set_mode((WINDOWSIZE, WINDOWSIZE))
pygame.display.set_caption("Pendulum")
screen = pygame.display.get_surface()
screen.fill((255,255,255))
PIVOT = (WI... |
Rewrite this program in VB while keeping its functionality equivalent to the REXX version. | pendulum = .pendulum~new(10, 30)
before = .datetime~new
do 100 -- somewhat arbitrary loop count
call syssleep .2
now = .datetime~new
pendulum~update(now - before)
before = now
say " X:" pendulum~x " Y:" pendulum~y
end
::class pendulum
::method init
expose length theta x y velocity
use arg length... | option explicit
const dt = 0.15
const length=23
dim ans0:ans0=chr(27)&"["
dim Veloc,Accel,angle,olr,olc,r,c
const r0=1
const c0=40
cls
angle=0.7
while 1
wscript.sleep(50)
Accel = -.9 * sin(Angle)
Veloc = Veloc + Accel * dt
Angle = Angle + Veloc * dt
r = r0 + int(cos(Angle) * Length)
... |
Generate an equivalent Go version of this REXX code. | pendulum = .pendulum~new(10, 30)
before = .datetime~new
do 100 -- somewhat arbitrary loop count
call syssleep .2
now = .datetime~new
pendulum~update(now - before)
before = now
say " X:" pendulum~x " Y:" pendulum~y
end
::class pendulum
::method init
expose length theta x y velocity
use arg length... | package main
import (
"github.com/google/gxui"
"github.com/google/gxui/drivers/gl"
"github.com/google/gxui/math"
"github.com/google/gxui/themes/dark"
omath "math"
"time"
)
const (
ANIMATION_WIDTH int = 480
ANIMATION_HEIGHT int = 320
BALL_RADIUS float32 = 25.0
METER_PER_PIXEL float64 = 1.0... |
Convert this Ruby snippet to C and keep its semantics consistent. | require 'tk'
$root = TkRoot.new("title" => "Pendulum Animation")
$canvas = TkCanvas.new($root) do
width 320
height 200
create TkcLine, 0,25,320,25, 'tags' => 'plate', 'width' => 2, 'fill' => 'grey50'
create TkcOval, 155,20,165,30, 'tags' => 'pivot', 'outline' => "", 'fill' => 'grey50'
create TkcLine, 1,1,1... | #include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <sys/time.h>
#define length 5
#define g 9.8
double alpha, accl, omega = 0, E;
struct timeval tv;
double elappsed() {
struct timeval now;
gettimeofday(&now, 0);
int ret = (now.tv_sec - tv.tv_sec) * 1000000
+ now.tv_usec - tv.tv... |
Translate this program into C# but keep the logic exactly as in Ruby. | require 'tk'
$root = TkRoot.new("title" => "Pendulum Animation")
$canvas = TkCanvas.new($root) do
width 320
height 200
create TkcLine, 0,25,320,25, 'tags' => 'plate', 'width' => 2, 'fill' => 'grey50'
create TkcOval, 155,20,165,30, 'tags' => 'pivot', 'outline' => "", 'fill' => 'grey50'
create TkcLine, 1,1,1... | using System;
using System.Drawing;
using System.Windows.Forms;
class CSharpPendulum
{
Form _form;
Timer _timer;
double _angle = Math.PI / 2,
_angleAccel,
_angleVelocity = 0,
_dt = 0.1;
int _length = 50;
[STAThread]
static void Main()
{
... |
Transform the following Ruby implementation into C++, maintaining the same output and logic. | require 'tk'
$root = TkRoot.new("title" => "Pendulum Animation")
$canvas = TkCanvas.new($root) do
width 320
height 200
create TkcLine, 0,25,320,25, 'tags' => 'plate', 'width' => 2, 'fill' => 'grey50'
create TkcOval, 155,20,165,30, 'tags' => 'pivot', 'outline' => "", 'fill' => 'grey50'
create TkcLine, 1,1,1... | #ifndef __wxPendulumDlg_h__
#define __wxPendulumDlg_h__
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#include <wx/dialog.h>
#else
#include <wx/wxprec.h>
#endif
#include <wx/timer.h>
#include <wx/dcbuffer.h>
#include <cmath>
class wxPendulumDlgApp : public wxApp
{
public:
... |
Produce a language-to-language conversion: from Ruby to Java, same semantics. | require 'tk'
$root = TkRoot.new("title" => "Pendulum Animation")
$canvas = TkCanvas.new($root) do
width 320
height 200
create TkcLine, 0,25,320,25, 'tags' => 'plate', 'width' => 2, 'fill' => 'grey50'
create TkcOval, 155,20,165,30, 'tags' => 'pivot', 'outline' => "", 'fill' => 'grey50'
create TkcLine, 1,1,1... | import java.awt.*;
import javax.swing.*;
public class Pendulum extends JPanel implements Runnable {
private double angle = Math.PI / 2;
private int length;
public Pendulum(int length) {
this.length = length;
setDoubleBuffered(true);
}
@Override
public void paint(Graphics g) {... |
Please provide an equivalent version of this Ruby code in Python. | require 'tk'
$root = TkRoot.new("title" => "Pendulum Animation")
$canvas = TkCanvas.new($root) do
width 320
height 200
create TkcLine, 0,25,320,25, 'tags' => 'plate', 'width' => 2, 'fill' => 'grey50'
create TkcOval, 155,20,165,30, 'tags' => 'pivot', 'outline' => "", 'fill' => 'grey50'
create TkcLine, 1,1,1... | import pygame, sys
from pygame.locals import *
from math import sin, cos, radians
pygame.init()
WINDOWSIZE = 250
TIMETICK = 100
BOBSIZE = 15
window = pygame.display.set_mode((WINDOWSIZE, WINDOWSIZE))
pygame.display.set_caption("Pendulum")
screen = pygame.display.get_surface()
screen.fill((255,255,255))
PIVOT = (WI... |
Keep all operations the same but rewrite the snippet in VB. | require 'tk'
$root = TkRoot.new("title" => "Pendulum Animation")
$canvas = TkCanvas.new($root) do
width 320
height 200
create TkcLine, 0,25,320,25, 'tags' => 'plate', 'width' => 2, 'fill' => 'grey50'
create TkcOval, 155,20,165,30, 'tags' => 'pivot', 'outline' => "", 'fill' => 'grey50'
create TkcLine, 1,1,1... | option explicit
const dt = 0.15
const length=23
dim ans0:ans0=chr(27)&"["
dim Veloc,Accel,angle,olr,olc,r,c
const r0=1
const c0=40
cls
angle=0.7
while 1
wscript.sleep(50)
Accel = -.9 * sin(Angle)
Veloc = Veloc + Accel * dt
Angle = Angle + Veloc * dt
r = r0 + int(cos(Angle) * Length)
... |
Transform the following Ruby implementation into Go, maintaining the same output and logic. | require 'tk'
$root = TkRoot.new("title" => "Pendulum Animation")
$canvas = TkCanvas.new($root) do
width 320
height 200
create TkcLine, 0,25,320,25, 'tags' => 'plate', 'width' => 2, 'fill' => 'grey50'
create TkcOval, 155,20,165,30, 'tags' => 'pivot', 'outline' => "", 'fill' => 'grey50'
create TkcLine, 1,1,1... | package main
import (
"github.com/google/gxui"
"github.com/google/gxui/drivers/gl"
"github.com/google/gxui/math"
"github.com/google/gxui/themes/dark"
omath "math"
"time"
)
const (
ANIMATION_WIDTH int = 480
ANIMATION_HEIGHT int = 320
BALL_RADIUS float32 = 25.0
METER_PER_PIXEL float64 = 1.0... |
Produce a language-to-language conversion: from Scala to C, same semantics. | import java.awt.*
import java.util.concurrent.*
import javax.swing.*
class Pendulum(private val length: Int) : JPanel(), Runnable {
init {
val f = JFrame("Pendulum")
f.add(this)
f.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
f.pack()
f.isVisible = true
isDoubleBuffer... | #include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <sys/time.h>
#define length 5
#define g 9.8
double alpha, accl, omega = 0, E;
struct timeval tv;
double elappsed() {
struct timeval now;
gettimeofday(&now, 0);
int ret = (now.tv_sec - tv.tv_sec) * 1000000
+ now.tv_usec - tv.tv... |
Transform the following Scala implementation into C#, maintaining the same output and logic. | import java.awt.*
import java.util.concurrent.*
import javax.swing.*
class Pendulum(private val length: Int) : JPanel(), Runnable {
init {
val f = JFrame("Pendulum")
f.add(this)
f.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
f.pack()
f.isVisible = true
isDoubleBuffer... | using System;
using System.Drawing;
using System.Windows.Forms;
class CSharpPendulum
{
Form _form;
Timer _timer;
double _angle = Math.PI / 2,
_angleAccel,
_angleVelocity = 0,
_dt = 0.1;
int _length = 50;
[STAThread]
static void Main()
{
... |
Transform the following Scala implementation into C++, maintaining the same output and logic. | import java.awt.*
import java.util.concurrent.*
import javax.swing.*
class Pendulum(private val length: Int) : JPanel(), Runnable {
init {
val f = JFrame("Pendulum")
f.add(this)
f.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
f.pack()
f.isVisible = true
isDoubleBuffer... | #ifndef __wxPendulumDlg_h__
#define __wxPendulumDlg_h__
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#include <wx/dialog.h>
#else
#include <wx/wxprec.h>
#endif
#include <wx/timer.h>
#include <wx/dcbuffer.h>
#include <cmath>
class wxPendulumDlgApp : public wxApp
{
public:
... |
Rewrite this program in Java while keeping its functionality equivalent to the Scala version. | import java.awt.*
import java.util.concurrent.*
import javax.swing.*
class Pendulum(private val length: Int) : JPanel(), Runnable {
init {
val f = JFrame("Pendulum")
f.add(this)
f.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
f.pack()
f.isVisible = true
isDoubleBuffer... | import java.awt.*;
import javax.swing.*;
public class Pendulum extends JPanel implements Runnable {
private double angle = Math.PI / 2;
private int length;
public Pendulum(int length) {
this.length = length;
setDoubleBuffered(true);
}
@Override
public void paint(Graphics g) {... |
Port the provided Scala code into Python while preserving the original functionality. | import java.awt.*
import java.util.concurrent.*
import javax.swing.*
class Pendulum(private val length: Int) : JPanel(), Runnable {
init {
val f = JFrame("Pendulum")
f.add(this)
f.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
f.pack()
f.isVisible = true
isDoubleBuffer... | import pygame, sys
from pygame.locals import *
from math import sin, cos, radians
pygame.init()
WINDOWSIZE = 250
TIMETICK = 100
BOBSIZE = 15
window = pygame.display.set_mode((WINDOWSIZE, WINDOWSIZE))
pygame.display.set_caption("Pendulum")
screen = pygame.display.get_surface()
screen.fill((255,255,255))
PIVOT = (WI... |
Generate a VB translation of this Scala snippet without changing its computational steps. | import java.awt.*
import java.util.concurrent.*
import javax.swing.*
class Pendulum(private val length: Int) : JPanel(), Runnable {
init {
val f = JFrame("Pendulum")
f.add(this)
f.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
f.pack()
f.isVisible = true
isDoubleBuffer... | option explicit
const dt = 0.15
const length=23
dim ans0:ans0=chr(27)&"["
dim Veloc,Accel,angle,olr,olc,r,c
const r0=1
const c0=40
cls
angle=0.7
while 1
wscript.sleep(50)
Accel = -.9 * sin(Angle)
Veloc = Veloc + Accel * dt
Angle = Angle + Veloc * dt
r = r0 + int(cos(Angle) * Length)
... |
Generate a Go translation of this Scala snippet without changing its computational steps. | import java.awt.*
import java.util.concurrent.*
import javax.swing.*
class Pendulum(private val length: Int) : JPanel(), Runnable {
init {
val f = JFrame("Pendulum")
f.add(this)
f.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
f.pack()
f.isVisible = true
isDoubleBuffer... | package main
import (
"github.com/google/gxui"
"github.com/google/gxui/drivers/gl"
"github.com/google/gxui/math"
"github.com/google/gxui/themes/dark"
omath "math"
"time"
)
const (
ANIMATION_WIDTH int = 480
ANIMATION_HEIGHT int = 320
BALL_RADIUS float32 = 25.0
METER_PER_PIXEL float64 = 1.0... |
Port the following code from Tcl to C with equivalent syntax and logic. | package require Tcl 8.5
package require Tk
pack [canvas .c -width 320 -height 200] -fill both -expand 1
.c create line 0 25 320 25 -width 2 -fill grey50 -tags plate
.c create line 1 1 1 1 -tags rod -width 3 -fill black
.c create oval 1 1 2 2 -tags bob -fill yellow -outline black
.c create oval 155 20 165 30 -fill gre... | #include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <sys/time.h>
#define length 5
#define g 9.8
double alpha, accl, omega = 0, E;
struct timeval tv;
double elappsed() {
struct timeval now;
gettimeofday(&now, 0);
int ret = (now.tv_sec - tv.tv_sec) * 1000000
+ now.tv_usec - tv.tv... |
Translate this program into C# but keep the logic exactly as in Tcl. | package require Tcl 8.5
package require Tk
pack [canvas .c -width 320 -height 200] -fill both -expand 1
.c create line 0 25 320 25 -width 2 -fill grey50 -tags plate
.c create line 1 1 1 1 -tags rod -width 3 -fill black
.c create oval 1 1 2 2 -tags bob -fill yellow -outline black
.c create oval 155 20 165 30 -fill gre... | using System;
using System.Drawing;
using System.Windows.Forms;
class CSharpPendulum
{
Form _form;
Timer _timer;
double _angle = Math.PI / 2,
_angleAccel,
_angleVelocity = 0,
_dt = 0.1;
int _length = 50;
[STAThread]
static void Main()
{
... |
Can you help me rewrite this code in C++ instead of Tcl, keeping it the same logically? | package require Tcl 8.5
package require Tk
pack [canvas .c -width 320 -height 200] -fill both -expand 1
.c create line 0 25 320 25 -width 2 -fill grey50 -tags plate
.c create line 1 1 1 1 -tags rod -width 3 -fill black
.c create oval 1 1 2 2 -tags bob -fill yellow -outline black
.c create oval 155 20 165 30 -fill gre... | #ifndef __wxPendulumDlg_h__
#define __wxPendulumDlg_h__
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#include <wx/dialog.h>
#else
#include <wx/wxprec.h>
#endif
#include <wx/timer.h>
#include <wx/dcbuffer.h>
#include <cmath>
class wxPendulumDlgApp : public wxApp
{
public:
... |
Change the following Tcl code into Java without altering its purpose. | package require Tcl 8.5
package require Tk
pack [canvas .c -width 320 -height 200] -fill both -expand 1
.c create line 0 25 320 25 -width 2 -fill grey50 -tags plate
.c create line 1 1 1 1 -tags rod -width 3 -fill black
.c create oval 1 1 2 2 -tags bob -fill yellow -outline black
.c create oval 155 20 165 30 -fill gre... | import java.awt.*;
import javax.swing.*;
public class Pendulum extends JPanel implements Runnable {
private double angle = Math.PI / 2;
private int length;
public Pendulum(int length) {
this.length = length;
setDoubleBuffered(true);
}
@Override
public void paint(Graphics g) {... |
Rewrite this program in Python while keeping its functionality equivalent to the Tcl version. | package require Tcl 8.5
package require Tk
pack [canvas .c -width 320 -height 200] -fill both -expand 1
.c create line 0 25 320 25 -width 2 -fill grey50 -tags plate
.c create line 1 1 1 1 -tags rod -width 3 -fill black
.c create oval 1 1 2 2 -tags bob -fill yellow -outline black
.c create oval 155 20 165 30 -fill gre... | import pygame, sys
from pygame.locals import *
from math import sin, cos, radians
pygame.init()
WINDOWSIZE = 250
TIMETICK = 100
BOBSIZE = 15
window = pygame.display.set_mode((WINDOWSIZE, WINDOWSIZE))
pygame.display.set_caption("Pendulum")
screen = pygame.display.get_surface()
screen.fill((255,255,255))
PIVOT = (WI... |
Port the provided Tcl code into VB while preserving the original functionality. | package require Tcl 8.5
package require Tk
pack [canvas .c -width 320 -height 200] -fill both -expand 1
.c create line 0 25 320 25 -width 2 -fill grey50 -tags plate
.c create line 1 1 1 1 -tags rod -width 3 -fill black
.c create oval 1 1 2 2 -tags bob -fill yellow -outline black
.c create oval 155 20 165 30 -fill gre... | option explicit
const dt = 0.15
const length=23
dim ans0:ans0=chr(27)&"["
dim Veloc,Accel,angle,olr,olc,r,c
const r0=1
const c0=40
cls
angle=0.7
while 1
wscript.sleep(50)
Accel = -.9 * sin(Angle)
Veloc = Veloc + Accel * dt
Angle = Angle + Veloc * dt
r = r0 + int(cos(Angle) * Length)
... |
Convert this Tcl block to Go, preserving its control flow and logic. | package require Tcl 8.5
package require Tk
pack [canvas .c -width 320 -height 200] -fill both -expand 1
.c create line 0 25 320 25 -width 2 -fill grey50 -tags plate
.c create line 1 1 1 1 -tags rod -width 3 -fill black
.c create oval 1 1 2 2 -tags bob -fill yellow -outline black
.c create oval 155 20 165 30 -fill gre... | package main
import (
"github.com/google/gxui"
"github.com/google/gxui/drivers/gl"
"github.com/google/gxui/math"
"github.com/google/gxui/themes/dark"
omath "math"
"time"
)
const (
ANIMATION_WIDTH int = 480
ANIMATION_HEIGHT int = 320
BALL_RADIUS float32 = 25.0
METER_PER_PIXEL float64 = 1.0... |
Keep all operations the same but rewrite the snippet in Rust. | #include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <sys/time.h>
#define length 5
#define g 9.8
double alpha, accl, omega = 0, E;
struct timeval tv;
double elappsed() {
struct timeval now;
gettimeofday(&now, 0);
int ret = (now.tv_sec - tv.tv_sec) * 1000000
+ now.tv_usec - tv.tv... |
use piston_window::{clear, ellipse, line_from_to, PistonWindow, WindowSettings};
const PI: f64 = std::f64::consts::PI;
const WIDTH: u32 = 640;
const HEIGHT: u32 = 480;
const ANCHOR_X: f64 = WIDTH as f64 / 2. - 12.;
const ANCHOR_Y: f64 = HEIGHT as f64 / 4.;
const ANCHOR_ELLIPSE: [f64; 4] = [ANCHOR_X - 3., ANCHOR_Y - ... |
Transform the following C++ implementation into Rust, maintaining the same output and logic. | #ifndef __wxPendulumDlg_h__
#define __wxPendulumDlg_h__
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#include <wx/dialog.h>
#else
#include <wx/wxprec.h>
#endif
#include <wx/timer.h>
#include <wx/dcbuffer.h>
#include <cmath>
class wxPendulumDlgApp : public wxApp
{
public:
... |
use piston_window::{clear, ellipse, line_from_to, PistonWindow, WindowSettings};
const PI: f64 = std::f64::consts::PI;
const WIDTH: u32 = 640;
const HEIGHT: u32 = 480;
const ANCHOR_X: f64 = WIDTH as f64 / 2. - 12.;
const ANCHOR_Y: f64 = HEIGHT as f64 / 4.;
const ANCHOR_ELLIPSE: [f64; 4] = [ANCHOR_X - 3., ANCHOR_Y - ... |
Change the following C# code into Rust without altering its purpose. | using System;
using System.Drawing;
using System.Windows.Forms;
class CSharpPendulum
{
Form _form;
Timer _timer;
double _angle = Math.PI / 2,
_angleAccel,
_angleVelocity = 0,
_dt = 0.1;
int _length = 50;
[STAThread]
static void Main()
{
... |
use piston_window::{clear, ellipse, line_from_to, PistonWindow, WindowSettings};
const PI: f64 = std::f64::consts::PI;
const WIDTH: u32 = 640;
const HEIGHT: u32 = 480;
const ANCHOR_X: f64 = WIDTH as f64 / 2. - 12.;
const ANCHOR_Y: f64 = HEIGHT as f64 / 4.;
const ANCHOR_ELLIPSE: [f64; 4] = [ANCHOR_X - 3., ANCHOR_Y - ... |
Convert this Java snippet to Rust and keep its semantics consistent. | import java.awt.*;
import javax.swing.*;
public class Pendulum extends JPanel implements Runnable {
private double angle = Math.PI / 2;
private int length;
public Pendulum(int length) {
this.length = length;
setDoubleBuffered(true);
}
@Override
public void paint(Graphics g) {... |
use piston_window::{clear, ellipse, line_from_to, PistonWindow, WindowSettings};
const PI: f64 = std::f64::consts::PI;
const WIDTH: u32 = 640;
const HEIGHT: u32 = 480;
const ANCHOR_X: f64 = WIDTH as f64 / 2. - 12.;
const ANCHOR_Y: f64 = HEIGHT as f64 / 4.;
const ANCHOR_ELLIPSE: [f64; 4] = [ANCHOR_X - 3., ANCHOR_Y - ... |
Preserve the algorithm and functionality while converting the code from Go to Rust. | package main
import (
"github.com/google/gxui"
"github.com/google/gxui/drivers/gl"
"github.com/google/gxui/math"
"github.com/google/gxui/themes/dark"
omath "math"
"time"
)
const (
ANIMATION_WIDTH int = 480
ANIMATION_HEIGHT int = 320
BALL_RADIUS float32 = 25.0
METER_PER_PIXEL float64 = 1.0... |
use piston_window::{clear, ellipse, line_from_to, PistonWindow, WindowSettings};
const PI: f64 = std::f64::consts::PI;
const WIDTH: u32 = 640;
const HEIGHT: u32 = 480;
const ANCHOR_X: f64 = WIDTH as f64 / 2. - 12.;
const ANCHOR_Y: f64 = HEIGHT as f64 / 4.;
const ANCHOR_ELLIPSE: [f64; 4] = [ANCHOR_X - 3., ANCHOR_Y - ... |
Write the same algorithm in VB as shown in this Rust implementation. |
use piston_window::{clear, ellipse, line_from_to, PistonWindow, WindowSettings};
const PI: f64 = std::f64::consts::PI;
const WIDTH: u32 = 640;
const HEIGHT: u32 = 480;
const ANCHOR_X: f64 = WIDTH as f64 / 2. - 12.;
const ANCHOR_Y: f64 = HEIGHT as f64 / 4.;
const ANCHOR_ELLIPSE: [f64; 4] = [ANCHOR_X - 3., ANCHOR_Y - ... | option explicit
const dt = 0.15
const length=23
dim ans0:ans0=chr(27)&"["
dim Veloc,Accel,angle,olr,olc,r,c
const r0=1
const c0=40
cls
angle=0.7
while 1
wscript.sleep(50)
Accel = -.9 * sin(Angle)
Veloc = Veloc + Accel * dt
Angle = Angle + Veloc * dt
r = r0 + int(cos(Angle) * Length)
... |
Convert the following code from Rust to Python, ensuring the logic remains intact. |
use piston_window::{clear, ellipse, line_from_to, PistonWindow, WindowSettings};
const PI: f64 = std::f64::consts::PI;
const WIDTH: u32 = 640;
const HEIGHT: u32 = 480;
const ANCHOR_X: f64 = WIDTH as f64 / 2. - 12.;
const ANCHOR_Y: f64 = HEIGHT as f64 / 4.;
const ANCHOR_ELLIPSE: [f64; 4] = [ANCHOR_X - 3., ANCHOR_Y - ... | import pygame, sys
from pygame.locals import *
from math import sin, cos, radians
pygame.init()
WINDOWSIZE = 250
TIMETICK = 100
BOBSIZE = 15
window = pygame.display.set_mode((WINDOWSIZE, WINDOWSIZE))
pygame.display.set_caption("Pendulum")
screen = pygame.display.get_surface()
screen.fill((255,255,255))
PIVOT = (WI... |
Convert this Ada block to C#, preserving its control flow and logic. | with Ada.Text_IO;
procedure Numbers is
package Int_IO is new Ada.Text_IO.Integer_IO (Integer);
package Float_IO is new Ada.Text_IO.Float_IO (Float);
begin
Int_IO.Put (Integer'Value ("16#ABCF123#"));
Ada.Text_IO.New_Line;
Int_IO.Put (Integer'Value ("8#7651#"));
Ada.Text_IO.New_Line;
Int_IO.Put (Inte... | using System;
class Program
{
static void Main()
{
var value = "100";
var fromBases = new[] { 2, 8, 10, 16 };
var toBase = 10;
foreach (var fromBase in fromBases)
{
Console.WriteLine("{0} in base {1} is {2} in base {3}",
value, fromBase, Conve... |
Maintain the same structure and functionality when rewriting this code in C. | with Ada.Text_IO;
procedure Numbers is
package Int_IO is new Ada.Text_IO.Integer_IO (Integer);
package Float_IO is new Ada.Text_IO.Float_IO (Float);
begin
Int_IO.Put (Integer'Value ("16#ABCF123#"));
Ada.Text_IO.New_Line;
Int_IO.Put (Integer'Value ("8#7651#"));
Ada.Text_IO.New_Line;
Int_IO.Put (Inte... | #include <stdio.h>
int main()
{
int num;
sscanf("0123459", "%d", &num);
printf("%d\n", num);
sscanf("abcf123", "%x", &num);
printf("%d\n", num);
sscanf("7651", "%o", &num);
printf("%d\n", num);
return 0;
}
|
Generate an equivalent C++ version of this Ada code. | with Ada.Text_IO;
procedure Numbers is
package Int_IO is new Ada.Text_IO.Integer_IO (Integer);
package Float_IO is new Ada.Text_IO.Float_IO (Float);
begin
Int_IO.Put (Integer'Value ("16#ABCF123#"));
Ada.Text_IO.New_Line;
Int_IO.Put (Integer'Value ("8#7651#"));
Ada.Text_IO.New_Line;
Int_IO.Put (Inte... | #include <iostream>
#include <sstream>
int main()
{
int num;
std::istringstream("0123459") >> num;
std::cout << num << std::endl;
std::istringstream("0123459") >> std::dec >> num;
std::cout << num << std::endl;
std::istringstream("abcf123") >> std::hex >> num;
std::cout << num << std::endl;
std:... |
Convert this Ada block to Go, preserving its control flow and logic. | with Ada.Text_IO;
procedure Numbers is
package Int_IO is new Ada.Text_IO.Integer_IO (Integer);
package Float_IO is new Ada.Text_IO.Float_IO (Float);
begin
Int_IO.Put (Integer'Value ("16#ABCF123#"));
Ada.Text_IO.New_Line;
Int_IO.Put (Integer'Value ("8#7651#"));
Ada.Text_IO.New_Line;
Int_IO.Put (Inte... | package main
import (
"fmt"
"math/big"
"strconv"
)
func main() {
x, _ := strconv.Atoi("13")
fmt.Println(x)
x64, _ := strconv.ParseInt("3c2", 19, 64)
fmt.Println(x64)
fmt.Sscanf("1101", "%b", &x)
fmt.Println(x)
fmt.S... |
Convert the following code from Ada to Java, ensuring the logic remains intact. | with Ada.Text_IO;
procedure Numbers is
package Int_IO is new Ada.Text_IO.Integer_IO (Integer);
package Float_IO is new Ada.Text_IO.Float_IO (Float);
begin
Int_IO.Put (Integer'Value ("16#ABCF123#"));
Ada.Text_IO.New_Line;
Int_IO.Put (Integer'Value ("8#7651#"));
Ada.Text_IO.New_Line;
Int_IO.Put (Inte... | Scanner sc = new Scanner(System.in);
sc.useRadix(base);
sc.nextInt();
|
Convert the following code from Ada to Python, ensuring the logic remains intact. | with Ada.Text_IO;
procedure Numbers is
package Int_IO is new Ada.Text_IO.Integer_IO (Integer);
package Float_IO is new Ada.Text_IO.Float_IO (Float);
begin
Int_IO.Put (Integer'Value ("16#ABCF123#"));
Ada.Text_IO.New_Line;
Int_IO.Put (Integer'Value ("8#7651#"));
Ada.Text_IO.New_Line;
Int_IO.Put (Inte... | >>> text = '100'
>>> for base in range(2,21):
print ("String '%s' in base %i is %i in base 10"
% (text, base, int(text, base)))
String '100' in base 2 is 4 in base 10
String '100' in base 3 is 9 in base 10
String '100' in base 4 is 16 in base 10
String '100' in base 5 is 25 in base 10
String '1... |
Convert this Arturo snippet to C and keep its semantics consistent. | print to :integer "10"
print from.hex "10"
print from.octal "120"
print from.binary "10101"
| #include <stdio.h>
int main()
{
int num;
sscanf("0123459", "%d", &num);
printf("%d\n", num);
sscanf("abcf123", "%x", &num);
printf("%d\n", num);
sscanf("7651", "%o", &num);
printf("%d\n", num);
return 0;
}
|
Change the following Arturo code into C# without altering its purpose. | print to :integer "10"
print from.hex "10"
print from.octal "120"
print from.binary "10101"
| using System;
class Program
{
static void Main()
{
var value = "100";
var fromBases = new[] { 2, 8, 10, 16 };
var toBase = 10;
foreach (var fromBase in fromBases)
{
Console.WriteLine("{0} in base {1} is {2} in base {3}",
value, fromBase, Conve... |
Rewrite the snippet below in C++ so it works the same as the original Arturo code. | print to :integer "10"
print from.hex "10"
print from.octal "120"
print from.binary "10101"
| #include <iostream>
#include <sstream>
int main()
{
int num;
std::istringstream("0123459") >> num;
std::cout << num << std::endl;
std::istringstream("0123459") >> std::dec >> num;
std::cout << num << std::endl;
std::istringstream("abcf123") >> std::hex >> num;
std::cout << num << std::endl;
std:... |
Ensure the translated Java code behaves exactly like the original Arturo snippet. | print to :integer "10"
print from.hex "10"
print from.octal "120"
print from.binary "10101"
| Scanner sc = new Scanner(System.in);
sc.useRadix(base);
sc.nextInt();
|
Convert this Arturo block to Python, preserving its control flow and logic. | print to :integer "10"
print from.hex "10"
print from.octal "120"
print from.binary "10101"
| >>> text = '100'
>>> for base in range(2,21):
print ("String '%s' in base %i is %i in base 10"
% (text, base, int(text, base)))
String '100' in base 2 is 4 in base 10
String '100' in base 3 is 9 in base 10
String '100' in base 4 is 16 in base 10
String '100' in base 5 is 25 in base 10
String '1... |
Produce a functionally identical Go code for the snippet given in Arturo. | print to :integer "10"
print from.hex "10"
print from.octal "120"
print from.binary "10101"
| package main
import (
"fmt"
"math/big"
"strconv"
)
func main() {
x, _ := strconv.Atoi("13")
fmt.Println(x)
x64, _ := strconv.ParseInt("3c2", 19, 64)
fmt.Println(x64)
fmt.Sscanf("1101", "%b", &x)
fmt.Println(x)
fmt.S... |
Rewrite this program in C while keeping its functionality equivalent to the BBC_Basic version. |
PRINT VAL("0")
PRINT VAL("123456789")
PRINT VAL("-987654321")
PRINT EVAL("%10101010")
PRINT EVAL("%1111111111")
PRINT EVAL("&ABCD")
PRINT EVAL("&FFFFFFFF")
| #include <stdio.h>
int main()
{
int num;
sscanf("0123459", "%d", &num);
printf("%d\n", num);
sscanf("abcf123", "%x", &num);
printf("%d\n", num);
sscanf("7651", "%o", &num);
printf("%d\n", num);
return 0;
}
|
Write a version of this BBC_Basic function in C# with identical behavior. |
PRINT VAL("0")
PRINT VAL("123456789")
PRINT VAL("-987654321")
PRINT EVAL("%10101010")
PRINT EVAL("%1111111111")
PRINT EVAL("&ABCD")
PRINT EVAL("&FFFFFFFF")
| using System;
class Program
{
static void Main()
{
var value = "100";
var fromBases = new[] { 2, 8, 10, 16 };
var toBase = 10;
foreach (var fromBase in fromBases)
{
Console.WriteLine("{0} in base {1} is {2} in base {3}",
value, fromBase, Conve... |
Write the same code in C++ as shown below in BBC_Basic. |
PRINT VAL("0")
PRINT VAL("123456789")
PRINT VAL("-987654321")
PRINT EVAL("%10101010")
PRINT EVAL("%1111111111")
PRINT EVAL("&ABCD")
PRINT EVAL("&FFFFFFFF")
| #include <iostream>
#include <sstream>
int main()
{
int num;
std::istringstream("0123459") >> num;
std::cout << num << std::endl;
std::istringstream("0123459") >> std::dec >> num;
std::cout << num << std::endl;
std::istringstream("abcf123") >> std::hex >> num;
std::cout << num << std::endl;
std:... |
Port the provided BBC_Basic code into Java while preserving the original functionality. |
PRINT VAL("0")
PRINT VAL("123456789")
PRINT VAL("-987654321")
PRINT EVAL("%10101010")
PRINT EVAL("%1111111111")
PRINT EVAL("&ABCD")
PRINT EVAL("&FFFFFFFF")
| Scanner sc = new Scanner(System.in);
sc.useRadix(base);
sc.nextInt();
|
Change the following BBC_Basic code into Python without altering its purpose. |
PRINT VAL("0")
PRINT VAL("123456789")
PRINT VAL("-987654321")
PRINT EVAL("%10101010")
PRINT EVAL("%1111111111")
PRINT EVAL("&ABCD")
PRINT EVAL("&FFFFFFFF")
| >>> text = '100'
>>> for base in range(2,21):
print ("String '%s' in base %i is %i in base 10"
% (text, base, int(text, base)))
String '100' in base 2 is 4 in base 10
String '100' in base 3 is 9 in base 10
String '100' in base 4 is 16 in base 10
String '100' in base 5 is 25 in base 10
String '1... |
Can you help me rewrite this code in Go instead of BBC_Basic, keeping it the same logically? |
PRINT VAL("0")
PRINT VAL("123456789")
PRINT VAL("-987654321")
PRINT EVAL("%10101010")
PRINT EVAL("%1111111111")
PRINT EVAL("&ABCD")
PRINT EVAL("&FFFFFFFF")
| package main
import (
"fmt"
"math/big"
"strconv"
)
func main() {
x, _ := strconv.Atoi("13")
fmt.Println(x)
x64, _ := strconv.ParseInt("3c2", 19, 64)
fmt.Println(x64)
fmt.Sscanf("1101", "%b", &x)
fmt.Println(x)
fmt.S... |
Convert this Common_Lisp block to C, preserving its control flow and logic. | (parse-integer "abc" :radix 20 :junk-allowed t)
| #include <stdio.h>
int main()
{
int num;
sscanf("0123459", "%d", &num);
printf("%d\n", num);
sscanf("abcf123", "%x", &num);
printf("%d\n", num);
sscanf("7651", "%o", &num);
printf("%d\n", num);
return 0;
}
|
Rewrite the snippet below in C# so it works the same as the original Common_Lisp code. | (parse-integer "abc" :radix 20 :junk-allowed t)
| using System;
class Program
{
static void Main()
{
var value = "100";
var fromBases = new[] { 2, 8, 10, 16 };
var toBase = 10;
foreach (var fromBase in fromBases)
{
Console.WriteLine("{0} in base {1} is {2} in base {3}",
value, fromBase, Conve... |
Convert the following code from Common_Lisp to C++, ensuring the logic remains intact. | (parse-integer "abc" :radix 20 :junk-allowed t)
| #include <iostream>
#include <sstream>
int main()
{
int num;
std::istringstream("0123459") >> num;
std::cout << num << std::endl;
std::istringstream("0123459") >> std::dec >> num;
std::cout << num << std::endl;
std::istringstream("abcf123") >> std::hex >> num;
std::cout << num << std::endl;
std:... |
Can you help me rewrite this code in Java instead of Common_Lisp, keeping it the same logically? | (parse-integer "abc" :radix 20 :junk-allowed t)
| Scanner sc = new Scanner(System.in);
sc.useRadix(base);
sc.nextInt();
|
Change the following Common_Lisp code into Python without altering its purpose. | (parse-integer "abc" :radix 20 :junk-allowed t)
| >>> text = '100'
>>> for base in range(2,21):
print ("String '%s' in base %i is %i in base 10"
% (text, base, int(text, base)))
String '100' in base 2 is 4 in base 10
String '100' in base 3 is 9 in base 10
String '100' in base 4 is 16 in base 10
String '100' in base 5 is 25 in base 10
String '1... |
Please provide an equivalent version of this Common_Lisp code in Go. | (parse-integer "abc" :radix 20 :junk-allowed t)
| package main
import (
"fmt"
"math/big"
"strconv"
)
func main() {
x, _ := strconv.Atoi("13")
fmt.Println(x)
x64, _ := strconv.ParseInt("3c2", 19, 64)
fmt.Println(x64)
fmt.Sscanf("1101", "%b", &x)
fmt.Println(x)
fmt.S... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.