Generators

  • An Iterator for the Collatz conjecture

    The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined as follows: start with any positive integer n. Then each term is obtained from the previous term as follows: if the previous term is even, the next term is one half the previous term. If the previous term is odd, the next term is 3 times the previous term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.

    After it reaches 1, the iterator will return nil

    See more

    Declaration

    Swift

    public struct Collatz : IteratorProtocol, Sequence
  • An Iterator for the Fibonacci sequence

    In mathematics, the Fibonacci numbers, commonly denoted Fn form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1.

    Since the sequence is infinite, the iterator will always return a BigInt.

    See more

    Declaration

    Swift

    public struct Fibonacci : IteratorProtocol, Sequence
  • A generator for finding prime numbers

    A prime sieve or prime number sieve is a fast type of algorithm for finding primes. It does so by iterating over the natural integers, and returning every number that is indeed prime.

    See more

    Declaration

    Swift

    public struct Sieve : IteratorProtocol