The 2024 Developer Survey results are live! See the results

# Tag Info

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: ...
• 8,658
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 ...
• 66.5k
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. ...
• 1,064
Accepted

### Find the most frequent integer in an array

Your original Python code translates line-for-line into C++11 as: ...
• 19.4k

### 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}$...
• 56.9k
Accepted

Bug This calculation looks suspiciously buggy: int tzm = ((double) avg * 3 + TEZA) / 4; Why are you taking avg, which is ...
• 144k
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 <...
• 66.5k
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 ...
• 49.6k

### 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 ...
• 49.6k

### 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 ...
• 29.2k

### 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 ...
• 13.4k
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 ...
• 2,311

### 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 ...
• 1,570

### 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. ...

### 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 ...

Initialize variables Both sum and avg can be declared and initialized later: ...
• 19.3k
Accepted

• 9,130
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 ...
• 2,518

### 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 ...
• 24k

### 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 ...
• 3,095

### 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: ...
• 43.4k
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 ...
• 2,562
Accepted

### Compute mean and variance, incrementally

The loop while (first != last) *this += *first++; is std::accumulate. ...
• 56.9k

### 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 ...
• 333

### Calculate the median value of combining two sorted lists

Assuming that nums1 and nums2 are each already sorted, nums1.extend(nums2) nums1.sort() ...
• 144k

### Find the most frequent integer in an array

If you want to go python like we can compress it a bit more. The std::accumulate() function is designed to run over a container and collect information. Normally ...
• 95.5k

### Find the most frequent integer in an array

Here are some things that may help you improve your code. Use the required #includes The code uses std::make_pair which means ...
• 66.5k

### Counting density of Python code

Great job overall, the code looks quite clean. There are only few things that I would mention: you can calculate count using ...
• 17.3k

### Computing mean and median

I have a confusion about this temps[temps.size()/2] when temps.size() is an odd number. How does the "vector::operator[]" handle ...
• 6,148