Loops are a type of control flow structure, in which, a series of statements may be executed repeatedly until some condition is met.
-2
votes
0answers
20 views
How can I speed up the following function in R?
I wrote the following function in R. I want to iterate it, say 50000 times. I used "sapply" in my function but it runs slowly in R.My PC is still working about 20h now and I have no idea about the run ...
1
vote
3answers
342 views
Determine if requested documents exist and if they do, whether they match requested revision number
Is there a better way than using 2 for loops and 2 if statements deep?
jsfiddle:
https://jsfiddle.net/bobbyrne01/bmnk9bLz/
...
4
votes
1answer
46 views
Add entities to and execute “ExecuteMultipleRequest”
I have a method which takes a list of Entity objects, loop through elements in that list and add them to a "ExecuteMultipleRequest" object. After that the ExecuteMultipleRequest will be executed.
...
0
votes
1answer
35 views
Slider PHP loop
I am working on a image slider for a website, the user can add up to 0 - 3 images to the slider. What kind of loop should I use to make this code more efficient and DRY? "data-slide-number" starts ...
4
votes
1answer
61 views
Armstrong numbers in a given range using Java 8
Was fiddling with java-8; trying to write a program for getting all Armstrong Numbers between 1 and 10_000_000.
Following is my ...
7
votes
2answers
753 views
Looking for primes with all-different digits
I recently answered a question on Mathematics Stack Exchange, where I used a small Python program to check the following :
For all 6-digit numbers, with all digits being different, choosing the ...
-1
votes
1answer
37 views
Synchronous loop with internal asynchronous calls
Below I've written a simple version of what I'm attempting to accomplish. I'm new to asynchronous functions, so it's difficult to wrap my head around this. My goal is to wait for the loop to finish ...
3
votes
1answer
32 views
Babysitting a server reboot
I'm looking to improve a loop within a script that performs scheduled server restarts.
Currently, I'm using a DO While loop with an exit condition within an IF statement once a counter reaches a ...
1
vote
1answer
42 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 ...
2
votes
1answer
33 views
Converting values to Dates in column
I'm not happy about my code, but is the better way that I find,
I'm not happy because I see that there are many code repetitions and when any change is easy to make mistakes. Do you think you can do ...
4
votes
3answers
131 views
Producer/consumer problem with four priority levels
Here you can see a mediocre code of mine where I have fun with four deques, each with a different priority.
Here is how it works: in a ...
2
votes
1answer
99 views
Find the number of possible infinite cycles that Bessie the Cow can get stuck in
Bessie the cow is in Farmer John's field. The field is of size 0..1,000,000,000 for x and y. Farmer John knows that there are N/2 wormholes at certain coordinates, but he does not know which wormholes ...
8
votes
3answers
84 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 ...
11
votes
4answers
594 views
Copying values from one sheet to another
I am trying to copy values from one sheet to another using loop with two conditions and it is very slow. Removing conditions from code doesn't have any effect on the speed of the execution.
I already ...
1
vote
1answer
39 views
Event handler for conditions
I am trying to detect whether a condition is being returned true or false. The only problem is, I have a bunch of if/else ...
0
votes
1answer
41 views
How to generate Datarows based on a delimiter in a Datacolumn from a DataTable in C#
In my office, we use a software called Blue Prism, a Robotic Process Automation System. The idea is to allocate tasks for the robots to perform thereby simulating users. The system enables you to use ...
3
votes
1answer
47 views
Add Field To PDF with Options for Multiple Pages
This is related to here and here. These two methods are used to programatically add a text field to a PDF document. The field can be of any user determined size and have any user determined title, and ...
3
votes
3answers
117 views
Find majority element in an array given constant external space
Given constant external space (yes no HashMap), how would you improve the following code (code-wise or complexity-wise with stress on the latter) to find the ...
3
votes
1answer
96 views
Python program to lock and unlock files
The code takes srcPaths and actionType as parameters. The former is a string with tab-delimited file paths, while the latter is ...
0
votes
1answer
64 views
Load title from database based on member country
As tim suggested, some changes to the database was necessary. I have posed an improved version of this question at Get title from database based on member country.
I have the following database:
...
4
votes
2answers
102 views
Optimise nested loops used to compare champions which have abilities which have effects
I'm creating a counter picker for a game called League of Legends, and for this I need to compare effects of abilities, which each champion has. For this I'm using 4 lists of champions, the returnList,...
3
votes
0answers
53 views
Optimising looping through large data set and updating database
I have a database table storing information about documents (MigrationMaster). There is another table with security information on these (DocumentSecurity).
There are 4 steps I can see that I need to ...
3
votes
1answer
51 views
Extracting coordinates file that are inside a bounding box
I'm scanning a CSV file to see which values fit inside of a given box. The CSV file has X and Y coordinates, and the arguments to the function are the perimeters of a box (i.e, top, bottom, left side, ...
0
votes
1answer
63 views
Shell command line program
I have refactored a for loop into a function. I'm still a beginner at using C utility functions such as strtok, ...
0
votes
1answer
62 views
Exponentiation using while loop in Python
I could not think of any better way to raise to power, except this, but how do I refactor it? I should only use while loop, not for loop, not x**y.
I shall not use pow(x,y)
...
4
votes
4answers
110 views
Advent of Code Day 6: toggling lights in a grid with Powershell
I am using the "Advent of Code" series to help with my PowerShell education. The Day 6 puzzle has a 1000 × 1000 grid of lights. After processing instructions to turn on, turn off, or toggle rectangles ...
7
votes
1answer
968 views
Drawing the flag of Liberia
I am working on this assignment to draw the flag of Liberia for my essentials of computer programming class.
I finished it but had extra time to kill and noticed that a couple similar blocks of ...
-3
votes
1answer
32 views
this procedure basically gets a sentence of the user and the splits it up into its position values and writes them to a file
this program does work entirely without any errors appearing however I would like to shorten it down to make it more reliable and neat
...
3
votes
0answers
141 views
Google CodeJam 2016 - Ruby - Counting Sheep
https://code.google.com/codejam/contest/6254486/dashboard#s=p0&a=0
I just wrote a small Ruby class to solve the first of the challenges in the G CodeJam. I am not strong at this sort thing so ...
10
votes
5answers
836 views
Finding two consecutive triangular numbers with a given target sum
I need to speed up this code so it can handle inputs in the thousands. It adds triangular numbers to a list based on input n, then it loops through to find if any two consecutive numbers squared in ...
2
votes
1answer
61 views
Methods to check form validity and to count invalid form fields
I have two these methods. Their loops are pretty similar. I'd like to refactor it to avoid duplicate nested loops. How could I do that?
...
3
votes
0answers
119 views
A general iterator to replace “non-standard” C-style for loops
Since the deprecation of C-style for loops in Swift 2.2 (and the removal in Swift 3),
several questions about the possible replacements were asked on Stack Overflow. In most cases, a ...
4
votes
2answers
82 views
Product of 2 numbers equals sum of numbers between them
Problem: Find all the pairs (a, b) whose product is equal to the sum of all numbers in the sequence [1..n] excluding both a and b.
I have made code for one program and need refactoring for code to ...
1
vote
1answer
56 views
5
votes
3answers
161 views
OnStartApplicationsCommand function
The foreach loop seems ridiculously lengthy and I am trying to get rid of it altogether is possible. But there are a lot of things happening in there which I need ...
3
votes
1answer
62 views
Learning nested for loops in Python with Pig Latin translator
I've been trying to learn Python for a bit now. I've taken a few courses, but I've found that I've been going about them wrong and had allowed them to "hold my hand" too much. I'm trying to build ...
0
votes
2answers
46 views
2
votes
1answer
224 views
Calculating all possible Knight turns (Chess)
I'm creating a console application that takes as input starting column and starting row, also the ending column and the ending row and it's going to output all the possible way's to get to that point ...
1
vote
0answers
127 views
CasperJS continue equivalent inside for loop with casper.then
CasperJS doesn't allow continue statement inside a casper.then functions. This was my solution but I'm not happy about it. Is ...
-3
votes
1answer
84 views
Four-function calculator with a text menu
This code works but I don't know if I am doing this correctly. I want to have a do-while loop for the menu and app. How could I ...
2
votes
1answer
54 views
Nested loops - Random Forest, multiple parameters
I'm writing a code which task is to grow Random Forest trees based on multiple parameters. In short:
Firstly, I declare a data frame in which model parameters and some stats will be saved.
Secondly, ...
2
votes
1answer
60 views
3
votes
2answers
227 views
“Guess my Number” game in Python (2.7.9)
First time posting to Code Review. Just looking to get some advice on how I can write better code.
I found the following exercise for a "Guess my Number" game on DaniWeb, but the linked source code ...
3
votes
0answers
111 views
Basic game engine: timer, FPS and logic loop
I'm creating a simple Java game engine (just for fun). The idea is to create a basic framework for developing any kind of 2D game, an abstract engine that does the hard work. Would you like to review ...
0
votes
2answers
47 views
Partitioning an array of objects into four arrays by one attribute
I have an array of API objects, below is an example of one object:
...
0
votes
2answers
61 views
PHP alternative syntax confusion
Newbie to PHP.
Trying to output the results of an array inside a foreach loop. I have got the following code but I cannot understand what to do with it next.
Mainly;
Where/how do I start and end ...
4
votes
3answers
220 views
Using Enum to Handle String literals
I have a java component that was using a lot of string literals that I need to make comparisons on and return booleans based on these comparisons.
In order to make the code more robust I externalized ...
4
votes
3answers
81 views
Extracting sleep quality scores from periodic readings
How can I optimize the next function to work faster? The function must prepare a list to put in a CSV file. The list must contain values of average percentage of sleep per minute counted from ...
3
votes
1answer
57 views
1
vote
3answers
66 views
Reading denormalized data using a stateful loop body
I'm reading denormalized data with a SqlDataReader, the data has this form:
...