Skip to main content

Questions tagged [iteration]

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

3 votes
2 answers
295 views

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 ...
Tobias Grothe's user avatar
2 votes
2 answers
347 views

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. ...
Tobias Grothe's user avatar
1 vote
1 answer
87 views

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 ...
Joe's user avatar
  • 11
1 vote
0 answers
97 views

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. ...
ppinha's user avatar
  • 21
5 votes
1 answer
1k views

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 ...
Tobias Grothe's user avatar
1 vote
1 answer
91 views

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 ...
Tobias Grothe's user avatar
5 votes
2 answers
773 views

Fast unpack of SAM flag bitfield to named symbols

...
Crispy13's user avatar
  • 153
3 votes
1 answer
1k views

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 ...
driver's user avatar
  • 232
1 vote
1 answer
75 views

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 ...
G_Hosa_Phat's user avatar
2 votes
2 answers
187 views

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, ...
Khaled's user avatar
  • 309
-2 votes
2 answers
226 views

Count the number of mismatches between two arrays [closed]

This function may compute the amount of unequal elements of two char-arrays of the length n: ...
HeapUnderStop's user avatar
2 votes
1 answer
2k views

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 ...
thebear8's user avatar
  • 123
0 votes
1 answer
140 views

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 ...
smac89's user avatar
  • 1,499
1 vote
2 answers
74 views

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 ...
Finn E's user avatar
  • 111
0 votes
1 answer
48 views

Grouping countries and years

Here is an input array that contains country name, year and value. I need to group values by country and years. I use this approach that works for me, but I wonder how to optimize it: ...
user264870's user avatar

15 30 50 per page
1
2 3 4 5
18