New answers tagged

2

This seems to run quickly. The idea is to use nonzero() grab the indices of non-zero elements. Use choice() to select 1/3 of them. and set those indices to zero. Repeat for each row in the matrix. rng = np.random.default_rng() matrix = np.random.rand(1000,3000) for k in range(matrix.shape[0]): r = matrix[k,:].nonzero()[0] n = round(len(r) * 0.33) ...


2

Verbs for methods g.checker() should be g.check() "Checker" would be an appropriate name for a class or variable; "check" for a function. Grammar you losed -> you lost


4

It looks like you'd benefit from moving duplicated logic into functions. Additionally, you manage all of your state within the checker() method, when this state could be stored on the Game object. Passing a user guess into the constructor seems really strange. There's nothing special about the first guess, so don't treat it as a special case. class Game: ...


3

My guess is that the bottleneck is drawing random numbers at each iteration. Why guess when you can measure? I changed the height to 100 so the whole thing takes me about 8 seconds, reasonable to play around with. Removing the assert line on the bottom makes it a bit faster. Also removing the dirty = [j if...] line makes it a lot faster. As you'd expect ...


4

The output is not uniformly distributed The resulting characters in the output string are not uniformly distributed. In fact, some characters never occur in the output. After shifting a random byte right by two, if the result is larger than or equal to 32, you always clear the second least significant bit. So all values up to 32 are possible, but then it is ...


3

I personally find the fun part of programming to be the challenge of trying to find the leanest, most direct way to execute a task. One measure of how careful a developer is is to pay attention to occurrences where a script repeats something. You should always strive to not repeat yourself (D.R.Y. means Don't Repeat Yourself). You don't need to bloat your ...


1

As a first attempt in F# you have passed the test, but the overall impression is a little messy, while the algorithm seems to (almost) work as expected. If calling it with an empty argument list - from this: match args with | [] -> lower @ upper @ numbers in buildChars, I would expect it to produce a 16 chars password from the default settings. ...


Top 50 recent answers are included