34 votes
Accepted

Designing a coffee machine

I have since been informed that the team was hoping for "A more OO design"...felt like I took it in that direction, personally. All the methods in your DrinkMachine...
29 votes
Accepted

Simple n-body class in C++

The Great! You're not making the basic beginner error of using using namespace std;! The main() function is only 3 lines of code....
  • 19.5k
28 votes
Accepted

C++ Coin flip simulator and data collector

There's a lot that can be improved here, so I hope that these suggestions are useful to you. Don't abuse using namespace std Putting ...
  • 64.6k
24 votes

Designing a coffee machine

First of all, I'm sorry that you didn't get the job. Better luck next time :) Overall, I don't think your code is bad. But I do have a couple of points: OOP My main complaint would be that you are ...
  • 24.9k
21 votes
Accepted

Benchmarks of various scientific programming languages for theoretical modelling

I started with the Julia code you had and also got ~20 seconds, so I think my timings are similar to yours. Let me give a step by step breakdown on how to do this. To start, notice that if you are ...
19 votes

Designing a coffee machine

I agree with their assessment that the OOP design could be improved. In particular, the way you initialize the data is cumbersome, and I object to the necessity of calling ...
16 votes
Accepted

Monty Hall implementation

Available doors Why is this a stand-alone function? Why are door identifiers hard-coded here? The MontyHallBox knows what the doors are, and what they are called:...
  • 32.2k
15 votes

Brute Force N Body Implementation in C++

Here are some observations that may help you improve your code. Make sure to #include all required headers This program calls ...
  • 64.6k
15 votes

Ising model simulation

There are many, many things wrong with your code; I'll list some, and then I advise you to fix as many of them as you can (and more) and then repost a new question with the revised code. First of all,...
  • 19.1k
15 votes

Simple n-body class in C++

First Of All You are doing a great job as a beginner. I have been programming for 10 years and my code for a long time was much, much less readable that what you have written. That said: What needs ...
14 votes

Premier League simulation

This looks good overall. For the code review, I'll start with general comments and then try to get into smaller details. Documentation Documentating the code looks like an easy task but doing it ...
  • 28.7k
13 votes
Accepted

WaTor Code in Java

Animal private int SIZE; Why do you start using uppercase here? It's no constant. ...
  • 13.4k
13 votes

Simulating a printer

There are several things I would do to increase readability of your code. The first would be to create methods that query some field. It will allow the code to be more human readable and self ...
  • 545
13 votes

Newton-Pepys, common birthdays and other probability simulations in Python 3

1. Design I think that using the @mean_of_experiments decorator is not the best approach to this problem: There might be cases where you want to run the ...
  • 49.3k
12 votes

Espresso Queue simulation

1. Failed requirements The program fails to implement the following details from the specification: The specification says, "Input parameters are ..." but these parameters as implemented as global ...
  • 49.3k
12 votes
Accepted

Souped-up random walk terrain generator

Extract repeated code into functions. Loading the tile images is the same operation with a different file name. ...
12 votes
Accepted

Solar System model

After reading the program, I think it is pretty good for start, but there is some room for further improvement. Small improvements Imports Consider importing specific classes, instead of using the ...
  • 1,645
12 votes

Premier League simulation

Very nice program for a beginner! Great attempt! Here are some points. Imports For multiple imports for the same module, you use , ...
11 votes

Designing a coffee machine

I believe your interviewer was looking for the usage of the decorator pattern. Atleast, I've seen almost the exact same problem description in a design pattern book I read. It's a very good read and ...
  • 1,450
11 votes
Accepted

ALOHA network simulation in Python

Lists of the same primitive elements Instead of this: ...
  • 110k
11 votes

C++ Coin flip simulator and data collector

The biggest issue with your code is, as you remarked, the use of global variables. Cosmetically, the code is quite readable, but there's still room for improvement: Try to keep line length under 100 ...
  • 1,530
11 votes

Simulates flipping a coin repeatedly and continues until however many consecutive heads are tossed

Loop Also i assume assigning -1 to i was an appropriate move as well because after a loop cycle it will iterate (i++) causing i to become 1 if I had not, resulting in one less loop. Well, that ...
  • 2,738
11 votes
Accepted

Simulating a two-body collision problem to find digits of Pi

First, this is an awesome video! Upvoted for that reason alone. :) If n=2, the program finishes within milliseconds, whereas for n=3, it takes a whopping 115 seconds. Do you know about big-O ...
  • 19.1k
10 votes
Accepted

Vehicle-crossing simulation

As mentioned in the comments, there's not much to review. Don't abuse using namespace std Putting using namespace std within ...
  • 64.6k
10 votes

90 year data simulation in need of performance increase

This cleanup code at the end is indicative of the problem with this program: clear i clear j clear k clear l clear m clear n clear o clear p Nobody is going to ...
10 votes

Souped-up random walk terrain generator

This is a short answer to your question about line 81. Instead of all the False, you can do this: ...
  • 9,414
10 votes

Monty Hall Paradox in Java

A few thoughts: Some of your lines are very long. While it may seem convenient that they fit on your screen, code gets more difficult to understand as lines become longer. Many people have good ...
  • 2,511
10 votes

Brute Force N Body Implementation in C++

All points by @Edvard are good. Here are a couple more. Encapsulation All your functions mutate a Particle structure. So why not just make this methods on your ...
  • 92.1k
10 votes

WaTor Code in Java

I'm not a Java expert, and I've only looked over this code a little bit, so I only have a few tips. Why are your moveDirection methods in the specific animal ...

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