Questions tagged [iteration]
Iteration is the repetition of a block of statements within a computer program, usually with mutable state.
264 questions
2votes
1answer
55views
Match pattern in Polars (Python) native API vs the slow map_elements
I have a Polars dataframe in which the cells contain a sequence of single digits as a string of characters, and I want to find the number of differences between the single-digits elements of the ...
3votes
2answers
326views
Calculate the base 10 log with loops in Java without using Math
I'm looking for a simple way to calculate the logarithm without using java.lang.Math, just out of interest. Here's my try (I adopted some code parts from this ...
2votes
2answers
359views
Another cash machine with special bill values in Java
Task: An ATM dispenses banknotes with the following values/denominations: {5, 30, 35, 40, 150, 200}. The user should be able to repeatedly enter an amount divisible by 5 without leaving a remainder. ...
1vote
1answer
87views
Code that performs 2500 simulations by running a regression after randomly assigning 10 friends to each observation in a data took 20 days to run
I am running the following code to conduct a simulation. I have a dataset of around 100K observations. The simulation does the following: It randomly assign 10 "friends" to each observation ...
2votes
1answer
137views
Electro-thermal simulation
I'm working on an electro-thermal simulation with variable parameters. Model require the calculation of all the electrical and thermal quantities at each time step, between a starting and ending time. ...
5votes
1answer
1kviews
Determine if it is EU summer time in Java
I wanted to write a utility method for learning purposes to determine if a given date (year, month and day) falls within EU summer time or not, without using any of the Java library methods. Is here ...
1vote
1answer
95views
Shrink an array of double elements (uniformly)
Is there a way to avoid the first loop in the method shrink? (if and while...) The utility ...
5votes
2answers
791views
3votes
1answer
1kviews
Knock down tall buildings
I'm trying to solve the following problem: As you know Bob likes to destroy the buildings. There are N buildings in a city, ith building has ai floors. Bob can do the following operation. Choose a ...
1vote
1answer
77views
Increment sequence value for multiple styles
I've found several examples of code to increment various sequence values but they are usually specific to either alpha characters or numeric characters. I wanted something that could increment a ...
2votes
2answers
193views
Increasing writing speed to file inside a for-loop for large files
I have a .csv file containing 100 millions records, I would to create multiple files from this file, after certain condition satisfied in each line, I came to this code below, but it is slow, I think, ...
1vote
2answers
266views
Count the number of mismatches between two arrays
This function may compute the amount of unequal elements of two char-arrays of the length n: ...
2votes
1answer
2kviews
std::ranges zip view to iterate over two equal size ranges at the same time
Since c++20 std::ranges doesn't have a zip view like range-v3 does, I am working on implementing a basic version of such a zip view to iterate over two ranges at the same time. The ranges should be ...
1vote
1answer
147views
Readlines abstraction for Golang
I've just started learning Golang and was solving some problems which required me to read lines of text from a file. I decided to abstract away the reading part so that I can use Go's ...
1vote
2answers
84views
Create a random list of values with corresponding tokens
I have this code that uses loops and random generators to create a random list of values (operators, strings, integers, floats, and new lines) and a corresponding list of the correct tokens to test a ...