Skip to main content
11 votes

A simple C++ function converting the environment variables in main() to an unordered_map

Idiomatic C++ It's hard to specify what idiomatic C++ is, but let's assume it's using a recent version of the standard and using best practices. With that in mind, there are several changes I would ...
G. Sliepen's user avatar
  • 69.5k
10 votes

Checking for string isomorphism in C++

namespace io::github::coderodde::string::utils { I know this is ported from a Java solution, but in C++ we don’t really use the “reversed domain name” notation for ...
indi's user avatar
  • 16.6k
8 votes
Accepted

A simple C++ function converting the environment variables in main() to an unordered_map

In addition to G. Sliepen's fine answer, I would recommend more use of auto for the return type of the function. Using auto in ...
Toby Speight's user avatar
  • 88.7k
8 votes
Accepted

Multiplying two large numbers whose digits you have in a string, in AEC compiled to WebAssembly

...
user555045's user avatar
  • 12.6k
8 votes
Accepted

A simple method for compressing white space in text (Java)

Simplicity It strikes me that the simplest method to do this is to leverage the standard library. You will want to learn how to use regular expressions. Your effort will be rewarded. ...
Chris's user avatar
  • 6,126
7 votes

A View over java.lang.String - improved take II

grow / shrink / shift There's no need to construct a new StringView instance if any of these methods receives zero as an argument. Add guard clauses returning <...
Alexander Ivanchenko's user avatar
7 votes

Checking for string isomorphism in C++

For a more modern C++ take, I think we'd likely replace your for loop indexing over indices with a range-based for loop that zips together the two views, and then destructures them into ...
Chris's user avatar
  • 6,126
7 votes

Substitute patterns with values from lists

I would prefer to take Iterable[tuple[str, Iterable[str]]] rather than dict[str, list[str]] for two reasons: ...
Peilonrayz's user avatar
  • 44.6k
6 votes

A View over java.lang.String

Just two observations from me: I don't understand why toString() works a character at a time, rather than simply returning ...
Toby Speight's user avatar
  • 88.7k
6 votes
Accepted

A simple method for compressing white space in text (Java) - Take II

For exhaustiveness, I'd probably suggest your test if loIndex equals hiIndex should test to see if the former is greater than or ...
Chris's user avatar
  • 6,126
6 votes

Substitute patterns with values from lists

Tests It's nice to see that you have included various tests to verify that replace_in_string works as expected. Docstring Its great that you have provided a ...
Booboo's user avatar
  • 4,101
5 votes

Converting a char string to wchar_t string based on a given toWideStr() starting point

Consider using std::string_view for the input parameter You are passing the input string as a const std::string&. However, ...
G. Sliepen's user avatar
  • 69.5k
5 votes
Accepted

A View over java.lang.String

Mutability / Lack of Functionality Despite StringView being a cheap to instantiate thin wrapper, this class is not attractive to use. Reasons: ...
Alexander Ivanchenko's user avatar
5 votes

Advent of Code 2023 - Day 19: Aplenty (Part 1)

The current code has many positive qualities. It is well organized. It decomposes the problem into smaller parts. The variables and functions have clear names. And so forth. The paragraph parsing is ...
FMc's user avatar
  • 13.1k
5 votes

Z-Function/ Algorithms on strings. C++

Without looking at the algorithm itself, there are a couple of things in the program that are redundant or wasteful. I will just do a review for that low-hanging fruit, and leave a review of the ...
indi's user avatar
  • 16.6k
5 votes

A simple method for compressing white space in text (Java) - Take II

Readable. (A big plus in my book.) Verbose. I find what benefits I see unconvincing. (Given the ease of copies, the typo // Scan empty suffix is any: is strange.) I'...
greybeard's user avatar
  • 7,819
4 votes
Accepted

Advent of Code 2023 - Day 6: Wait For It

Part 1 You ask what might be done differently. In function total_possibilities I would probably replace the use of the enumerate ...
Booboo's user avatar
  • 4,101
4 votes
Accepted

LKM: Extract cpu model name from /proc/cpuinfo

get_cpu_model_name() should define a string constant for "N/A" which can be used by both it and its consumers. There ...
J_H's user avatar
  • 43.3k
4 votes

Funny time with DNA: a \$k\$-mer index data structure in Java

I like how direct this is: generate a string, cut into k-mers, and index them. While scanning the code, I spotted a few places where the Java details could be tightened up. Use ...
Yuliia Baranetska's user avatar
4 votes

Checking for string isomorphism in C++

The problem statement There's no definition of what it means for two strings to be "isomorphic" (not in comments, nor even the review request itself), so readers have to deduce which meaning ...
Toby Speight's user avatar
  • 88.7k
4 votes

Substitute patterns with values from lists

Given that the problem states enough replacement values must be provided to the function, it would seem reasonable to catch that IndexError and raise a ...
Chris's user avatar
  • 6,126
3 votes
Accepted

C++ arithmetic calculator built without resorting to tree structure as conventionally done, but by parsing input string and then std::stoi

There are quite some issues with this code. Apart from the fact that string manipulation is best avoided as much as possible, the code looks quite unreadable; it's dense and there's lots of almost-but-...
G. Sliepen's user avatar
  • 69.5k
3 votes

A View over java.lang.String - improved take II

There are only two hard things in computer science: concurrency and getting programmers to pay attention to naming things. Naming is really simple. You look at what the component you are naming does, ...
TorbenPutkonen's user avatar
3 votes

A simple C++ function converting the environment variables in main() to an unordered_map

Structured binding One point not raised by previous reviews: the code would be cleaner using a structured binding in your loop over the map contents. As well as making the key and value ...
Chris's user avatar
  • 6,126
3 votes
Accepted

Z-Function/ Algorithms on strings. C++

Instead of doing the one by one addition, we shall calculate cumulative sums. Let vector<int> freqs(s.length(), 0) be the frequencies of the prefixes lengths <...
panik's user avatar
  • 618
3 votes

Advent of Code 2023 - Day 19: Aplenty (Part 1)

Let me add to the FMc's answer and address your specific questions: How Can I Simplify Parse Parts? Your function read_items could be improved. You are establishing ...
Booboo's user avatar
  • 4,101
3 votes

Advent of Code 2023 - Day 4: Scratchcards

Nice shebang! I like how it obeys $PATH, which is good for {venv, conda, poetry} environments. Also, typer FTW! list types ...
J_H's user avatar
  • 43.3k
3 votes
Accepted

Advent of Code 2023 day 1: Trebuchet (Part 1 and 2) Follow-up

Since Part 2 is mostly a superset of Part 1, I'll just review that. ...
Toby Speight's user avatar
  • 88.7k
3 votes

Advent of Code 2023 day 1: Trebuchet (Part 1 and 2) Follow-up

General Observations While it is interesting to see your thoughts in the code, if you are using a version control system such as Git there is no reason to comment out code, you can go back to an ...
pacmaninbw's user avatar
  • 26.2k
3 votes
Accepted

Advent of Code 2023 - Day 5: If You Give A Seed A Fertilizer (Part 1)

Algorithmically your code looks fine and there is nothing that has to be changed. There are a few changes I would suggest that could slightly improve performance or be more Pythonic. There are ...
Booboo's user avatar
  • 4,101

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