Hacker News new | past | comments | ask | show | jobs | submit login

Maybe the author wanted to squeeze as many hours out of the task as they could? Plenty of non-top-quartile people love this sort of thing as a day at the beach.

For the diametrical opposite, here's one time on an embedded system where I really didn't want to bring in a library dependency, so I wrote an inconspicuous-looking good-enough version:

   y = (d - (d + 366 + (d >= 47847)) / 1461 + (d >= 47847)) / 365;
   d = d - (d + 365 + (d >= 47848)) / 1461 + (d >= 47848) - y * 365;
   y += 1970;



#include <iostream>

int main() { long long d; std::cout << "Enter a Julian Day Number: "; std::cin >> d;

    if (d < 0) {
        std::cerr << "Error: Invalid Julian Day Number (must be non-negative)." << std::endl;
        return 1; // Indicate an error to the system
    }

    const int DAYS_PER_YEAR = 365;
    const int DAYS_PER_LEAP_YEAR = 366;
    const int DAYS_PER_LEAP_CYCLE = 1461; // 4 years
    const int JULIAN_TO_GREGORIAN_THRESHOLD = 2299161; // Oct 15, 1582

    // Adjust for Julian-to-Gregorian transition
    if (d >= JULIAN_TO_GREGORIAN_THRESHOLD) {
        d += 10; // Account for dropped days
    }

    int a = d + 32044;
    int b = (4 * a + 3) / DAYS_PER_LEAP_CYCLE;
    int c = (4 * a + 3) % DAYS_PER_LEAP_CYCLE;

    int y = (b / 1460) + 1970; 
    d = (c / 4) - 365;

    if (d < 0) {
        y--;
        d += DAYS_PER_YEAR + (y % 4 == 0);
    }

    std::cout << "Gregorian Year: " << y << std::endl;
    std::cout << "Day of Year: " << d + 1 << std::endl; // Add 1 as days are typically 1-indexed

    return 0;
}


Not only that, but you can ask it to rewrite it in iambic pentameter and with pirate-speak identifiers.

Really begs the question of what the long-term outlook is for the non-top-quartile people. Maybe re-prompting LLMs is the new ball of mud?


> Maybe re-prompting LLMs is the new ball of mud?

Recently, my company acquired some engineers, and while I cannot evaluate their "percentile", I have been low-key flabbergasted at some of their suggestions for using LLMs in place of scripts. (For example, to modify or move nested data in a non-public JSON representation of a program.)


> As a rule of thumb, leap days come around every four years. But there are exceptions to this rule. For example, at the turn of every century we miss a leap year. Even though the year is divisible by four, we don't add a leap day in the years that end in 00. But there's an exception to this rule too. If the year is a multiple of 400 then we do add in an extra leap day again. At the turn of the millennium, despite being divisible by 100, the year 2000 did, in fact, have a 29 February because it was also divisible by 400.

https://www.bbc.com/future/article/20240228-leap-year-the-im...


That reminds me of this program, which calculates the month and day given the year and the day of the year [0]. There's a version that abuses goto, and one that stores state in variables and only uses structured statements. You probably won't see people similarly abuse goto today, though. I think it was translated from Fortran.

[0]: https://craftofcoding.wordpress.com/2020/02/12/the-world-of-...



Not for the task at hand. The initial d was divided down from an unsigned 32-bit timestamp in seconds from the Unix epoch (hence the 1970.) It accounts for 2000 (leap) and 2100 (not leap), after which the u32 overflows.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: