Skip to main content

New answers tagged

4 votes
Accepted

Speed up searching for the lowest element that is not in the array

You present code for a typical "challenge" submission without ever spelling out the problem in the source code. What's more, you miss the opportunity to declare a suggestively named business ...
greybeard's user avatar
  • 6,519
4 votes
Accepted

A search function that searches for a contact inside a vector

Keeping in mind that it is impossible to give good answers, or a good review, without a clear context of what the code is for or how it is going to be used. A single member function—not even a full ...
indi's user avatar
  • 12k
11 votes
Accepted

Optimized data structure mapping finite set of integers to values in C++

Design review You are massively over-complicating the problem You call it a map, and you talk about using integers as keys. But… in reality, because your keys are small, you are just using indices. So ...
indi's user avatar
  • 12k
4 votes

Optimized data structure mapping finite set of integers to values in C++

range check There's no provision for validating key against N, not even in a debug build. ...
J_H's user avatar
  • 30.8k
9 votes

Beginner level password generator optimization

Security The documentation for the random module gives the following warning: Warning: The pseudo-random generators of this module should not be used for security ...
gazoh's user avatar
  • 3,359
13 votes
Accepted

Beginner level password generator optimization

Remarks: Bug: you have an extra letter sneaking in with for req in range(0, nr_letters + 1):, making your output longer than it should be. That should be ...
ggorlen's user avatar
  • 3,811
6 votes

Optimizing Pi Estimation Code

You can calculate Pi using numerical integration of the circular arc-segment centred at (0,0), from the point (radius, 0) to <...
MT0's user avatar
  • 1,009
3 votes

Reversing vowels in a string

All good things have already been said, alas. Perhaps a solution using numpy, where you can use arrays to select members of arrays. ...
Eman Yalpsid's user avatar
  • 1,499
3 votes

Optimizing Pi Estimation Code

on the pure optimization part you must precompute more while x**2 + y**2 <= rs: if (x*1.00001)**2 + (y*1.00001)**2 <= rs: can be faster if you precompute ...
folen gateis's user avatar
4 votes

Optimizing Pi Estimation Code

scientific notation effectively work out 100 trillion coordinates (radius of 10,000,000) Prefer to describe these numbers as \$10^{14}\$ and \$10^7\$, which immediately makes the "squared" ...
J_H's user avatar
  • 30.8k
3 votes

Reversing vowels in a string

The logic behind your function is this: Create a list of the vowels in the target string Reverse this list Iterate through the indices pointing to each character of the target string For each index, ...
Schmuddi's user avatar
  • 517
3 votes

Reversing vowels in a string

Benchmarks Highly likely this is from LeetCode, so I benchmarked our solutions there. Times from three submissions: ...
no comment's user avatar
1 vote

Reversing vowels in a string

I instantly thought about looping the characters in the string directly instead of looping by the index and also wanted to test just adding to a string instead of the conversion to and from a list. ...
Jan_B's user avatar
  • 127
0 votes

Reversing vowels in a string

The biggest problem with the code presented is that it does not document what it is to accomplish: See how your take and MatBailie's do a substitution based on the position in a/the sequence of vowels ...
greybeard's user avatar
  • 6,519
10 votes

Reversing vowels in a string

This is your mistake: if s[i] in v: Simply change that to if s[i].lower() in vowels:. Then it easily gets accepted where I ...
no comment's user avatar
7 votes

Reversing vowels in a string

You could convert vowels into a set for a slight improvement, since sets are quicker to check for a certain value than lists. For your second loop, you don't need ...
Simon Brahan's user avatar
10 votes

Reversing vowels in a string

A set is slightly faster when using in, and a comprehension is slightly faster than a loop with append() ...
MatBailie's user avatar
  • 200
2 votes

Implement Huffman code in C17

Be concise; be expressive Code is a recipe expressing a series of operations on data values to achieve a goal. It's ironic that this code whose purpose is to compress (and decompress) data should be ...
Fe2O3's user avatar
  • 1,459
3 votes
Accepted

String art program in Python using PyTorch

Strategies to speed up the code: Instead of computing all the lines in one large array, then picking one, you should compute one line at the time, and keep only the best one iteratively. Loops in ...
Cris Luengo's user avatar
  • 6,052
2 votes

Golang Optimize Unzipping FiIes

(It's going to be difficult to actually try this code, since it's not self-contained. Better to have either a single file that can be run directly, or link a repository that can be cloned and built as-...
ferada's user avatar
  • 11.1k
0 votes

A thread-safe performant Money Transfer API in Java

The approach is flawed from the start. An Account does not perform money transfers. Accounts are just data objects. A money transfer is done by a service, that ...
TorbenPutkonen's user avatar
3 votes

A thread-safe performant Money Transfer API in Java

This is not code where you should be remotely worried about the performance. Maximize readability until you have a tested, proven bottleneck. What happens when an external thread acquires and does not ...
Eric Stein's user avatar
  • 6,562
7 votes
Accepted

Implement Huffman code in C17

Valgrind reports no leaks or errors. Good job on that, and welcome to programming and C. To complement @user555045's nice answer, this review would be about the intricate details of the code, the ...
Harith's user avatar
  • 9,462
6 votes

Implement Huffman code in C17

This will be a somewhat higher-level review of the algorithms and approach to Huffman coding, I'll let other people worry about the intricate details of the code and the issues brought up in the ...
user555045's user avatar
  • 10.1k
1 vote

Project Euler 127 - abc-hits

Because c gets quite large, there is a small advantage to altering your short cut test to avoid a multiplication inside the loop on ...
Martin Brown's user avatar
1 vote
Accepted

CSV Data Plotting Program using CsvHelper in C#

Highlights : CSV_Processing should be ProcessCsvFile or ProcessFile. ...
iSR5's user avatar
  • 5,478
2 votes
Accepted

Srivastava multivariate Fox H function in MATLAB

Avoid Symbolic Math for Numerical Evaluations: Replace symbolic computations with MATLAB's numeric gamma function. Symbolic math should only be used for symbolic ...
138 Aspen's user avatar
  • 169
5 votes

Srivastava multivariate Fox H function in MATLAB

There are some obvious inefficiencies in the code that I can point out. The profiler shows that most time is spent doing symbolic math. You use symbolic math to compute the product of a series of ...
Cris Luengo's user avatar
  • 6,052
3 votes
Accepted

Project Euler 127 - abc-hits

Given that: \$GCD(a,b)=GCD(a,c)=GCD(b,c)=1\$ Since \$a\$, \$b\$ and \$c\$ have no common divisors then it also follows that: \$GCD(rad(a),rad(b))=GCD(rad(a),rad(c))=GCD(rad(b),rad(c))=1\$ And: \$rad(...
MT0's user avatar
  • 1,009
8 votes

Project Euler 127 - abc-hits

Possible Bug Whenever c is odd, for a in range(1, c // 2) misses an a, b combo. For example: ...
AJNeufeld's user avatar
  • 33.9k

Top 50 recent answers are included