43 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: ...
Shepmaster's user avatar
  • 8,638
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 ...
Eric Lippert's user avatar
  • 14.9k
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 ...
Heslacher's user avatar
  • 50.4k
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
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. ...
trent's user avatar
  • 1,064
15 votes
Accepted

Find the most frequent integer in an array

Your original Python code translates line-for-line into C++11 as: ...
Quuxplusone's user avatar
  • 19.3k
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}\$...
vnp's user avatar
  • 56.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 ...
Nikita B's 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 ...
200_success's 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 <...
Edward's user avatar
  • 66.4k
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 ...
Gareth Rees's user avatar
  • 49.6k
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
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 ...
SylvainD's user avatar
  • 29.2k
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's user avatar
  • 13.4k
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 ...
Tamoghna Chowdhury's user avatar
11 votes

Calculate odds of winning (UK) Lottery jackpot

A quick note to start: Console.WriteLine(String.Format("the odds are 1/{0:n0}", totalWinOdds)); Is exactly the same as: ...
RobH's user avatar
  • 16.9k
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

Calculate min, max, mean and median out of array

Avoid overflow *left - *right can readily overflow. Use 2 compares instead. This common idiom is recognized by various compilers to emit efficient code. ...
chux - Reinstate Monica's user avatar
10 votes

Chi Square Independence Test for Two Pandas DF columns

Using pandas.crosstab, this can be done in a single step: pandas.crosstab(index=test_df['var1'],columns=test_df['var2']) It ...
Thameem Ansari's user avatar
10 votes

Simple average grade calculator

Initialize variables Both sum and avg can be declared and initialized later: ...
Zeta's user avatar
  • 19.3k
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
Accepted

Program to accept numbers, then calculate the mean, median, and range

Disclaimer: You asked me to be harsh, so I'm not holding back as much. I tried to though... Welcome to Code Review! Your python code has been put through my scrutiny and I have some concerns and ...
Thomas Ward's user avatar
  • 2,518
10 votes

Shoe shine shop model in Rust

Forgive me, I am unable to review the rust code because I do not know rust, I am only reviewing the c++ code.. Use System Defined Exit Codes Returning -1 as an ...
pacmaninbw's user avatar
  • 23.8k
9 votes

Median Calculator

Like @Mast mentioned already mentioned you should use proper variable named in your program. A good variable name makes the program so much easier to read, specially if you're reading it after couple ...
Ashwini Chaudhary's user avatar
9 votes

Median Calculator

If you're willing to upgrade to Python 3 you can do this with statistics.median. I'd recommend that you upgrade. And would make your code: ...
Peilonrayz's user avatar
  • 43.3k
9 votes
Accepted

A bag of numbers in C++ for constant time statistics queries - follow-up

Some general comments: If you compile with gcc, use -Wall -Wextra -pedantic (or every warning turned on, with extensions disabled) - As posted, your code generates ...
Rakete1111's user avatar
  • 2,562
9 votes
Accepted

Compute mean and variance, incrementally

The loop while (first != last) *this += *first++; is std::accumulate. ...
vnp's user avatar
  • 56.4k
9 votes

A probability distribution function, to be called repeatedly during numerical integration

This is a possible solution to harolds open point about exp in his answer. Note that exp(x+y) = exp(x) * exp(y) holds for any ...
BlameTheBits's user avatar
9 votes

Calculate the median value of combining two sorted lists

Assuming that nums1 and nums2 are each already sorted, nums1.extend(nums2) nums1.sort() ...
200_success's user avatar
8 votes
Accepted

Calculate odds of winning (UK) Lottery jackpot

Quick remarks: Don't abbreviate needlessly: di. Why assign totalBallsFactorialSum and ...
BCdotWEB's user avatar
  • 11.2k

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