Loops are a type of control flow structure in programming in which a series of statements may be executed repeatedly until some condition is met.
4
votes
0answers
46 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 ...
0
votes
0answers
16 views
Mutation to Lists; Values not mutating correctly [on hold]
Purpose of code is as follows:
My code is as follows:
...
2
votes
2answers
50 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
48 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
101 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
94 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
60 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
113 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
33 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
155 views
1
vote
2answers
293 views
The efficiency of looping over nested dictionaries in Python
How to make the following code more efficient?
...
1
vote
0answers
17 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
52 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
44 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
317 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
307 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
38 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
112 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
104 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
124 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 ...
10
votes
3answers
395 views
Simple integer range for C++11 range-based for loops
I'm really tired of having to type
for (int iSomething = rangeBegin; iSomething < rangeEnd; ++iSomething)
{
...
}
whenever I want to iterate over an ...
1
vote
1answer
46 views
Robots files generation - simplifying foreach code
I'm trying to figure out if there's a way I can simplify this code which is used to generate a robots.txt file with numerous rules. Different files/folders are separated in separate arrays because ...
2
votes
2answers
190 views
Making a nested loop structure more pythonic
I'm looking for a review on my code. I am also looking for ways to transform this function into something more Pythonic. I'm fairly new to Python, so any advice would be appreciated.
...
10
votes
6answers
1k views
Find the maximum number of consecutive zeros in an array
Question: To find the maximum number of consecutive zeros in a given
array.
Example:
Input: \${1, 2, 0, 0, 2, 4, 0, 2, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 7, 0}\$
Output: "Maximum number ...
2
votes
1answer
45 views
Performance for, foreach and for key
I have a question about of the performance of using for loops (normal for, for each and for key in object) in JavaScript.
Just now I created this code to test:
...
3
votes
1answer
95 views
Replace for loop while with apply family function in R
I have trouble with for loop, my code runs very slowly. The thing I want to do is to use function from apply family to make my codes run faster (instead of using ...
2
votes
0answers
28 views
Merton default model with complex iterative approach
I am using Merton default model with complex iterative approach.
I have already prepared my R codes but as I am quite new in R, they seem very inefficient, in sense that they runs almost 7 hours. My ...
1
vote
0answers
22 views
For loop in javascript [closed]
Whether it is Java, C#, C++ syntax for the for loop looks like that:
for (int i = 1; i <= 5; i++)
{
// something
}
...
9
votes
3answers
303 views
Optimizing “Herd Sums” problem using dynamic programming
I'm trying to solve a practice problem and all is well except for the last 2 inputs my solution is too slow. Just one loop is slowing it down I think.
Herd Sums
Execution Time Limit: 2 ...
3
votes
1answer
52 views
What's your opinion on this approach to creating a repetitive string in Common Lisp?
I needed to have a Lisp function that could produce a string of a certain length, created by repeated concatenations of a another string given as argument (so for example by giving 10 and "abc" i ...
6
votes
3answers
561 views
Any performance difficulties related to List<Type>?
I'm using the following structure:
class Map
{
public List<List<Point>> points;
public List<Base> bases;
}
...
4
votes
1answer
61 views
Loop cleanly through different classes
If I have a number of different classes which manage certain tests. At the moment I have to launch each test individually which results in a lot of if statements.
...
5
votes
1answer
91 views
Is there a more elegant solution than this spaghetti code without completely revamping the whole page?
I use 'GROUP_CONCAT' to get comma separated lists of a person's educational background. Included in those lists are the type of degree, major, issuing establishment, and year received. ...
5
votes
1answer
113 views
Date ranges from a given start date
I'm trying to get a certain number of date ranges given a start date. Here's my code:
...
6
votes
2answers
79 views
Foreach-loop for and print commands
How can I make the following code shorter or efficient (maybe with other loops or other nice ideas), and keep the current functionality?
...
7
votes
1answer
71 views
Compute stats on two class vectors
Below is a full working code example of code which is used to compute stats on two class vectors (partitions).
There are two functions:
pairwise_indication and
...
4
votes
1answer
41 views
7
votes
2answers
735 views
Repetitive For Loops in 2048 Game
I have the following function defined in a program that implements the 2048 game. I tried condensing the repeating part of the code into one loop containing +1 offset variables for the indices, which ...
10
votes
2answers
321 views
Using a Pythonesque range() generator function with the Java foreach loop
Now that we have the nice new foreach loop in Java, the old-style loop looks ugly be comparison.
I like the way Python has a ...
7
votes
2answers
386 views
Merge some child values back into the parent multidimensional array
This is a wonky PHP function I came up with to merge some select values from child arrays into the original. It could really use some help simplifying / making it more elegant.
Is there a built-in ...
10
votes
5answers
421 views
Refactoring my problem-solution to reduce complexity
I need some help refactoring my solution to the problem below:
Problem Statement
An Association of Computer Scientists meets on a weekly basis. There is a certain number of seats in the meeting ...
2
votes
2answers
131 views
A matrix with square diagonals and transpose being increments of other
Construct a matrix with the following property:
North-west to South East diagonals are squares.
Matrix[i][j] + 1 = Matrix[j][i] for each i less than j.
Example of such m a matrix is ...
1
vote
1answer
67 views
Construct date sequence in Scala
I want to have a continuous date sequence like ['2014-01-01','2014-01-02', ...]
Then I define a stream to do that.
...
7
votes
2answers
234 views
Pulling JSON using jQuery and manipulating the Front-end
My JavaScript is fairly new and want to learn new ways to create clean, fast code. Can you have a look at this code and guide me on how to optimise this code to improve my skills? I have provided the ...
8
votes
3answers
2k views
Brute force password-cracker
I am just coding some classic brute force password cracking program, just to improve myself.
I've explained how my program works at the start of the code. Check some of those screenshots to ...
6
votes
1answer
353 views
Mini mind reader
Here is a code that guesses the number chosen by the user. I know that using goto is a bad practice, but it seems unavoidable here.
that's because using do while ...
2
votes
1answer
53 views
How to shorten the JavaScript in Raphaël?
The Rapheal script seems to be too long. Is there any option to make it shorter ?
I think loop can make this script smaller. Does anyone have good suggestions or ...
25
votes
5answers
4k views
Is it OK to use while ((line = r.readLine()) != null) construct?
I want to refactor the following code because I don't feel comfortable about using assignment inside comparison operator. It looks like pretty idiomatic C, but do you think this is a good practice in ...
3
votes
3answers
191 views
Loop optimization for image processing
I have this piece of code that is running too slow. I was wondering if anyone can help me optimize it as I can't seem to find any more shortcuts. I'm not sure if using ...