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....
pacmaninbw's user avatar
  • 23.8k
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 ...
Edward's user avatar
  • 66.4k
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 ...
Chris Rackauckas's user avatar
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:...
AJNeufeld's user avatar
  • 33.4k
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,...
Quuxplusone's user avatar
  • 19.3k
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 ...
Marc Olberding's user avatar
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 ...
SylvainD's user avatar
  • 29.2k
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 ...
yitzih's user avatar
  • 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 ...
Gareth Rees's user avatar
  • 49.6k
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 , ...
Abdur-Rahmaan Janhangeer's user avatar
11 votes
Accepted

ALOHA network simulation in Python

Lists of the same primitive elements Instead of this: ...
janos's user avatar
  • 111k
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 ...
kyrill's user avatar
  • 1,570
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 ...
BenC's user avatar
  • 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 ...
Quuxplusone's user avatar
  • 19.3k
10 votes

Simulating a printer

One little thing you can do is related to methods like ...
DrOliver's user avatar
  • 101
10 votes

"Do I understand the gravity of the situation?"

I spent quite some time looking at this: High Level I love what you did here, a great showcase of using JavaScript in a powerful way. But from a readability and maintainability perspective, this ...
konijn's user avatar
  • 33.1k
10 votes

Monty hall python simulation

Two things stick out to me: First, Python has an official style-guide, PEP8. It recommends consistently using 4 spaces as indentation (you use a mix of two and four). It also recommends using ...
Graipher's user avatar
  • 40.9k
10 votes
Accepted

C++ Beginner Bunny Exercise

Includes I figured your std_lib_facilities.h has some includes for vector, list, ...
Sebastian Stern's user avatar
10 votes
Accepted

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

for loop I find both, your solution and the approach of @BenC difficult to understand. I'd suggest to use a while loop instead: ...
Timothy Truckle's user avatar
10 votes
Accepted

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

functools.wraps Unrelated to your main question, I advice you to use functools.wraps. This way, your methods metadata get ...
Maarten Fabré's user avatar
10 votes

Ising model simulation

I'll build off of Quuxplusone's answer. You have issues with tab. int tab[N]; tab[0] = N-1; tab[N+1] = 0; // out of bounds ...
kmdreko's user avatar
  • 271
10 votes
Accepted

Razzle Dazzle simulator

First, your use of camelCase isn't ideal in Python. For variable and function names, snake_case is preferred. I'll be using that with any re-written code that I show. I think ...
Carcigenicate's user avatar
10 votes

Simple n-body class in C++

Your code is written in a hybrid C/C++ style. For instance your destructor has a delete (I can't find where the corresponding new...
Victor Eijkhout's user avatar
10 votes

Simple n-body class in C++

In addition to the other answers: Use unsigned integer type for DIM, Nbody.step, and Nbody.n...
eanmos's user avatar
  • 395
10 votes

High performance physics simulation - core class design

Missing #includes You are using std::vector, but did not #include <vector>. The code ...
G. Sliepen's user avatar
  • 54.2k
9 votes

Doodlebug vs. ant population simulation

Do not use namespace std; This is a bad habit, that might bring you into trouble. You might want to search for it. Avoid magic numbers For example your board size is 20. And all over the code there ...
miscco's user avatar
  • 4,241
9 votes
Accepted

Doodlebug vs. ant population simulation

I see some things that may help you improve your program. Don't abuse using namespace std Putting using namespace std at the ...
Edward's user avatar
  • 66.4k
9 votes
Accepted

Simulate round-robin tournament draw

Making the code testable and tested The first step to improve your code is to try to make it testable. By doing so, you usually have to deal with Separation of Concerns: in your case, you have to ...
SylvainD's user avatar
  • 29.2k
9 votes

Simple n-body class in C++

In addition to the other answers: The init_data function does not belong in the Nbody class. Nowhere in the definition of the N-...
Roland Illig's user avatar
  • 21.3k
9 votes
Accepted

Molecular simulation: Minimum Image Convention

periodic_boundary_int = 5 # size of the periodic box in A temperature_float = 2 # temperature of the simulation Thank you for the first comment, that's lovely, ...
J_H's user avatar
  • 22.3k

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