Tagged Questions
Performance is a subset of Optimization: performance is the goal when you want the execution time of your program or routine to be optimal.
4
votes
1answer
18 views
Broken keyboard challenge
Inspired by Reddit r/dailyprogrammer
Help! My keyboard is broken, only a few keys work any more. If I tell you what keys work, can you tell me what words I can write?
The program works fine, ...
0
votes
0answers
6 views
6
votes
0answers
35 views
Create edges from cells
I have a (large) number of nodes and (triangular) cells, e.g.,
cells_nodes = [
[0, 3, 1],
[0, 2, 3]
]
This example represents the small mesh
(...
-1
votes
0answers
30 views
Find the possible mathematic expressions from the given integers to evaluate a value
How can I decompose this code into multiple threads so that it can run in parallel and enhance the efficiency (speed)?
Can anyone suggest how I can use OpenMP here and where I can apply an OpenMP ...
0
votes
2answers
70 views
C++ XOR Function
This XOR function is costing my program too much time (specifically the conversions.)
How can this code be made faster?
...
2
votes
0answers
38 views
In-memory B-Tree
I know B-Trees are meant to be used for external memory, but I implement it to understand the algorithms involved in insertion and deletion. Also, I didn't use a vector because I was asked not to use ...
3
votes
1answer
38 views
Vampire number generator
Inspired by Reddit r/dailyprogrammer
A vampire number v is a number v=xy with an even number n of digits formed by multiplying a pair of n/2-digit numbers (where the digits are taken from the ...
3
votes
2answers
39 views
Distinct unordered pairs of an array which satisfy a condition
I came across the below problem in a coding challenge:
Let's define 2 functions, \$F(i)\$ and \$Val(i,j)\$, for an array \$A\$ of size \$N\$ as follows:
$$
\begin{align}
F(i) =& \sum_{j=i+1}^{N} ...
3
votes
1answer
63 views
Tetris random piece generator
I was inspired by this Reddit /r/dailyprogrammer challenge:
Contrary to popular belief, the tetromino pieces you are given in a game of Tetris are not randomly selected. Instead, all seven pieces ...
5
votes
1answer
69 views
Reversing a word or sentence
Was just wanting some general feedback on the below code regarding
1. Readability
2. Structure
3. Efficiency
...
3
votes
0answers
41 views
Recursive Breadth First Search Knights Tour
This program was written on Windows 7 using Visual Studio 2012 Professional. Some of the issues encountered may have been fixed or changed in a more recent version.
This is a quote from my second ...
0
votes
0answers
27 views
Palindromic prime search using the Sieve of Atkins
I am working on a project that deals with prime numbers and am currently looking for a way to make the function max_palprime() work faster and possibly simpler.
...
1
vote
3answers
62 views
Searching values of range X in range Y
This allows me to search each cell J4:J6525 in range K4:K6525. If it is found it will paste the values in Offset(0, 2) (column M).
I run it for files with more than 60000 lines, and sometimes much ...
3
votes
2answers
69 views
A String.prototype.diff() implementation (text diff)
I just had the idea to develop an algorithm to calculate and highlight the difference between two strings. I know that there are already some libraries to do the job but i just tried to make my own. I ...
5
votes
3answers
205 views
Finding the duplicate with an array with 1,000,000 integers between 1 and 1,000,000
I recently had an interview and got to phase 2 which is a coding assessment. One of the questions was:
Given an array with 1,000,000 integers between 1 and 1,000,000, one integer is in the array ...
1
vote
1answer
29 views
Solving for a seed value in R
I'm trying to reproduce a gbm model which was estimated without a set.seed value. To do so I need to determine what seed was ...
0
votes
0answers
32 views
4
votes
1answer
51 views
Custom Python 'Server Status Checker'
I've written a home-grown solution for checking the status of my servers. This is both an exercise for me in learning further about Python, but it's also critical to status-checking critical things ...
1
vote
1answer
63 views
Neural net in C++
I wrote a Matrix struct and a neural net that uses it. Why is this slow? Gprof blames Matrix::operator()(int, int) which I ...
0
votes
0answers
46 views
Fastest way for multiplying a matrix to a matrix [migrated]
Let A and B be n\$\times\$n matrices. In my code this multiplication takes one minute, is there any way or packages that can make this calculation faster?
I only found a command in R for a matrix by ...
2
votes
1answer
43 views
Copy sheet contents faster in Excel
I have code that opens a workbook and copies the sheet to the workbook running the code. I know activating is generally bad for speed but I can't figure out how to speed this up anymore. The data ...
2
votes
2answers
102 views
How do I write my multithreading code correctly so that it is faster than a single thread?
I have the following code that I am trying to optimize. I am running it on a Linux machine with 24 cores. So, I thought I could use multi threading to make it faster. But multi threading is some how ...
5
votes
3answers
120 views
Console RPG - show cycle optimization
I have this RPG game and this has elements such as the map, the monsters and the items. The monsters and the items are stored in Lists and every time I want to show ...
0
votes
4answers
140 views
Program to display array elements in the ascending order of number of factors each element has
Input:
1000 23 100 26 32
Output:
23 26 32 100 1000
Since 23 has '2' factors and 26 has '4' factors and 32 has '6' ...
2
votes
1answer
76 views
Prime number checker in Python 3 - follow-up
I have updated my code from the last time it got reviewed. If anyone has some more suggestions on how I can improve this and/or make it faster it would be appreciated!
...
3
votes
0answers
30 views
Animation for android ImageViews acting as game pieces
My question is about how to achieve a well-performing animation for a set of ImageViews, so that the foreground fades away and the background stays the same.
...
5
votes
1answer
81 views
Clustering nodes with Hamming distance < 3
I want to speed up the following code, which is from an algorithm class.
I get a list of 200000 nodes where every node is a tuple of the length of 24 where every item is either a 1 or 0.
These ...
7
votes
1answer
47 views
A CNN in Python WITHOUT frameworks
Here's some code that I've written for implementing a Convolutional Neural Network for recognising handwritten digits from the MNIST dataset over the last two days (after a lot of research into ...
5
votes
2answers
148 views
Unexpected Low FPS while drawing images
I am in the process of making a game, and during this endeavour, I have come across problems maintaining a good frames per second while drawing my sprites. When I draw my background image, my frames ...
7
votes
2answers
120 views
Mad Libs Generator
I created this Mad Libs generator, but I don't know how to get the value of the key "ans" into a format string tuple. I feel like it's not Pythonic and that it's very convoluted and over-complicated.
...
14
votes
2answers
244 views
Guitar Hero III Bot
I made a Guitar Hero III bot for PC. I was able to beat the song "Through the Fire and Flames" on Expert with the bot which can you see here.
If you watched the video, you can see that the bot misses ...
6
votes
3answers
184 views
+50
Flatten an array
I have got this interview question which has asked me to write a production level code which flattens the arbitrary nested array of arrays.
Code
...
4
votes
3answers
162 views
Find expressions equal to a given number using 15 integers with 4 operators
For example, given 15 integers
70, 75, 32, 4, 64, 98, 73, 52, 36, 88, 96, 58, 79, 39, 75
How can we obtain is 72?
4 operators can be used for the 15 integers to ...
2
votes
0answers
41 views
Low performance of HTTP request using Haskell wreq
The program makes HTTP requests (checks video stream status) and calls an external program.
...
12
votes
9answers
2k views
Given three numbers, find the second greatest of them
I've just coded this for my country's programming Olympiad. I want to know if this method is a good approach in terms of readability and performance. I would also like to know how to improve it.
Note:...
-1
votes
3answers
91 views
Shortest prime number generator we could come up with?
I worked with a friend on the following prime number generator. Our goal was to make it as short and as fast as possible. This is what we came up with:
...
2
votes
1answer
114 views
+50
PHP web crawler
I'm working on a "nice" crawler that start with one URL, and find the other URLs to process each page, a kind of "Google" crawler, to index pages.
I worked hard on this crawler to respect many points ...
3
votes
3answers
58 views
List(Of ) like operation in macro
NOTE: I previously asked this question in Stack Overflow and got pointed here.
I have a macro that I am trying to get running a little more quickly. The intent of the macro is to merge multiple files ...
6
votes
2answers
72 views
Crop black border of image using NumPy
Objective: Crop the image so only the number stays in the image
Problem: Slow Performance
I have code that crops an image.
The image pixels are 0 or 255. There are no values between.
The ...
5
votes
2answers
42 views
Splitting a CAN bus log in .asc format
I've written a quick script for a coworker to split a large CAN log into smaller chunks. (If you're not familiar with CAN, it's a communication protocol used by the ECUs in many cars.) I know where ...
4
votes
0answers
48 views
Knights Tour - Improved Refactored Recursive Breadth First Search for
This development and testing was done on a Dell M6400 Laptop (Intel Core 2 Duo) running Centos 7, g++ compiler, compiler switches -O3 -std=c++0x -D__cplusplus=201103L. (machine bought August 2009 with ...
4
votes
2answers
56 views
Cython: Weighted Random Choice
I have a Cython function the takes a list of weights/probabilities (double) and returns a random index into the list.
For example
...
5
votes
2answers
77 views
Function to check truth value of a specific statement
I want to check the truth of A + B - (A & B) == A | B for N-bit numbers. For example, here's a "truth" table for 2-bit numbers. (I know I'm taking liberty with ...
1
vote
1answer
50 views
Permutations part two
This is a follow up from this question. The goal is to make some function that can return the number of possible permutations with repetitions. As Gareth pointed out there is a nice formula for this ...
2
votes
1answer
48 views
Finding permutation from given lexicographical rank
I wrote the following little piece of Python code to take in some integer, and return a permutation that has that rank in the lexicographical ordering of permutations. While this works, I'm worried ...
0
votes
1answer
19 views
Assign values to a matrix based on the location of non-zero elements in another matrix
I have a matrix, A containing ones and zeros. I want to create a new matrix B where the non-zero elements are in the same ...
6
votes
2answers
95 views
Rectangle-segment collision detection
I am working with C++ and SDL, hoping to create a game later. I am implementing the collision detection between rectangles and segments.
I found this (NateS user's solution) about line-rectangle ...
0
votes
0answers
25 views
Dataframe helper in R
In order to have a "unified" (I realize how ambitious this actually is) syntax when working on dataframes, I wrote the following functions that is a general purpose dataframe set of tools in R.
...
6
votes
3answers
74 views
Loop through a unique combinations driven by choices
I am trying to optimize my code and make it as fast as it can be, I have researched as much as I can and am now asking the community for any tips because there are definitely people more experienced ...
0
votes
0answers
13 views
Add and merge 2D array items so no nested duplicates on the outer array
this.collisions is a 2D array containing a list of collisions that, when bodies collide, they should be added to it. Here's an example:
...