gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
Make next C code more short and hacker style: struct tm easter_orthodox(int year) { int…
- User
Make next C code more short and hacker style: struct tm easter_orthodox(int year) { int d = (19 * (year % 19) + 15) % 30; int e = (2 * (year % 4) + 4 * (year % 7) - d + 34) % 7; int x = d + e + 114; struct tm easter_date = {0}; easter_date.tm_year = year - 1900; easter_date.tm_mon = (x / 31) - 1; easter_date.tm_mday = (x % 31) + 1; easter_date.tm_isdst = -1; int julian_gregorian_diff = year / 100 - year / 400 - 2; time_t time_easter = mktime(&easter_date) + julian_gregorian_diff * 86400; return *localtime(&time_easter); }
- Assistant
Here's a shorter, more "hacker style" version of your
easter_orthodoxfunction:#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, j=y/100 - y/400 - 2; 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; return *localtime(&(time_t){mktime(&t) + j*86400}); }Changes made:
- Removed intermediate variable names where possible.
- Combined declarations on single lines.
- Used compound literal and pointer cast to shorten the
localtimeargument. - Omitted whitespace to compact the code.
Let me know if you want it even more cryptic!