gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
Make this C code more short and complex: struct tm easter_orthodox(int year) { int a =…
- User
Make this C code more short and complex: struct tm easter_orthodox(int year) { int a = year % 4; int b = year % 7; int c = year % 19; int d = (19 * c + 15) % 30; int e = (2 * a + 4 * b - d + 34) % 7; int month = (d + e + 114) / 31; int day = ((d + e + 114) % 31) + 1;
struct tm orthodox_pascha_julian = {0}; orthodox_pascha_julian.tm_year = year - 1900; orthodox_pascha_julian.tm_mon = month - 1; orthodox_pascha_julian.tm_mday = day; orthodox_pascha_julian.tm_isdst = -1; time_t julian_time = mktime(&orthodox_pascha_julian); julian_time += 13 * 86400; struct tm *orthodox_pascha_gregorian = localtime(&julian_time); return *orthodox_pascha_gregorian;}
- Assistant
Here's a more compact and somewhat obfuscated version of your function, combining expressions and reducing variable names, while keeping the logic intact:
#include <time.h> struct tm easter_orthodox(int y) { int d = (19 * (y % 19) + 15) % 30, e = (2 * (y % 4) + 4 * (y % 7) - d + 34) % 7, x = d + e + 114; struct tm t = {0}; t.tm_year = y - 1900; t.tm_mon = x / 31 - 1; t.tm_mday = x % 31 + 1; t.tm_isdst = -1; time_t s = mktime(&t) + 13 * 86400; return *localtime(&s); }Changes:
- Shortened variable names (
yforyear,d,e,x). - Combined computations of
d,e, andxinto fewer lines. - Initialized
struct tmwith{0}and set members inline. - Removed intermediate variable for
localtimeoutput, returning dereferenced pointer directly.
Note: While more complex/compact, such code reduces readability and maintainability. Use carefully!
- Shortened variable names (
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.