# Questions tagged [iteration]

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

229 questions
Filter by
Sorted by
Tagged with
57 views

### Calculator that finds the area under a curve

The program is meant to collect from the user: The function under which to calculate the area The left and right boundaries of the region The amount and position of rectangles to use to approximate ...
180 views

### Microsoft OA | Longest Substring Without 3 Contiguous Occurrences of Letter

For the following question, does my JS Solution seem correct? I'm looking for some peer review. Q: Given a string s containing only a and b, find longest substring of s such that s does not contain ...
81 views

### C program to print a triangle of stars

This C code is to print a triangle of stars. ...
336 views

### Comma formatted list printer

I'm working on a list practice project from the book "Automate the Boring Stuff with Python" which asks for this: Write a function that takes a list value as an argument and returns a ...
69 views

### Cyclomatic Complexity (complexity)

I have a program for finding shortest distance/path and I got a correct answer but I am getting an issue i.e., "Function 'shortestPath' has a complexity of 9. Maximum allowed is 6." This is ...
187 views

### PHP comment system

Basics I created a simple comment-system. My goal was it to create a system that can easily be used on everyone's server without having to install a load of programs. I also tried to create it as ...
104 views

### Computing the Kronecker product over a tensor chain

I'm working on some Python code and have a few functions which do similar things, and the only way I've found of writing them is quite ugly and not very clear. In the example below, the goal is to ...
58 views

### Checking for duplicate email in api response data

I am working on a small internal app that works along an external API for provisioning purpose. The code essentially is comprised of a series of forms where the user inputs data, this data is then ...
54 views

### Improving the speed of the injection of class element selectors to HTML tables (sometimes nested) at scale through loop iteration or other methods

Background and Code I am using the following JavaScript code to inject CSS classes into a webpage after the page has loaded. These classes act as selectors that I can use to pinpoint a table cell to ...
357 views

### Finding the first pair of prime numbers that have some specified difference

I tried printing the first pair of prime number in between a list of numbers with a particular difference. But my run time is still too high (for large range of numbers). I want to reduce the run time ...
57 views

### Recursively displaying json data on website [closed]

I am displaying the data from a json file onto a website, with recursive and iterative tables side by side. i have the iterative code working, but I have no idea on how to make it recursive. Here is ...
57 views

### Reduce database touches for one to many data pull

I have the following function which works properly and grabs all of the rows from a specific table, then loops through each row to add data related to it as a subarray. ...
61 views

### String data manipulated given CSV variables

The Requirements: List the expensable items sorted by date and location given two variables: 'categories' and 'expenses'. The Categories variable provides the following information in order: Category ...
121 views

### Maxcounters in JavaScript

I am trying to solve this question: MaxCounters. Solving it is straightforward, but solving it fast enough is proving very difficult. How can I improve the performance of this code? At the moment it ...
102 views

### Delays using multiple for loops

I got this script which work perfectly but I got some delays because of this 2 for loops [i][j] is there any way to do the same ...
40 views

### Best way of converting a dynamic number of list items into variables in Python [closed]

I have a simple scrapy spider that crawls a page and returns H1 on the pages. Since, each page is unique, one cannot know how many h1's will be on the page. Since the scrapy spider returns a list, I ...
32 views

### Iterate over a short list, pairing the elements with the sequential elements of a longer list [closed]

I am a relatively new programmer. I am trying to use iter and cycle to cycle over a list (key) and 'pair' each item with each ...
22 views

### How to convert Recursive Approach to iterative one(Super Reduced String)? [closed]

The Question: Steve has a string of lowercase characters in range ascii[āaā..āzā]. He wants to reduce the string to its shortest length by doing a series of operations. In each operation he selects a ...
32 views

### conditional simulation(path dependent simulation) in R

My codes are not good, I want to konw how to solve my problem efficicently and learn writing some elegant R codes.Thanks in advance! "r" is the starting value in ...
23 views

### Join ArcGIS tables in Python of plant greenness in response to prior month's rainfall

I am using Python 3.8 with ArcGIS Pro 2.5. This code creates a joined table where I match values for plant greenness in the current month with rainfall X number of months into the past. Each loop ...
1k views

### Sliding window iteration in Python

I'm creating a small library of Python utilities, and I'd like feedback on a function which allows iterating over an arbitrary iterable in a sliding-window fashion. Relevant parts of ...
54 views

### Which solution is good to generate a list without None results from a function? [closed]

I'm relatively new to Python and learned, that function cannot return nothing, not even None. In my application I want to iterate over a list and keep all non-...
53 views

### Best way to optimize multiple search on Lists java

Anyone could help me to optimize this block of code, I already did a bit improvement but since I'm really bad with this kind of algorithms this all I've done so far. Much appreciate if you can explain ...
78 views

### Divide the last element in an array of arrays among the remaining elements

The function below is part of an overall chunk of code to partition an array of size M into sub-arrays of size N. The function in question is written to handle the case: what if M isn't divisible by ...
36 views

...
50 views

### Flagging system: Check for changing values in a data frame

I've written the following code to check if a value in a data frame changes. I'm looking at the last 5 values. If there was no change at all I want my code to return 1, if a single one (or multiple) ...
218 views

### Pandas iteration over rows for features calculation

I have a pandas data frame and I want to calculate some features based on some short_window, long_window and ...
80 views

### Reduce time taken for VBA loop when copying multiple sets of input values, performing Excel formula calculations and recording results

My VBA code currently loops for 5,000 iterations and takes about 25 minutes to collect the output data in the Output excel sheet. Is there a way to reduce the time taken for instance by improving the ...
363 views

### Extracting mail data out of MS Outlook's generic mailbox

This code extract data from generic mailbox mapped by MS Outlook I failed at recursive iteration in subfolders, so it stays as iterative one. Added ASCII encoding to deal with crazy national symbols ...
2k views

### Forming error messages from a multidimensional associative array

I'm working with an input array, which is 3 levels deep, and creating error message strings accordingly in a separate output array. Below is the code. ...
97 views

### Listing last 3 items (or all if less than 3) in an ArrayList

Writing a code to return the last 3 items in a list, if the list has 3 or more elements, otherwise return all list items. But the code looks really bad. What is a better way to write the same code? <...
36 views

### Merge adjacent occurrences of identical elements in data collection

There is a small programming exercise to merge adjacent identical elements in a collection. Here are two solutions (passing the tests from the exercise). I am asking for review of the first version ...
1k views

### Generating sequential alphanumeric values that match a certain pattern

I'm working on generating large volumes of test data for some performance testing. Part of this is going to involve generating a lot of values that represent an "MBI", which is a certain kind of alpha-...
912 views

### Shuffling multiple iterators in order

I have a Python function w/ specified functionality, and two proposed approaches - which do you prefer, and why? (performance, simplicity, clarity, etc) (both use ...
244 views

### Map unique raw words to a list of code words

Problem Write a function that replaces the words in raw with the words in code_words such that the first occurrence of each ...
293 views

### Nested for-loops in xml parsing

I wrote program that reads and processes xml files submitted by external users. The part of the code in question iterates over xml node's children, appends a dictionary - a future row in a table, and ...
1k views

### Finding the closest string match for each string in two dataframe columns

I was wondering what's the fastest method to compare similarity between two lists of strings (e.g. two dataframes, documents etc.) using levenshtein distance or other procedures. I am currently using:...
167 views

### Challenge: phone keypad to letters - return all possible strings

The challenge: Given a mapping of digits to letters (as in a phone number), and a digit string, return all possible letters the number could represent. You can assume each valid number in the ...
752 views

### JavaScript Sort Stack Coding Challenge

A coding challenge to write a function sortStack that receives a stack of integers into ascending order (with largest integers on top) and returns another stack ...
48 views

### Traversing two trees until a common value has been found

I am traversing two objects that may share a common ancestor. To make the code small enough to show here, I have changed it into two dictionaries with values. As you can see, ...
116 views

### Find a Sum of Particles in A Set of Boxes Given a Number of Rows and Columns

This is a code challenge, from Codewars, the details of the specific challenge in depth can be found here: https://www.codewars.com/kata/magnet-particules-in-boxes/javascript. The summary of it ...
368 views

### JSON selector class in Python

I've created a simple little class called JSONSelector to be able to select relevant data from a JSON object (a dict in Python). ...
561 views

### Parallelized for loop in Bash

I am using a Bash script to execute a Python script multiple times. In order to speed up the execution, I would like to execute these (independent) processes in parallel. The code below does so: <...
525 views

### Iterating over a range of integer ranges in Java

My use case is this: RangeDemo.java: ...
4k views

### Count Even Digits In Number

I was asked to complete this CodeStepByStep problem. Here's a quick summary: Write a function named count_even_digits that accepts two integers as parameters ...
312 views

### Blackjack game: Count Hand Value method

I am almost completing my BlackJack game in Javascript. But I realize that there must be a way to improve the performance for these two methods. Any pointers? ...
47 views

### Check if a web element has a specific property and apply changes to the DOM according to the property's existence

I wrote this Javascript snippet for a Polymer fronted, it works without issues. The only thing that it accomplishes is changing an icon's orientation whenever a user is clicking on any expandable-...
151 views

### Grouping objects that have the same attributes

A list of objects needs to be grouped. The list is iterated and checked with other objects in the same list except itself. The method People.isAttributeEqual() checks if two objects can be grouped. ...