Ad
  • Custom User Avatar

    Jaja so do I

  • Custom User Avatar

    Good catch! It certainly would make sense to make baryon_number a class variable, since it's a property of all quarks that is never expected to change.

    Examining this kata's sample tests, I see that the baryon_number test is inside the test section labelled "Class attributes", so it would seem that you are correct in thinking that it should be a class variable.

    But since the baryon_number is never supposed to change, it doesn't matter too much whether it's a class variable or an instance variable. The only time it makes a real difference is if you want to query the baryon_number, and there are no quarks that exist. Should we still be able to query the baryon_number? (Most people would say yes, but there are physicists who insist that measurements for particles that don't exist are non-sensical. For instance, every proton in the universe may have the exact same mass, but that measurement lacks meaning if there exist zero protons. But I digress...)

    If you'll let me digress even more, what would be expected to happen if a quark suddenly happened to get its baryon number changed? Would that be an unusual quark, or would every quark in the universe also get its baryon number changed to the same value? (To be honest, I don't really know what a "baryon_number" is, but I'm sure if it changed for all quarks everywhere, life as we know it would be very different!)

    Hopefully, we'll never have to worry about that scenario. But as for the purposes of the code here, it looks like that your hunch to make "baryon_number" a class variable is a correct one.

  • Custom User Avatar

    Considering the topic is refactoring:
    "Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior"
    One way to minimize altering it's external behavior is to write self.name = my_name in case my_name is used as a keyword somewhere.

  • Custom User Avatar

    Shouldn't baryon_number be a class variable, since it's the same for every object?

  • Custom User Avatar

    Maybe add this to sample tests:
    test.assert_equals(sum_fracts([[1, 3], [2, 6]]), [2, 3])

    Without it a simple LCM function works for all tests samples.

  • Custom User Avatar

    The fact that there is only one test out of 106 that tests for the 3x3 rule certainly has caused a lot of confusion.

    Annoyed me enough to cheat.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Almost makes me regret not googling it

  • Custom User Avatar

    And I thought mine was clever...

  • Custom User Avatar

    Leading zeros, probably.

  • Custom User Avatar

    This comment has been deleted.

  • Custom User Avatar
  • Custom User Avatar

    look at your function name

  • Custom User Avatar

    Hey, I'm surely doing something wrong, but I don't understand the error I'm getting.

    STDERR - NameError: name 'is_valid_walk' is not defined

    The test examples seem to work fine in pyCharm.

  • Loading more items...