# Tag Info

### Print a hollow Rhombus

Imagine you know someone beginning Java three years after writing this. You show them the code presented: Can they easily find out from looking at the code what it is to do? Whether it is correct? Do ...

### Optimizing __getitem__ for a bioinformatics script in Python

new to the area and I've been learning while developing Great, welcome! Software is almost as interesting as biology. And it's much less messy. measurements much longer for larger files “When you ...

### Spatial radius search in Boid simulation

Nice problem! I gotta tell ya, QuadTrees is definitely the appropriate datastructure. And it's just not that hard. Let coord be the bit interleaving of ...

### Spatial radius search in Boid simulation

The slowness comes from drawing Your query() function is actually quite efficient. The problem comes from drawing the boids. If you remove the calls to ...

### Pentomino solver in Python

Kudos on tackling such an interesting problem! design of Public API ...

### Sum of all possible concatenations of array values

You can reduce the line count of Donald's answer to improve readability by: Removing the for loop with Array.reduce(), Using ...
1 vote

### Trailing Digits

finally I found a link with a lot of examples. I found trailingdigits.py with a much more elegant approach github.com/RussellDash332/kattis/blob/main/src/… and another webpage that shows more detail ...
1 vote
Accepted

### Given an array, remove zero or more elements to maximize the reduction where you add odd values and subtract even values

You could simply use this pattern: [greatest value, smallest value, greatest value, smallest value, ...] local maximum, local minimum, ... That means, go until ...

### Trailing Digits

Picture yourself coming back to "V1 code" a decade from now: You can read it, you can run it. Do you know what does, and to what end? Name things for what they are good for. ...

### Finding a distinct triplet where the sum of the values is divisible by a given number

Its possible to solve the problem in O(N + D*log(D)) time, using the Fast Fourier Transform (FFT). In a nutshell- reduce each value mod ...
1 vote

### Finding a distinct triplet where the sum of the values is divisible by a given number

I'd prefer divisible_triplets(integers, divisor). And it deserves a docstring. You state I want to count the number of … - I don't want to be caught telling people ...

### Finding a distinct triplet where the sum of the values is divisible by a given number

One of the weaknesses of the code is that we're actually finding every triple. We're not required to do so - the only thing that matters is the count of results. That means that we can group the ...

### Finding a distinct triplet where the sum of the values is divisible by a given number

We can preprocess the array by setting each a_i to a_i modulo d. We're asked for a sum of ...
1 vote

### Finding a distinct triplet where the sum of the values is divisible by a given number

One improvement might be derived from changing every array entry to its modulo 5 value: ...

### Python (API requests)

Here goes the new code following @J_H advices: Project structure ...

### Project Euler 60: Prime Pair Sets

Eliminate 2 and 5 from your sieve! Any 2+ digit prime cannot end in a 2 or a 5, as these will be multiples of ...
1 vote

### another Merge Sort

Code risks invoking undefined behavior: None of the calls to malloc() have their return values checked. ...
1 vote

### another Merge Sort

Is there any other good practices that I've missed to follow in my try? Sort stability Agree with @Martin York code has stable sort concerns. A stable sort keeps the array elements in the same order ...
Accepted

### another Merge Sort

Three things pop out to me: This is not a stable sort. Probably does not matter, as you currently only support integers. This only support integer sorts. If you look at the standard qsort you will ...
1 vote

### Python: Detect if a number is divisible by any number in a list

i is not divisible by a factor of step_size iff gcd(i, step_size) == 1. Otherwise, that gcd ...

### Python: Detect if a number is divisible by any number in a list

natural log I'm unhappy with this expression: prime_count = ... len(str(number)) // 3 Since the length computes log10(), and <...
Accepted

### Python (API requests)

In a pathname like logs/err-logs.log, the -logs suffix seems redudnant. one level down Based on ...
Accepted

### Distance on a unit grid

min_x = min(abs(x1 - x2), dist_x = (x1 - x2) ** 2 We can see the border cross algorithm and the standard algorithm are ...

### Find the closest named color

Incorrect calculation of color distance sRGB is a logarithmic scale RGB (AKA sRGB) as used by the browser is a logarithmic scale (apart from the very darker values which are linear) Your calculation ...
Accepted

### Multi producer/consumer lock-free queue

This is not lock-free Unfortunately, your queue is not lock-free. Basically, your _canUpdate is used as a lock. Consider a thread that has taken the lock, so it's ...
1 vote

### Optimisation: Fastest way to multiply every number in an array by 2

Thanks to @harold the goal of getting under 50 ns was achieved with loop unrolling and removing the unnecessary copy instruction. The code below is similar to his but is bithacked and instead of using ...
1 vote

### Optimisation: Fastest way to multiply every number in an array by 2

A couple of further things we can do are: Use Vector256.StoreUnsafe for the store. It's not a huge deal, but going by the assembly, the ...
Accepted

### How to optimize the player movement code like in Tomb Of The Musk game?

In terms of performance what I have done is removed unnecessary method calls and helped out your branch predictor by removing if/else statements. What I have mainly done though is to enhance code ...
1 vote

### Optimisation: Fastest way to multiply every number in an array by 2

After a suggestion by @harold a further 15ns has been shaved off by using the Vector.ShiftLeft(v, 1) method instead of doing the multiplication and secondly to use <...
1 vote

### Optimisation: Fastest way to multiply every number in an array by 2

Upon a suggestion from @iSR5 I have reimplemented the SIMD instruction using the MemoryMarshall method. This has shaved off a further 60ns. I think SIMD instructions and the memory marshall method go ...

### Optimisation: Fastest way to multiply every number in an array by 2

I have shaved off about 100ns with the following improvements: used a shift operator to perform the multiplication by 2, since I know that my Vector<int>.Count...
Accepted

### Convert 64-bit Gray code to integer

While it's not your code, I'll point out that the routine from OEIS can be significantly shortened by using an assignment expression, available since Python 3.8: ...

### Convert 64-bit Gray code to integer

I assume that your first example is depicted in human-legible (i.e. big-endian) order. The right-most digit is indeed then the least-significant digit. When you call ...