• 0 Posts
  • 5 Comments
Joined 1 year ago
cake
Cake day: June 15th, 2023

help-circle

  • This is only tangentially related to improving your code directly as you have asked. However, in a similar vein as using source control (git), when using Python learn to manage your environments. Venv, poetry, conda/mamba, etc are tools to look into.

    I used to work with mostly scientists, and a good number of them knew some Python, but none of them knew how to properly manage their environments and it was a huge problem. They would often come to me and say “I ran this script a week ago and it worked, I tried it today without making any changes and it’s throwing this error now that I don’t understand.” Every time it was because they accidentally changed their dependencies, using their global python install. It also made it a nightmare to try to revive old code for them, since there was almost no way to know what version of various libraries were used.



  • I found this amusing enough to try it out. It does actually compile (I used g++ for this). However, the current implementation just goes into an infinite loop if you enter a number >= 2.

    I think the original author meant to do n -= 1 rn in the tweakin loop that is inside the bussin loop. That way, at some point n % i finna cap will be false, and i will bouta. Which then makes the expression i <= n in the bussin loop eventually false, so we stop bussin and yeet cap rn.

    However, that would mean that the intention of the program isn’t to output prime factors, because even with this fix it does not do so. The structure of mf chief() also doesn’t suggest that is the purpose as it is missing another tweakin and sussin like this example of calculating prime factors in C++.

    Example run:

    $ ./zpp.exe
    Enter a number larger than 1: 50
    2
    7
    8
    47