Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [iteration]

Iteration is the repetition of a block of statements within a computer program, usually with mutable state.

2
votes
1answer
29 views

Web scraping JSON-data from API put into Dataframe

The web-scraping process currently takes quite a bit of time, and I wonder if I can structure the code otherwise or improve it in any way. Code looks like this: ...
16
votes
7answers
8k views

FizzBuzz in Javascript

I'm sure everyone here knows what FizzBuzz is. I would like constructive criticism for my solution. I'm a beginner to programming as a whole and this isn't my first solution, but it's what I think is ...
4
votes
3answers
93 views

Java Magic square program

Here is my improved version of my Magic square program from following this earlier version. I also added a few comments. Any help for improvements would be really appreciated. ...
0
votes
1answer
35 views

Generating probability table of 2-character combinations from text file in Java

I have written a probability table generator in Java to help me generate randomized girl's names for the game I am making. It reads from a text file and creates a ...
3
votes
2answers
53 views

Storing statistics as JSON in a simulation game

I am working on a choice-based simulation and players have to choose between different locations, I am pushing those choices to an array locationLog and my ...
2
votes
3answers
89 views

Extracting data in ES6

I have this array const idArray = ["12", "231", "73", "4"] and an object ...
1
vote
6answers
1k views

Elegantly exclude part of an operation for the last iteration in a loop [closed]

I'm afraid just about everybody who read this question has misunderstood it. I'm not trying to find the best way of printing a vector. I'm trying to find the best way of excluding part of an operation ...
2
votes
1answer
32 views

Finding the Original Fractions from Rounded Decimals

The data I'm using is summoning rates from a gacha game, One Piece Treasure Cruise. The game provides the probability of getting a certain character in percents rounded to the nearest thousandth. ...
2
votes
2answers
60 views

Collect members from custom tree nodes

In my program, I have a tree of Group nodes, each identified by their ImportId. Each group has zero or more members, that I ...
3
votes
1answer
34 views

Toggle Event Delegation

NOTE: the Javascript is all I'm concerned about, the HTML/CSS is just DEMO code. One caveat is ARIA states or attributes, if you have input on that, by all means, dive in. I had the need for and ...
1
vote
1answer
64 views

Short Ruby program that opens a random video file from a directory

I am currently learning to code in ruby. I have created a small program that iterates through a directory of video files and opens one at random. The program is fully functioning (with the odd issue). ...
3
votes
1answer
108 views

C++ inorder traversal of binary tree

The challenge was to create a function which performs an in order traversal without using recursion. What I came up with was to use a stack and some clever popping and pushing. I was wondering if ...
0
votes
1answer
32 views

Process CSV files that follow the first nonempty one

I have a list of CSV files (all have the same fields), some of which are empty. My goal is to find the first nonempty file and use that as the "base" file for an aggregation. After finding the base ...
2
votes
1answer
63 views

Iteratively simulate a parasite population

I'm trying to build a simulation in R to model the effects of different parasite egg laying behaviors on how many offspring the parasite has, given a limited amount of resources. In brief, this ...
3
votes
3answers
224 views

Effieciently validate multiple DataRows with return early option

I'm looking for an efficient way to validate multiple rows originating from multiple .csv files. Below is the current code to accomplish that. The validation logic is in the function ...
1
vote
1answer
36 views

Merging and summing multi-dimensional arrays

I've found myself today really struggling with this subject and I'm pretty sure that there must be a better way to do this. First of all my arrays have the same layout, I need to merge them and sum ...
3
votes
1answer
88 views

Plotting quadratic equations with varying parameters

On Wikipedia, there is a graph shown: It shows the quadratic \$y = ax2 + bx + c\$, varying each coefficient separately while the other coefficients are fixed (at values a = 1, b = 0, c = 0) As a ...
0
votes
1answer
80 views

Retrive relation on a polymorphic model

I have a Game model that is "static". Containing game information and such, and users can comment on all games. Games model <...
1
vote
3answers
104 views

Find value that occurs in odd number of elements

I am trying to solve the following exercise using Javascript: A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be ...
3
votes
1answer
40 views

D minMax function implementation

I happened to need to find both the maximum and the minimum of an array, so I decided to implement a minMax function in D. Questions: Is this an efficient ...
0
votes
1answer
54 views

VBA code which creates a daily report, based on data gathered in Worksheets in an Excel Workbook

I'm looking for some enlightening, since I'm still learning to code in VBA. I'm running code to create a daily report. It has to compare dates and check certain values in those dates and based on that ...
4
votes
2answers
2k views

Median Filter Implementation In Python

I implemented median filter in Python in order to remove the salt & pepper noise from the images. It is working fine and all but I would love to hear your advice or opinions. ...
4
votes
3answers
419 views

Using an offset variable to keep track of the next item in a Rust array

I am using an offset variable to track the iteration position, and modifying / returning it. Is the below considered bad practice in Rust? I ask this because I don'...
2
votes
1answer
1k views

Script to load controllers dynamically for AngularJS

I would like to hear your thoughts, idea's or feedback on the following code. Ive added to code to github. https://github.com/redbullzuiper/angularjs-dynamic-controllers Usually when you attach a ...
5
votes
1answer
2k views

Check if multiple lists contain an element from a large external list

I have a list of lists (many tokenised sentences). For anyone who doesn't know what tokenised sentences are, my list is like so: ...
2
votes
2answers
124 views

Iterative version of Hanoi Tower exercise

I just finished a iterative version of Hanoi Tower. This is how the algorithm works: I'm trying to find a method to delete the goto instruction. Any tips? ...
1
vote
1answer
44 views

Simple backtracking code

Is this good or can it be improved? The program should backtrack the two variables until this logic operation is true: a & b. ...
1
vote
2answers
4k views

Iterate two lists and find matches

I have 2 lists with varying length. Both lists contain data which has to be matched with entries from the other list. Currently I am iterating both lists with a nested ...
10
votes
1answer
3k views

Remove all values duplicates from list

I'm new to programming in general, started on boxing day. I'm trying to learn python. The list remove method only removes the first instance of the value found. In the code below I attempted to ...
8
votes
2answers
1k views

Interleave two lists of strings

I've got a fairly simple task here, but I think it's worth trying to perfect the implementation, because I can probably learn a thing or two about using .NET's enumerables correctly in the process. I ...
6
votes
1answer
83 views

A database of books, part 1

Backstory I collect books. A lot of books. Whitepapers, (programming) cookbooks, transcripts, important letters, overviews, you name it. Usually in PDF, otherwise my house would be too small. To ...
5
votes
0answers
63 views

Comparing the size of tumors over time using PANDAS

I have a dataframe in pandas like this ...
4
votes
1answer
419 views

Check if two date ranges overlap by X minutes

I have a list of volunteer shifts. The shifts are time ranges- for example, 9AM-2PM and 12PM-5PM. I need to check by how many minutes multiple selected shifts overlap, and then throw an error if the ...
10
votes
10answers
5k views

Tests for palindromes in C and C++

A question I've been asked on interactive phone screens is to code a test to determine whether a string is a palindrome or not. I am providing two examples here: one in C and one in C++. They both ...
2
votes
1answer
1k views

find the index of subarray from a parent array

Are there any improvements that can be made on the below code, especially in terms of memory and time? I feel bad about setting found = false in every iteration of ...
1
vote
1answer
896 views

Checks size of and number of files in each subdirectory

The code snippet here checks in every folder for subfolders, and stores the sub-sub folders This is my sample directory structure. I want to read through every sub-folders to find the number of files ...
5
votes
1answer
1k views

Iterative in-place quicksort

I have implemented an iterative in-place quicksort algorithm in Python, which by default selects the pivot as the last element: ...
4
votes
2answers
828 views

PHP loop to generate an HTML form for the days in the coming week

There are two arrays, $states and $weekdays. I want to loop through them to create a form, an HTML table, or possibly some other ...
3
votes
1answer
125 views

Bill settlement for multiple users

I want to improve the logic for bill settlement and calculation of amount due. I managed to write code with T.D.D., but I think those loops could be improved somehow. Do you have any ideas on that ...
6
votes
5answers
2k views

Find number repeated odd times in array

I completed the following exercise: You are given an array of repeating numbers. All numbers repeat in an even way, except for one. Find that odd occurring number. ...
1
vote
1answer
37 views

JointIterable: iterates over all elements of a list of collections

I have this small utility class that allows me to iterate over a series of collections. Please tell me anything that comes to mind. JointIterable.java ...
1
vote
1answer
232 views

Mixed PHP with jQuery AJAX

I have a quick script I came up with and I was wondering if this is a bad idea. First let me explain what I want to do. I want to create a dynamic script which will add custom AJAX calls for ...
3
votes
5answers
104 views

Product iteration while checking for overlaps

This is an extended question to the following question I posted Class scheduling tool with image output Context of previous question: I have a multilayered dictionary that contains information ...
1
vote
3answers
134 views

Get a collection of child positions for a given parent position

I am trying to get a complete tree in a single loop using an iterative function. For instance, this is what I have: ...
1
vote
1answer
593 views

Iterative quicksort in Java

I have this quicksort implementation that relies on heap memory instead of actual stack. It uses two integer stacks for keeping track what subranges are yet to be sorted. When a partition routine is ...
7
votes
1answer
312 views

Counting nodes in a binary tree with odd values, using an iterative algorithm

I've to simulate exactly a recursive algorithm with an iterative one. Assuming that I have a binary search tree that contains only a key and two references at his right and left child I want to do ...
2
votes
2answers
717 views

Prime Factorisation in Swift

I made a playground to try find prime factors of any given number, and it works, and I'm happy with the first function, even if not correctly named - I don't know what to name it. My main need for ...
0
votes
1answer
306 views

Foreach vs Iterator [closed]

I have implemented a trim method which removes objects having empty properties. This list has average size of 3 or so. Probably, the max length is 7 or 8. I ...
3
votes
1answer
1k views

Iterating 2D array in Swift

I have a situation where I needed to convert NSNumber 2D array to Float 2D array, so I did it like this: ...
6
votes
0answers
221 views

Solve alphametics puzzles in non-brute-force, iterative manner

The goal: Trying to optimize solution for the alphametics problem on exercism. From the question text: Alphametics is a puzzle where letters in words are replaced with numbers. For example ...