42
votes
Accepted
Prettify math formula in code
Let me quote the wonderful book Numerical Recipes in C++ (but also applicable):
We assume that you know enough never to evaluate a polynomial this way:
...
40
votes
Accepted
Benchmarking things in C#
Small issues before I get into the big one:
Please make those setters private. The caller of this code has no business changing any of those values.
Don't use ...
37
votes
Benchmarking things in C#
The problem with an approach like that is that you you don't take into account that switching processors/cores is taking some time which will fake the results. This can be avoided by setting the ...
34
votes
Accepted
Calculate mean, median, and mode in Rust
Learn to love rustfmt. For example, the Rust standard is 4-space indents.
Learn to love Clippy, which can show you the more idiomatic way to iterate over a collection:
...
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 ...
23
votes
Prettify math formula in code
As it turns out, a similar question was asked recently on Math.SE. Rather than reinventing-the-wheel, take advantage of built-in functionality in Python.
Your ...
22
votes
Standardly deviated Fibonacci
I have found a couple of things that could help you improve your code.
Don't abuse using namespace std
Putting ...
18
votes
Prettify math formula in code
I'll only address the so-called "magic numbers" that several reviewers have mentioned.
Sometimes, when you're working in pure mathematics, what seems at first glance to be a "magic number" really isn'...
16
votes
Prettify math formula in code
Instead of math.pow, use the builtin ** operator. You don't need the \s at EOL, because the ...
16
votes
Accepted
Shoe shine shop model in Rust
Correctness of the solution
On reflection, I'm not sure either the C++ or the Rust code solves the problem as stated. I'm not completely sure I understand the shoe shine shop model so I may be wrong. ...
15
votes
Prettify math formula in code
Not sure if this helps but you could easily define a function to evaluate the value of a polynom at a given position
...
15
votes
15
votes
Accepted
Find the most frequent integer in an array
Your original Python code translates line-for-line into C++11 as:
...
15
votes
Markov-chain sentence generator in Python
chooseNextWord distorts the probabilities.
For example, consider a list of 3 words with the inherent probabilities \$\frac{1}{3}\$, \$\frac{1}{3}\$, \$\frac{1}{3}\$...
14
votes
Benchmarking things in C#
You've got some pretty poor variable names there. For example, what's m2 supposed to mean?
I don't like the fact, that result generates itself. I would rather have ...
14
votes
Accepted
Simple average grade calculator
Bug
This calculation looks suspiciously buggy:
int tzm = ((double) avg * 3 + TEZA) / 4;
Why are you taking avg, which is ...
14
votes
Accepted
Calculate min, max, mean and median out of array
I see a number of things that may help you improve your program.
Don't violate const
The calculate_median routine takes a <...
13
votes
Chi Square Independence Test for Two Pandas DF columns
I would try to use existing pandas features where possible to keep this code minimal - this aids readability and reduces the possibility of bugs being introduced in complicated loop structures.
...
13
votes
13
votes
Accepted
Counting density of Python code
The docstrings are vague. Documentation needs to be precise and complete. It should answer questions like "what arguments should I pass?" and "what does it return?" For example, "go through the AST ...
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 ...
13
votes
Program to accept numbers, then calculate the mean, median, and range
On top of Thomas Ward answer, here is a short and important comment:
More beautiful functions
Your functions are performing some mathematical computations and handling the formatting to show the ...
12
votes
Accepted
Calculating and displaying score statistics using C# 6.0 features
I prefer to use explicit access modifiers -- it keeps everything uniform: you have internal int[][] JaggedArray so I'd make the others like ...
12
votes
Unbreakable average program
You are doing way too much work to validate the input; the Scanner already has a method for reading doubles: ...
12
votes
Unbreakable average program
Useless code
On the first line of code, I already saw a problem:
double[] nums = new double[4];
nums = inputHandler();
Why do you allocate an array for <...
12
votes
Median Calculator
Please name your variables appropriately. Single-letter variables are in most cases sub-optimal and make it needlessly hard for the you-in-six-weeks to figure out what it does.
I'm fairly sure your ...

Mast♦
- 12.7k
12
votes
Accepted
Algorithms to find statistical information of an array
Glaring Deficiencies
Let me venture here that your getMedian method is slower than your getMode method. Thanks to your ...
11
votes
Standardly deviated Fibonacci
Yes, the code's terrible and yes you've used overloading incorrectly, but it's hard for me to see how you were supposed to fill your project spec without using it incorrectly. Your lecturer must be ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
statistics × 366python × 136
performance × 73
c++ × 55
java × 50
beginner × 41
numpy × 38
r × 37
python-3.x × 34
algorithm × 20
pandas × 20
simulation × 20
random × 17
array × 16
csv × 15
c# × 14
javascript × 14
c × 13
c++11 × 13
data-visualization × 12
time-limit-exceeded × 11
object-oriented × 10
mathematics × 10
numerical-methods × 10
machine-learning × 9