People who code: we want your input. Take the Survey

New answers tagged

1

Nice work building a very fast Sudoko validator. As others have mentioned, getting beyond the hard-coded size will take some tweaking. If I were writing a Sudoko solver (and the requisite validator), I'd probably start with the object model before the algorithms. So, I started thinking about the classes I might implement and sketched out some high-level ...


1

As it was stated by @harold and @iSR5 your current implementation is not bullet-proof. I will not repeat their suggestions. Rather I want to show you how to reduce repetition. So, let me share with you my revised version for IsValidSudokuBoard9x9 then I will explain it: public static bool IsValidSudokuBoard9x9New(int[][] board) { const byte numberOfRows =...


3

Your code looks nice. I give some additional advice. You can debug by calling the source command in your terminal (REPL). You can divide the common codes and the main codes by writing the source in the main code. Take care of an enormous number. The number 99999999999999999999999999999999999999999999999999, and so on. The action of writing some function is ...


2

I've mainly got three points: The whole thing should be wrapped in a function with the reference to the input element passed in. Currently it is hard coded to (only) apply to the first input on the page, which doesn't seem like a practical scenerio. Instead of using the deprecated/non-standard keyCode and which, you should be using key. And if you do use ...


1

Given that your focus is on readability and simplicity, rather than performance (which matters too), I would suggest using the netaddr module. Then all you need is something like: import netaddr if netaddr.valid_ipv4('192.168.0.1'): # do something However, it has to be installed, this is not a built-in package. The reason why I am mentioning this is ...


2

Return value The function is supposed to return a boolean, but it doesn't. It returns None or an exception. To avoid confusion, decide what to return and adjust the type hint accordingly. My suggestion is to return a boolean, as it is easier for the caller to deal with and avoids the additional argument expectFail. However, this might depend on your use case....


3

assert is for debugging/testing Don't use assert for runtime validation. Per the documentation, the assert statement assert expression is equivalent to: if __debug__: if not expression: raise AssertionError and if the interpreter is run with the -O flag, the assert statements are elided: ...the built-in variable debug is True under normal circumstances,...


4

As Linny noted, is_leading_zeros has an error because you want != intead of is not. My Python 3.8.2 actually says SyntaxWarning: "is not" with a literal. Did you mean "!="? on those two lines. But my bigger problem is with the name of the function: is_leading_zeros(s) is True when s doesn't have leading zeros (a docstring could have ...


5

When to use is not Your usage of is not is incorrect. You want to use == when you're testing equality, like when you check if s doesn't equal a '0'. You want to use is not when checking for identity, like when you're ensuring two variables are of the same object. def is_leading_zeros(s: str) -> bool: if s != '0': return s[0] != '0' return ...


Top 50 recent answers are included