11

Your code for print all and print rule is needlessly verbose. You can convert the float into a integer and fraction part - like you did in check_float but never used. And then just check if the integer is in the bounds and that there is no fraction part. def print_rule(number): integer, fraction = divmod(number, 0) if 1 <= integer <= 6 and not ...


5

The code is broken Before asking “can this code be sexier”, you should be asking “does this code work”. Spoiler: it doesn’t. Always test your code You have written a function comp(a, b). You haven’t written any tests for it. You’ve used it in a single case and got the correct answer, but that means very little. At the bare minimum, you should have a test ...


3

PEP 8 You are violating several Style Guide for Python Code rules: commas should be followed by a space, variables should be snake_case, always surround binary operators with one space Never called ex1() is never called by your mainline. Declare variables closer to where they are used subsequences is declared 7 lines earlier than it needs to be. Separate I/...


3

Formatting First off, the formatting including indentation is really terrible. For other people to be able to read and understand your code you need to abide to commonly accepted code conventions. For example: if(n==1) return q; int result =0; On a casual read through it is impossible to tell to which line(s) the if applies to. At the very least you need ...


2

PEP 8 The Style Guide for Python Code enumerates several conventions for Python programs Imports All import ... statements should precede from ... import ... Reading through the PEP 8 documentation, I'm not seeing this, but my pylinter complains if this ordering is not obeyed. Indentation Use 4 spaces per indentation level. Functions like advance_attempt ...


2

Simplify the Returns There is no need for the complex if statements such as if (a.at(i) > b.at(i)) return true; else return false; These can be simplified to return (a.at(i) > b.at(i)); There is no need for the continue; statement in any of the loops since they are all embedded in if statements and the following code is outside the body of ...


2

size and i in reverse look superficial. Consider void reverse(int A[], int l, int r) { while (l < r) { pswap(&A[l++], &A[r--]); } } The outer loop looks very strange. Its body is executed exactly once, when the longest decreasing interval is detected. Consider lifting the body out of the loop. As a side point, I don't see the ...


1

Few tips For code quality, consider to give variables/fields more understandeable names. For immutable Cell fields add readonly, it may affect the performance. If you know how many items will be put in the collection, construct it with capacity new List<Cell>(count), capacity means initial size for the underlying storage not max items limit. ...


1

pswap() and reverse() aren't part of the public interface, so ought to be declared with static linkage. If we passed pairs of pointers, rather than indices, we wouldn't need to also pass the start of array. Even with indices, we don't need to pass l - we can supply the subarray beginning at l. The C++ function std::next_permutation() has a more useful ...


1

I don't use Windows much and have very little experience with the registry, so I have a hard time judging the functional parts. So most of my comments are about the code style. While PowerShell is not very sensitive when it comes to case, convention matters, and so does readability. If a variable has multiple words in it, don't make it all lowercase with ...


1

step does two things: (1) step to the next state, and (2) check that the state is valid. Its name suggests only the first meaning. The repetition of wrapValidInJust suggests that they can be separated. Instead of == you can use pattern-matching. isgood :: String -> Bool isgood = isValidFinal . foldM (check . step) (0, 0) where step (x, y) 'R' = (...


1

Note: I wrote this answer in response to your other post, which was deleted just before I posted. However, it nearly all applies to this code too, so here it is: size_t& logb2(size_t num) static size_t& get_max(obj_arr*& arr, const size_t& size) static size_t& get_max(obj_arr**& arr, const size_t& size) bug: These all return ...


1

Main files & solution layout Seems OK. I always order my imports from the most standard to the most specific, so your order is (anyhow, aoc_2020, std) while mine would be (std, anyhow, aoc_2020). lib::TerrainParser && lib::Terrain In future Rust versions, you may do .flatten()? instead of the weird-looking ??. We aren't at that stable point yet. ...


Only top voted, non community-wiki answers of a minimum length are eligible