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
4
votes
2answers
5k views

Incrementing a sequence of letters by one

I'm creating a C# application that produces unique lines of data. The main purpose of the application is for me to learn C#. The secondary purpose is to have available lines of (dummy) data when ...
0
votes
2answers
627 views

Iterative “counting change” implementation in mit-scheme

Here is my iterative implementation of the Counting change example in SICP. Please note that I'm a beginner, which means I only know the basic syntax for the time being. Requirement: How many ...
2
votes
1answer
63 views

Calculating some worst-case values for angles in an interval

Sadly enough I have a bit of code that is really slow and being a newbie in programmation, I don't have the faintest clue on how to optimize. Is there any way to make those calculations faster? This ...
3
votes
1answer
36 views

Robustness of this first difference function

Here is a first difference function I threw together for a quick check in another program: ...
1
vote
1answer
481 views

Displaying a conflict marker

I'm displaying a conflict marker for each actor for each day, if the current day is in their conflicts: ...
4
votes
4answers
2k views

School grading string calculator

For my training, i've been given an assignment to build a simple, extendable 'grade' String calculator by a given grade. For now, I had to work by this table: When the ...
2
votes
2answers
13k views

Python: check if all array values are same [closed]

I have an example array like: array = [1, 2, 3, 4, 5, 6] Every of this numbers refers to an object that has text property. I want to make sure that every of ...
4
votes
1answer
294 views

String permutation iterative improvements?

I have written some code (below) which iterates over each character of a string and adds that character to every index of previous permutations. For example, in case of abc: b is added to every index ...
4
votes
2answers
209 views

Generic class to generate combinations

As junior java programmer I am working with Euler project and I would like to create a general purpose class which generates all the combinations from the length ...
3
votes
0answers
958 views

C++11 generator implementation emulating Python's yield keyword

C++11's range-based loops allow convenient and easy iteration over containers, but what about more complicated iterations such as tree traversal? Usually this involves a lot of boilerplate code and ...
5
votes
1answer
263 views

Pair, differences and correlations

This has a couple of twists which I personally found rather awkward... All code can be downloaded in a read-to-run format from here The problem Consider a classic interview question: "Find given ...
19
votes
1answer
2k views

for_each for tuple-likes

I've implemented a C++14 for_each for tuple-like objects. It's similar to std::for_each in that it also returns the functor once ...
4
votes
1answer
652 views

Extracting the first two initials of a person's name

I've come up with a hackish approach to get my XSL function to only return the first 2 initials of a person. I think there should be a more efficient way to do this though. The ...
4
votes
1answer
120 views

Biometric matching score calculator

I'm working on a biometric matching system and I would like to have few suggestions regarding vectorizing the following code: ...
4
votes
2answers
115 views

Vectorizing a polar coordinate conversion loop in a fingerprint-matching process

I am working on a fingerprint matching technique and it takes a lot of computation time to obtain the result. I am trying to implement the matching process given in A Minutia Matching Algorithm in ...
4
votes
1answer
149 views

Tic Tac Toe algorithm using itertools

I'm looking for feedback on the readability of my code and opinions on the pick_best algorithm. I do this stuff for fun when I have time, and never get a chance to have anyone else look at it. ...
2
votes
3answers
2k views

Building XML elements from a list using LINQ and foreach

I wrote the following code: ...
5
votes
1answer
135 views

Alternately taking elements from an array

Given the task of having to return an array that alternately takes elements from two arrays, what would be most Ruby way of completing the task? As of now, I have this code, but it doesn't feel very ...
1
vote
1answer
70 views

Iterations with asynchronous functions

I haven't really worked much with asynchronous code so I'm wondering if I am doing something wrong/something could go wrong. Right now of all the test cases that I have done, my code has worked but I'...
2
votes
3answers
230 views

JavaScript Iteration

In my current project I have objects of the following structure: CanvasBundle - Object Some elements... gridCanvas axesCanvas <...
3
votes
1answer
149 views

Tail-recursive call vs looping for a Poker app

I'm developing a Poker app. It is almost done, and I'm looking for improvement. One of the things I wonder is whether I should change how I perform iterations. I currently iterate by using tail-...
1
vote
1answer
395 views

Checking for items in sublists

Today I'll demonstrate a simple function that searches for a item in all sublists of a list. For this it uses iteration, and keep in mind that it can be slow because of this. How can I improve it? ...
7
votes
2answers
1k views

An iterator returning all possible partitions of a list in Java

Given a list of \$n\$ objects and an integer \$k \in \{ 1, 2, \dots, n \}\$, this iterator generates all possible ways of partitioning the elements in the list into exactly \$k\$ disjoint, non-empty ...
6
votes
5answers
363 views

CombinedIterable for Java

This class combines multiple instances of Iterable into one and iterates through them in the order they are given to ...
4
votes
1answer
73 views

Tic-Tac-Toe in Python 2.x

This is a class called Board which handles the tracking and checking of the state of the game. self.board is a dict of ...
3
votes
1answer
929 views

Object-oriented web scraping with Python

I usually write function-only Python programs, but have decided on an OOP approach (my first thereof) for my current program, a web-scraper. Here is the working code I wrote which I am looking to have ...
2
votes
0answers
708 views

Nested loops with linear array

i have found this article on how to loop through multi-dimensional arrays quickly. http://nadeausoftware.com/articles/2012/06/c_c_tip_how_loop_through_multi_dimensional_arrays_quickly I am using ...
5
votes
3answers
294 views

Java String iterations

I am working with some Java code. Basically I have a wrapper class that holds a string and implements some of the many useful python string methods in Java. My goal here is to implement the Python ...
9
votes
2answers
6k views

Filtered Iterator

I have written a wrapper for Java's Iterator class using Java 7, which is designed to only iterate items that match a certain filter. When the filter is null, all ...
4
votes
1answer
61 views

Which loop to use for multiple if statements which serialize objects

I have figured out how to serialize multiple objects, however I am utterly convinced I can use some kind of loop for the if statements below, to avoid duplication. Please can someone advise how I ...
5
votes
2answers
1k views

An implementation for the double factorial

I have written this piece of code that implements the double factorial in Python both iteratively and recursively; the code works without problems, but I'm interested in improving my overall ...
3
votes
1answer
2k views

Serializing multiple objects to a file

I am very new to Java and although my code works, I know that it must be possible to write this using fewer lines of code. I am serializing multiple objects, eventually I will look into serializing to ...
4
votes
1answer
66 views

Write Once Use Everywhere: Multidimensional array traversal

I have a structure that is organized much like a Sudoku board, where individual cells reside in an n x n region, and those regions reside in an n x n area. I need to be able to address both the ...
10
votes
3answers
3k views

Find the Nth number divisible by only 2,3,5, or 7

I recently participated in a small friendly competition and this was one of the questions: A number whose only prime factors are 2, 3, 5 or 7 is called a humble number. The first 20 humble ...
7
votes
1answer
216 views

Saving and resuming position while iterating over a container

Background: I'm in the process of writing a relatively simple behavior tree driven AI system for a game that I'm working on. Basically, the behavior tree is made up of individual gameplay tasks (move,...
0
votes
1answer
174 views

JW Player + Brightcove Integration

The following code gets video renditions from Brightcove using the media API. It then generates an ordered source list for the JW Player and selects the default rendition based on a pre-set bitrate. <...
3
votes
2answers
168 views

Iterate over large amount of words in Python

I wrote a program that should check a dictionary that contains about 50000 other dictionaries. In those dictionaries, one of the keys has a list of words as value. Now, I iterate over those words, ...
6
votes
2answers
359 views

Choosing a clubName

Please can someone advise me, how I could use a loop for this code, in the interests of code reuse. My code is as follows ...
4
votes
2answers
85 views

Implementation of a list-like array

This is a follow up question for this question: Implementation of a dynamic list-like array This is an implementation of an array that behaves like a list, granting me an easy and quick way to: ...
5
votes
2answers
171 views

Implementation of a dynamic list-like array

I needed to address an issue that I met with quite a bit, which has sort of a bag of data that I can easily add items and remove them, and iterate over them at any point without an issue. First thing ...
1
vote
2answers
911 views

Bottom up mergesort in C++

See the next iteration. I have this C++ implementation of bottom-up mergesort (mergesort using iteration instead of recursion): bottom_up_mergesort.h: ...
6
votes
2answers
709 views

Iterate faster through the Android file system and find specific files using java multithreading

I'm trying to extract specific files and visualise them in a list/grid. For that purpose I'm starting a Service to do the background job, and when it finishes it fires an Intent which will be captured ...
4
votes
3answers
2k views

Creating number pattern (triangle numbers) in C++ with minimum loops

We were asked to make a triangular number pattern in C++ with minimum loops: ____1_____ ___2__3____ __4__5__6__ 7__8__9__10 Code: ...
1
vote
1answer
47 views

Looking within a directory for a file

I have written this code to build a list by looking inside directory within deep to the level it finds a audio file and then move to the next level or next folder. Can there be a more efficient way ...
2
votes
2answers
1k views

Root-finding by iterated bisection

Both of the following code give the same result. But I'm not sure where should I put the raise statement. ...
2
votes
0answers
467 views

Efficient Sets and Maps with Treaps

I wrote up a Treap implementation to serve as the base class for a bunch of augmented data structures (interval sets, plane (2D) sets, order statistic trees), replacing my RB-tree base. Some ...
2
votes
0answers
32 views

Iterative procedure to get 3D coordinates from distance constraints

Imagine you have a series of n points randomly generated in a box in 3D space. You also have a list of distance bounds, e.g. points 5 and 3 should be between 1.0 and 2.0 Angstroms apart. There are ...
6
votes
1answer
497 views

Print permutations in an iterative way

I've written the following code to print all the permutations of a list. For example: \$[1, 2, 3]\$ has these permutations: \$[1,2,3]\$, \$[1,3,2]\$, \$[2,1,3]\$, \$[2,3,1]\$, \$[3,1,2]\$, and \$[3,...
8
votes
3answers
2k views

Finding the percentage of even numbers in an array

I wrote a method which computes the ratio of even to odd numbers in an array. I know it's a simple piece of code, but I wanted to see if you have any feedback for improving it. ...
4
votes
2answers
398 views

Epilogue to a binary search to find the range of matching indexes

I am trying to find out the best practice for writing a loop which does one check and at the same time has to increment a value so that the while loop will ...