Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Keep all operations the same but rewrite the snippet in C#. | x, y, z, one, three, seven = 5, -5, -2, 1, 3, 7
enums = (-three).step(3**3, three) +
(-seven).step(seven, x) +
555 .step(550-y, -1) +
22 .step(-28, -three) +
(1927..1939) +
x .step(y, z) +
(11**x) .step(11**x + one)
puts "Sum of absolute numbers:
prod = enums.inject(1){|prod, j| ((prod.abs < 2**27) && j!=0) ? prod*j : prod}
puts "Product (but not really):
| using System;
using System.Collections.Generic;
using System.Linq;
public static class LoopsWithMultipleRanges
{
public static void Main() {
int prod = 1;
int sum = 0;
int x = 5;
int y = -5;
int z = -2;
int one = 1;
int three = 3;
int seven = 7;
foreach (int j in Concat(
For(-three, 3.Pow(3), three),
For(-seven, seven, x),
For(555, 550 - y),
For(22, -28, -three),
For(1927, 1939),
For(x, y, z),
For(11.Pow(x), 11.Pow(x) + one)
)) {
sum += Math.Abs(j);
if (Math.Abs(prod) < (1 << 27) && j != 0) prod *= j;
}
Console.WriteLine($" sum = {sum:N0}");
Console.WriteLine($"prod = {prod:N0}");
}
static IEnumerable<int> For(int start, int end, int by = 1) {
for (int i = start; by > 0 ? (i <= end) : (i >= end); i += by) yield return i;
}
static IEnumerable<int> Concat(params IEnumerable<int>[] ranges) => ranges.Aggregate((acc, r) => acc.Concat(r));
static int Pow(this int b, int e) => (int)Math.Pow(b, e);
}
|
Rewrite the snippet below in C++ so it works the same as the original Ruby code. | x, y, z, one, three, seven = 5, -5, -2, 1, 3, 7
enums = (-three).step(3**3, three) +
(-seven).step(seven, x) +
555 .step(550-y, -1) +
22 .step(-28, -three) +
(1927..1939) +
x .step(y, z) +
(11**x) .step(11**x + one)
puts "Sum of absolute numbers:
prod = enums.inject(1){|prod, j| ((prod.abs < 2**27) && j!=0) ? prod*j : prod}
puts "Product (but not really):
| #include <iostream>
#include <cmath>
#include <vector>
using std::abs;
using std::cout;
using std::pow;
using std::vector;
int main()
{
int prod = 1,
sum = 0,
x = 5,
y = -5,
z = -2,
one = 1,
three = 3,
seven = 7;
auto summingValues = vector<int>{};
for(int n = -three; n <= pow(3, 3); n += three)
summingValues.push_back(n);
for(int n = -seven; n <= seven; n += x)
summingValues.push_back(n);
for(int n = 555; n <= 550 - y; ++n)
summingValues.push_back(n);
for(int n = 22; n >= -28; n -= three)
summingValues.push_back(n);
for(int n = 1927; n <= 1939; ++n)
summingValues.push_back(n);
for(int n = x; n >= y; n += z)
summingValues.push_back(n);
for(int n = pow(11, x); n <= pow(11, x) + one; ++n)
summingValues.push_back(n);
for(auto j : summingValues)
{
sum += abs(j);
if(abs(prod) < pow(2, 27) && j != 0)
prod *= j;
}
cout << "sum = " << sum << "\n";
cout << "prod = " << prod << "\n";
}
|
Convert the following code from Ruby to Java, ensuring the logic remains intact. | x, y, z, one, three, seven = 5, -5, -2, 1, 3, 7
enums = (-three).step(3**3, three) +
(-seven).step(seven, x) +
555 .step(550-y, -1) +
22 .step(-28, -three) +
(1927..1939) +
x .step(y, z) +
(11**x) .step(11**x + one)
puts "Sum of absolute numbers:
prod = enums.inject(1){|prod, j| ((prod.abs < 2**27) && j!=0) ? prod*j : prod}
puts "Product (but not really):
| import java.util.ArrayList;
import java.util.List;
public class LoopsWithMultipleRanges {
private static long sum = 0;
private static long prod = 1;
public static void main(String[] args) {
long x = 5;
long y = -5;
long z = -2;
long one = 1;
long three = 3;
long seven = 7;
List<Long> jList = new ArrayList<>();
for ( long j = -three ; j <= pow(3, 3) ; j += three ) jList.add(j);
for ( long j = -seven ; j <= seven ; j += x ) jList.add(j);
for ( long j = 555 ; j <= 550-y ; j += 1 ) jList.add(j);
for ( long j = 22 ; j >= -28 ; j += -three ) jList.add(j);
for ( long j = 1927 ; j <= 1939 ; j += 1 ) jList.add(j);
for ( long j = x ; j >= y ; j += z ) jList.add(j);
for ( long j = pow(11, x) ; j <= pow(11, x) + one ; j += 1 ) jList.add(j);
List<Long> prodList = new ArrayList<>();
for ( long j : jList ) {
sum += Math.abs(j);
if ( Math.abs(prod) < pow(2, 27) && j != 0 ) {
prodList.add(j);
prod *= j;
}
}
System.out.printf(" sum = %,d%n", sum);
System.out.printf("prod = %,d%n", prod);
System.out.printf("j values = %s%n", jList);
System.out.printf("prod values = %s%n", prodList);
}
private static long pow(long base, long exponent) {
return (long) Math.pow(base, exponent);
}
}
|
Rewrite the snippet below in Python so it works the same as the original Ruby code. | x, y, z, one, three, seven = 5, -5, -2, 1, 3, 7
enums = (-three).step(3**3, three) +
(-seven).step(seven, x) +
555 .step(550-y, -1) +
22 .step(-28, -three) +
(1927..1939) +
x .step(y, z) +
(11**x) .step(11**x + one)
puts "Sum of absolute numbers:
prod = enums.inject(1){|prod, j| ((prod.abs < 2**27) && j!=0) ? prod*j : prod}
puts "Product (but not really):
| from itertools import chain
prod, sum_, x, y, z, one,three,seven = 1, 0, 5, -5, -2, 1, 3, 7
def _range(x, y, z=1):
return range(x, y + (1 if z > 0 else -1), z)
print(f'list(_range(x, y, z)) = {list(_range(x, y, z))}')
print(f'list(_range(-seven, seven, x)) = {list(_range(-seven, seven, x))}')
for j in chain(_range(-three, 3**3, three), _range(-seven, seven, x),
_range(555, 550 - y), _range(22, -28, -three),
_range(1927, 1939), _range(x, y, z),
_range(11**x, 11**x + 1)):
sum_ += abs(j)
if abs(prod) < 2**27 and (j != 0):
prod *= j
print(f' sum= {sum_}\nprod= {prod}')
|
Please provide an equivalent version of this Ruby code in VB. | x, y, z, one, three, seven = 5, -5, -2, 1, 3, 7
enums = (-three).step(3**3, three) +
(-seven).step(seven, x) +
555 .step(550-y, -1) +
22 .step(-28, -three) +
(1927..1939) +
x .step(y, z) +
(11**x) .step(11**x + one)
puts "Sum of absolute numbers:
prod = enums.inject(1){|prod, j| ((prod.abs < 2**27) && j!=0) ? prod*j : prod}
puts "Product (but not really):
| Dim prod As Long, sum As Long
Public Sub LoopsWithMultipleRanges()
Dim x As Integer, y As Integer, z As Integer, one As Integer, three As Integer, seven As Integer, j As Long
prod = 1
sum = 0
x = 5
y = -5
z = -2
one = 1
three = 3
seven = 7
For j = -three To pow(3, 3) Step three: Call process(j): Next j
For j = -seven To seven Step x: Call process(j): Next j
For j = 555 To 550 - y: Call process(j): Next j
For j = 22 To -28 Step -three: Call process(j): Next j
For j = 1927 To 1939: Call process(j): Next j
For j = x To y Step z: Call process(j): Next j
For j = pow(11, x) To pow(11, x) + one: Call process(j): Next j
Debug.Print " sum= " & Format(sum, "#,##0")
Debug.Print "prod= " & Format(prod, "#,##0")
End Sub
Private Function pow(x As Long, y As Integer) As Long
pow = WorksheetFunction.Power(x, y)
End Function
Private Sub process(x As Long)
sum = sum + Abs(x)
If Abs(prod) < pow(2, 27) And x <> 0 Then prod = prod * x
End Sub
|
Change the following Scala code into C without altering its purpose. |
import kotlin.math.abs
infix fun Int.pow(e: Int): Int {
if (e == 0) return 1
var prod = this
for (i in 2..e) {
prod *= this
}
return prod
}
fun main(args: Array<String>) {
var prod = 1
var sum = 0
val x = 5
val y = -5
val z = -2
val one = 1
val three = 3
val seven = 7
val p = 11 pow x
fun process(j: Int) {
sum += abs(j)
if (abs(prod) < (1 shl 27) && j != 0) prod *= j
}
for (j in -three..(3 pow 3) step three) process(j)
for (j in -seven..seven step x) process(j)
for (j in 555..550-y) process(j)
for (j in 22 downTo -28 step three) process(j)
for (j in 1927..1939) process(j)
for (j in x downTo y step -z) process(j)
for (j in p..p + one) process(j)
System.out.printf("sum = % ,d\n", sum)
System.out.printf("prod = % ,d\n", prod)
}
| #include <stdio.h>
#include <stdlib.h>
#include <locale.h>
long prod = 1L, sum = 0L;
void process(int j) {
sum += abs(j);
if (labs(prod) < (1 << 27) && j) prod *= j;
}
long ipow(int n, uint e) {
long pr = n;
int i;
if (e == 0) return 1L;
for (i = 2; i <= e; ++i) pr *= n;
return pr;
}
int main() {
int j;
const int x = 5, y = -5, z = -2;
const int one = 1, three = 3, seven = 7;
long p = ipow(11, x);
for (j = -three; j <= ipow(3, 3); j += three) process(j);
for (j = -seven; j <= seven; j += x) process(j);
for (j = 555; j <= 550 - y; ++j) process(j);
for (j = 22; j >= -28; j -= three) process(j);
for (j = 1927; j <= 1939; ++j) process(j);
for (j = x; j >= y; j -= -z) process(j);
for (j = p; j <= p + one; ++j) process(j);
setlocale(LC_NUMERIC, "");
printf("sum = % 'ld\n", sum);
printf("prod = % 'ld\n", prod);
return 0;
}
|
Port the provided Scala code into C# while preserving the original functionality. |
import kotlin.math.abs
infix fun Int.pow(e: Int): Int {
if (e == 0) return 1
var prod = this
for (i in 2..e) {
prod *= this
}
return prod
}
fun main(args: Array<String>) {
var prod = 1
var sum = 0
val x = 5
val y = -5
val z = -2
val one = 1
val three = 3
val seven = 7
val p = 11 pow x
fun process(j: Int) {
sum += abs(j)
if (abs(prod) < (1 shl 27) && j != 0) prod *= j
}
for (j in -three..(3 pow 3) step three) process(j)
for (j in -seven..seven step x) process(j)
for (j in 555..550-y) process(j)
for (j in 22 downTo -28 step three) process(j)
for (j in 1927..1939) process(j)
for (j in x downTo y step -z) process(j)
for (j in p..p + one) process(j)
System.out.printf("sum = % ,d\n", sum)
System.out.printf("prod = % ,d\n", prod)
}
| using System;
using System.Collections.Generic;
using System.Linq;
public static class LoopsWithMultipleRanges
{
public static void Main() {
int prod = 1;
int sum = 0;
int x = 5;
int y = -5;
int z = -2;
int one = 1;
int three = 3;
int seven = 7;
foreach (int j in Concat(
For(-three, 3.Pow(3), three),
For(-seven, seven, x),
For(555, 550 - y),
For(22, -28, -three),
For(1927, 1939),
For(x, y, z),
For(11.Pow(x), 11.Pow(x) + one)
)) {
sum += Math.Abs(j);
if (Math.Abs(prod) < (1 << 27) && j != 0) prod *= j;
}
Console.WriteLine($" sum = {sum:N0}");
Console.WriteLine($"prod = {prod:N0}");
}
static IEnumerable<int> For(int start, int end, int by = 1) {
for (int i = start; by > 0 ? (i <= end) : (i >= end); i += by) yield return i;
}
static IEnumerable<int> Concat(params IEnumerable<int>[] ranges) => ranges.Aggregate((acc, r) => acc.Concat(r));
static int Pow(this int b, int e) => (int)Math.Pow(b, e);
}
|
Convert the following code from Scala to C++, ensuring the logic remains intact. |
import kotlin.math.abs
infix fun Int.pow(e: Int): Int {
if (e == 0) return 1
var prod = this
for (i in 2..e) {
prod *= this
}
return prod
}
fun main(args: Array<String>) {
var prod = 1
var sum = 0
val x = 5
val y = -5
val z = -2
val one = 1
val three = 3
val seven = 7
val p = 11 pow x
fun process(j: Int) {
sum += abs(j)
if (abs(prod) < (1 shl 27) && j != 0) prod *= j
}
for (j in -three..(3 pow 3) step three) process(j)
for (j in -seven..seven step x) process(j)
for (j in 555..550-y) process(j)
for (j in 22 downTo -28 step three) process(j)
for (j in 1927..1939) process(j)
for (j in x downTo y step -z) process(j)
for (j in p..p + one) process(j)
System.out.printf("sum = % ,d\n", sum)
System.out.printf("prod = % ,d\n", prod)
}
| #include <iostream>
#include <cmath>
#include <vector>
using std::abs;
using std::cout;
using std::pow;
using std::vector;
int main()
{
int prod = 1,
sum = 0,
x = 5,
y = -5,
z = -2,
one = 1,
three = 3,
seven = 7;
auto summingValues = vector<int>{};
for(int n = -three; n <= pow(3, 3); n += three)
summingValues.push_back(n);
for(int n = -seven; n <= seven; n += x)
summingValues.push_back(n);
for(int n = 555; n <= 550 - y; ++n)
summingValues.push_back(n);
for(int n = 22; n >= -28; n -= three)
summingValues.push_back(n);
for(int n = 1927; n <= 1939; ++n)
summingValues.push_back(n);
for(int n = x; n >= y; n += z)
summingValues.push_back(n);
for(int n = pow(11, x); n <= pow(11, x) + one; ++n)
summingValues.push_back(n);
for(auto j : summingValues)
{
sum += abs(j);
if(abs(prod) < pow(2, 27) && j != 0)
prod *= j;
}
cout << "sum = " << sum << "\n";
cout << "prod = " << prod << "\n";
}
|
Change the programming language of this snippet from Scala to Java without modifying what it does. |
import kotlin.math.abs
infix fun Int.pow(e: Int): Int {
if (e == 0) return 1
var prod = this
for (i in 2..e) {
prod *= this
}
return prod
}
fun main(args: Array<String>) {
var prod = 1
var sum = 0
val x = 5
val y = -5
val z = -2
val one = 1
val three = 3
val seven = 7
val p = 11 pow x
fun process(j: Int) {
sum += abs(j)
if (abs(prod) < (1 shl 27) && j != 0) prod *= j
}
for (j in -three..(3 pow 3) step three) process(j)
for (j in -seven..seven step x) process(j)
for (j in 555..550-y) process(j)
for (j in 22 downTo -28 step three) process(j)
for (j in 1927..1939) process(j)
for (j in x downTo y step -z) process(j)
for (j in p..p + one) process(j)
System.out.printf("sum = % ,d\n", sum)
System.out.printf("prod = % ,d\n", prod)
}
| import java.util.ArrayList;
import java.util.List;
public class LoopsWithMultipleRanges {
private static long sum = 0;
private static long prod = 1;
public static void main(String[] args) {
long x = 5;
long y = -5;
long z = -2;
long one = 1;
long three = 3;
long seven = 7;
List<Long> jList = new ArrayList<>();
for ( long j = -three ; j <= pow(3, 3) ; j += three ) jList.add(j);
for ( long j = -seven ; j <= seven ; j += x ) jList.add(j);
for ( long j = 555 ; j <= 550-y ; j += 1 ) jList.add(j);
for ( long j = 22 ; j >= -28 ; j += -three ) jList.add(j);
for ( long j = 1927 ; j <= 1939 ; j += 1 ) jList.add(j);
for ( long j = x ; j >= y ; j += z ) jList.add(j);
for ( long j = pow(11, x) ; j <= pow(11, x) + one ; j += 1 ) jList.add(j);
List<Long> prodList = new ArrayList<>();
for ( long j : jList ) {
sum += Math.abs(j);
if ( Math.abs(prod) < pow(2, 27) && j != 0 ) {
prodList.add(j);
prod *= j;
}
}
System.out.printf(" sum = %,d%n", sum);
System.out.printf("prod = %,d%n", prod);
System.out.printf("j values = %s%n", jList);
System.out.printf("prod values = %s%n", prodList);
}
private static long pow(long base, long exponent) {
return (long) Math.pow(base, exponent);
}
}
|
Can you help me rewrite this code in Python instead of Scala, keeping it the same logically? |
import kotlin.math.abs
infix fun Int.pow(e: Int): Int {
if (e == 0) return 1
var prod = this
for (i in 2..e) {
prod *= this
}
return prod
}
fun main(args: Array<String>) {
var prod = 1
var sum = 0
val x = 5
val y = -5
val z = -2
val one = 1
val three = 3
val seven = 7
val p = 11 pow x
fun process(j: Int) {
sum += abs(j)
if (abs(prod) < (1 shl 27) && j != 0) prod *= j
}
for (j in -three..(3 pow 3) step three) process(j)
for (j in -seven..seven step x) process(j)
for (j in 555..550-y) process(j)
for (j in 22 downTo -28 step three) process(j)
for (j in 1927..1939) process(j)
for (j in x downTo y step -z) process(j)
for (j in p..p + one) process(j)
System.out.printf("sum = % ,d\n", sum)
System.out.printf("prod = % ,d\n", prod)
}
| from itertools import chain
prod, sum_, x, y, z, one,three,seven = 1, 0, 5, -5, -2, 1, 3, 7
def _range(x, y, z=1):
return range(x, y + (1 if z > 0 else -1), z)
print(f'list(_range(x, y, z)) = {list(_range(x, y, z))}')
print(f'list(_range(-seven, seven, x)) = {list(_range(-seven, seven, x))}')
for j in chain(_range(-three, 3**3, three), _range(-seven, seven, x),
_range(555, 550 - y), _range(22, -28, -three),
_range(1927, 1939), _range(x, y, z),
_range(11**x, 11**x + 1)):
sum_ += abs(j)
if abs(prod) < 2**27 and (j != 0):
prod *= j
print(f' sum= {sum_}\nprod= {prod}')
|
Rewrite the snippet below in VB so it works the same as the original Scala code. |
import kotlin.math.abs
infix fun Int.pow(e: Int): Int {
if (e == 0) return 1
var prod = this
for (i in 2..e) {
prod *= this
}
return prod
}
fun main(args: Array<String>) {
var prod = 1
var sum = 0
val x = 5
val y = -5
val z = -2
val one = 1
val three = 3
val seven = 7
val p = 11 pow x
fun process(j: Int) {
sum += abs(j)
if (abs(prod) < (1 shl 27) && j != 0) prod *= j
}
for (j in -three..(3 pow 3) step three) process(j)
for (j in -seven..seven step x) process(j)
for (j in 555..550-y) process(j)
for (j in 22 downTo -28 step three) process(j)
for (j in 1927..1939) process(j)
for (j in x downTo y step -z) process(j)
for (j in p..p + one) process(j)
System.out.printf("sum = % ,d\n", sum)
System.out.printf("prod = % ,d\n", prod)
}
| Dim prod As Long, sum As Long
Public Sub LoopsWithMultipleRanges()
Dim x As Integer, y As Integer, z As Integer, one As Integer, three As Integer, seven As Integer, j As Long
prod = 1
sum = 0
x = 5
y = -5
z = -2
one = 1
three = 3
seven = 7
For j = -three To pow(3, 3) Step three: Call process(j): Next j
For j = -seven To seven Step x: Call process(j): Next j
For j = 555 To 550 - y: Call process(j): Next j
For j = 22 To -28 Step -three: Call process(j): Next j
For j = 1927 To 1939: Call process(j): Next j
For j = x To y Step z: Call process(j): Next j
For j = pow(11, x) To pow(11, x) + one: Call process(j): Next j
Debug.Print " sum= " & Format(sum, "#,##0")
Debug.Print "prod= " & Format(prod, "#,##0")
End Sub
Private Function pow(x As Long, y As Integer) As Long
pow = WorksheetFunction.Power(x, y)
End Function
Private Sub process(x As Long)
sum = sum + Abs(x)
If Abs(prod) < pow(2, 27) And x <> 0 Then prod = prod * x
End Sub
|
Convert this Scala snippet to Go and keep its semantics consistent. |
import kotlin.math.abs
infix fun Int.pow(e: Int): Int {
if (e == 0) return 1
var prod = this
for (i in 2..e) {
prod *= this
}
return prod
}
fun main(args: Array<String>) {
var prod = 1
var sum = 0
val x = 5
val y = -5
val z = -2
val one = 1
val three = 3
val seven = 7
val p = 11 pow x
fun process(j: Int) {
sum += abs(j)
if (abs(prod) < (1 shl 27) && j != 0) prod *= j
}
for (j in -three..(3 pow 3) step three) process(j)
for (j in -seven..seven step x) process(j)
for (j in 555..550-y) process(j)
for (j in 22 downTo -28 step three) process(j)
for (j in 1927..1939) process(j)
for (j in x downTo y step -z) process(j)
for (j in p..p + one) process(j)
System.out.printf("sum = % ,d\n", sum)
System.out.printf("prod = % ,d\n", prod)
}
| package main
import "fmt"
func pow(n int, e uint) int {
if e == 0 {
return 1
}
prod := n
for i := uint(2); i <= e; i++ {
prod *= n
}
return prod
}
func abs(n int) int {
if n >= 0 {
return n
}
return -n
}
func commatize(n int) string {
s := fmt.Sprintf("%d", n)
if n < 0 {
s = s[1:]
}
le := len(s)
for i := le - 3; i >= 1; i -= 3 {
s = s[0:i] + "," + s[i:]
}
if n >= 0 {
return " " + s
}
return "-" + s
}
func main() {
prod := 1
sum := 0
const (
x = 5
y = -5
z = -2
one = 1
three = 3
seven = 7
)
p := pow(11, x)
var j int
process := func() {
sum += abs(j)
if abs(prod) < (1<<27) && j != 0 {
prod *= j
}
}
for j = -three; j <= pow(3, 3); j += three {
process()
}
for j = -seven; j <= seven; j += x {
process()
}
for j = 555; j <= 550-y; j++ {
process()
}
for j = 22; j >= -28; j -= three {
process()
}
for j = 1927; j <= 1939; j++ {
process()
}
for j = x; j >= y; j -= -z {
process()
}
for j = p; j <= p+one; j++ {
process()
}
fmt.Println("sum = ", commatize(sum))
fmt.Println("prod = ", commatize(prod))
}
|
Port the following code from Ada to C# with equivalent syntax and logic. | with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Text_IO; use Ada.Text_IO;
procedure Yuletide is
begin
for Year in 2008..2121 loop
if Day_Of_Week (Time_Of (Year, 12, 25)) = Sunday then
Put_Line (Image (Time_Of (Year, 12, 25)));
end if;
end loop;
end Yuletide;
| using System;
class Program
{
static void Main(string[] args)
{
for (int i = 2008; i <= 2121; i++)
{
DateTime date = new DateTime(i, 12, 25);
if (date.DayOfWeek == DayOfWeek.Sunday)
{
Console.WriteLine(date.ToString("dd MMM yyyy"));
}
}
}
}
|
Port the following code from Ada to C with equivalent syntax and logic. | with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Text_IO; use Ada.Text_IO;
procedure Yuletide is
begin
for Year in 2008..2121 loop
if Day_Of_Week (Time_Of (Year, 12, 25)) = Sunday then
Put_Line (Image (Time_Of (Year, 12, 25)));
end if;
end loop;
end Yuletide;
| #include <stdio.h>
int wday(int year, int month, int day)
{
int adjustment, mm, yy;
adjustment = (14 - month) / 12;
mm = month + 12 * adjustment - 2;
yy = year - adjustment;
return (day + (13 * mm - 1) / 5 +
yy + yy / 4 - yy / 100 + yy / 400) % 7;
}
int main()
{
int y;
for (y = 2008; y <= 2121; y++) {
if (wday(y, 12, 25) == 0) printf("%04d-12-25\n", y);
}
return 0;
}
|
Convert this Ada block to C++, preserving its control flow and logic. | with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Text_IO; use Ada.Text_IO;
procedure Yuletide is
begin
for Year in 2008..2121 loop
if Day_Of_Week (Time_Of (Year, 12, 25)) = Sunday then
Put_Line (Image (Time_Of (Year, 12, 25)));
end if;
end loop;
end Yuletide;
| #include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
int main( ) {
using namespace boost::gregorian ;
std::cout
<< "Yuletide holidays must be allowed in the following years:\n" ;
for ( int i = 2008 ; i < 2121 ; i++ ) {
greg_year gy = i ;
date d ( gy, Dec , 25 ) ;
if ( d.day_of_week( ) == Sunday ) {
std::cout << i << std::endl ;
}
}
std::cout << "\n" ;
return 0 ;
}
|
Rewrite this program in Go while keeping its functionality equivalent to the Ada version. | with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Text_IO; use Ada.Text_IO;
procedure Yuletide is
begin
for Year in 2008..2121 loop
if Day_Of_Week (Time_Of (Year, 12, 25)) = Sunday then
Put_Line (Image (Time_Of (Year, 12, 25)));
end if;
end loop;
end Yuletide;
| package main
import "fmt"
import "time"
func main() {
for year := 2008; year <= 2121; year++ {
if time.Date(year, 12, 25, 0, 0, 0, 0, time.UTC).Weekday() ==
time.Sunday {
fmt.Printf("25 December %d is Sunday\n", year)
}
}
}
|
Please provide an equivalent version of this Ada code in Java. | with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Text_IO; use Ada.Text_IO;
procedure Yuletide is
begin
for Year in 2008..2121 loop
if Day_Of_Week (Time_Of (Year, 12, 25)) = Sunday then
Put_Line (Image (Time_Of (Year, 12, 25)));
end if;
end loop;
end Yuletide;
| import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Yuletide{
public static void main(String[] args) {
for(int i = 2008;i<=2121;i++){
Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
25);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
System.out.println(cal.getTime());
}
}
}
}
|
Keep all operations the same but rewrite the snippet in Python. | with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Text_IO; use Ada.Text_IO;
procedure Yuletide is
begin
for Year in 2008..2121 loop
if Day_Of_Week (Time_Of (Year, 12, 25)) = Sunday then
Put_Line (Image (Time_Of (Year, 12, 25)));
end if;
end loop;
end Yuletide;
| from calendar import weekday, SUNDAY
[year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
|
Port the provided Ada code into VB while preserving the original functionality. | with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Text_IO; use Ada.Text_IO;
procedure Yuletide is
begin
for Year in 2008..2121 loop
if Day_Of_Week (Time_Of (Year, 12, 25)) = Sunday then
Put_Line (Image (Time_Of (Year, 12, 25)));
end if;
end loop;
end Yuletide;
| Option Explicit
Sub MainDayOfTheWeek()
Debug.Print "Xmas will be a Sunday in : " & XmasSunday(2008, 2121)
End Sub
Private Function XmasSunday(firstYear As Integer, lastYear As Integer) As String
Dim i As Integer, temp$
For i = firstYear To lastYear
If Weekday(CDate("25/12/" & i)) = vbSunday Then temp = temp & ", " & i
Next
XmasSunday = Mid(temp, 2)
End Function
|
Produce a functionally identical C code for the snippet given in Arturo. | print select 2008..2121 'year [
"Sunday" = get to :date.format:"dd-MM-YYYY" ~"25-12-|year|" 'Day
]
| #include <stdio.h>
int wday(int year, int month, int day)
{
int adjustment, mm, yy;
adjustment = (14 - month) / 12;
mm = month + 12 * adjustment - 2;
yy = year - adjustment;
return (day + (13 * mm - 1) / 5 +
yy + yy / 4 - yy / 100 + yy / 400) % 7;
}
int main()
{
int y;
for (y = 2008; y <= 2121; y++) {
if (wday(y, 12, 25) == 0) printf("%04d-12-25\n", y);
}
return 0;
}
|
Maintain the same structure and functionality when rewriting this code in C#. | print select 2008..2121 'year [
"Sunday" = get to :date.format:"dd-MM-YYYY" ~"25-12-|year|" 'Day
]
| using System;
class Program
{
static void Main(string[] args)
{
for (int i = 2008; i <= 2121; i++)
{
DateTime date = new DateTime(i, 12, 25);
if (date.DayOfWeek == DayOfWeek.Sunday)
{
Console.WriteLine(date.ToString("dd MMM yyyy"));
}
}
}
}
|
Produce a language-to-language conversion: from Arturo to C++, same semantics. | print select 2008..2121 'year [
"Sunday" = get to :date.format:"dd-MM-YYYY" ~"25-12-|year|" 'Day
]
| #include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
int main( ) {
using namespace boost::gregorian ;
std::cout
<< "Yuletide holidays must be allowed in the following years:\n" ;
for ( int i = 2008 ; i < 2121 ; i++ ) {
greg_year gy = i ;
date d ( gy, Dec , 25 ) ;
if ( d.day_of_week( ) == Sunday ) {
std::cout << i << std::endl ;
}
}
std::cout << "\n" ;
return 0 ;
}
|
Generate an equivalent Java version of this Arturo code. | print select 2008..2121 'year [
"Sunday" = get to :date.format:"dd-MM-YYYY" ~"25-12-|year|" 'Day
]
| import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Yuletide{
public static void main(String[] args) {
for(int i = 2008;i<=2121;i++){
Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
25);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
System.out.println(cal.getTime());
}
}
}
}
|
Preserve the algorithm and functionality while converting the code from Arturo to Python. | print select 2008..2121 'year [
"Sunday" = get to :date.format:"dd-MM-YYYY" ~"25-12-|year|" 'Day
]
| from calendar import weekday, SUNDAY
[year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
|
Translate this program into VB but keep the logic exactly as in Arturo. | print select 2008..2121 'year [
"Sunday" = get to :date.format:"dd-MM-YYYY" ~"25-12-|year|" 'Day
]
| Option Explicit
Sub MainDayOfTheWeek()
Debug.Print "Xmas will be a Sunday in : " & XmasSunday(2008, 2121)
End Sub
Private Function XmasSunday(firstYear As Integer, lastYear As Integer) As String
Dim i As Integer, temp$
For i = firstYear To lastYear
If Weekday(CDate("25/12/" & i)) = vbSunday Then temp = temp & ", " & i
Next
XmasSunday = Mid(temp, 2)
End Function
|
Produce a functionally identical Go code for the snippet given in Arturo. | print select 2008..2121 'year [
"Sunday" = get to :date.format:"dd-MM-YYYY" ~"25-12-|year|" 'Day
]
| package main
import "fmt"
import "time"
func main() {
for year := 2008; year <= 2121; year++ {
if time.Date(year, 12, 25, 0, 0, 0, 0, time.UTC).Weekday() ==
time.Sunday {
fmt.Printf("25 December %d is Sunday\n", year)
}
}
}
|
Convert this AutoHotKey block to C, preserving its control flow and logic. | year = 2008
stop = 2121
While year <= stop {
FormatTime, day,% year 1225, dddd
If day = Sunday
out .= year "`n"
year++
}
MsgBox,% out
| #include <stdio.h>
int wday(int year, int month, int day)
{
int adjustment, mm, yy;
adjustment = (14 - month) / 12;
mm = month + 12 * adjustment - 2;
yy = year - adjustment;
return (day + (13 * mm - 1) / 5 +
yy + yy / 4 - yy / 100 + yy / 400) % 7;
}
int main()
{
int y;
for (y = 2008; y <= 2121; y++) {
if (wday(y, 12, 25) == 0) printf("%04d-12-25\n", y);
}
return 0;
}
|
Generate an equivalent C# version of this AutoHotKey code. | year = 2008
stop = 2121
While year <= stop {
FormatTime, day,% year 1225, dddd
If day = Sunday
out .= year "`n"
year++
}
MsgBox,% out
| using System;
class Program
{
static void Main(string[] args)
{
for (int i = 2008; i <= 2121; i++)
{
DateTime date = new DateTime(i, 12, 25);
if (date.DayOfWeek == DayOfWeek.Sunday)
{
Console.WriteLine(date.ToString("dd MMM yyyy"));
}
}
}
}
|
Keep all operations the same but rewrite the snippet in C++. | year = 2008
stop = 2121
While year <= stop {
FormatTime, day,% year 1225, dddd
If day = Sunday
out .= year "`n"
year++
}
MsgBox,% out
| #include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
int main( ) {
using namespace boost::gregorian ;
std::cout
<< "Yuletide holidays must be allowed in the following years:\n" ;
for ( int i = 2008 ; i < 2121 ; i++ ) {
greg_year gy = i ;
date d ( gy, Dec , 25 ) ;
if ( d.day_of_week( ) == Sunday ) {
std::cout << i << std::endl ;
}
}
std::cout << "\n" ;
return 0 ;
}
|
Generate a Java translation of this AutoHotKey snippet without changing its computational steps. | year = 2008
stop = 2121
While year <= stop {
FormatTime, day,% year 1225, dddd
If day = Sunday
out .= year "`n"
year++
}
MsgBox,% out
| import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Yuletide{
public static void main(String[] args) {
for(int i = 2008;i<=2121;i++){
Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
25);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
System.out.println(cal.getTime());
}
}
}
}
|
Can you help me rewrite this code in Python instead of AutoHotKey, keeping it the same logically? | year = 2008
stop = 2121
While year <= stop {
FormatTime, day,% year 1225, dddd
If day = Sunday
out .= year "`n"
year++
}
MsgBox,% out
| from calendar import weekday, SUNDAY
[year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
|
Can you help me rewrite this code in VB instead of AutoHotKey, keeping it the same logically? | year = 2008
stop = 2121
While year <= stop {
FormatTime, day,% year 1225, dddd
If day = Sunday
out .= year "`n"
year++
}
MsgBox,% out
| Option Explicit
Sub MainDayOfTheWeek()
Debug.Print "Xmas will be a Sunday in : " & XmasSunday(2008, 2121)
End Sub
Private Function XmasSunday(firstYear As Integer, lastYear As Integer) As String
Dim i As Integer, temp$
For i = firstYear To lastYear
If Weekday(CDate("25/12/" & i)) = vbSunday Then temp = temp & ", " & i
Next
XmasSunday = Mid(temp, 2)
End Function
|
Rewrite the snippet below in Go so it works the same as the original AutoHotKey code. | year = 2008
stop = 2121
While year <= stop {
FormatTime, day,% year 1225, dddd
If day = Sunday
out .= year "`n"
year++
}
MsgBox,% out
| package main
import "fmt"
import "time"
func main() {
for year := 2008; year <= 2121; year++ {
if time.Date(year, 12, 25, 0, 0, 0, 0, time.UTC).Weekday() ==
time.Sunday {
fmt.Printf("25 December %d is Sunday\n", year)
}
}
}
|
Translate this program into C but keep the logic exactly as in AWK. |
BEGIN {
for (i=2008; i<=2121; i++) {
x = strftime("%Y/%m/%d %a",mktime(sprintf("%d 12 25 0 0 0",i)))
if (x ~ /Sun/) { print(x) }
}
}
| #include <stdio.h>
int wday(int year, int month, int day)
{
int adjustment, mm, yy;
adjustment = (14 - month) / 12;
mm = month + 12 * adjustment - 2;
yy = year - adjustment;
return (day + (13 * mm - 1) / 5 +
yy + yy / 4 - yy / 100 + yy / 400) % 7;
}
int main()
{
int y;
for (y = 2008; y <= 2121; y++) {
if (wday(y, 12, 25) == 0) printf("%04d-12-25\n", y);
}
return 0;
}
|
Rewrite this program in C# while keeping its functionality equivalent to the AWK version. |
BEGIN {
for (i=2008; i<=2121; i++) {
x = strftime("%Y/%m/%d %a",mktime(sprintf("%d 12 25 0 0 0",i)))
if (x ~ /Sun/) { print(x) }
}
}
| using System;
class Program
{
static void Main(string[] args)
{
for (int i = 2008; i <= 2121; i++)
{
DateTime date = new DateTime(i, 12, 25);
if (date.DayOfWeek == DayOfWeek.Sunday)
{
Console.WriteLine(date.ToString("dd MMM yyyy"));
}
}
}
}
|
Preserve the algorithm and functionality while converting the code from AWK to C++. |
BEGIN {
for (i=2008; i<=2121; i++) {
x = strftime("%Y/%m/%d %a",mktime(sprintf("%d 12 25 0 0 0",i)))
if (x ~ /Sun/) { print(x) }
}
}
| #include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
int main( ) {
using namespace boost::gregorian ;
std::cout
<< "Yuletide holidays must be allowed in the following years:\n" ;
for ( int i = 2008 ; i < 2121 ; i++ ) {
greg_year gy = i ;
date d ( gy, Dec , 25 ) ;
if ( d.day_of_week( ) == Sunday ) {
std::cout << i << std::endl ;
}
}
std::cout << "\n" ;
return 0 ;
}
|
Write the same algorithm in Java as shown in this AWK implementation. |
BEGIN {
for (i=2008; i<=2121; i++) {
x = strftime("%Y/%m/%d %a",mktime(sprintf("%d 12 25 0 0 0",i)))
if (x ~ /Sun/) { print(x) }
}
}
| import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Yuletide{
public static void main(String[] args) {
for(int i = 2008;i<=2121;i++){
Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
25);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
System.out.println(cal.getTime());
}
}
}
}
|
Convert the following code from AWK to Python, ensuring the logic remains intact. |
BEGIN {
for (i=2008; i<=2121; i++) {
x = strftime("%Y/%m/%d %a",mktime(sprintf("%d 12 25 0 0 0",i)))
if (x ~ /Sun/) { print(x) }
}
}
| from calendar import weekday, SUNDAY
[year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
|
Please provide an equivalent version of this AWK code in VB. |
BEGIN {
for (i=2008; i<=2121; i++) {
x = strftime("%Y/%m/%d %a",mktime(sprintf("%d 12 25 0 0 0",i)))
if (x ~ /Sun/) { print(x) }
}
}
| Option Explicit
Sub MainDayOfTheWeek()
Debug.Print "Xmas will be a Sunday in : " & XmasSunday(2008, 2121)
End Sub
Private Function XmasSunday(firstYear As Integer, lastYear As Integer) As String
Dim i As Integer, temp$
For i = firstYear To lastYear
If Weekday(CDate("25/12/" & i)) = vbSunday Then temp = temp & ", " & i
Next
XmasSunday = Mid(temp, 2)
End Function
|
Port the provided AWK code into Go while preserving the original functionality. |
BEGIN {
for (i=2008; i<=2121; i++) {
x = strftime("%Y/%m/%d %a",mktime(sprintf("%d 12 25 0 0 0",i)))
if (x ~ /Sun/) { print(x) }
}
}
| package main
import "fmt"
import "time"
func main() {
for year := 2008; year <= 2121; year++ {
if time.Date(year, 12, 25, 0, 0, 0, 0, time.UTC).Weekday() ==
time.Sunday {
fmt.Printf("25 December %d is Sunday\n", year)
}
}
}
|
Produce a functionally identical C code for the snippet given in BBC_Basic. | INSTALL @lib$+"DATELIB"
FOR year% = 2008 TO 2121
IF FN_dow(FN_mjd(25, 12, year%)) = 0 THEN
PRINT "Christmas Day is a Sunday in "; year%
ENDIF
NEXT
| #include <stdio.h>
int wday(int year, int month, int day)
{
int adjustment, mm, yy;
adjustment = (14 - month) / 12;
mm = month + 12 * adjustment - 2;
yy = year - adjustment;
return (day + (13 * mm - 1) / 5 +
yy + yy / 4 - yy / 100 + yy / 400) % 7;
}
int main()
{
int y;
for (y = 2008; y <= 2121; y++) {
if (wday(y, 12, 25) == 0) printf("%04d-12-25\n", y);
}
return 0;
}
|
Generate an equivalent C# version of this BBC_Basic code. | INSTALL @lib$+"DATELIB"
FOR year% = 2008 TO 2121
IF FN_dow(FN_mjd(25, 12, year%)) = 0 THEN
PRINT "Christmas Day is a Sunday in "; year%
ENDIF
NEXT
| using System;
class Program
{
static void Main(string[] args)
{
for (int i = 2008; i <= 2121; i++)
{
DateTime date = new DateTime(i, 12, 25);
if (date.DayOfWeek == DayOfWeek.Sunday)
{
Console.WriteLine(date.ToString("dd MMM yyyy"));
}
}
}
}
|
Translate the given BBC_Basic code snippet into C++ without altering its behavior. | INSTALL @lib$+"DATELIB"
FOR year% = 2008 TO 2121
IF FN_dow(FN_mjd(25, 12, year%)) = 0 THEN
PRINT "Christmas Day is a Sunday in "; year%
ENDIF
NEXT
| #include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
int main( ) {
using namespace boost::gregorian ;
std::cout
<< "Yuletide holidays must be allowed in the following years:\n" ;
for ( int i = 2008 ; i < 2121 ; i++ ) {
greg_year gy = i ;
date d ( gy, Dec , 25 ) ;
if ( d.day_of_week( ) == Sunday ) {
std::cout << i << std::endl ;
}
}
std::cout << "\n" ;
return 0 ;
}
|
Rewrite this program in Java while keeping its functionality equivalent to the BBC_Basic version. | INSTALL @lib$+"DATELIB"
FOR year% = 2008 TO 2121
IF FN_dow(FN_mjd(25, 12, year%)) = 0 THEN
PRINT "Christmas Day is a Sunday in "; year%
ENDIF
NEXT
| import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Yuletide{
public static void main(String[] args) {
for(int i = 2008;i<=2121;i++){
Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
25);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
System.out.println(cal.getTime());
}
}
}
}
|
Write the same code in Python as shown below in BBC_Basic. | INSTALL @lib$+"DATELIB"
FOR year% = 2008 TO 2121
IF FN_dow(FN_mjd(25, 12, year%)) = 0 THEN
PRINT "Christmas Day is a Sunday in "; year%
ENDIF
NEXT
| from calendar import weekday, SUNDAY
[year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
|
Write the same code in VB as shown below in BBC_Basic. | INSTALL @lib$+"DATELIB"
FOR year% = 2008 TO 2121
IF FN_dow(FN_mjd(25, 12, year%)) = 0 THEN
PRINT "Christmas Day is a Sunday in "; year%
ENDIF
NEXT
| Option Explicit
Sub MainDayOfTheWeek()
Debug.Print "Xmas will be a Sunday in : " & XmasSunday(2008, 2121)
End Sub
Private Function XmasSunday(firstYear As Integer, lastYear As Integer) As String
Dim i As Integer, temp$
For i = firstYear To lastYear
If Weekday(CDate("25/12/" & i)) = vbSunday Then temp = temp & ", " & i
Next
XmasSunday = Mid(temp, 2)
End Function
|
Generate an equivalent Go version of this BBC_Basic code. | INSTALL @lib$+"DATELIB"
FOR year% = 2008 TO 2121
IF FN_dow(FN_mjd(25, 12, year%)) = 0 THEN
PRINT "Christmas Day is a Sunday in "; year%
ENDIF
NEXT
| package main
import "fmt"
import "time"
func main() {
for year := 2008; year <= 2121; year++ {
if time.Date(year, 12, 25, 0, 0, 0, 0, time.UTC).Weekday() ==
time.Sunday {
fmt.Printf("25 December %d is Sunday\n", year)
}
}
}
|
Rewrite this program in C while keeping its functionality equivalent to the Clojure version. | (import '[java.util GregorianCalendar])
(defn yuletide [start end]
(->> (range start (inc end))
(filter #(= GregorianCalendar/SUNDAY
(.get (GregorianCalendar. % GregorianCalendar/DECEMBER 25)
GregorianCalendar/DAY_OF_WEEK)))))
(println (yuletide 2008 2121))
| #include <stdio.h>
int wday(int year, int month, int day)
{
int adjustment, mm, yy;
adjustment = (14 - month) / 12;
mm = month + 12 * adjustment - 2;
yy = year - adjustment;
return (day + (13 * mm - 1) / 5 +
yy + yy / 4 - yy / 100 + yy / 400) % 7;
}
int main()
{
int y;
for (y = 2008; y <= 2121; y++) {
if (wday(y, 12, 25) == 0) printf("%04d-12-25\n", y);
}
return 0;
}
|
Change the programming language of this snippet from Clojure to C# without modifying what it does. | (import '[java.util GregorianCalendar])
(defn yuletide [start end]
(->> (range start (inc end))
(filter #(= GregorianCalendar/SUNDAY
(.get (GregorianCalendar. % GregorianCalendar/DECEMBER 25)
GregorianCalendar/DAY_OF_WEEK)))))
(println (yuletide 2008 2121))
| using System;
class Program
{
static void Main(string[] args)
{
for (int i = 2008; i <= 2121; i++)
{
DateTime date = new DateTime(i, 12, 25);
if (date.DayOfWeek == DayOfWeek.Sunday)
{
Console.WriteLine(date.ToString("dd MMM yyyy"));
}
}
}
}
|
Translate the given Clojure code snippet into C++ without altering its behavior. | (import '[java.util GregorianCalendar])
(defn yuletide [start end]
(->> (range start (inc end))
(filter #(= GregorianCalendar/SUNDAY
(.get (GregorianCalendar. % GregorianCalendar/DECEMBER 25)
GregorianCalendar/DAY_OF_WEEK)))))
(println (yuletide 2008 2121))
| #include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
int main( ) {
using namespace boost::gregorian ;
std::cout
<< "Yuletide holidays must be allowed in the following years:\n" ;
for ( int i = 2008 ; i < 2121 ; i++ ) {
greg_year gy = i ;
date d ( gy, Dec , 25 ) ;
if ( d.day_of_week( ) == Sunday ) {
std::cout << i << std::endl ;
}
}
std::cout << "\n" ;
return 0 ;
}
|
Convert this Clojure block to Java, preserving its control flow and logic. | (import '[java.util GregorianCalendar])
(defn yuletide [start end]
(->> (range start (inc end))
(filter #(= GregorianCalendar/SUNDAY
(.get (GregorianCalendar. % GregorianCalendar/DECEMBER 25)
GregorianCalendar/DAY_OF_WEEK)))))
(println (yuletide 2008 2121))
| import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Yuletide{
public static void main(String[] args) {
for(int i = 2008;i<=2121;i++){
Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
25);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
System.out.println(cal.getTime());
}
}
}
}
|
Produce a language-to-language conversion: from Clojure to Python, same semantics. | (import '[java.util GregorianCalendar])
(defn yuletide [start end]
(->> (range start (inc end))
(filter #(= GregorianCalendar/SUNDAY
(.get (GregorianCalendar. % GregorianCalendar/DECEMBER 25)
GregorianCalendar/DAY_OF_WEEK)))))
(println (yuletide 2008 2121))
| from calendar import weekday, SUNDAY
[year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
|
Change the following Clojure code into VB without altering its purpose. | (import '[java.util GregorianCalendar])
(defn yuletide [start end]
(->> (range start (inc end))
(filter #(= GregorianCalendar/SUNDAY
(.get (GregorianCalendar. % GregorianCalendar/DECEMBER 25)
GregorianCalendar/DAY_OF_WEEK)))))
(println (yuletide 2008 2121))
| Option Explicit
Sub MainDayOfTheWeek()
Debug.Print "Xmas will be a Sunday in : " & XmasSunday(2008, 2121)
End Sub
Private Function XmasSunday(firstYear As Integer, lastYear As Integer) As String
Dim i As Integer, temp$
For i = firstYear To lastYear
If Weekday(CDate("25/12/" & i)) = vbSunday Then temp = temp & ", " & i
Next
XmasSunday = Mid(temp, 2)
End Function
|
Write the same code in Go as shown below in Clojure. | (import '[java.util GregorianCalendar])
(defn yuletide [start end]
(->> (range start (inc end))
(filter #(= GregorianCalendar/SUNDAY
(.get (GregorianCalendar. % GregorianCalendar/DECEMBER 25)
GregorianCalendar/DAY_OF_WEEK)))))
(println (yuletide 2008 2121))
| package main
import "fmt"
import "time"
func main() {
for year := 2008; year <= 2121; year++ {
if time.Date(year, 12, 25, 0, 0, 0, 0, time.UTC).Weekday() ==
time.Sunday {
fmt.Printf("25 December %d is Sunday\n", year)
}
}
}
|
Keep all operations the same but rewrite the snippet in C. | (loop for year from 2008 upto 2121
when (= 6 (multiple-value-bind
(second minute hour date month year day-of-week dst-p tz)
(decode-universal-time (encode-universal-time 0 0 0 25 12 year))
(declare (ignore second minute hour date month year dst-p tz))
day-of-week))
collect year)
| #include <stdio.h>
int wday(int year, int month, int day)
{
int adjustment, mm, yy;
adjustment = (14 - month) / 12;
mm = month + 12 * adjustment - 2;
yy = year - adjustment;
return (day + (13 * mm - 1) / 5 +
yy + yy / 4 - yy / 100 + yy / 400) % 7;
}
int main()
{
int y;
for (y = 2008; y <= 2121; y++) {
if (wday(y, 12, 25) == 0) printf("%04d-12-25\n", y);
}
return 0;
}
|
Write the same code in C# as shown below in Common_Lisp. | (loop for year from 2008 upto 2121
when (= 6 (multiple-value-bind
(second minute hour date month year day-of-week dst-p tz)
(decode-universal-time (encode-universal-time 0 0 0 25 12 year))
(declare (ignore second minute hour date month year dst-p tz))
day-of-week))
collect year)
| using System;
class Program
{
static void Main(string[] args)
{
for (int i = 2008; i <= 2121; i++)
{
DateTime date = new DateTime(i, 12, 25);
if (date.DayOfWeek == DayOfWeek.Sunday)
{
Console.WriteLine(date.ToString("dd MMM yyyy"));
}
}
}
}
|
Translate the given Common_Lisp code snippet into C++ without altering its behavior. | (loop for year from 2008 upto 2121
when (= 6 (multiple-value-bind
(second minute hour date month year day-of-week dst-p tz)
(decode-universal-time (encode-universal-time 0 0 0 25 12 year))
(declare (ignore second minute hour date month year dst-p tz))
day-of-week))
collect year)
| #include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
int main( ) {
using namespace boost::gregorian ;
std::cout
<< "Yuletide holidays must be allowed in the following years:\n" ;
for ( int i = 2008 ; i < 2121 ; i++ ) {
greg_year gy = i ;
date d ( gy, Dec , 25 ) ;
if ( d.day_of_week( ) == Sunday ) {
std::cout << i << std::endl ;
}
}
std::cout << "\n" ;
return 0 ;
}
|
Write the same code in Java as shown below in Common_Lisp. | (loop for year from 2008 upto 2121
when (= 6 (multiple-value-bind
(second minute hour date month year day-of-week dst-p tz)
(decode-universal-time (encode-universal-time 0 0 0 25 12 year))
(declare (ignore second minute hour date month year dst-p tz))
day-of-week))
collect year)
| import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Yuletide{
public static void main(String[] args) {
for(int i = 2008;i<=2121;i++){
Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
25);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
System.out.println(cal.getTime());
}
}
}
}
|
Convert this Common_Lisp snippet to Python and keep its semantics consistent. | (loop for year from 2008 upto 2121
when (= 6 (multiple-value-bind
(second minute hour date month year day-of-week dst-p tz)
(decode-universal-time (encode-universal-time 0 0 0 25 12 year))
(declare (ignore second minute hour date month year dst-p tz))
day-of-week))
collect year)
| from calendar import weekday, SUNDAY
[year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
|
Write the same code in VB as shown below in Common_Lisp. | (loop for year from 2008 upto 2121
when (= 6 (multiple-value-bind
(second minute hour date month year day-of-week dst-p tz)
(decode-universal-time (encode-universal-time 0 0 0 25 12 year))
(declare (ignore second minute hour date month year dst-p tz))
day-of-week))
collect year)
| Option Explicit
Sub MainDayOfTheWeek()
Debug.Print "Xmas will be a Sunday in : " & XmasSunday(2008, 2121)
End Sub
Private Function XmasSunday(firstYear As Integer, lastYear As Integer) As String
Dim i As Integer, temp$
For i = firstYear To lastYear
If Weekday(CDate("25/12/" & i)) = vbSunday Then temp = temp & ", " & i
Next
XmasSunday = Mid(temp, 2)
End Function
|
Convert this Common_Lisp snippet to Go and keep its semantics consistent. | (loop for year from 2008 upto 2121
when (= 6 (multiple-value-bind
(second minute hour date month year day-of-week dst-p tz)
(decode-universal-time (encode-universal-time 0 0 0 25 12 year))
(declare (ignore second minute hour date month year dst-p tz))
day-of-week))
collect year)
| package main
import "fmt"
import "time"
func main() {
for year := 2008; year <= 2121; year++ {
if time.Date(year, 12, 25, 0, 0, 0, 0, time.UTC).Weekday() ==
time.Sunday {
fmt.Printf("25 December %d is Sunday\n", year)
}
}
}
|
Produce a language-to-language conversion: from D to C, same semantics. | void main() {
import std.stdio, std.range, std.algorithm, std.datetime;
writeln("Christmas comes on a Sunday in the years:\n",
iota(2008, 2122)
.filter!(y => Date(y, 12, 25).dayOfWeek == DayOfWeek.sun));
}
| #include <stdio.h>
int wday(int year, int month, int day)
{
int adjustment, mm, yy;
adjustment = (14 - month) / 12;
mm = month + 12 * adjustment - 2;
yy = year - adjustment;
return (day + (13 * mm - 1) / 5 +
yy + yy / 4 - yy / 100 + yy / 400) % 7;
}
int main()
{
int y;
for (y = 2008; y <= 2121; y++) {
if (wday(y, 12, 25) == 0) printf("%04d-12-25\n", y);
}
return 0;
}
|
Generate an equivalent C# version of this D code. | void main() {
import std.stdio, std.range, std.algorithm, std.datetime;
writeln("Christmas comes on a Sunday in the years:\n",
iota(2008, 2122)
.filter!(y => Date(y, 12, 25).dayOfWeek == DayOfWeek.sun));
}
| using System;
class Program
{
static void Main(string[] args)
{
for (int i = 2008; i <= 2121; i++)
{
DateTime date = new DateTime(i, 12, 25);
if (date.DayOfWeek == DayOfWeek.Sunday)
{
Console.WriteLine(date.ToString("dd MMM yyyy"));
}
}
}
}
|
Rewrite the snippet below in C++ so it works the same as the original D code. | void main() {
import std.stdio, std.range, std.algorithm, std.datetime;
writeln("Christmas comes on a Sunday in the years:\n",
iota(2008, 2122)
.filter!(y => Date(y, 12, 25).dayOfWeek == DayOfWeek.sun));
}
| #include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
int main( ) {
using namespace boost::gregorian ;
std::cout
<< "Yuletide holidays must be allowed in the following years:\n" ;
for ( int i = 2008 ; i < 2121 ; i++ ) {
greg_year gy = i ;
date d ( gy, Dec , 25 ) ;
if ( d.day_of_week( ) == Sunday ) {
std::cout << i << std::endl ;
}
}
std::cout << "\n" ;
return 0 ;
}
|
Convert this D block to Java, preserving its control flow and logic. | void main() {
import std.stdio, std.range, std.algorithm, std.datetime;
writeln("Christmas comes on a Sunday in the years:\n",
iota(2008, 2122)
.filter!(y => Date(y, 12, 25).dayOfWeek == DayOfWeek.sun));
}
| import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Yuletide{
public static void main(String[] args) {
for(int i = 2008;i<=2121;i++){
Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
25);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
System.out.println(cal.getTime());
}
}
}
}
|
Port the provided D code into Python while preserving the original functionality. | void main() {
import std.stdio, std.range, std.algorithm, std.datetime;
writeln("Christmas comes on a Sunday in the years:\n",
iota(2008, 2122)
.filter!(y => Date(y, 12, 25).dayOfWeek == DayOfWeek.sun));
}
| from calendar import weekday, SUNDAY
[year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
|
Maintain the same structure and functionality when rewriting this code in VB. | void main() {
import std.stdio, std.range, std.algorithm, std.datetime;
writeln("Christmas comes on a Sunday in the years:\n",
iota(2008, 2122)
.filter!(y => Date(y, 12, 25).dayOfWeek == DayOfWeek.sun));
}
| Option Explicit
Sub MainDayOfTheWeek()
Debug.Print "Xmas will be a Sunday in : " & XmasSunday(2008, 2121)
End Sub
Private Function XmasSunday(firstYear As Integer, lastYear As Integer) As String
Dim i As Integer, temp$
For i = firstYear To lastYear
If Weekday(CDate("25/12/" & i)) = vbSunday Then temp = temp & ", " & i
Next
XmasSunday = Mid(temp, 2)
End Function
|
Preserve the algorithm and functionality while converting the code from D to Go. | void main() {
import std.stdio, std.range, std.algorithm, std.datetime;
writeln("Christmas comes on a Sunday in the years:\n",
iota(2008, 2122)
.filter!(y => Date(y, 12, 25).dayOfWeek == DayOfWeek.sun));
}
| package main
import "fmt"
import "time"
func main() {
for year := 2008; year <= 2121; year++ {
if time.Date(year, 12, 25, 0, 0, 0, 0, time.UTC).Weekday() ==
time.Sunday {
fmt.Printf("25 December %d is Sunday\n", year)
}
}
}
|
Change the programming language of this snippet from Delphi to C without modifying what it does. | procedure IsXmasSunday(fromyear, toyear: integer);
var
i: integer;
TestDate: TDateTime;
outputyears: string;
begin
outputyears := '';
for i:= fromyear to toyear do
begin
TestDate := EncodeDate(i,12,25);
if dayofweek(TestDate) = 1 then
begin
outputyears := outputyears + inttostr(i) + ' ';
end;
end;
form1.label1.caption := outputyears;
end;
| #include <stdio.h>
int wday(int year, int month, int day)
{
int adjustment, mm, yy;
adjustment = (14 - month) / 12;
mm = month + 12 * adjustment - 2;
yy = year - adjustment;
return (day + (13 * mm - 1) / 5 +
yy + yy / 4 - yy / 100 + yy / 400) % 7;
}
int main()
{
int y;
for (y = 2008; y <= 2121; y++) {
if (wday(y, 12, 25) == 0) printf("%04d-12-25\n", y);
}
return 0;
}
|
Maintain the same structure and functionality when rewriting this code in C#. | procedure IsXmasSunday(fromyear, toyear: integer);
var
i: integer;
TestDate: TDateTime;
outputyears: string;
begin
outputyears := '';
for i:= fromyear to toyear do
begin
TestDate := EncodeDate(i,12,25);
if dayofweek(TestDate) = 1 then
begin
outputyears := outputyears + inttostr(i) + ' ';
end;
end;
form1.label1.caption := outputyears;
end;
| using System;
class Program
{
static void Main(string[] args)
{
for (int i = 2008; i <= 2121; i++)
{
DateTime date = new DateTime(i, 12, 25);
if (date.DayOfWeek == DayOfWeek.Sunday)
{
Console.WriteLine(date.ToString("dd MMM yyyy"));
}
}
}
}
|
Port the following code from Delphi to C++ with equivalent syntax and logic. | procedure IsXmasSunday(fromyear, toyear: integer);
var
i: integer;
TestDate: TDateTime;
outputyears: string;
begin
outputyears := '';
for i:= fromyear to toyear do
begin
TestDate := EncodeDate(i,12,25);
if dayofweek(TestDate) = 1 then
begin
outputyears := outputyears + inttostr(i) + ' ';
end;
end;
form1.label1.caption := outputyears;
end;
| #include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
int main( ) {
using namespace boost::gregorian ;
std::cout
<< "Yuletide holidays must be allowed in the following years:\n" ;
for ( int i = 2008 ; i < 2121 ; i++ ) {
greg_year gy = i ;
date d ( gy, Dec , 25 ) ;
if ( d.day_of_week( ) == Sunday ) {
std::cout << i << std::endl ;
}
}
std::cout << "\n" ;
return 0 ;
}
|
Transform the following Delphi implementation into Java, maintaining the same output and logic. | procedure IsXmasSunday(fromyear, toyear: integer);
var
i: integer;
TestDate: TDateTime;
outputyears: string;
begin
outputyears := '';
for i:= fromyear to toyear do
begin
TestDate := EncodeDate(i,12,25);
if dayofweek(TestDate) = 1 then
begin
outputyears := outputyears + inttostr(i) + ' ';
end;
end;
form1.label1.caption := outputyears;
end;
| import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Yuletide{
public static void main(String[] args) {
for(int i = 2008;i<=2121;i++){
Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
25);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
System.out.println(cal.getTime());
}
}
}
}
|
Ensure the translated Python code behaves exactly like the original Delphi snippet. | procedure IsXmasSunday(fromyear, toyear: integer);
var
i: integer;
TestDate: TDateTime;
outputyears: string;
begin
outputyears := '';
for i:= fromyear to toyear do
begin
TestDate := EncodeDate(i,12,25);
if dayofweek(TestDate) = 1 then
begin
outputyears := outputyears + inttostr(i) + ' ';
end;
end;
form1.label1.caption := outputyears;
end;
| from calendar import weekday, SUNDAY
[year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
|
Change the programming language of this snippet from Delphi to VB without modifying what it does. | procedure IsXmasSunday(fromyear, toyear: integer);
var
i: integer;
TestDate: TDateTime;
outputyears: string;
begin
outputyears := '';
for i:= fromyear to toyear do
begin
TestDate := EncodeDate(i,12,25);
if dayofweek(TestDate) = 1 then
begin
outputyears := outputyears + inttostr(i) + ' ';
end;
end;
form1.label1.caption := outputyears;
end;
| Option Explicit
Sub MainDayOfTheWeek()
Debug.Print "Xmas will be a Sunday in : " & XmasSunday(2008, 2121)
End Sub
Private Function XmasSunday(firstYear As Integer, lastYear As Integer) As String
Dim i As Integer, temp$
For i = firstYear To lastYear
If Weekday(CDate("25/12/" & i)) = vbSunday Then temp = temp & ", " & i
Next
XmasSunday = Mid(temp, 2)
End Function
|
Rewrite this program in Go while keeping its functionality equivalent to the Delphi version. | procedure IsXmasSunday(fromyear, toyear: integer);
var
i: integer;
TestDate: TDateTime;
outputyears: string;
begin
outputyears := '';
for i:= fromyear to toyear do
begin
TestDate := EncodeDate(i,12,25);
if dayofweek(TestDate) = 1 then
begin
outputyears := outputyears + inttostr(i) + ' ';
end;
end;
form1.label1.caption := outputyears;
end;
| package main
import "fmt"
import "time"
func main() {
for year := 2008; year <= 2121; year++ {
if time.Date(year, 12, 25, 0, 0, 0, 0, time.UTC).Weekday() ==
time.Sunday {
fmt.Printf("25 December %d is Sunday\n", year)
}
}
}
|
Transform the following Elixir implementation into C, maintaining the same output and logic. | Enum.each(2008..2121, fn year ->
wday = Date.from_erl!({year, 12, 25}) |> Date.day_of_week
if wday==7, do: IO.puts "25 December
end)
| #include <stdio.h>
int wday(int year, int month, int day)
{
int adjustment, mm, yy;
adjustment = (14 - month) / 12;
mm = month + 12 * adjustment - 2;
yy = year - adjustment;
return (day + (13 * mm - 1) / 5 +
yy + yy / 4 - yy / 100 + yy / 400) % 7;
}
int main()
{
int y;
for (y = 2008; y <= 2121; y++) {
if (wday(y, 12, 25) == 0) printf("%04d-12-25\n", y);
}
return 0;
}
|
Generate an equivalent C# version of this Elixir code. | Enum.each(2008..2121, fn year ->
wday = Date.from_erl!({year, 12, 25}) |> Date.day_of_week
if wday==7, do: IO.puts "25 December
end)
| using System;
class Program
{
static void Main(string[] args)
{
for (int i = 2008; i <= 2121; i++)
{
DateTime date = new DateTime(i, 12, 25);
if (date.DayOfWeek == DayOfWeek.Sunday)
{
Console.WriteLine(date.ToString("dd MMM yyyy"));
}
}
}
}
|
Please provide an equivalent version of this Elixir code in C++. | Enum.each(2008..2121, fn year ->
wday = Date.from_erl!({year, 12, 25}) |> Date.day_of_week
if wday==7, do: IO.puts "25 December
end)
| #include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
int main( ) {
using namespace boost::gregorian ;
std::cout
<< "Yuletide holidays must be allowed in the following years:\n" ;
for ( int i = 2008 ; i < 2121 ; i++ ) {
greg_year gy = i ;
date d ( gy, Dec , 25 ) ;
if ( d.day_of_week( ) == Sunday ) {
std::cout << i << std::endl ;
}
}
std::cout << "\n" ;
return 0 ;
}
|
Rewrite this program in Java while keeping its functionality equivalent to the Elixir version. | Enum.each(2008..2121, fn year ->
wday = Date.from_erl!({year, 12, 25}) |> Date.day_of_week
if wday==7, do: IO.puts "25 December
end)
| import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Yuletide{
public static void main(String[] args) {
for(int i = 2008;i<=2121;i++){
Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
25);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
System.out.println(cal.getTime());
}
}
}
}
|
Convert this Elixir snippet to Python and keep its semantics consistent. | Enum.each(2008..2121, fn year ->
wday = Date.from_erl!({year, 12, 25}) |> Date.day_of_week
if wday==7, do: IO.puts "25 December
end)
| from calendar import weekday, SUNDAY
[year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
|
Generate a VB translation of this Elixir snippet without changing its computational steps. | Enum.each(2008..2121, fn year ->
wday = Date.from_erl!({year, 12, 25}) |> Date.day_of_week
if wday==7, do: IO.puts "25 December
end)
| Option Explicit
Sub MainDayOfTheWeek()
Debug.Print "Xmas will be a Sunday in : " & XmasSunday(2008, 2121)
End Sub
Private Function XmasSunday(firstYear As Integer, lastYear As Integer) As String
Dim i As Integer, temp$
For i = firstYear To lastYear
If Weekday(CDate("25/12/" & i)) = vbSunday Then temp = temp & ", " & i
Next
XmasSunday = Mid(temp, 2)
End Function
|
Change the programming language of this snippet from Elixir to Go without modifying what it does. | Enum.each(2008..2121, fn year ->
wday = Date.from_erl!({year, 12, 25}) |> Date.day_of_week
if wday==7, do: IO.puts "25 December
end)
| package main
import "fmt"
import "time"
func main() {
for year := 2008; year <= 2121; year++ {
if time.Date(year, 12, 25, 0, 0, 0, 0, time.UTC).Weekday() ==
time.Sunday {
fmt.Printf("25 December %d is Sunday\n", year)
}
}
}
|
Change the following Erlang code into C without altering its purpose. |
-module(yuletide).
-export([main/0, sunday_years/2]).
main() ->
[io:fwrite("25 December ~p is Sunday~n", [X]) || X <- sunday_years(2008, 2121)].
sunday_years( Start, Stop ) ->
[X || X <- lists:seq(Start, Stop), is_sunday(calendar:day_of_the_week({X, 12, 25}))].
is_sunday( 7 ) -> true;
is_sunday( _ ) -> false.
| #include <stdio.h>
int wday(int year, int month, int day)
{
int adjustment, mm, yy;
adjustment = (14 - month) / 12;
mm = month + 12 * adjustment - 2;
yy = year - adjustment;
return (day + (13 * mm - 1) / 5 +
yy + yy / 4 - yy / 100 + yy / 400) % 7;
}
int main()
{
int y;
for (y = 2008; y <= 2121; y++) {
if (wday(y, 12, 25) == 0) printf("%04d-12-25\n", y);
}
return 0;
}
|
Change the following Erlang code into C# without altering its purpose. |
-module(yuletide).
-export([main/0, sunday_years/2]).
main() ->
[io:fwrite("25 December ~p is Sunday~n", [X]) || X <- sunday_years(2008, 2121)].
sunday_years( Start, Stop ) ->
[X || X <- lists:seq(Start, Stop), is_sunday(calendar:day_of_the_week({X, 12, 25}))].
is_sunday( 7 ) -> true;
is_sunday( _ ) -> false.
| using System;
class Program
{
static void Main(string[] args)
{
for (int i = 2008; i <= 2121; i++)
{
DateTime date = new DateTime(i, 12, 25);
if (date.DayOfWeek == DayOfWeek.Sunday)
{
Console.WriteLine(date.ToString("dd MMM yyyy"));
}
}
}
}
|
Write the same code in C++ as shown below in Erlang. |
-module(yuletide).
-export([main/0, sunday_years/2]).
main() ->
[io:fwrite("25 December ~p is Sunday~n", [X]) || X <- sunday_years(2008, 2121)].
sunday_years( Start, Stop ) ->
[X || X <- lists:seq(Start, Stop), is_sunday(calendar:day_of_the_week({X, 12, 25}))].
is_sunday( 7 ) -> true;
is_sunday( _ ) -> false.
| #include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
int main( ) {
using namespace boost::gregorian ;
std::cout
<< "Yuletide holidays must be allowed in the following years:\n" ;
for ( int i = 2008 ; i < 2121 ; i++ ) {
greg_year gy = i ;
date d ( gy, Dec , 25 ) ;
if ( d.day_of_week( ) == Sunday ) {
std::cout << i << std::endl ;
}
}
std::cout << "\n" ;
return 0 ;
}
|
Translate the given Erlang code snippet into Java without altering its behavior. |
-module(yuletide).
-export([main/0, sunday_years/2]).
main() ->
[io:fwrite("25 December ~p is Sunday~n", [X]) || X <- sunday_years(2008, 2121)].
sunday_years( Start, Stop ) ->
[X || X <- lists:seq(Start, Stop), is_sunday(calendar:day_of_the_week({X, 12, 25}))].
is_sunday( 7 ) -> true;
is_sunday( _ ) -> false.
| import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Yuletide{
public static void main(String[] args) {
for(int i = 2008;i<=2121;i++){
Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
25);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
System.out.println(cal.getTime());
}
}
}
}
|
Convert this Erlang snippet to Python and keep its semantics consistent. |
-module(yuletide).
-export([main/0, sunday_years/2]).
main() ->
[io:fwrite("25 December ~p is Sunday~n", [X]) || X <- sunday_years(2008, 2121)].
sunday_years( Start, Stop ) ->
[X || X <- lists:seq(Start, Stop), is_sunday(calendar:day_of_the_week({X, 12, 25}))].
is_sunday( 7 ) -> true;
is_sunday( _ ) -> false.
| from calendar import weekday, SUNDAY
[year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
|
Produce a language-to-language conversion: from Erlang to VB, same semantics. |
-module(yuletide).
-export([main/0, sunday_years/2]).
main() ->
[io:fwrite("25 December ~p is Sunday~n", [X]) || X <- sunday_years(2008, 2121)].
sunday_years( Start, Stop ) ->
[X || X <- lists:seq(Start, Stop), is_sunday(calendar:day_of_the_week({X, 12, 25}))].
is_sunday( 7 ) -> true;
is_sunday( _ ) -> false.
| Option Explicit
Sub MainDayOfTheWeek()
Debug.Print "Xmas will be a Sunday in : " & XmasSunday(2008, 2121)
End Sub
Private Function XmasSunday(firstYear As Integer, lastYear As Integer) As String
Dim i As Integer, temp$
For i = firstYear To lastYear
If Weekday(CDate("25/12/" & i)) = vbSunday Then temp = temp & ", " & i
Next
XmasSunday = Mid(temp, 2)
End Function
|
Please provide an equivalent version of this Erlang code in Go. |
-module(yuletide).
-export([main/0, sunday_years/2]).
main() ->
[io:fwrite("25 December ~p is Sunday~n", [X]) || X <- sunday_years(2008, 2121)].
sunday_years( Start, Stop ) ->
[X || X <- lists:seq(Start, Stop), is_sunday(calendar:day_of_the_week({X, 12, 25}))].
is_sunday( 7 ) -> true;
is_sunday( _ ) -> false.
| package main
import "fmt"
import "time"
func main() {
for year := 2008; year <= 2121; year++ {
if time.Date(year, 12, 25, 0, 0, 0, 0, time.UTC).Weekday() ==
time.Sunday {
fmt.Printf("25 December %d is Sunday\n", year)
}
}
}
|
Rewrite this program in C while keeping its functionality equivalent to the F# version. | open System
[ 2008 .. 2121 ]
|> List.choose (fun y -> if DateTime(y,12,25).DayOfWeek = DayOfWeek.Sunday then Some(y) else None)
|> printfn "%A"
| #include <stdio.h>
int wday(int year, int month, int day)
{
int adjustment, mm, yy;
adjustment = (14 - month) / 12;
mm = month + 12 * adjustment - 2;
yy = year - adjustment;
return (day + (13 * mm - 1) / 5 +
yy + yy / 4 - yy / 100 + yy / 400) % 7;
}
int main()
{
int y;
for (y = 2008; y <= 2121; y++) {
if (wday(y, 12, 25) == 0) printf("%04d-12-25\n", y);
}
return 0;
}
|
Keep all operations the same but rewrite the snippet in C#. | open System
[ 2008 .. 2121 ]
|> List.choose (fun y -> if DateTime(y,12,25).DayOfWeek = DayOfWeek.Sunday then Some(y) else None)
|> printfn "%A"
| using System;
class Program
{
static void Main(string[] args)
{
for (int i = 2008; i <= 2121; i++)
{
DateTime date = new DateTime(i, 12, 25);
if (date.DayOfWeek == DayOfWeek.Sunday)
{
Console.WriteLine(date.ToString("dd MMM yyyy"));
}
}
}
}
|
Produce a language-to-language conversion: from F# to C++, same semantics. | open System
[ 2008 .. 2121 ]
|> List.choose (fun y -> if DateTime(y,12,25).DayOfWeek = DayOfWeek.Sunday then Some(y) else None)
|> printfn "%A"
| #include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
int main( ) {
using namespace boost::gregorian ;
std::cout
<< "Yuletide holidays must be allowed in the following years:\n" ;
for ( int i = 2008 ; i < 2121 ; i++ ) {
greg_year gy = i ;
date d ( gy, Dec , 25 ) ;
if ( d.day_of_week( ) == Sunday ) {
std::cout << i << std::endl ;
}
}
std::cout << "\n" ;
return 0 ;
}
|
Port the following code from F# to Java with equivalent syntax and logic. | open System
[ 2008 .. 2121 ]
|> List.choose (fun y -> if DateTime(y,12,25).DayOfWeek = DayOfWeek.Sunday then Some(y) else None)
|> printfn "%A"
| import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Yuletide{
public static void main(String[] args) {
for(int i = 2008;i<=2121;i++){
Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
25);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
System.out.println(cal.getTime());
}
}
}
}
|
Change the programming language of this snippet from F# to Python without modifying what it does. | open System
[ 2008 .. 2121 ]
|> List.choose (fun y -> if DateTime(y,12,25).DayOfWeek = DayOfWeek.Sunday then Some(y) else None)
|> printfn "%A"
| from calendar import weekday, SUNDAY
[year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
|
Translate this program into VB but keep the logic exactly as in F#. | open System
[ 2008 .. 2121 ]
|> List.choose (fun y -> if DateTime(y,12,25).DayOfWeek = DayOfWeek.Sunday then Some(y) else None)
|> printfn "%A"
| Option Explicit
Sub MainDayOfTheWeek()
Debug.Print "Xmas will be a Sunday in : " & XmasSunday(2008, 2121)
End Sub
Private Function XmasSunday(firstYear As Integer, lastYear As Integer) As String
Dim i As Integer, temp$
For i = firstYear To lastYear
If Weekday(CDate("25/12/" & i)) = vbSunday Then temp = temp & ", " & i
Next
XmasSunday = Mid(temp, 2)
End Function
|
Preserve the algorithm and functionality while converting the code from F# to Go. | open System
[ 2008 .. 2121 ]
|> List.choose (fun y -> if DateTime(y,12,25).DayOfWeek = DayOfWeek.Sunday then Some(y) else None)
|> printfn "%A"
| package main
import "fmt"
import "time"
func main() {
for year := 2008; year <= 2121; year++ {
if time.Date(year, 12, 25, 0, 0, 0, 0, time.UTC).Weekday() ==
time.Sunday {
fmt.Printf("25 December %d is Sunday\n", year)
}
}
}
|
Can you help me rewrite this code in C instead of Factor, keeping it the same logically? | USING: calendar math.ranges prettyprint sequences ;
2008 2121 [a,b] [ 12 25 <date> sunday? ] filter .
| #include <stdio.h>
int wday(int year, int month, int day)
{
int adjustment, mm, yy;
adjustment = (14 - month) / 12;
mm = month + 12 * adjustment - 2;
yy = year - adjustment;
return (day + (13 * mm - 1) / 5 +
yy + yy / 4 - yy / 100 + yy / 400) % 7;
}
int main()
{
int y;
for (y = 2008; y <= 2121; y++) {
if (wday(y, 12, 25) == 0) printf("%04d-12-25\n", y);
}
return 0;
}
|
Produce a functionally identical C# code for the snippet given in Factor. | USING: calendar math.ranges prettyprint sequences ;
2008 2121 [a,b] [ 12 25 <date> sunday? ] filter .
| using System;
class Program
{
static void Main(string[] args)
{
for (int i = 2008; i <= 2121; i++)
{
DateTime date = new DateTime(i, 12, 25);
if (date.DayOfWeek == DayOfWeek.Sunday)
{
Console.WriteLine(date.ToString("dd MMM yyyy"));
}
}
}
}
|
Generate a C++ translation of this Factor snippet without changing its computational steps. | USING: calendar math.ranges prettyprint sequences ;
2008 2121 [a,b] [ 12 25 <date> sunday? ] filter .
| #include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
int main( ) {
using namespace boost::gregorian ;
std::cout
<< "Yuletide holidays must be allowed in the following years:\n" ;
for ( int i = 2008 ; i < 2121 ; i++ ) {
greg_year gy = i ;
date d ( gy, Dec , 25 ) ;
if ( d.day_of_week( ) == Sunday ) {
std::cout << i << std::endl ;
}
}
std::cout << "\n" ;
return 0 ;
}
|
Port the provided Factor code into Java while preserving the original functionality. | USING: calendar math.ranges prettyprint sequences ;
2008 2121 [a,b] [ 12 25 <date> sunday? ] filter .
| import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Yuletide{
public static void main(String[] args) {
for(int i = 2008;i<=2121;i++){
Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
25);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
System.out.println(cal.getTime());
}
}
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.