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.
0
votes
0answers
9 views
nelqslv package for loop [on hold]
I have a data frame which could be approximated by the following example:
...
9
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
26 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
48 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
16 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
19 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
}
...
8
votes
3answers
256 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
44 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
536 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
59 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
85 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
68 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
75 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
69 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
37 views
7
votes
2answers
409 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 ...
9
votes
2answers
233 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 range() generator that allows the ...
7
votes
2answers
131 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
403 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
98 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
46 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
139 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
1k 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
335 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
46 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
3k 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
150 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 ...
21
votes
3answers
3k views
Is my coding technique progressing in terms of C# loops?
I have isolated a little bit of code that was causing a small debate between myself and another user. I have taken some of the things that he said and meshed it with the code that was being reviewed ...
-2
votes
2answers
109 views
Is this correct way to use loops or should it be in LINQ?
The results variable is coming from an API that have a arrays in arrays, etc.
I have made a foreach with ...
11
votes
9answers
2k views
Is there a more succinct way of writing this simple JavaScript loop?
This seems a bit redundant to me, but I'm not sure of how else I might be able to write this. Normally I'd use a switch statement, but I don't think that'll work ...
8
votes
2answers
396 views
Object Creation during loops
I'm trying to parse a CSV file into objects. I've already got a very efficient CSV parser (SuperCSV). The problem arises when trying to create the object with the data that is being read out.
I've ...
7
votes
3answers
97 views
Collect and calculate average times from log, then display top 10 longest durations
Here's a novel-length summary of the issue:
I'm trying to write a VB.net program to help me collect remote site statistics from system-generated logs, but I'm a little like a carpenter who only knows ...
9
votes
1answer
204 views
Making C++11 range-based for loops a bit more useful
C++11 is great. Probably one of the most beautiful features (in my opinion) is the so-called range-based-for-loop.
Instead of
...
4
votes
1answer
186 views
Building <div>text</div> inside a while loop [closed]
I use the following code <div><?php echo $obj->text; ?></div> in while loop.
Is this the best way?
Is there a better way, either to optimize ...
5
votes
1answer
97 views
5
votes
1answer
51 views
Read line and combine duplicate entries based on one of the fields
The following Java code reads lines from an input text file and will output the entry that has the highest number in field-2 to an output file:
INPUT:
William J. Clinton 6 Q1124
42nd President ...
5
votes
2answers
312 views
10
votes
2answers
136 views
Thread-safe prime number source
I am working on some multi-threaded code that requires a prime-number source.
The following code keeps an array of primes in memory, extending it as needed. It works in the 'int' domain, being ...
3
votes
1answer
71 views
Display PHP Menu Stored in an Array and Looped
I'm creating a PHP website for a non-profit. They have some restrictions (no MySQL or pre-installed CMS) so I'm creating a CSS menu displayed by an unordered list where all of the elements are stored ...
6
votes
2answers
427 views
6
votes
1answer
171 views
How to fill an ArrayList of ArrayLists with a Left Join?
I have a class Employee that contains an ArrayList of Projects.
I'm storing the Employees in one table, and the Projects in another.
I'm trying to find the best way to create an ArrayList of ...
0
votes
1answer
85 views
Time Limit Exceed Problem [closed]
When I submitted below code in codepad.org, it shows "Time limit exceed" problem. Please provide alternative solution :
Problem Statement :
Given a number K, find the smallest Fibonacci number that ...
6
votes
2answers
3k views
Read an input text file and store the tokens in 2 different arrays
I am very new to Java so please ignore if there are obvious mistakes. If my question seems redundant then please guide me towards the correct link. However, I have surfed enough in order to find the ...
7
votes
1answer
188 views
Creating a thread for file transfer
I am creating an application in Java that runs at scheduled intervals and it transfer files from one server to another server.
For SFTP I'm using ...
10
votes
5answers
1k views
Printing star greater symbol in Java
I need to print this in Java. I have written code for this, but I feel that my code is too big.
*
**
***
****
***
**
*
My Code:
...
21
votes
5answers
2k views
Print an ASCII diamond
This takes a width specified by user and prints a diamond of that width. It uses only three for loops, but could I reduce that further? Is there a more elegant ...
2
votes
2answers
68 views
Optimizing Python code for Project Euler #5 (LCM of all numbers from 1 to 20)
This is my solution for the 5th problem of Project Euler, which asks for the least common multiples of the numbers from 1 to 20 (inclusive). Is there any way to improve the while loop conditional ...
41
votes
11answers
9k views
Nesting versus GOTO: which is better to avoid?
In Java they're not really known as GOTO statements and are rather referred to as Branching Statements, but I find that the former term is a bit more indicative of ...
1
vote
2answers
55 views
Managing while loop in bash
Two difference scenario in bash program,
First
Here i am breaking loop in function testFunc.
...
18
votes
6answers
4k views
Guessing a unique 4 random digits number
I've created a simple game, in which the user needs to guess 4 digits number between 0-9, generated randomly using Random() Each of the 4 digits are different from ...