Hot answers tagged

36 votes

Car crash reaction time

Some of the numbers might seem plucked out of thin air but they aren't Still better have them explained. I can understand 3.6 and even ...
vnp's user avatar
  • 55.5k
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
22 votes
Accepted

Planetary simulation in python

Use a vector type to store positions, velocities and forces Instead of writing out all the calculations for the x and y direction separately, consider using a library that provides you with vector ...
G. Sliepen's user avatar
  • 49.3k
18 votes

Car crash reaction time

I suggest breaking the code into functions, so you can easily import your code into a Python shell and test that your computation is exact (and not just thinking it ...
301_Moved_Permanently's user avatar
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

Celebratory fireworks animation

(I know I'm quite late to celebrate...anyway) I wanted the firework to sparkle, so I created a Color object. When the firework is "old enough", the particles ...
oliverpool's user avatar
  • 1,902
13 votes

Car crash reaction time

It crashes if user input for speed_ms is not integer If user presses any key before t = input("GO!! ") his reaction time is ...
Lau's user avatar
  • 231
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 ...
Attilio's user avatar
  • 1,645
12 votes

Car crash reaction time

If it's wet, the friction_coefficient will be lower. Which means that Bd will be lower (which is probably wrong). It's ...
Reinstate Monica's user avatar
12 votes

Car crash reaction time

player_1 is read and assigned but never used. If the user misspells wet (e.g. as Wet or as <...
Toby Speight's user avatar
11 votes
Accepted

Visual solution of the Newtonial differential equation with Python

This is pretty good work for a self-taught programmer. I'd like to make a few suggestions to improve readability. First, I would define a 2D vector class. That would allow you to simplify ...
200_success's user avatar
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
11 votes
Accepted

Simulation of a falling ball

using namespace std; is a bad habit to get into, as it can lead to name-collisions and other issues. It's best to explicitly qualify the names we need where ...
user673679's user avatar
  • 11.4k
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
  • 32.9k
10 votes

Complex scientific formula for nuclear magnetic resonance

I would consider the practice ok in this case. Your variable try appear to be roughly the "ASCII" equivalent of the ones used in the equation. You cite the paper where you got the equations from. (...
Dair's user avatar
  • 5,824
10 votes
Accepted

Metaballs and Gravity game;

Refactoring code structure As of right now, you have: A struct named Object. A global std::vector<Object> of ...
Ethan Bierlein'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

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
  • 49.3k
9 votes

Artillery game C++ practice project

I see a number of things that may help you improve your code. Don't abuse using namespace std Putting using namespace std at ...
Edward's user avatar
  • 65k
9 votes
Accepted

Calculating a table of deBroglie wavelengths for various electron energies

First, simplify: factor out \$C^4\$ out of square root: \$\lambda(E_k) = h\left/C\sqrt{(\frac{E_k}{C^2}+m_e)^2-m_e^2}\right.\$ Simplify even more: factor out \$m_e^2\$: \$\lambda(E_k) = h\left/C ...
vnp's user avatar
  • 55.5k
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.2k
9 votes

Planetary simulation in python

TL;DR: I created a Github project with everything I suggested and more (like taking all PyGame-related logic away from the Planet class, leaving it only with planet-related logic). Take a look at the ...
KiriSakow's user avatar
  • 191
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
  • 13.8k
8 votes

Kinematic Equations Calculator

This is pretty clever work for someone self taught! In my opinion, it's more work than is necessary, though. Your OrderedArray class looks like a cross between <...
user1118321's user avatar
  • 11.6k
8 votes
Accepted

Calculators for gas law equations

First things first: Do not use namespace std; This is bad style. Create a class to properly encapsulate your code and simplify passing of variables. I would suggest, that you use enumerations to ...
miscco's user avatar
  • 4,221
7 votes
Accepted

Golf game boilerplate

Some of this is nit-pickery, some is more fundamental: Import Order PEP-8 suggests an ordering to imports. No reason not to use it: Imports should be grouped in the following order: ...
aghast's user avatar
  • 12.2k
7 votes

Simple n-body class in C++

Use a vector math library Find a suitable library that implements coordinate vectors, so you don't have to implement them as arrays of doubles. Ideally your ...
G. Sliepen's user avatar
  • 49.3k

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