Ad
  • Default User Avatar

    I like this solution:

    1. just 30 lines, compared to my 200 lines...
    2. understandable coding, nothing to "genius", just well thought trough (wheras my own is just a clumsy implementation of all stages in a process)
    3. I learned something new from the line: ys, xs = zip(*alive)
    • it gives us an iterator of 2-tuples - AND - we can dis-assemble this iterator into the components of the tuples - that is new to me and a very nice property - no fumbling with a list of pairs, as we would have gotten from something like "list(alive)"
    1. the double/tripple for-loops in the comprehensions - I have never seen this before and would never have thought of doing this myself, again a lesson learned!
  • Default User Avatar

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

  • Default User Avatar

    If I log out the input array after the method has run, I get the same as before, i.e. the input is not changed.

  • Default User Avatar

    Well, yes: hurts to look at...
    but every other solution (including my own) does so too: fiddling with minus and space and bla

    Still some nice things to learn from this one...

  • Default User Avatar

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

  • Default User Avatar

    Perhaps I'm to picky here: like most of the solutions You reformulate the conditions, i.e. You calculate the negations somewhere, in Your head or a sheet of paper and test for these calculated conditions - which in this case is easy enough. In general I don't think that this is advisable: it is prone to error, and everybody maintaining your code has to do these calculations in order to check if they are equivalent to those in the specification. I think it is better to test for !(h>0) as specified, instead of testing for (h<=0).

  • Default User Avatar

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

  • Default User Avatar

    Ok, I would have thought that You are proficient, because of the prime-number stuff... Unfortunately I do not know about a way to generate primes, i.e. every algorithm like yours has the limitation of just finding the right answer for the primes you included - and for all of their possible products of course. Probably execution-times are very low, since you are only checking for the primes.
    My own algorithm is much worse - though it passed the auto-grader... But - in the end we are here for learning, aren't we?

  • Default User Avatar

    Is it genius ? Is it madness? - I would refuse to maintain such code. If I absolutely had to, I would delete it and start afresh, not wasting my time to try to understand it. At least a few comments to explain what is done should be given.

  • Default User Avatar

    Yes, You are right - realized this the other day, but could not find my comment to Your solution to correct myself.

  • Default User Avatar

    n=2048 : should [2, 11] ---> get: None
    Nice idea to use prime powers only, but keeps the algorithm from working when k consists of primes not in your list.

  • Default User Avatar

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

  • Default User Avatar

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

  • Default User Avatar

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

  • Default User Avatar

    page_index() seems to be wrong:

    helper = PaginationHelper(['a','b','c','d','e','f'], 4)
    print(helper.page_index(4)) # should == 0 (zero based index) ----> get: 1

  • Loading more items...