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: ...
user avatar
  • 698
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 ...
user avatar
  • 14.6k
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 ...
user avatar
  • 50k
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: ...
user avatar
  • 8,308
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 ...
user avatar
  • 64.4k
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 ...
user avatar
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 ...
user avatar
  • 64.4k
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'...
user avatar
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 ...
user avatar
  • 416
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. ...
user avatar
  • 1,034
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 ...
user avatar
  • 28.7k
15 votes

Unbreakable average program

The program cannot be made totally unbreakable. ...
user avatar
  • 481
15 votes
Accepted

Find the most frequent integer in an array

Your original Python code translates line-for-line into C++11 as: ...
user avatar
  • 19.1k
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}\$...
user avatar
  • 53.4k
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 ...
user avatar
  • 13k
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 ...
user avatar
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 <...
user avatar
  • 64.4k
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. ...
user avatar
  • 131
13 votes

Unbreakable average program

...
user avatar
  • 19.1k
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 ...
user avatar
  • 49.2k
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 ...
user avatar
  • 49.2k
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 ...
user avatar
  • 28.7k
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 ...
user avatar
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: ...
user avatar
  • 13.2k
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 <...
user avatar
  • 28.4k
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 ...
user avatar
  • 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 ...
user avatar
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 ...
user avatar
  • 849
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 ...
user avatar
  • 1,530

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