Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Rewrite this program in Python while keeping its functionality equivalent to the Factor version.
USING: calendar math.ranges prettyprint sequences ; 2008 2121 [a,b] [ 12 25 <date> sunday? ] filter .
from calendar import weekday, SUNDAY [year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
Rewrite the snippet below in VB so it works the same as the original Factor code.
USING: calendar math.ranges prettyprint sequences ; 2008 2121 [a,b] [ 12 25 <date> sunday? ] filter .
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
Ensure the translated Go code behaves exactly like the original Factor snippet.
USING: calendar math.ranges prettyprint sequences ; 2008 2121 [a,b] [ 12 25 <date> sunday? ] filter .
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) } } }
Port the following code from Forth to C with equivalent syntax and logic.
: weekday over 3 < if 1- swap 12 + swap then 100 /mod dup 4 / swap 2* - swap dup 4 / + + swap 1+ 13 5 */ + + 2- 7 mod 1+ ; : yuletide ." December 25 is Sunday in " 2122 2008 do 25 12 i weekday 7 = if i . then loop cr ;
#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 Forth.
: weekday over 3 < if 1- swap 12 + swap then 100 /mod dup 4 / swap 2* - swap dup 4 / + + swap 1+ 13 5 */ + + 2- 7 mod 1+ ; : yuletide ." December 25 is Sunday in " 2122 2008 do 25 12 i weekday 7 = if i . then loop cr ;
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")); } } } }
Convert this Forth snippet to C++ and keep its semantics consistent.
: weekday over 3 < if 1- swap 12 + swap then 100 /mod dup 4 / swap 2* - swap dup 4 / + + swap 1+ 13 5 */ + + 2- 7 mod 1+ ; : yuletide ." December 25 is Sunday in " 2122 2008 do 25 12 i weekday 7 = if i . then loop cr ;
#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 the snippet below in Java so it works the same as the original Forth code.
: weekday over 3 < if 1- swap 12 + swap then 100 /mod dup 4 / swap 2* - swap dup 4 / + + swap 1+ 13 5 */ + + 2- 7 mod 1+ ; : yuletide ." December 25 is Sunday in " 2122 2008 do 25 12 i weekday 7 = if i . then loop cr ;
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 algorithm in Python as shown in this Forth implementation.
: weekday over 3 < if 1- swap 12 + swap then 100 /mod dup 4 / swap 2* - swap dup 4 / + + swap 1+ 13 5 */ + + 2- 7 mod 1+ ; : yuletide ." December 25 is Sunday in " 2122 2008 do 25 12 i weekday 7 = if i . then loop cr ;
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 Forth.
: weekday over 3 < if 1- swap 12 + swap then 100 /mod dup 4 / swap 2* - swap dup 4 / + + swap 1+ 13 5 */ + + 2- 7 mod 1+ ; : yuletide ." December 25 is Sunday in " 2122 2008 do 25 12 i weekday 7 = if i . then loop cr ;
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 Forth.
: weekday over 3 < if 1- swap 12 + swap then 100 /mod dup 4 / swap 2* - swap dup 4 / + + swap 1+ 13 5 */ + + 2- 7 mod 1+ ; : yuletide ." December 25 is Sunday in " 2122 2008 do 25 12 i weekday 7 = if i . then loop cr ;
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) } } }
Port the following code from Fortran to C# with equivalent syntax and logic.
PROGRAM YULETIDE IMPLICIT NONE INTEGER :: day, year WRITE(*, "(A)", ADVANCE="NO") "25th of December is a Sunday in" DO year = 2008, 2121 day = Day_of_week(25, 12, year) IF (day == 1) WRITE(*, "(I5)", ADVANCE="NO") year END DO CONTAINS FUNCTION Day_of_week(d, m, y) INTEGER :: Day_of_week, j, k, mm, yy INTEGER, INTENT(IN) :: d, m, y mm=m yy=y IF(mm.le.2) THEN mm=mm+12 yy=yy-1 END IF j = yy / 100 k = MOD(yy, 100) Day_of_week = MOD(d + ((mm+1)*26)/10 + k + k/4 + j/4 + 5*j, 7) END FUNCTION Day_of_week END PROGRAM 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")); } } } }
Convert the following code from Fortran to C++, ensuring the logic remains intact.
PROGRAM YULETIDE IMPLICIT NONE INTEGER :: day, year WRITE(*, "(A)", ADVANCE="NO") "25th of December is a Sunday in" DO year = 2008, 2121 day = Day_of_week(25, 12, year) IF (day == 1) WRITE(*, "(I5)", ADVANCE="NO") year END DO CONTAINS FUNCTION Day_of_week(d, m, y) INTEGER :: Day_of_week, j, k, mm, yy INTEGER, INTENT(IN) :: d, m, y mm=m yy=y IF(mm.le.2) THEN mm=mm+12 yy=yy-1 END IF j = yy / 100 k = MOD(yy, 100) Day_of_week = MOD(d + ((mm+1)*26)/10 + k + k/4 + j/4 + 5*j, 7) END FUNCTION Day_of_week END PROGRAM 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 ; }
Please provide an equivalent version of this Fortran code in C.
PROGRAM YULETIDE IMPLICIT NONE INTEGER :: day, year WRITE(*, "(A)", ADVANCE="NO") "25th of December is a Sunday in" DO year = 2008, 2121 day = Day_of_week(25, 12, year) IF (day == 1) WRITE(*, "(I5)", ADVANCE="NO") year END DO CONTAINS FUNCTION Day_of_week(d, m, y) INTEGER :: Day_of_week, j, k, mm, yy INTEGER, INTENT(IN) :: d, m, y mm=m yy=y IF(mm.le.2) THEN mm=mm+12 yy=yy-1 END IF j = yy / 100 k = MOD(yy, 100) Day_of_week = MOD(d + ((mm+1)*26)/10 + k + k/4 + j/4 + 5*j, 7) END FUNCTION Day_of_week END PROGRAM 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; }
Rewrite the snippet below in Java so it works the same as the original Fortran code.
PROGRAM YULETIDE IMPLICIT NONE INTEGER :: day, year WRITE(*, "(A)", ADVANCE="NO") "25th of December is a Sunday in" DO year = 2008, 2121 day = Day_of_week(25, 12, year) IF (day == 1) WRITE(*, "(I5)", ADVANCE="NO") year END DO CONTAINS FUNCTION Day_of_week(d, m, y) INTEGER :: Day_of_week, j, k, mm, yy INTEGER, INTENT(IN) :: d, m, y mm=m yy=y IF(mm.le.2) THEN mm=mm+12 yy=yy-1 END IF j = yy / 100 k = MOD(yy, 100) Day_of_week = MOD(d + ((mm+1)*26)/10 + k + k/4 + j/4 + 5*j, 7) END FUNCTION Day_of_week END PROGRAM 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()); } } } }
Transform the following Fortran implementation into Python, maintaining the same output and logic.
PROGRAM YULETIDE IMPLICIT NONE INTEGER :: day, year WRITE(*, "(A)", ADVANCE="NO") "25th of December is a Sunday in" DO year = 2008, 2121 day = Day_of_week(25, 12, year) IF (day == 1) WRITE(*, "(I5)", ADVANCE="NO") year END DO CONTAINS FUNCTION Day_of_week(d, m, y) INTEGER :: Day_of_week, j, k, mm, yy INTEGER, INTENT(IN) :: d, m, y mm=m yy=y IF(mm.le.2) THEN mm=mm+12 yy=yy-1 END IF j = yy / 100 k = MOD(yy, 100) Day_of_week = MOD(d + ((mm+1)*26)/10 + k + k/4 + j/4 + 5*j, 7) END FUNCTION Day_of_week END PROGRAM YULETIDE
from calendar import weekday, SUNDAY [year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
Ensure the translated VB code behaves exactly like the original Fortran snippet.
PROGRAM YULETIDE IMPLICIT NONE INTEGER :: day, year WRITE(*, "(A)", ADVANCE="NO") "25th of December is a Sunday in" DO year = 2008, 2121 day = Day_of_week(25, 12, year) IF (day == 1) WRITE(*, "(I5)", ADVANCE="NO") year END DO CONTAINS FUNCTION Day_of_week(d, m, y) INTEGER :: Day_of_week, j, k, mm, yy INTEGER, INTENT(IN) :: d, m, y mm=m yy=y IF(mm.le.2) THEN mm=mm+12 yy=yy-1 END IF j = yy / 100 k = MOD(yy, 100) Day_of_week = MOD(d + ((mm+1)*26)/10 + k + k/4 + j/4 + 5*j, 7) END FUNCTION Day_of_week END PROGRAM 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
Generate an equivalent PHP version of this Fortran code.
PROGRAM YULETIDE IMPLICIT NONE INTEGER :: day, year WRITE(*, "(A)", ADVANCE="NO") "25th of December is a Sunday in" DO year = 2008, 2121 day = Day_of_week(25, 12, year) IF (day == 1) WRITE(*, "(I5)", ADVANCE="NO") year END DO CONTAINS FUNCTION Day_of_week(d, m, y) INTEGER :: Day_of_week, j, k, mm, yy INTEGER, INTENT(IN) :: d, m, y mm=m yy=y IF(mm.le.2) THEN mm=mm+12 yy=yy-1 END IF j = yy / 100 k = MOD(yy, 100) Day_of_week = MOD(d + ((mm+1)*26)/10 + k + k/4 + j/4 + 5*j, 7) END FUNCTION Day_of_week END PROGRAM YULETIDE
<?php for($i=2008; $i<2121; $i++) { $datetime = new DateTime("$i-12-25 00:00:00"); if ( $datetime->format("w") == 0 ) { echo "25 Dec $i is Sunday\n"; } } ?>
Port the provided Groovy code into C while preserving the original functionality.
def yuletide = { start, stop -> (start..stop).findAll { Date.parse("yyyy-MM-dd", "${it}-12-25").format("EEE") == "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; }
Rewrite the snippet below in C# so it works the same as the original Groovy code.
def yuletide = { start, stop -> (start..stop).findAll { Date.parse("yyyy-MM-dd", "${it}-12-25").format("EEE") == "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")); } } } }
Maintain the same structure and functionality when rewriting this code in C++.
def yuletide = { start, stop -> (start..stop).findAll { Date.parse("yyyy-MM-dd", "${it}-12-25").format("EEE") == "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 ; }
Ensure the translated Java code behaves exactly like the original Groovy snippet.
def yuletide = { start, stop -> (start..stop).findAll { Date.parse("yyyy-MM-dd", "${it}-12-25").format("EEE") == "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()); } } } }
Change the programming language of this snippet from Groovy to Python without modifying what it does.
def yuletide = { start, stop -> (start..stop).findAll { Date.parse("yyyy-MM-dd", "${it}-12-25").format("EEE") == "Sun" } }
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 Groovy.
def yuletide = { start, stop -> (start..stop).findAll { Date.parse("yyyy-MM-dd", "${it}-12-25").format("EEE") == "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
Convert the following code from Groovy to Go, ensuring the logic remains intact.
def yuletide = { start, stop -> (start..stop).findAll { Date.parse("yyyy-MM-dd", "${it}-12-25").format("EEE") == "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) } } }
Port the following code from Haskell to C with equivalent syntax and logic.
import Data.Time (fromGregorian) import Data.Time.Calendar.WeekDate (toWeekDate) isXmasSunday :: Integer -> Bool isXmasSunday year = 7 == weekDay where (_, _, weekDay) = toWeekDate $ fromGregorian year 12 25 main :: IO () main = mapM_ putStrLn [ "Sunday 25 December " <> show year | year <- [2008 .. 2121], isXmasSunday 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; }
Convert this Haskell block to C++, preserving its control flow and logic.
import Data.Time (fromGregorian) import Data.Time.Calendar.WeekDate (toWeekDate) isXmasSunday :: Integer -> Bool isXmasSunday year = 7 == weekDay where (_, _, weekDay) = toWeekDate $ fromGregorian year 12 25 main :: IO () main = mapM_ putStrLn [ "Sunday 25 December " <> show year | year <- [2008 .. 2121], isXmasSunday 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 Haskell.
import Data.Time (fromGregorian) import Data.Time.Calendar.WeekDate (toWeekDate) isXmasSunday :: Integer -> Bool isXmasSunday year = 7 == weekDay where (_, _, weekDay) = toWeekDate $ fromGregorian year 12 25 main :: IO () main = mapM_ putStrLn [ "Sunday 25 December " <> show year | year <- [2008 .. 2121], isXmasSunday 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()); } } } }
Write the same algorithm in Python as shown in this Haskell implementation.
import Data.Time (fromGregorian) import Data.Time.Calendar.WeekDate (toWeekDate) isXmasSunday :: Integer -> Bool isXmasSunday year = 7 == weekDay where (_, _, weekDay) = toWeekDate $ fromGregorian year 12 25 main :: IO () main = mapM_ putStrLn [ "Sunday 25 December " <> show year | year <- [2008 .. 2121], isXmasSunday year ]
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.
import Data.Time (fromGregorian) import Data.Time.Calendar.WeekDate (toWeekDate) isXmasSunday :: Integer -> Bool isXmasSunday year = 7 == weekDay where (_, _, weekDay) = toWeekDate $ fromGregorian year 12 25 main :: IO () main = mapM_ putStrLn [ "Sunday 25 December " <> show year | year <- [2008 .. 2121], isXmasSunday 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
Keep all operations the same but rewrite the snippet in Go.
import Data.Time (fromGregorian) import Data.Time.Calendar.WeekDate (toWeekDate) isXmasSunday :: Integer -> Bool isXmasSunday year = 7 == weekDay where (_, _, weekDay) = toWeekDate $ fromGregorian year 12 25 main :: IO () main = mapM_ putStrLn [ "Sunday 25 December " <> show year | year <- [2008 .. 2121], isXmasSunday 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) } } }
Preserve the algorithm and functionality while converting the code from Icon to C.
link datetime procedure main() writes("December 25th is a Sunday in: ") every writes((dayoweek(25,12,y := 2008 to 2122)=="Sunday",y)," ") 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; }
Can you help me rewrite this code in C# instead of Icon, keeping it the same logically?
link datetime procedure main() writes("December 25th is a Sunday in: ") every writes((dayoweek(25,12,y := 2008 to 2122)=="Sunday",y)," ") 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")); } } } }
Change the following Icon code into C++ without altering its purpose.
link datetime procedure main() writes("December 25th is a Sunday in: ") every writes((dayoweek(25,12,y := 2008 to 2122)=="Sunday",y)," ") 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 ; }
Generate a Java translation of this Icon snippet without changing its computational steps.
link datetime procedure main() writes("December 25th is a Sunday in: ") every writes((dayoweek(25,12,y := 2008 to 2122)=="Sunday",y)," ") 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()); } } } }
Write the same code in Python as shown below in Icon.
link datetime procedure main() writes("December 25th is a Sunday in: ") every writes((dayoweek(25,12,y := 2008 to 2122)=="Sunday",y)," ") end
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 Icon code in VB.
link datetime procedure main() writes("December 25th is a Sunday in: ") every writes((dayoweek(25,12,y := 2008 to 2122)=="Sunday",y)," ") 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
Generate an equivalent Go version of this Icon code.
link datetime procedure main() writes("December 25th is a Sunday in: ") every writes((dayoweek(25,12,y := 2008 to 2122)=="Sunday",y)," ") 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) } } }
Produce a functionally identical C code for the snippet given in J.
load 'dates' xmasSunday=: #~ 0 = [: weekday 12 25 ,~"1 0 ] xmasSunday 2008 + i.114 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
#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 J block to C#, preserving its control flow and logic.
load 'dates' xmasSunday=: #~ 0 = [: weekday 12 25 ,~"1 0 ] xmasSunday 2008 + i.114 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
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 J code snippet into C++ without altering its behavior.
load 'dates' xmasSunday=: #~ 0 = [: weekday 12 25 ,~"1 0 ] xmasSunday 2008 + i.114 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
#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 ; }
Change the following J code into Java without altering its purpose.
load 'dates' xmasSunday=: #~ 0 = [: weekday 12 25 ,~"1 0 ] xmasSunday 2008 + i.114 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
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 following J code into Python without altering its purpose.
load 'dates' xmasSunday=: #~ 0 = [: weekday 12 25 ,~"1 0 ] xmasSunday 2008 + i.114 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
from calendar import weekday, SUNDAY [year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
Generate a VB translation of this J snippet without changing its computational steps.
load 'dates' xmasSunday=: #~ 0 = [: weekday 12 25 ,~"1 0 ] xmasSunday 2008 + i.114 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
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 J version.
load 'dates' xmasSunday=: #~ 0 = [: weekday 12 25 ,~"1 0 ] xmasSunday 2008 + i.114 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
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 the given Julia code snippet into C without altering its behavior.
using Dates lo, hi = 2008, 2121 xmas = collect(Date(lo, 12, 25):Year(1):Date(hi, 12, 25)) filter!(xmas) do dt dayofweek(dt) == Dates.Sunday end println("Years from $lo to $hi having Christmas on Sunday: ") foreach(println, year.(xmas))
#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 Julia to C# without modifying what it does.
using Dates lo, hi = 2008, 2121 xmas = collect(Date(lo, 12, 25):Year(1):Date(hi, 12, 25)) filter!(xmas) do dt dayofweek(dt) == Dates.Sunday end println("Years from $lo to $hi having Christmas on Sunday: ") foreach(println, year.(xmas))
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")); } } } }
Maintain the same structure and functionality when rewriting this code in C++.
using Dates lo, hi = 2008, 2121 xmas = collect(Date(lo, 12, 25):Year(1):Date(hi, 12, 25)) filter!(xmas) do dt dayofweek(dt) == Dates.Sunday end println("Years from $lo to $hi having Christmas on Sunday: ") foreach(println, year.(xmas))
#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 ; }
Produce a language-to-language conversion: from Julia to Java, same semantics.
using Dates lo, hi = 2008, 2121 xmas = collect(Date(lo, 12, 25):Year(1):Date(hi, 12, 25)) filter!(xmas) do dt dayofweek(dt) == Dates.Sunday end println("Years from $lo to $hi having Christmas on Sunday: ") foreach(println, year.(xmas))
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 Julia to Python, ensuring the logic remains intact.
using Dates lo, hi = 2008, 2121 xmas = collect(Date(lo, 12, 25):Year(1):Date(hi, 12, 25)) filter!(xmas) do dt dayofweek(dt) == Dates.Sunday end println("Years from $lo to $hi having Christmas on Sunday: ") foreach(println, year.(xmas))
from calendar import weekday, SUNDAY [year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
Write the same algorithm in VB as shown in this Julia implementation.
using Dates lo, hi = 2008, 2121 xmas = collect(Date(lo, 12, 25):Year(1):Date(hi, 12, 25)) filter!(xmas) do dt dayofweek(dt) == Dates.Sunday end println("Years from $lo to $hi having Christmas on Sunday: ") foreach(println, year.(xmas))
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 Julia code.
using Dates lo, hi = 2008, 2121 xmas = collect(Date(lo, 12, 25):Year(1):Date(hi, 12, 25)) filter!(xmas) do dt dayofweek(dt) == Dates.Sunday end println("Years from $lo to $hi having Christmas on Sunday: ") foreach(println, year.(xmas))
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 the snippet below in C so it works the same as the original Lua code.
require("date") for year=2008,2121 do if date(year, 12, 25):getweekday() == 1 then print(year) end 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; }
Transform the following Lua implementation into C#, maintaining the same output and logic.
require("date") for year=2008,2121 do if date(year, 12, 25):getweekday() == 1 then print(year) end 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")); } } } }
Preserve the algorithm and functionality while converting the code from Lua to C++.
require("date") for year=2008,2121 do if date(year, 12, 25):getweekday() == 1 then print(year) end 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 ; }
Please provide an equivalent version of this Lua code in Java.
require("date") for year=2008,2121 do if date(year, 12, 25):getweekday() == 1 then print(year) end 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()); } } } }
Write the same code in Python as shown below in Lua.
require("date") for year=2008,2121 do if date(year, 12, 25):getweekday() == 1 then print(year) end end
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 Lua, keeping it the same logically?
require("date") for year=2008,2121 do if date(year, 12, 25):getweekday() == 1 then print(year) end 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
Write the same algorithm in Go as shown in this Lua implementation.
require("date") for year=2008,2121 do if date(year, 12, 25):getweekday() == 1 then print(year) end 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 Mathematica code into C without altering its purpose.
Reap[If[DateString[{#,12,25},"DayName"]=="Sunday",Sow[#]]&/@Range[2008,2121]][[2,1]]
#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; }
Transform the following Mathematica implementation into C#, maintaining the same output and logic.
Reap[If[DateString[{#,12,25},"DayName"]=="Sunday",Sow[#]]&/@Range[2008,2121]][[2,1]]
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 Mathematica code in C++.
Reap[If[DateString[{#,12,25},"DayName"]=="Sunday",Sow[#]]&/@Range[2008,2121]][[2,1]]
#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 Mathematica code snippet into Java without altering its behavior.
Reap[If[DateString[{#,12,25},"DayName"]=="Sunday",Sow[#]]&/@Range[2008,2121]][[2,1]]
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()); } } } }
Rewrite this program in Python while keeping its functionality equivalent to the Mathematica version.
Reap[If[DateString[{#,12,25},"DayName"]=="Sunday",Sow[#]]&/@Range[2008,2121]][[2,1]]
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 Mathematica.
Reap[If[DateString[{#,12,25},"DayName"]=="Sunday",Sow[#]]&/@Range[2008,2121]][[2,1]]
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 Mathematica.
Reap[If[DateString[{#,12,25},"DayName"]=="Sunday",Sow[#]]&/@Range[2008,2121]][[2,1]]
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 MATLAB.
t = datenum([[2008:2121]',repmat([12,25,0,0,0], 2121-2007, 1)]); t = t(strmatch('Sunday', datestr(t,'dddd')), :); datestr(t,'yyyy')
#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; }
Ensure the translated C# code behaves exactly like the original MATLAB snippet.
t = datenum([[2008:2121]',repmat([12,25,0,0,0], 2121-2007, 1)]); t = t(strmatch('Sunday', datestr(t,'dddd')), :); datestr(t,'yyyy')
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 MATLAB code in C++.
t = datenum([[2008:2121]',repmat([12,25,0,0,0], 2121-2007, 1)]); t = t(strmatch('Sunday', datestr(t,'dddd')), :); datestr(t,'yyyy')
#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 MATLAB code.
t = datenum([[2008:2121]',repmat([12,25,0,0,0], 2121-2007, 1)]); t = t(strmatch('Sunday', datestr(t,'dddd')), :); datestr(t,'yyyy')
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 MATLAB to Python without modifying what it does.
t = datenum([[2008:2121]',repmat([12,25,0,0,0], 2121-2007, 1)]); t = t(strmatch('Sunday', datestr(t,'dddd')), :); datestr(t,'yyyy')
from calendar import weekday, SUNDAY [year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
Translate the given MATLAB code snippet into VB without altering its behavior.
t = datenum([[2008:2121]',repmat([12,25,0,0,0], 2121-2007, 1)]); t = t(strmatch('Sunday', datestr(t,'dddd')), :); datestr(t,'yyyy')
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 MATLAB code.
t = datenum([[2008:2121]',repmat([12,25,0,0,0], 2121-2007, 1)]); t = t(strmatch('Sunday', datestr(t,'dddd')), :); datestr(t,'yyyy')
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 Nim.
import times for year in 2008..2121: if getDayOfWeek(25, mDec, year) == dSun: stdout.write year, ' ' echo ""
#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 the snippet below in C# so it works the same as the original Nim code.
import times for year in 2008..2121: if getDayOfWeek(25, mDec, year) == dSun: stdout.write year, ' ' echo ""
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 Nim code in C++.
import times for year in 2008..2121: if getDayOfWeek(25, mDec, year) == dSun: stdout.write year, ' ' echo ""
#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 ; }
Change the programming language of this snippet from Nim to Java without modifying what it does.
import times for year in 2008..2121: if getDayOfWeek(25, mDec, year) == dSun: stdout.write year, ' ' echo ""
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()); } } } }
Please provide an equivalent version of this Nim code in Python.
import times for year in 2008..2121: if getDayOfWeek(25, mDec, year) == dSun: stdout.write year, ' ' echo ""
from calendar import weekday, SUNDAY [year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
Generate an equivalent VB version of this Nim code.
import times for year in 2008..2121: if getDayOfWeek(25, mDec, year) == dSun: stdout.write year, ' ' echo ""
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 Nim version.
import times for year in 2008..2121: if getDayOfWeek(25, mDec, year) == dSun: stdout.write year, ' ' echo ""
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 OCaml block to C, preserving its control flow and logic.
#load "unix.cma" open Unix try for i = 2008 to 2121 do let mytime = { (localtime (time ())) with tm_year = i - 1900; tm_mon = 11; tm_mday = 25 } in try let _, mytime = mktime mytime in if mytime.tm_wday = 0 then Printf.printf "25 December %d is Sunday\n" i with e -> Printf.printf "%d is the last year we can specify\n" (i-1); raise e done with _ -> ()
#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; }
Ensure the translated C# code behaves exactly like the original OCaml snippet.
#load "unix.cma" open Unix try for i = 2008 to 2121 do let mytime = { (localtime (time ())) with tm_year = i - 1900; tm_mon = 11; tm_mday = 25 } in try let _, mytime = mktime mytime in if mytime.tm_wday = 0 then Printf.printf "25 December %d is Sunday\n" i with e -> Printf.printf "%d is the last year we can specify\n" (i-1); raise e done with _ -> ()
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 functionally identical Java code for the snippet given in OCaml.
#load "unix.cma" open Unix try for i = 2008 to 2121 do let mytime = { (localtime (time ())) with tm_year = i - 1900; tm_mon = 11; tm_mday = 25 } in try let _, mytime = mktime mytime in if mytime.tm_wday = 0 then Printf.printf "25 December %d is Sunday\n" i with e -> Printf.printf "%d is the last year we can specify\n" (i-1); raise e done with _ -> ()
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.
#load "unix.cma" open Unix try for i = 2008 to 2121 do let mytime = { (localtime (time ())) with tm_year = i - 1900; tm_mon = 11; tm_mday = 25 } in try let _, mytime = mktime mytime in if mytime.tm_wday = 0 then Printf.printf "25 December %d is Sunday\n" i with e -> Printf.printf "%d is the last year we can specify\n" (i-1); raise e done with _ -> ()
from calendar import weekday, SUNDAY [year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
Produce a functionally identical VB code for the snippet given in OCaml.
#load "unix.cma" open Unix try for i = 2008 to 2121 do let mytime = { (localtime (time ())) with tm_year = i - 1900; tm_mon = 11; tm_mday = 25 } in try let _, mytime = mktime mytime in if mytime.tm_wday = 0 then Printf.printf "25 December %d is Sunday\n" i with e -> Printf.printf "%d is the last year we can specify\n" (i-1); raise e done with _ -> ()
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 OCaml version.
#load "unix.cma" open Unix try for i = 2008 to 2121 do let mytime = { (localtime (time ())) with tm_year = i - 1900; tm_mon = 11; tm_mday = 25 } in try let _, mytime = mktime mytime in if mytime.tm_wday = 0 then Printf.printf "25 December %d is Sunday\n" i with e -> Printf.printf "%d is the last year we can specify\n" (i-1); raise e done with _ -> ()
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) } } }
Generate an equivalent C version of this Pascal code.
var year, month, day, dayofweek; procedure calcdayofweek; begin if month < 3 then begin year := year - 1; month := month + 12 end; dayofweek := year + year / 4 - year / 100 + year / 400; dayofweek := dayofweek + day + (153 * month + 8) / 5; dayofweek := dayofweek - (dayofweek / 7) * 7 end; begin month := 12; day := 25; year := 2007; while year <= 2122 do begin call calcdayofweek; if dayofweek = 0 then ! year; year := year + 1 end 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; }
Produce a language-to-language conversion: from Pascal to C#, same semantics.
var year, month, day, dayofweek; procedure calcdayofweek; begin if month < 3 then begin year := year - 1; month := month + 12 end; dayofweek := year + year / 4 - year / 100 + year / 400; dayofweek := dayofweek + day + (153 * month + 8) / 5; dayofweek := dayofweek - (dayofweek / 7) * 7 end; begin month := 12; day := 25; year := 2007; while year <= 2122 do begin call calcdayofweek; if dayofweek = 0 then ! year; year := year + 1 end 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")); } } } }
Rewrite the snippet below in C++ so it works the same as the original Pascal code.
var year, month, day, dayofweek; procedure calcdayofweek; begin if month < 3 then begin year := year - 1; month := month + 12 end; dayofweek := year + year / 4 - year / 100 + year / 400; dayofweek := dayofweek + day + (153 * month + 8) / 5; dayofweek := dayofweek - (dayofweek / 7) * 7 end; begin month := 12; day := 25; year := 2007; while year <= 2122 do begin call calcdayofweek; if dayofweek = 0 then ! year; year := year + 1 end 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 ; }
Change the programming language of this snippet from Pascal to Java without modifying what it does.
var year, month, day, dayofweek; procedure calcdayofweek; begin if month < 3 then begin year := year - 1; month := month + 12 end; dayofweek := year + year / 4 - year / 100 + year / 400; dayofweek := dayofweek + day + (153 * month + 8) / 5; dayofweek := dayofweek - (dayofweek / 7) * 7 end; begin month := 12; day := 25; year := 2007; while year <= 2122 do begin call calcdayofweek; if dayofweek = 0 then ! year; year := year + 1 end 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()); } } } }
Generate a Python translation of this Pascal snippet without changing its computational steps.
var year, month, day, dayofweek; procedure calcdayofweek; begin if month < 3 then begin year := year - 1; month := month + 12 end; dayofweek := year + year / 4 - year / 100 + year / 400; dayofweek := dayofweek + day + (153 * month + 8) / 5; dayofweek := dayofweek - (dayofweek / 7) * 7 end; begin month := 12; day := 25; year := 2007; while year <= 2122 do begin call calcdayofweek; if dayofweek = 0 then ! year; year := year + 1 end end.
from calendar import weekday, SUNDAY [year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
Translate the given Pascal code snippet into VB without altering its behavior.
var year, month, day, dayofweek; procedure calcdayofweek; begin if month < 3 then begin year := year - 1; month := month + 12 end; dayofweek := year + year / 4 - year / 100 + year / 400; dayofweek := dayofweek + day + (153 * month + 8) / 5; dayofweek := dayofweek - (dayofweek / 7) * 7 end; begin month := 12; day := 25; year := 2007; while year <= 2122 do begin call calcdayofweek; if dayofweek = 0 then ! year; year := year + 1 end 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 Pascal version.
var year, month, day, dayofweek; procedure calcdayofweek; begin if month < 3 then begin year := year - 1; month := month + 12 end; dayofweek := year + year / 4 - year / 100 + year / 400; dayofweek := dayofweek + day + (153 * month + 8) / 5; dayofweek := dayofweek - (dayofweek / 7) * 7 end; begin month := 12; day := 25; year := 2007; while year <= 2122 do begin call calcdayofweek; if dayofweek = 0 then ! year; year := year + 1 end 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 programming language of this snippet from Perl to C without modifying what it does.
use Time::Local; use strict; foreach my $i (2008 .. 2121) { my $time = timelocal(0,0,0,25,11,$i); my ($s,$m,$h,$md,$mon,$y,$wd,$yd,$is) = localtime($time); if ( $wd == 0 ) { print "25 Dec $i is Sunday\n"; } } exit 0;
#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 algorithm in C# as shown in this Perl implementation.
use Time::Local; use strict; foreach my $i (2008 .. 2121) { my $time = timelocal(0,0,0,25,11,$i); my ($s,$m,$h,$md,$mon,$y,$wd,$yd,$is) = localtime($time); if ( $wd == 0 ) { print "25 Dec $i is Sunday\n"; } } exit 0;
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 Perl code in C++.
use Time::Local; use strict; foreach my $i (2008 .. 2121) { my $time = timelocal(0,0,0,25,11,$i); my ($s,$m,$h,$md,$mon,$y,$wd,$yd,$is) = localtime($time); if ( $wd == 0 ) { print "25 Dec $i is Sunday\n"; } } exit 0;
#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 Perl version.
use Time::Local; use strict; foreach my $i (2008 .. 2121) { my $time = timelocal(0,0,0,25,11,$i); my ($s,$m,$h,$md,$mon,$y,$wd,$yd,$is) = localtime($time); if ( $wd == 0 ) { print "25 Dec $i is Sunday\n"; } } exit 0;
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 Perl code into Python while preserving the original functionality.
use Time::Local; use strict; foreach my $i (2008 .. 2121) { my $time = timelocal(0,0,0,25,11,$i); my ($s,$m,$h,$md,$mon,$y,$wd,$yd,$is) = localtime($time); if ( $wd == 0 ) { print "25 Dec $i is Sunday\n"; } } exit 0;
from calendar import weekday, SUNDAY [year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
Generate an equivalent VB version of this Perl code.
use Time::Local; use strict; foreach my $i (2008 .. 2121) { my $time = timelocal(0,0,0,25,11,$i); my ($s,$m,$h,$md,$mon,$y,$wd,$yd,$is) = localtime($time); if ( $wd == 0 ) { print "25 Dec $i is Sunday\n"; } } exit 0;
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 Perl code into Go while preserving the original functionality.
use Time::Local; use strict; foreach my $i (2008 .. 2121) { my $time = timelocal(0,0,0,25,11,$i); my ($s,$m,$h,$md,$mon,$y,$wd,$yd,$is) = localtime($time); if ( $wd == 0 ) { print "25 Dec $i is Sunday\n"; } } exit 0;
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 the snippet below in C so it works the same as the original PowerShell code.
2008..2121 | Where-Object { (Get-Date $_-12-25).DayOfWeek -eq "Sunday" }
#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; }