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
13 votes
10 answers
8k views

Tests for palindromes in C and C++

A question I've been asked on interactive phone screens is to code a test to determine whether a string is a palindrome or not. I am providing two examples here: one in C and one in C++. They both ...
pacmaninbw's user avatar
  • 23.8k
24 votes
7 answers
10k views

FizzBuzz in Javascript

I'm sure everyone here knows what FizzBuzz is. I would like constructive criticism for my solution. I'm a beginner to programming as a whole and this isn't my first solution, but it's what I think is ...
Zachary Woods's user avatar
6 votes
2 answers
591 views

Integer Partition using an iterator

I tried implementing Integer Partition (enumerating all possible sets of whole numbers whose sum is a given integer). Looking at @rolfl's answer, I reasoned that with a stack data structure, we ...
200_success's user avatar
6 votes
1 answer
1k views

Missing level of technical depth (Recursive to Iterative)

I recently have given a coding test in a reputable IT company. There were three coding questions. They refused me by saying that as we felt they didn't demonstrate the level of technical depth we'...
AAhad's user avatar
  • 409
5 votes
4 answers
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 ...
Bas's user avatar
  • 699
19 votes
1 answer
3k 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 ...
Zizheng Tai's user avatar
11 votes
3 answers
4k views

Generating sequential alphanumeric values that match a certain pattern

I'm working on generating large volumes of test data for some performance testing. Part of this is going to involve generating a lot of values that represent an "MBI", which is a certain kind of alpha-...
Dan Oberlam's user avatar
  • 7,794
10 votes
3 answers
4k 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 ...
txizzle's user avatar
  • 203
8 votes
2 answers
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 ...
coderodde's user avatar
  • 27.8k
7 votes
5 answers
4k views

Find number repeated odd times in array

I completed the following exercise: You are given an array of repeating numbers. All numbers repeat in an even way, except for one. Find that odd occurring number. ...
user7496931's user avatar
5 votes
2 answers
192 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 ...
Daniel Mendel's user avatar
5 votes
2 answers
3k 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 ...
coderodde's user avatar
  • 27.8k
4 votes
2 answers
95 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: ...
Daniel Mendel's user avatar
4 votes
3 answers
1k views

Java Magic square program

Here is my improved version of my Magic square program from following this earlier version. I also added a few comments. Any help for improvements would be really appreciated. ...
Marten's user avatar
  • 585
3 votes
5 answers
129 views

Product iteration while checking for overlaps

This is an extended question to the following question I posted Class scheduling tool with image output Context of previous question: I have a multilayered dictionary that contains information ...
Jake's user avatar
  • 211
2 votes
1 answer
130 views

lexical scope v let in scheme functions

I've been chewing through a bit of The Little Schemer and the Peano examples got me thinking about operation size and time. I got some help on making Peano Multiplication linear -- however ...
ricardo's user avatar
  • 265
2 votes
1 answer
10k 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; ...
coderodde's user avatar
  • 27.8k
2 votes
2 answers
320 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
-2 votes
2 answers
221 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