Iteration is the repetition of a block of statements within a computer program, usually with mutable state.
1
vote
1answer
40 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 ...
2
votes
3answers
211 views
JavaScript Iteration
In my current project I have objects of the following structure:
CanvasBundle - Object
Some elements...
gridCanvas
axesCanvas
...
3
votes
1answer
110 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 ...
1
vote
1answer
35 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
76 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 ...
5
votes
5answers
265 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
46 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
86 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
81 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 ...
0
votes
1answer
19 views
Python 3 - better iterate over list or over range of indexes? [closed]
Using Python 3 (3.5 to be exact), I want to iterate over a two-dimensional list.
I have the choice to either iterate over the list content directly, or to iterate over the list indexes (...
5
votes
3answers
254 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
227 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
38 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
151 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
56 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
49 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
264 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
53 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 ...
0
votes
1answer
22 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.
...
2
votes
2answers
61 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
349 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
60 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 ...
5
votes
2answers
71 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
332 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
86 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
592 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
40 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
94 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
85 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
25 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
103 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 ...
8
votes
3answers
977 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.
...
3
votes
2answers
144 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 ...
1
vote
1answer
72 views
Deleting an item from a Set while iterating
I know that I'm not suppose to alter a Set as I iterate through it. But, in the deleteRow(String counter, String reading) method below, doing just that will make ...
2
votes
1answer
53 views
Adding a node to a Binary Search Tree and printing the path to it
I wrote BST insertion code with the book. The book uses recursion, but I just want to know how I can do it without recursion.
My code is working, but I don't know if it is correct.
...
3
votes
2answers
139 views
Summing the digits of a sum of digits of a sum
I'm a beginner in Python, and computer languages in general, and I'm totally stumped on how to format this iteration into a function. The iteration takes the sum of someone's birth year, month, and ...
3
votes
0answers
127 views
Print the nodes of binary tree column-wise, using recursion and iteration
I am trying to code for both recursive and iterative approach to a problem.
Below is a recursive code to print the nodes of binarytree column wise. Basically I have count of root as 0 and if I move ...
6
votes
3answers
524 views
Nested loop to render tiles in a grid
This code works but I'm not really sure if I wrote it good enough. It seems a bit vague but I can't really assess it properly. I'm particularly concerned with the ...
1
vote
0answers
41 views
While loops in SCSS to produce circles for an animation
I've finally written my first loop in SCSS, trying to avoid it for quite some time since I thought it was unnecessary (was writing vanilla CSS not so long ago, so I was used to manual work).
However, ...
2
votes
0answers
65 views
Storing large amount of iterations (of multiple variables) in a single object [closed]
I am writing a simulation program in C++ which must be able to iterate over multiple variables over multiple classes (according by user input). The basic design of the device is as following:
...
4
votes
2answers
1k views
Square Root Calculator
I have now written a simple square root calculator using the division method:
...
1
vote
0answers
50 views
Parallel for loop in Java - follow-up 2
The previous iteration at Parallel for loop in Java 8 - follow-up.
The changes are as follows:
MyTask is removed.
Synchronization removed. Now the user is ...
1
vote
1answer
1k views
Parallel for loop in Java 8 - follow-up
The previous and initial iteration at Parallel for loop in Java 8.
Changes are as follows:
ParallelLoopBody removed; ...
3
votes
2answers
401 views
Parallel for loop in Java 8
This is my first attempt to provide some syntactic sugar for doing mutually independent loop iterations in parallel. Thanks to Java 8 lambdas, I can write the parallel loops in pretty elegant fashion ...
11
votes
3answers
606 views
Predicting the next pseudorandom value
The archived material for the Stanford University course on cryptography at coursera.org includes a problem where you have to predict the next output of a weak PRG. It can be briefly restated as ...
1
vote
1answer
57 views
Changing the id field to an _id field for the lowest tweet id
I am collecting tweets using a Python script and I want to store them in a MongoDB database.
I want to find out the lowest tweet id and for each tweet, I want to change the ...
1
vote
1answer
2k views
Flattening a HashMap of (String → ArrayList) to an ArrayList
I have one HashMap<String, ArrayList<String>> and I want to concatenate a key with every item in its ArrayList.
...
4
votes
1answer
37 views
Finding the next XML element
I am looking for a better way to do a while cycle with the variable update.
The background is that I'm writing a StAX-line XML reader in JavaScript and want to ...
6
votes
1answer
2k views
Implementation of Tower of Hanoi iterative procedure
I have been working last night on implementing Tower of Hanoi without using recursion. I have found an algorithm on Wikipedia about the same topic here. I have implemented it and it's working fine ...
1
vote
2answers
81 views
Looking for matching names among two text files
I'm trying to enhance the execution speed of my below code. I am using only vanilla JavaScript. I would be willing to bring in additional libraries and plugins as long as they will enhance the overall ...