39
votes
Accepted
Count all vowels in string
An alternative route is to use string.replace() and Regular Expressions to strip everything but the vowels from the string. Then count the length of the resulting ...
28
votes
Count all vowels in string
I'm just wondering if there's an easier way to solve this problem without the big blocky code in the if statement.
Well, you could put all of those in an array:
<...
25
votes
Accepted
Transcode UCS-4BE to UTF-8
Efficient file I/O
By default, files opened with fopen() are buffered, meaning that not every call to fread() or ...
24
votes
Dungeon Crawl game for the terminal
Overall, this is really well done. You've missed the usual traps of using magic numbers, not creating structures for related items, and other common things. So nice work! I think it could be improved ...
24
votes
Transcode UCS-4BE to UTF-8
log is already declared in <math.h>. You don't need to declare it yourself. In fact, it could be harmful.
As stated in ...
22
votes
Accepted
21
votes
Accepted
COBOL Database Program
ZOMG, that is frightening along so many dimensions.
Disclaimer: Within the last decade I wrote lots of python code to parse production COBOL database record formats. And as an undergraduate I had ...
20
votes
Accepted
Python code that sorts books
It looks good and readable IMHO. For brownie points, you could:
modify the structure a bit. Not every LinkedList will contain books. Similarly, not every ...
20
votes
Multiplying binary strings using divide and conquer in C++
Design review
Since you are interested in good coding design, I thought I’d give a little preamble to the actual review to discuss C++ design guidelines.
There are two key features of C++ that I ...
19
votes
Accepted
Customization of memory class C++
Try to be more consistent with naming
I'm seeing camelCase, PascalCase and snake_case all mixed together. Pick one style and stick with it. Furthermore, I see redundant things in names like ...
18
votes
Dungeon Crawl game for the terminal
That's an awesome little game!
User experience
Before we dive into the code, let's talk about the game itself.
Random hangs
Sometimes, the executable hangs when I ...
18
votes
Naïve RSA decryption in Python
Simple does not mean fast, so you cannot judge performance based on how simple the implementation looks. Usually the most efficient way to perform a non-trivial task is not also the simplest way to do ...
17
votes
Accepted
Huffman Code in C++
Looks pretty readable and I agree with most of your formatting however there are some things that stand out.
using namespace std;
Kick this habit before it kicks ...
16
votes
Accepted
Implementing a rectangle class
PEP-8
Class names should be CapWords, so instead of rectangle you should have Rectangle.
...
15
votes
Accepted
Phone Book Program in C++
There are a number of things that could be improved, and I hope you find this list of suggestions useful.
Don't abuse using namespace std
Putting ...
15
votes
Count the frequency of items in an array
Answer to the Performance Issue
Anytime there are a list of variables named NAMEi where i is an integer, there is a strong chance that a container such as std::array or std::vector should be used. ...
15
votes
Value store ("optional" type)
About these assignments
As someone who’s been teaching C++ for 15 holy shit, almost 20 years now, I have to say that these assignments are pretty terrible… especially the “vector” one. (To be clear, I ...
14
votes
Accepted
Checking for parentheses balance in C
Bugs
The loop header is wrong:
for(i=0;line[i]!=NULL;i++){
Here, you want to scan until you find a byte with ASCII value 0 (also called an ASCII NUL, and written ...
14
votes
Python code that sorts books
A little late here as I just got back in front of a non-mobile device, so let me try to add some new points:
Most importantly (with the caveat that I'm super pedantic), the format of this assignment ...
14
votes
Egg size Prompt Box
The parseInt(eggWeight); calls are not doing anything, because you are not using its return value. And since you aren't using the return value, the comparisons are ...
13
votes
Checking for parentheses balance in C
The idea is correct, the implementation is not.
Upon exiting the loop you need to test for pilepointer == -1. Otherwise, the strings like ...
13
votes
Transcode UCS-4BE to UTF-8
This program reads 4 byte codepoints (in BIG ENDIAN) from a file strictly called "input.data" and creates another file called "ENCODED.data" with the relative encoding in UTF8.
Needless to say, ...
13
votes
Egg size Prompt Box
Since you already checked > 69 , if you get to the next else if you don't need to check that it is ...
13
votes
Accepted
Toggle 2 LEDs using a timer XMEGA-A3BU Xplained
The optimizer has a habit of optimizing out my timing loops.
This is (a) a non-surprise, and (b) somewhat of a red flag when it comes to coding practice. If you're writing timing loops that attempt ...
12
votes
Accepted
A Date Class with simple methods
What's in the public interface?
Most of the public interface looks reasonable, except it's not obvious what Date::magic() means to a user - I think that's more ...
12
votes
Accepted
Array Stutter Implementation
By reviewing your code, the first thing that comes to my mind is a lot of if statements. You should try and keep those minimal by writing solutions to be as general ...
12
votes
Accepted
Function that returns a sequence of numbers [x: sqrt(x_(n-1)^3)] given a start value and a max value
Instead of using comments to describe the function, use a doc string. This can then be used by tools, unlike comments.
...
11
votes
Checking for parentheses balance in C
Here are some things that may help you improve your code.
Don't use gets
Using gets is not good practice because it can lead ...
11
votes
Accepted
C++ code to read, sort, and write data
Your code doesn't seem to work. However, let's break down just the sort routine, since that's what you seem to think is the bottleneck.
using namespace std;
Get ...
10
votes
Accepted
'Snakes and Ladders' game
First of all: "Lines of Code" doesn't mean a thing if it is unreadable code.
Dry
The don't repeat yourself principle, (which also handily removes duplicate lines and therefore greatly reduces LoC)
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
homework × 567java × 174
beginner × 127
c++ × 110
python × 96
c × 94
algorithm × 48
performance × 46
python-3.x × 35
object-oriented × 34
strings × 32
array × 27
game × 27
c# × 22
javascript × 17
c++11 × 16
sorting × 15
linked-list × 15
haskell × 14
reinventing-the-wheel × 14
calculator × 14
finance × 14
file × 13
datetime × 11
hash-map × 10