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
1answer
31 views
Three ways to read a number for a BitInputStream
I'm trying to learn how to write more readable code without introducing easily avoidable performance killers.
This is part of a BitInputStream Java class I'm ...
4
votes
1answer
28 views
Slicing time spans into calendar months
I have apparently correct code that still runs for weeks on my data (tens of millions of rows). I show the entire code for reference (and maybe other gains to be made), but the key operation is in the ...
-2
votes
1answer
26 views
Finding the smallest prime number greater than a user input [closed]
As it says in the title, I am trying to find the smallest prime number greater than my input, 'input.'
I have to use the following guidelines when creating my code...
You program should implement ...
-2
votes
0answers
18 views
Calculating average using a loop [closed]
For my homework I need to create a program that calculates a students average for 3 tests, and the total average of the class. I have to do this by using a single user input to gather their names, and ...
1
vote
2answers
25 views
Assign object keys to another object's keys dynamically
I have an array called viewObject.terms. This array can contain up to 3 items, I need to iterate through this array and save the values into a data object.
ie:
...
1
vote
1answer
34 views
For loop step including last value
I've got the following code. I want to loop through my dataset (which is a matrix) in steps of let's say 50.000 and perform biglm on it.
...
0
votes
1answer
52 views
Fetching of JSON data through an api with AngularJS
I have been trying out AngularJS and developing a mobile application to test out its features and I wanted to see if I could somehow refactor to make my JSON response hopefully quicker in fetching the ...
1
vote
2answers
52 views
Using break for nested for loop
I want to apply three levels of filtering on record.
rec in cname. rec is string of >2 ...
5
votes
3answers
119 views
Numerology Calculator
I've built the beginnings of a numerology calculator, and would like an experienced javascript developer to review this code.
It works as expected, but I can't help but think there is a better way to ...
5
votes
3answers
692 views
Convert Foreach Loop into Linq in C#
I want to convert these loops into simple loop. I want the code to look neat and short. I saw answers related to LINQ but couldn't make out from that. Are there any other possible ways for this ...
3
votes
2answers
80 views
Efficient method for loop iteration
I have chosen two options for looping through files in a directory. Let me know which one is more efficient (in speed/memory and GC).
Option 1: (collect the file name in an array and loop through it)
...
7
votes
2answers
459 views
Countdown clock in Python
This project is from the subreddit for beginner Python projects:
The goal of the project is to create a program that allows the user to choose a time and date, and then prints out a message at ...
6
votes
2answers
75 views
2D array to draw a letter 'F'
This is my code to print letter 'F' with nested loop 2d array. Are there changes that could be made in it to make it look better or more efficient?
...
4
votes
3answers
125 views
Getting count value for matched document
I have a list of keywords and I want to count the number of records in a db which contain any one of these keywords. From each record, I want to consider only title ...
3
votes
3answers
55 views
Displaying days of the week for all of 2015
This program is supposed to determine the day of the week for 2015. Could someone tell me how I could shorten my code?
...
3
votes
1answer
35 views
Updating an inventory with R using apply functions
I have created an inventory that works via QR codes. Briefly: the QR code codes for an email with the book/student checking it out. The email is downloaded into R using the gmailR package (code not ...
2
votes
3answers
76 views
Showing the path of a projectile
I'm trying to dive deeper into C#, and so I've been experimenting with some code. I'm creating a console application that shows the path of a projectile depending on the angle, and it works great! You ...
2
votes
0answers
51 views
Optimizing D3 Stream Graph Code
I have two javascript functions that generate a D3 Stream graph. I feel I may be excessively and unnecessarily iterating over my dataset to get it into the desired form.
How might I optimize or ...
3
votes
1answer
46 views
Checking tag colors
I have an array vs.tags which may contain hundreds of objects, and a smaller array coloredTags which only contains up to 3 ...
7
votes
2answers
84 views
Series sum calculator
This is my program currently to calculate sum of following series:
$$\frac{x^2}{2!} + \frac{x^4}{4!} + \frac{x^6}{6!} \dots$$
...
7
votes
2answers
69 views
19
votes
4answers
1k views
Performing and timing loops
I am a casual C# programmer, not formally trained in OOP at all; mostly I focus on Transact-SQL in SQL Server, and so when I write C# apps I get grief about the constructs and methods I use. Here is a ...
2
votes
1answer
63 views
Counting occurrences of sorted elements [closed]
Forgive the hard coded test data - but I'm looking to make the inner while loop disappear, or at least simplified so this code doesn't run in \$O(n^2)\$. I've been thinking over some ideas of how to ...
4
votes
1answer
54 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
70 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 ...
-2
votes
2answers
74 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
1k 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
65 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
220 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
36 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
408 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:
...
8
votes
3answers
232 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. ...
5
votes
2answers
224 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
41 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 ...
3
votes
0answers
331 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
35 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
35 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
25 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
77 views
-2
votes
2answers
110 views
3
votes
2answers
381 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
86 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
58 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
539 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
113 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
52 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
478 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
168 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
51 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
269 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 ...