[swift-evolution] About the PermutationGenerator

Susan Cheng susan.doggie at gmail.com
Thu Dec 31 08:09:41 CST 2015


sequence can have more methods with it, we can find first five values of
a sequence.

but we don't do this with a generator

struct Fibonacci: SequenceType {



    var first, second: Int



    func generate() -> AnyGenerator<Int> {



        var a = first

        var b = second



        return anyGenerator {

            let temp = a

            (a, b) = (b, a + b)

            return temp

        }

    }

}


Array(Fibonacci(first: 1, second: 1).prefix(10))

Happy new year to all


2015-12-31 21:57 GMT+08:00 Dmitri Gribenko <gribozavr at gmail.com>:

> On Thu, Dec 31, 2015 at 3:36 PM, Susan Cheng <susan.doggie at gmail.com>
> wrote:
> > I don't think so.
> >
> > As we don't say "Fibonacci collection", we know Fibonacci numbers are in
> > order. But we can't tell the number immediately if I asked a specific
> index
> > of Fibonacci sequence. The only way is calculate the sequence one by one
> > from start.
>
> That's OK, collections can have Forward indices which have exactly
> these properties.
>
> Dmitri
>
> --
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151231/a3fb8676/attachment.html>


More information about the swift-evolution mailing list