<div dir="ltr">sequence can have more methods with it, we can find first five values of a sequence.<div><br></div><div>but we don't do this with a generator<br><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">struct</span> Fibonacci: <span style="color:rgb(112,61,170)">SequenceType</span> {</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"> </p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(187,44,162)">var</span> first, second: <span style="color:rgb(112,61,170)">Int</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"> </p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(187,44,162)">func</span> generate() -> <span style="color:rgb(112,61,170)">AnyGenerator</span><<span style="color:rgb(112,61,170)">Int</span>> {</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"> </p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(187,44,162)">var</span> a = <span style="color:rgb(79,129,135)">first</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(187,44,162)">var</span> b = <span style="color:rgb(79,129,135)">second</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"> </p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(61,29,129)"><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(187,44,162)">return</span><span style="color:rgb(0,0,0)"> </span>anyGenerator<span style="color:rgb(0,0,0)"> {</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(187,44,162)">let</span> temp = a</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> (a, b) = (b, a + b)</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(187,44,162)">return</span> temp</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(112,61,170)">Array</span>(<span style="color:rgb(79,129,135)">Fibonacci</span>(first: <span style="color:rgb(39,42,216)">1</span>, second: <span style="color:rgb(39,42,216)">1</span>).<span style="color:rgb(61,29,129)">prefix</span>(<span style="color:rgb(39,42,216)">10</span>))</p></div></div><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div><span style="font-size:14px">Happy new year to all</span><br></div><div><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-12-31 21:57 GMT+08:00 Dmitri Gribenko <span dir="ltr"><<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Thu, Dec 31, 2015 at 3:36 PM, Susan Cheng <<a href="mailto:susan.doggie@gmail.com">susan.doggie@gmail.com</a>> wrote:<br>
> I don't think so.<br>
><br>
> As we don't say "Fibonacci collection", we know Fibonacci numbers are in<br>
> order. But we can't tell the number immediately if I asked a specific index<br>
> of Fibonacci sequence. The only way is calculate the sequence one by one<br>
> from start.<br>
<br>
</span>That's OK, collections can have Forward indices which have exactly<br>
these properties.<br>
<div class="HOEnZb"><div class="h5"><br>
Dmitri<br>
<br>
--<br>
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if<br>
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>>*/<br>
</div></div></blockquote></div><br></div>