Loops are a type of control flow structure, in which, a series of statements may be executed repeatedly until some condition is met.
0
votes
0answers
19 views
Speed up Pandas DataFrame expansion to include time-lagged information about events
Using pandas and Python 3, information about a simple timeseries data set is being processed. Within the span of .5 seconds, 3 names are being said. We record the onset of each utterance, the length ...
0
votes
0answers
14 views
Undefined variable outside a foreach loop [migrated]
I've written code that grabs google fonts and adds them as an HTML body class. The code works fine but in my IDE, I am getting an undefined variable message. I can see why as the variable is outside ...
5
votes
2answers
184 views
Applying different filters within loops
What I have is an outer loop which loops through a list of strings, followed by another loop which loops through a list of filters; and if the current column is the current filter in the list of ...
6
votes
2answers
185 views
Array from file
I have this code which is performed each time I click the 'show polygons' button. The problem is that it takes a few seconds to finish running through the code before actually drawing the polygons + ...
5
votes
1answer
68 views
Using Reddit API in R
I'm scraping some comments from Reddit using Reddit JSON API and R. Since the data does not have a flat structure, extracting it is a little tricky, but I've found a way.
To give you a flavour of ...
4
votes
3answers
363 views
More efficient loops to generate unpronounceable words
I wanted to write a function to generate only unpronounceable words. I realised afterwards that the same thing could probably be achieved by just taking out the vowels. Regardless, I feel that there ...
2
votes
2answers
52 views
Optimizing a particle filter weighted selection step
I have a vector with 10000 particles that I use in a Particle Filter. The problem is that it's taking too long to compute the weighted selection of the particles.
I want to use a vector of weights ...
2
votes
0answers
40 views
Pausing a SwingWorker with a Timer
I made a SwingWorker which is fetching tweets using the twitter4j API.
The twitter API will allow 180 queries every 15 minutes, and then throw an exception with ...
4
votes
3answers
199 views
More efficient and readable nested loop to compare keywords
I've created an algorithm which weighs the relevance of a list of articles against two lists of keywords that correlate to attributes of the article.
It works great and is super efficient... but it's ...
3
votes
1answer
61 views
Where is the bottleneck in my Cython code?
The profile tells me it took ~15s to run, but without telling me more.
...
7
votes
1answer
105 views
Incrementing letter-spacing of one line of text
I was asked to create a script which will increment the letter-spacing of one line of text, until its width matches that of the first line; for use in headline/subheadline text to maintain a block ...
6
votes
1answer
270 views
Sorting numbers into bins
I have two 2D arrays of doubles a and b. Both have two rows and different numbers of columns.
...
4
votes
2answers
68 views
Finding matching strings in a column
I have col D (in sheet1 called Students), col A (in Sheet2 called Students too) and col B ...
3
votes
1answer
40 views
Showing the domain of a URL
I have such a method which takes a URL, such as http://twitter.com/ttt or twitter.com/dasd, and should show its domain with http: http://twitter.com and name twitter
...
3
votes
2answers
73 views
While loop uses extra variables - can this be cleaned up?
A piece of my program allows the looping and incrementing of a targeted entity to be used in a while loop somewhere else. Here is a sample of the while loop:
...
5
votes
3answers
171 views
Assigning value to cells with Excel VBA
I have an Excel Worksheet consisting of two columns, one of which is filled with strings and the other of which is empty. I would like to use VBA to assign the value of the cells in the empty column ...
3
votes
1answer
113 views
Is this roulette selection extension method beautiful or disgusting?
So I just wrote the following extension method to do roulette selection on a generic list. I'm specifically unsure of the use of the while loop. Is this beautiful or a disgusting mess?
...
1
vote
6answers
134 views
Looping through an array of strings containing approximately 3 million lines of strings
I have a function that loops through an array of strings containing approximately 3 million lines of strings. My problem is this loop is running too slowly and I want to know how to make it faster.
...
5
votes
1answer
59 views
Periodically checking for internet connection
I have a SwingWorker which checks periodically for an internet connection and updates a jLabel accordingly.
...
6
votes
2answers
87 views
Basic Imitation of C# Enumerable in VBA - or any other static class
Since implementing static classes in VBA actually seems possible I came up with an idea to try to imitate C#' Enumerable class (well, to some extent...). This is ...
1
vote
2answers
308 views
Printing the sums of numbers from 1 to 10 with only 1 loop
The code below prints sum from 1 to 10:
1
1+2 =
1+2+3 =
1+2+3+4 =
......
1 + ... 10 = 55
...
2
votes
3answers
157 views
Foreach loop to generate HTML table with title in first cell of each row in PHP
I've used quite a lot of foreach loops to achieve this type of HTML table that has titles in the first cell of each row:
...
7
votes
3answers
390 views
Ticket management system
I am building a ticket management system for a state server we use at work. Back end is node.js with multiple front ends. I am rewriting my back end to be more maintainable as the scope grows.
For ...
5
votes
3answers
50 views
Faster way to group email-date pairs by date without many nested for loops?
Given list of pairs (email-date):
...
2
votes
1answer
123 views
6
votes
2answers
158 views
Improving performance for Codility max slice swap problem
Problem Description:
Find the maximum sum of a compact subsequence of array elements after
performing a single swap operation.
Solution:
...
3
votes
2answers
50 views
More efficient way to draw bufferedimage into another
For what I'm doing, I need to be able to draw a buffered image directly into a larger buffered image. I've searched around a little and still have failed to find a better way, but my current way is ...
3
votes
2answers
82 views
Multiple loops versus multiple stringbuilders
I've come across the following piece of code in a Razor view
...
7
votes
1answer
101 views
Perfect game loop
I've been working on development for an Android game, and this is the game loop I have so far:
...
5
votes
1answer
68 views
Efficiently matching IP addresses with a list of CIDRs
I am using Python3 to extract some information from a dictionary that contains 10k of CIDRs, but the running time is pretty long.
Here is my purpose: I have a dictionary of CIDRs (10000) and a list ...
5
votes
1answer
70 views
ListBox Update Handling
I have UserGroups for Users to be assigned to in a ListBox in HTML form. Items from listbox can be multi-selected or completely ...
2
votes
2answers
69 views
List of search results using Selenium
I have written the following code for looping through WebElements in Selenium.
Can someone please provide me with feedback on how to improve my code?
...
1
vote
2answers
54 views
Looking for matching names among two text files
I'm trying to enhance the execution speed of my below code. I am using only vanilla JavaScript. I would be willing to bring in additional libraries and plugins as long as they will enhance the overall ...
7
votes
3answers
123 views
Numerically stable sum of `double`s
It's known that if you naively sum up a collection of arbitrary floating-point numbers using any floating-point standard (e.g. floats or ...
2
votes
1answer
107 views
Sum the Multiples of 3 and 5
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below N.
...
5
votes
1answer
67 views
List files and download
The following code list all files in a folder and allows the user to download one of them. It is working but I think it could be done better.
Is there a way to reduce the number of forms to only one ...
7
votes
3answers
255 views
Compare string with wildcard string
I have the following function to compare a string with a wildcard string (containing ? and *), as C# doesn't seem to have a builtin function to do it.
...
2
votes
3answers
43 views
Is it possible to simplify two for loops and a foreach?
I'm writing a PHP function to collect data from different positions in an given array. I've done it as follows which gives me what I require.
...
0
votes
2answers
162 views
1
vote
2answers
373 views
The efficiency of looping over nested dictionaries in Python
How to make the following code more efficient?
...
1
vote
0answers
20 views
Editing Surfaces Removing Color
So I have recently tried to load an image and save it, but remove all of a certain color. I'm running the program and it is running really slow, is there a more efficient way to edit an image? My code ...
3
votes
2answers
66 views
Java Cross with characters
I managed to make a perfectly even cross with for loops.
I'm trying to make this cross easier to code. I have to keep it with ...
-2
votes
1answer
56 views
Optimizimg ugly if else loop in python [closed]
So, I`m getting some values from large nested dictionary.
s_copy['productStyleVariantSizeInfo']['sizeDimension2SizeOptions'] and f_copy['productStyleVariantSizeInfo']['sizeDimension2SizeOptions'] ...
3
votes
2answers
353 views
Check winner in a Tic Tac Toe game
I have the below code to check for a winner in a Tic Tac Toe game. I'm wondering if this is a good approach, and if there is a better way of doing this (maybe by monitoring the state of the board).
...
7
votes
4answers
345 views
Ruby-ize for loop - counting all the n-digit numbers that contain the digit 5 anywhere
I wrote this a while back when my fiance was taking a Number Theory class. I wrote about it here and it recently came back to my attention. Anytime I write a for ...
0
votes
1answer
83 views
For and if loops in Python math game [closed]
I'm trying to get my program to iterate through a loop after a person gets the correct answers to the first question. I feel like there is a better way to do things syntactically.
...
4
votes
1answer
169 views
Optimize PHP foreach loops
By any means, if any can tell me if this code can be more optimized than it already is, please say so. It's a select statement to my PDO class. When I glare over my code, I'm certain there is a lot of ...
10
votes
6answers
2k views
Beehive numbers - using goto in C++
I understand that using goto in C++ code is strictly unadvised, but sometimes, it really reduces the number of lines of code like in the following case.
This is my ...
4
votes
1answer
129 views
Simple parallel foreach loop code correctness
I have both the regular for each loop and its equivalent paralleled version. The loop simply iterates through a collection, looking for the rate key in a local db ...
6
votes
2answers
130 views
Tight loop, string manipulation and calculations
I'm working on some precompilation operations for a world compiler. Currently to identify flags placed by the level designer I need recognize when a specific entity exists at specific coordinates from ...