Loops are a type of control flow structure, in which, a series of statements may be executed repeatedly until some condition is met.

learn more… | top users | synonyms

4
votes
1answer
40 views

Java 8 find array of countup sums

I have an array of some arbitrary int values; I want to find the array containing the sum of the past elements in the current index. Example: ...
2
votes
1answer
35 views

Fill missing values based on group

I am trying to fill values based on group, in my case id. I would like to fill the missing values according to the available ...
-3
votes
0answers
25 views

Can I shorten my Mexican Wave implementation? [on hold]

This code is for solving the Code Golf problem: The Mexican Wave. I take an array of chars, and print it out 26 times, for each iteration I capitalize the ...
-1
votes
0answers
20 views

Displaying an integer's separate digits using while/loops [closed]

I am trying to figure out how to display any integer's digits from first to last on separate lines using while loops. So far, I only know how to display a designated integers digits (three digit, four ...
0
votes
0answers
39 views

Optimising nested for loops Java [closed]

I am having a code that does scheduling of a days events based on the exact fit basis. I am kind of having three nested for loops and I'd love to hear thoughts on ...
-2
votes
2answers
46 views

Manipulating strings and character positions

Write a program that manipulates two strings. The program inputs two strings (string1 and string2) and a character (...
12
votes
3answers
924 views

Calculating Parking Fees

Here's the challenge description: A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $...
2
votes
2answers
58 views

Calculate number of co-occurrences for two vectors

I would like to understand how to get rid of all the loops I am using in this code. I have a dataframe of 20 rows. I am simply counting the number of occurrences that the variables ...
2
votes
4answers
131 views

Print factors of number using fencepost loop

I was wondering if this code could be optimized in any way? For instance, could I use a for each loop here? Are there other ways I could write this which would make it easier for me, or the person ...
-1
votes
1answer
26 views

Removing an element and the element following from an ArrayList [closed]

I have an ArrayList of Strings. I want to delete all elements with a particular value and the element immediately after that one. I have an ArrayList with the elements "Ape", "Bear", "Cat", "Dog", ...
11
votes
5answers
393 views

Populating a bag of Scrabble tiles

I am filling a bag full of scrabble tiles. There should be 100 tiles in the bag of these letters: ...
7
votes
3answers
184 views

Colorizing Excel cells with a date range filter

In a table there is a number of column (chambre) and a number of row (alveole). If these matches in a list in an other sheet then it checks if it the date is between two dates on that second sheets. ...
4
votes
2answers
220 views

Calculating how long sales reps are idle

I wrote a procedure to calculate the number of months elapsed since a sales agent' last sale. It works but runs in over 10 minutes... for 20 rows. ...
0
votes
1answer
34 views

Retry storing HTTP response into a variable until specific code

I want to keep trying to get response until its code is 200 or unknown yet. In first case it should be stored in response variable. In another case I should raise ...
2
votes
0answers
73 views

Asynchronous iterator for AngularJS

I wrote this as a convenient way to batch together multiple, repetitive AJAX calls. I was working in angular at the time, so I use the $q service, but I'm sure it ...
2
votes
1answer
32 views

Scaling up the intelligent concatenation of 2 columns in R

I've got a huge dataset in R which contains (among other things) 2 columns indicating "Term Code", which are "Term Code" and "Term Code1". "Term Code" is the mostly-correct column, which usually ...
0
votes
1answer
30 views

User and Score models

I have a couple of models - User & Score. I am displaying data from those models to my template. Data from ...
1
vote
0answers
21 views

Searching through rows of paged grid until row is found or there are no more pages

I have a GWT Grid, using a pager, so pages of the grid (table) can be any number of elements long. I'm looking to iterate over every row of each page until I find a row with the matching text in the ...
3
votes
1answer
53 views

Rename subkeys of nested dictionary dynamically

My nested (ordered) dictionary looks like this: ...
-2
votes
2answers
82 views
3
votes
2answers
355 views

Adding a bookmark, or changing an existing one

I have a very problematic nested if/else/for that I'm sure it could use some love. Here's how it looks originally: ...
0
votes
2answers
70 views

Improving code with loops in Java [closed]

I am working in a lemonade stand game in Java I have some conditions to determine the "perfect recipe" I see a lot of repeated code that I am sure it can be improved with a loop but I am having a hard ...
1
vote
1answer
53 views

Using a nonsense string to check if a call has completed, rather than timeout?

My question is whether or not this is a good practice, and/or if there is a more efficient way to do it. I have to access this Solidworks interop object and wait for it to return some value. The ...
8
votes
5answers
416 views

Print Consecutive numbers by comparing two parameters

input 3,5 output should be 3,4,5 input 5,3 output should be ...
2
votes
2answers
94 views

Dictionary foreach loop with multiple occurences

A little look on what are Dictionaries: dictWordCounter<string, int> dictWordPercent<string, double> topTwentySeven<string, double> ...
3
votes
1answer
47 views

Generating realistic terrain data - Part 2

I've made a "heightmap" terrain generator similar to my previous one, except this one has some improvements, and some new features. The way this one works is similar to my last one, but slightly ...
3
votes
4answers
405 views

Find duplicates in List where all the numbers in between is <= than the duplicates

My function is supposed to go through a given List<Integer> and find integers of same value, but only count them if the ...
2
votes
2answers
91 views

Looping through an Array of objects to find an ID in a sub array

I have an Array of objects, each which contain their own sub Tags Array, and I need to loop through and find a matching id. ...
1
vote
1answer
49 views

Character counter

This will go through and create every possible permutation of a username with a length of between 4 and 255 characters. ...
2
votes
1answer
65 views

Convert list of UTC to Current TimeZone

I found myself with a list of UTC timestamps and wanted to convert them into the local time zone. Using this web post as a starting point, I modified the script to grab a text file containing UTC ...
0
votes
1answer
65 views

Refactor nested foreach loop based on object property

I'm using a levenshtein matching algorithm to match a title to a filename (for anime). I either use the main show title for matching or its alternative titles (...
0
votes
1answer
42 views

Word Counting from Array onto Output File [closed]

For this problem, I have to have two text files: one for list of words that need to be found and other containing the document that needs to be search. The results would placed in a output "results" ...
4
votes
3answers
139 views

Minimum coins algorithm in Ruby

I am working on a puzzle to find the minimum number of coins needed to buy a product. I am given three coins: 1 3 5 and also a number representing the price of a product: 11 The answer here ...
1
vote
2answers
63 views

Identifying numeric substrings of an alphanumeric string, and summing them

I am going through the CodingBat exercises for Java. Here is the task I have just completed: Given a string, return the sum of the numbers appearing in the ...
2
votes
2answers
34 views

Returning matching substrings, of n length, at the beginning and end of a string

I am going through the Java CodingBat exercises. Here is the one I have just completed: Given a string, return the longest substring that appears at both the beginning and end of the string ...
6
votes
4answers
531 views

Summing digits of an alphanumeric string

I am going through the Java CodingBat exercises. Here is the one I have just completed: Given a string, return the sum of the digits 0-9 that appear in the ...
2
votes
0answers
48 views

groupJoin() in Swift

I have created the following function in Swift for this library I am writing, which joins two arrays on a key (extracted using given closures), and then groups them by key in a ...
2
votes
1answer
239 views

removeAll(closure) in Swift

From this library I wrote, I have created this function in Swift, but I'm not happy with the implementation. Can anyone suggest a better way to do this? I really don't like changing counters inside ...
4
votes
3answers
74 views

Case insensitively removing a substring, efficiently

I am going through the CodingBat exercises for Java. I have just completed this one: Given two strings, base and remove, ...
10
votes
4answers
784 views

Imaging with getPixel() and loops

I wrote perfectly working code that reads an image, and then does a kind of threshold on it by zone. If the zone has too much white then it turns all the zone into white, otherwise it turns into ...
0
votes
2answers
116 views

Changing algorithm to avoid looping with iterrows

I am new to Python. I wrote a code that works but the algorithm is obviously not efficient at all. I am stuck in the loop on iterrows and I do not see how to get rid of it. First a little bit on the ...
1
vote
4answers
112 views

Redacting everything in a string except a particular word

I am working through the Coding Bat exercises for Java. Here is one I have just completed: Given a string and a non-empty word string, return a version of the original String where all chars have ...
2
votes
1answer
62 views

Project Euler Problem 52: Permuted multiples

This is my solution to Project Euler Problem 52 - Permuted Multiples. In the problem I'm searching for the smallest value of x such that x, 2x, 3x, 4x, 5x, and 6x use the same digits. ...
6
votes
1answer
672 views

Cutting The Sticks

Problem Statement This is a challenge from HackerRank: You are given N sticks, where each stick has the length of a positive integer. A cut operation is performed on the sticks such that all of ...
5
votes
1answer
593 views

Counting occurrences of substring in string

I need to know how many times a substring occurs in a given string. I figured that I might as well create an extension method: ...
2
votes
2answers
86 views

Assembly Summation Implementation

I wrote a simple summation program in MARS to practice using loops and jump instructions. I feel like this is pretty lightweight and wanted some feedback on possible improvements: Lowering ...
2
votes
0answers
109 views

Genetic algorithm for the minimum of the Schaffer function

I have to implement a genetic algorithm in R to optimize the minimum of the Schaffer function. Below I describe each step and I need to create one big function and another loop for 100 iterations (and ...
2
votes
2answers
57 views

Increasing FPS of updateMobs

I am starting to experience frame rate issues in my game and I've tracked it down to my updateMobs function. I would like tips and code examples from you guys to ...
4
votes
2answers
66 views
0
votes
2answers
287 views

Array to Tuple in Swift

I am burdened with the requirement of interacting with a C based library, which has a bunch of constant sized arrays (e.g. char[17]). When trying to assign or read ...