155
votes
Accepted
152
votes
Accepted
Disproving Euler proposition by brute force in C
Note: At some point, this review drifted into the realm of assembler and GMP. An actual review is at the end of this post, whereas the first section discusses the runtime-problems concerning ...
81
votes
Accepted
Message decoder
That's not a bad program, despite the number of suggestions I'm about to make. I do recognize you're a learner, and a young learner at that.
There are several levels at which we can analyze this ...
79
votes
Disproving Euler proposition by brute force in C
Well let's start with this:
for (a = 1; a < 100000; a++) {
for (b = 1; b < 300000; b++) {
for (c = 1; c < 500000; c++) {
let's ignore ...
55
votes
Café in C++ program
Don't. Repeat. Yourself.
That's an essential principle. You repeat the "do you want XY" cycle over and over manually. That's not only error prone, but also hard to maintain. For example, let's say ...
53
votes
Accepted
FizzBuzz in Javascript
I'd like to see if this is a reasonable solution, or is just plain terrible.
I wouldn't say it is "terrible" - mostly because it works and doesn't appear to be very inefficient. However, ...
52
votes
A simple mastermind clone
This is sophisticated for a first attempt, but today would be a great day to break yourself of bad habits. Your code is full of them.
Start with: format your code using standard formatting ...
51
votes
Accepted
Password checker in Python
Concept
Obligatory XKCD comic, before I begin:
Enforcing password strength by requiring human-unfriendly characters is no longer considered good practice. Nevertheless, I'll review the code as you ...
48
votes
Brainfuck interpreter written in C
This is a pretty reasonable start on a simple interpreter. Edward's suggestions are all good; a few additional suggestions:
interpret("+++++++++++++[->....
...
42
votes
Accepted
Project Euler Problem 45
Arithmetic
Project Euler questions are meant to educate you about both mathematics and programming. It would be a good idea to understand what these triangular, pentagonal, and hexagonal numbers ...
41
votes
Rock Paper Scissors. My first C++ program. Please judge harshly
It's not too terrible, especially for a first program, but there are a number of things that you might improve.
Decompose your program into functions
Almost all of the logic here is in ...
39
votes
Accepted
Find nth Fibonacci Number, using iteration and recursion
Why do most people (on the internet) recommend using recursion because it's simpler and easier to write the program? Logically I thought that we should write it in a way that is fast and simple.
This ...
36
votes
Accepted
Fishing simulator
Welcome to CodeReview. It's never too early to develop good coding habits, and reviewing your code is about the best way to do so.
First, congratulations on writing a clean, straightforward program. ...
35
votes
Basic Pokedex in C++
Just a few things that seem like they might be open to improvement.
Evolution
Rather than having a Boolean to indicate whether a particular type is the final step in its evolution, I think I'd have ...
33
votes
Disproving Euler proposition by brute force in C
All of the answers given (when this 'answer' was first written) ignore an important constraint: native types. In C, a long int is a 32-bit (or greater) signed type,...
33
votes
Accepted
Basic Java library to hold books
Naming
Java has a Naming Conventions that you currently don't follow.
int Capacity = 10;
int Volume = 0;
You should have : ...
33
votes
Verifying IPv6 addresses
Python has a philosophy of "Batteries Included". Don't reinvent what's in the standard library!
In particular, this code is much more easily written if we take advantage of ...
33
votes
Accepted
Implementing any_of in C++
The algorithm looks correct.
Regarding the function signature, I'd make three changes:
You're not modifying elements, so take it by constant reference rather than reference.
You don't need to ...
32
votes
Disproving Euler proposition by brute force in C
Some interesting things no one have mentioned about this, but it is an improvement when looking for the smallest solution:
If the \$\gcd(a,b,c) \neq 1\$ then \$a^4\$,\$b^4\$,\$c^4\$ and \$d^4\$ are ...
32
votes
Disproving Euler proposition by brute force in C
I'm not able to comment on vnp's solution, but vnp was right the first time: you can brute force it in \$O(n^2\log(n))\$ time and \$O(n)\$ space. You don't need \$O(n^2)\$ space because you don't have ...
32
votes
Accepted
Project Euler Problem #4 - Palindromic number
The other answers are all giving you different ways to reorganize your loops. They're all not bad in their own way, but the better solution in C# is to not write any loops in the first place.
Your ...
32
votes
Tic Tac Toe console program
This is not bad for a programmer as new to C++ as you have said you are. Keep up the good work! With that said, here are some ideas on how you might be able to improve your program.
Don't abuse <...
31
votes
Accepted
Print 10 × 10 square of X and O characters, split diagonally
Lots of answers already, but most of them seem to be about alternative solutions. I'll review your code on the details and show you how to refactor your code step by step. (This is a long answer, link ...
31
votes
A counterexample in balanced parentheses
May I suggest a simpler solution:
You need only a counter. it is incremented by 1 whenever you encounter an openning parenthesis "(" and is decreased by 1 whenever you encounter a closing parenthesis ...
31
votes
Accepted
"Compliment giver" mini-program
Don't be discouraged by how much I have written. I'm a professional software developer and my colleagues make fun of me because of how pedantic my code reviews are. I think what you've done is ...
30
votes
Accepted
Yet another boring FizzBuzz
Coming from Python world, I was tempted to create a separate method named fizzBuzz() which I then called in my main() method. Is ...
30
votes
Perl CGI script to serve a PDF file
I will go through your code line by line and give feedback. We will skip the general advice on don't use CGI as it's actually suited for what you are trying to do here.
I wrote this answer in two ...
30
votes
A first "Hangman" game in Python
You define a clear_screen function, but then at the top you have
...
30
votes
Accepted
A Caesar cipher in Python3
You say you're new to Python. Well, that's ok. And a Caeser Cipher is a good place to start since it's complex enough for an absolute beginner while easy enough to understand what goes on, why and ...
Mast♦
- 13.4k
30
votes
Providing advice based on user's favourite YouTuber
I've heard of dictionary lookups but I don't really understand what they are so if anyone thinks that they maybe relevant and could show me how to implement it that would be great!
Here you go!
Use ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
beginner × 7556python × 1991
java × 1033
c++ × 899
python-3.x × 823
javascript × 685
performance × 623
c# × 565
c × 564
object-oriented × 476
programming-challenge × 430
game × 430
strings × 326
algorithm × 305
php × 237
calculator × 214
rust × 207
tic-tac-toe × 201
haskell × 198
html × 195
console × 184
array × 180
jquery × 175
ruby × 161
python-2.x × 148