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

learn more… | top users | synonyms

4
votes
1answer
72 views

Yet another vowel counting program

Several months ago, I asked Program to count vowels, which was asking for a code review of a vowel counting function in implemented in Python. Since I've been trying to learn Ruby, I decided to ...
2
votes
1answer
66 views

Loop combinations of byte for Poker simulator

In (this) Poker you have 2 hole cards that are combined with 5 shared cards on the board. Each player makes the best 5 card hand from the seven. Believe it or not that is over 2 billion runs to do ...
4
votes
2answers
77 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
1answer
42 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
52 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 ...
2
votes
1answer
30 views

Robustness of this first difference function

Here is a first difference function I threw together for a quick check in another program: ...
4
votes
4answers
443 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 ...
0
votes
2answers
148 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
148 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
91 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
107 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
86 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 ...
10
votes
0answers
140 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 ...
3
votes
1answer
69 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
83 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: ...
2
votes
1answer
79 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
75 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
653 views
5
votes
1answer
104 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 ...
0
votes
0answers
12 views

Outputting multiple looking-alike elements in React

I believe this is a classic problem when you have a component that outputs a bunch of similar DOM elements. Be it a list of answers to a question, or table rows, or whatever. So, I have tried many ...
1
vote
1answer
54 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
219 views

JavaScript Iteration

In my current project I have objects of the following structure: CanvasBundle - Object Some elements... gridCanvas axesCanvas <...
3
votes
1answer
129 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
39 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? ...
6
votes
2answers
154 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
287 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
53 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
226 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
105 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
259 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 ...
8
votes
2answers
957 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
50 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
285 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
71 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
55 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 ...
9
votes
3answers
500 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 ...
6
votes
1answer
79 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
58 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
71 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
352 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
70 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
90 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
502 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
171 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
1k 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
41 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
156 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
175 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
26 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
112 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,...