• merc@sh.itjust.works
    link
    fedilink
    arrow-up
    11
    ·
    1 year ago

    I like this bit at the end:

    As a side note, the program is amazingly performant. For small numbers the results are instantaneous and for the large number close to the 2^32 limit the result is still returned in around 10 seconds.

      • merc@sh.itjust.works
        link
        fedilink
        arrow-up
        3
        ·
        1 year ago

        For a long time I’ve been of the opinion that you should only ever optimize for the next sucker colleague who might need to read and edit your code. If you ever optimize for speed, it needs to be done with massive benchmarking / profiling support to ensure that the changes you make are worth it. This is especially true with modern compilers / interpreters that try to use clever techniques to optimize your code either on the fly, or before making the executable.

        • Klear@sh.itjust.works
          link
          fedilink
          arrow-up
          2
          ·
          edit-2
          1 year ago

          The first rule of optimization: Don’t do it
          The second rule of optimization: Don’t do it yet (experts only)

    • blusterydayve26@midwest.social
      link
      fedilink
      English
      arrow-up
      1
      arrow-down
      1
      ·
      edit-2
      1 year ago

      I’m still mad he didn’t use the size of the number to tell the system which block to read first. I feel like that would be a great use of division or maybe modulus?

  • case_when@feddit.uk
    link
    fedilink
    English
    arrow-up
    10
    ·
    1 year ago

    This is poetry.

    My favourite part is that he uses the modulo operator in his Python script to generate the C code.

  • Great Blue Heron@lemmy.ca
    link
    fedilink
    arrow-up
    6
    ·
    1 year ago

    I’m not a good reader - I skim most articles and often miss most of the meaning. I read, and enjoyed, every word of that!

  • Hotzilla@sopuli.xyz
    link
    fedilink
    arrow-up
    7
    arrow-down
    1
    ·
    1 year ago

    Could be easily made 50% space saving by only iffin all odds and return even on else. Maybe one if before to handle overflow to avoid wrong even if over the last if.

    • bjorney@lemmy.ca
      link
      fedilink
      arrow-up
      2
      ·
      edit-2
      1 year ago

      Yeah but then ALL even numbers would be slow to compute because you would have to chain through every odd before you know that 2 is even.

      Depends on the expected distribution of input values

    • Th4tGuyII@kbin.social
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      There’s not a single thing in this universe that cannot be accomplished with enough IF statements… as long as you’ve got infinite time to wait

      • firecat@kbin.social
        link
        fedilink
        arrow-up
        0
        arrow-down
        1
        ·
        1 year ago

        The problem with if is the answer comes from user. There’s no mathematical reason or scientific explanation, only programmer who thinks the answer should include the subject.

  • Hector_McG@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    I first saw this joke back in the days of 8-bit home microcomputers. Of course then it only needed 256 lines of code, and took up about 8k of your precious, precious RAM.