Ad
  • Custom User Avatar

    I honestly don't remember, I'll have a good look at it soon, see if i can crack my old code. This is why you should write good comments on everything you write!

  • Custom User Avatar

    Let's not*. I merely mentioned what can be done, I did not claim it is good practice. Understanding why it works might however lead to useful insights, or give you ideas when playing code golf.

  • Custom User Avatar

    Technically, yes. The use of curly brackets is misleading here (and in my opinion should be omitted, if anything, only the returned object should be possibly considered a set). The description asks for all tuples (a, b), but obviously those tuples also imply (b, a).

    In other words, yes. {15, 21} is the same as {21, 15}, but ((15,21), (21,15)) and {(15, 21), (21, 15)} are perfectly valid notations. It seems the description does not make a distinction between these brackets - which may lead to confusion.

    Under normal circumstances, curly brackets denote a set. In this case, the author appears to confuse the two.

  • Custom User Avatar

    You can treat the output of n % 2 as boolean and skip the == 0 condition altogether (though bear in mind it'll yield the opposite 'truth value').

  • Custom User Avatar

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

  • Custom User Avatar

    Missed a semi-colon or two, but you get my drift.

  • Custom User Avatar

    See my fork for a simple, clear, non-recursive solution to this, using a bit of abuse of default input to shorten the solution. I prefer that a lot over putting if/else statements on a single line though.

  • Custom User Avatar

    The boolean multiplication (c in b)* is redundant here, as - I have already commented this on another solution:

    b.find(c) will return -1 if c is not in b, thus 1 + b.find(c) equals 0, not adding to the total sum.

    I wouldn't say it is beautiful nor excellent.

  • 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

    Good point :), nice.

  • Custom User Avatar

    I didn't go through your entire solution, but glancing over your code, you could've made the tobase64 a string rather than a dictionary:

    tobase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
    frombase64 = {x: tobase64.index(x) for x in tobase64}
    

    I'm sure I am not the only one that dislikes lines over 80 characters long, let alone a dictionary 450 characters long on a single line.

  • Custom User Avatar

    @goodwin64 This is not what Just David is referring to. The boardstate in the screenshot you are linking to clearly has x as a winner (1s on the diagonal).

    @Just David an example of a cat's game according to the definition is a draw - so your code should be correct in the case that the moves do not matter for the outcome (which in your case would be a draw, or cat's game, hence 0)

    Your answer shouldn't depend on whose turn it is, the description says you have to determine whether the current state is a final one (x wins, o wins or it's a draw) or not (undeterminable, you do not know who's move it is)

  • Custom User Avatar

    Why are people voting best practice on this? max is a built-in function, the second if-statement is never reached if the first one applies (should be elif). I wouldn't call putting if-statements on a single line good practice either.

  • Custom User Avatar

    Mind you, this is not good practice, as the list is actually being stored and the values are not being used.

  • Loading more items...