Ad
  • Custom User Avatar

    Never thought of using the modulo operator that way! Excellent.

  • Custom User Avatar

    Thanks for expanding it! I'm still learning as well and there are a few things here I didn't notice myself.

  • Custom User Avatar

    A solution is a solution

    If we don't look at the fact that this solution is absolutely terrible:

    • saving arrays' length in variables and still calling len inside the loop
    • creating new references to the same arrays, and modifying these references
    • assigning ta = a and re-assigning it again if len(a) > len(b) for no reason
    • checking that arrays are not empty by looking at their length (the only time those array-length variables were used, which makes them even more useless)
    • O(n^3) time complexity because of terrible loops and if's
    • useless return inside if block
  • Custom User Avatar

    This one caught my eye--it's a pretty interesting approach to the problem! There are a lot of layers there for sure :) I'm honestly pretty new to programming myself, but it seems like your approach may be a bit of a roundabout way, though--there are a lot of simpler techniques you could use to get the job done.

    A few of the things I noticed:

    On the macro level:

    • The solution really doesn't need to have this many components. You should be able to do this with just one for loop and one if statement. A lot of this code could be easily replaced by something a lot shorter or just removed altogether.

    On the micro level:

    • The names for your lists and lengths are short, which is nice, but kind of confusing--clearer naming would help!
    • You really don't need the lengths of lists a and b at all; you can do what you need without specifying those
    • You seem to have two return statements--you could cut that down to one :)

    Great job getting the code to work though! A solution is a solution :)