Questions tagged [iteration]

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

Filter by
Sorted by
Tagged with
2
votes
3answers
42 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) ...
2
votes
1answer
179 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 ...
1
vote
2answers
71 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 ...
3
votes
1answer
45 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 ...
4
votes
4answers
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. ...
2
votes
2answers
94 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? <...
2
votes
1answer
33 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 ...
11
votes
3answers
774 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-...
10
votes
4answers
776 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 ...
7
votes
1answer
218 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 ...
3
votes
1answer
122 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 ...
5
votes
1answer
565 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:...
3
votes
2answers
141 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 ...
3
votes
3answers
658 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 ...
2
votes
1answer
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, ...
3
votes
1answer
59 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 ...
4
votes
2answers
260 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). ...
11
votes
2answers
526 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: <...
2
votes
2answers
129 views

Iterating over a range of integer ranges in Java

My use case is this: RangeDemo.java: ...
19
votes
5answers
3k 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 ...
5
votes
2answers
154 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? ...
1
vote
1answer
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-...
0
votes
1answer
87 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. ...
2
votes
2answers
124 views

N-Repeated Element in Size 2N Array

The task is taken from leetcode In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeated N times. Return the element repeated N times. ...
2
votes
3answers
94 views

Find non-duplicated integer in a list where every integer occurs three times except for one integer

The task Given an array of integers where every integer occurs three times except for one integer, which only occurs once, find and return the non-duplicated integer. For example, given [6,...
4
votes
1answer
150 views

Walking over a N branching tree

The aim of this code, written in Python3.6, was to write a function that will non-recursively walk over a N-branching tree structure. It works by using a list of indices that keep track of visited ...
2
votes
2answers
73 views

A Java Iterable over multiple arrays

GlueArrays is used for iterating over an array of arrays, and it looks like this: Main.java ...
2
votes
2answers
48 views

Iterating through two objects with different structures in parallel

I have two objects, one input = Array<Type> and one stored = Array<{..., Type}> What's the best (cleanest) way to ...
2
votes
1answer
86 views

Write a function that adds two numbers stored in a linked list and returns the sum

Just for fun I did the following exercise from "Cracking the coding interview. 4th edition": You have two numbers represented by a linked list, where each node contains a single digit. The digits ...
3
votes
3answers
114 views

Check if a postcode is in a list

I'm looking for improvement / advice / reviews on how I can improve this code. I feel like there is a better way or more efficient way of doing this and I am over looking it. The Plugin I made is ...
3
votes
0answers
18 views

IDL code for minimum distance calculation

I made a program in IDL for performing a minimum distance classification on multispectral satellite data. This is what my main function looks like: ...
2
votes
1answer
80 views

Creating objects from xml-data

I've got an XML file with some info about hosts connected to my home network and I would like to create objects containing that info in a neat way, so that I can make some nice front-end application ...
2
votes
0answers
42 views

Speed up iteration for large dataset in python

I'm trying to parse data into a csv prior to a bulk transaction into Neo4j. I'm using vast amounts of data in the relationships and wondered if anyone could help in speeding up the transactions below....
4
votes
2answers
160 views

Zig-zag child element with Flexbox and JavaScript

Recently I found a question on StackOverflow that seemed very interesting: How to make HTML elements "zig zag" this way: ...
2
votes
1answer
136 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: ...
22
votes
7answers
9k 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
380 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
45 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
58 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
94 views

Extracting data in ES6

I have this array const idArray = ["12", "231", "73", "4"] and an object ...
1
vote
6answers
3k 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
35 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. ...
3
votes
2answers
64 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
66 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 ...
3
votes
1answer
116 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
226 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
69 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 ...
4
votes
3answers
460 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
46 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 ...

1 2 3 4 5