11

Style Before diving in the actual code, some general style considerations first. Python comes with an official Style Guide. The most relevant parts for your code would be the sections on how to structure code using blank lines where appropriate (two blank lines between separate functions and classes, only single blank line within functions and classes) and ...


8

I'm on my phone, so it's hard to really see this code as a whole and really take the full context of everything. I'm just going to flip through and mention things as I notice them. At the top, you have vengeful = 'VENGEFUL.' And other such lines. This strikes me as odd. The only small benefit I can see is this would help the IDE auto-complete the word. ...


3

What a wall of text! Also known as write-only code, or job security. You want to write understandable code, that you can come back to in 6 months, and within 5 minutes understand enough to change it, if necessary. This has a for-loop over a sorted list comprehension, with embedded if-then-else, of a zip of two sorted json queries, with a lambda thrown in ...


3

Your getCount() method is a little difficult to read, on one long line like that, and way too complicated. s.count(_ == 'a') is both concise and efficient. It's not clear why the number of s repetitions possible in n is called duplicate. It seems an odd choice for that variable name. Your algorithm is sound, I just find it excessively verbose, especially ...


3

Is the graphic representation of a data structure an integral part of that data structure (val gString = myGrid.asText) or separate and independent from the data structure (val gString = asText(myGrid))? I tend to favor the former, but if the Grid API is solid and supplies everything needed for one or more graphic representations, then the latter is ...


2

The simple way of avoiding needing to define a named function like double_increment is just to use a lambda. You could simply write d3.select('#inc').on('click', () => { incrementer1.increment(); incrementer2.increment(); }); You could also get fancy and loop through the incrementers too var incrementors = [incrementer1, ...


2

I would move the story/writing out of the python script and into a text file. Even better, I would put it into some JSON compliant format. This isn't the only way to do this, but this is what I came up with just now: A given JSON object describes a single scene/event. Each possible event has a unique ID, and has a list of possible transitions (certain user ...


2

Here are some suggestions. This answers uses the Range-v3 library and assumes #include <range/v3/all.hpp> namespace view = ranges::view; Please include the #includes and supply a small test program in the future. You probably have written them anyway, so why not post them to save reviewers' time? :) int may be too small for indexes. Consider ...


2

Your counter is a cumulative sum of elevation changes; elevation would be a more precise name for it. Ultimately, the goal is to count the number of times the elevation changes from -1 to 0. To do that: Translate the 'U' and 'D' steps into +1 and -1, respectively. Obtain a sequence representing the elevation profile of the hike using Seq.scan. Count the ...


2

There's nothing wrong with or "not functional" about your approach. This might be opinion territory, but personally I would consider using foldLeft as it might be more readable and you can potentially eliminate some of the complexity of your cases. (also I got rid of n here as it is completely irrelevant, I know it's a problem from a website so you have to ...


2

Your code isn't functional, neither in the sense of working properly, nor in the sense of respecting the principles of functional programming. To parse a file, you need a way to consume the file. How would you do it with your function? csvStringView fh = readFile(filepath.csv); csvToken tok = csvFirstMatch(fh); // ??? You could imagine to compute a new ...


1

Overall a solid approach. Here's a few options to consider though: First of all, you could eliminate the separate curry function and just use the generateCurry function directly, after all, it's already curried itself ;) An approach that's maybe a bit more in line with Luas metaprogramming philosophy would be to replace your memoized function with a table ...


1

A small observation on the includes and namespaces: We have #include <cstddef>, but then use size_t in the global namespace, which is not portable according to the standard. We should be using std::size_t instead. In the other file, we include the C compatibility header <string.h> - prefer to include <cstring> in new code, so that the ...


1

First of all: the code does not work, so this is not the appropiate place for your question (code review is to improve code which works). Having said that, I proceed to give you some help (next time, ask your question where appropiate). card1 and card2 are taking values which are not numbers (look at what face_value() has as an output; it only prints ...


1

Since this is Code Review, and not Stack Overflow where you'd just want an answer... first a couple comments on your code: First off, this is not a monad with 4 shapes. This is a monad with 6 shapes. "maybe with" indicates you have more than one shape. This is a lot of shapes to keep track of with a single class. The data class is really: Maybe<OneOf<...


1

I don't really see anything that jumps out as an obvious simplification. I looked online for other code for this task and only found one in python which uses the same basic algorithm. The only suggestion I have is for readability, the name match in the functional solution might be slightly confusing for anyone reading the code. Perhaps a more appropriate ...


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