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 ...
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 ...
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 ...
8
votes
Accepted
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.
...
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 <...
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 ...
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:
...
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 ...
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 ...
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 ...
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, ...
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:
...
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 ...
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 ...
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'...
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 ...
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 ...
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 ...
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 ...
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 ...
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-...
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, ...
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 ...
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
<...
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 ...
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
...
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.
...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
string-processing × 29strings × 13
python × 10
java × 10
programming-challenge × 8
algorithm × 6
c++ × 5
compression × 4
c × 2
reinventing-the-wheel × 2
unit-testing × 2
bitwise × 2
c# × 1
python-3.x × 1
parsing × 1
.net × 1
hash-map × 1
console × 1
mathematics × 1
linux × 1
calculator × 1
networking × 1
c++20 × 1
library × 1
ai × 1