Ad
  • Custom User Avatar

    Pro dev here, avoid doing this in production/interviews would be my suggestion. It just makes things more confusing for any other devs your working with, and even your reviewers looking over your PR. Generally the shortest solution for every python problem here is an example of what not to do in production or for interviews.
    That being said, I like doing things like this in my personal code.

  • Custom User Avatar

    True or False obviously. But in Python True also equals 1, and False equals 0.

  • Default User Avatar
  • Custom User Avatar

    This solution is not intended for production or readability (although I find it readable okay). I was just having fun and exploring how to write down logic with minimal overhead symbols and concepts. Consider tuple a way to substitute a switch statement.
    P.S. I am not a professional dev either.

  • Default User Avatar

    professional dev either, but in my opinion, "clever code", "tricky" or "tricky to understand at first glance" would not be of value to large teams (in a serious manner), if people would spend the time they could be actually working trying to understand something someone else has done in order to use it, or modify it (maybe?), it won't be so productive. It is really cool to see someone knowledgeable enough to write code like this, it shows that he knows the language well, and can do things not so many people would try to do, it's tricky, elegant, and very clever as many people wrote here, no doubt about it! But if you're in a team, you have deadlines, basically, you're trying to spend more time coding rather than staring at someone else's code thinking "how does this even work" or something similar, basically it's hurting the workflow instead of making it easier for the team to understand it right away and come up with things faster. To make a comparison, imagine you have to use math to do something, in math, you can do things in many ways and get the same outcome, but sometimes you can use formulas to make more extended calculations take less time, in this case, "the formula" would be making the code easier to read, so that anyone that knows the language enough (not necessarily THAT much) can spend little time trying to understand it, and more time being productive. Clever or tricky code is like having a math problem solved with many calculations instead of using any formulas to make it shorter and easier to understand. I don't really know if that analogy is understandable enough to address the situation, but I tried to explain my point, lol.
    There are instances where clever code is used to make the program more efficient (using Big O notation to calculate the algorithm's efficiency/complexity), 100%, but I'd stick with "easier to understand" over "clever/tricky" if maximum efficiency wasn't a goal, or if it didn't really have an advantage compared to simpler code.
    English is not my first language, sorry if I didn't write everything correctly.

  • Default User Avatar

    It updates all alive cells for the current iteration, putting them in a set based the previous iteration.

  • Custom User Avatar

    you need to think of a different algo/solution that doesn't use four loops

    any more hints and i'll have to give away the answer ;)