<div class="gmail_quote">On Sun, May 30, 2010 at 19:01, Simen kjaeraas <span dir="ltr">&lt;<a href="mailto:simen.kjaras@gmail.com">simen.kjaras@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">Andrei Alexandrescu &lt;<a href="mailto:SeeWebsiteForEmail@erdani.org" target="_blank">SeeWebsiteForEmail@erdani.org</a>&gt; wrote:<br>
</div><div class="im"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

This reminded me that Phobos lacks a combinatorial range, taking two or<br>
more (forward) ranges and giving all combinations thereof:<br>
<br>
combine([0,1],[2,3])<br>
=&gt;<br>
(0,2), (0,3), (1,2), (1,3)<br>
<br>
Work has commenced on implementing just that.<br>
</blockquote>
<br>
Yah, that would be useful. If Philippe agrees to adapt his work, maybe that would be the fastest route. And don&#39;t forget - the gates of Phobos are open.<br>
</blockquote>
<br></div>
Too late for that, as I&#39;ve already written this. :p<br></blockquote><div><br>Hey, cool, lots of static foreach. Man, it&#39;s like I&#39;m reading my own code. I&#39;m happy to see convergent evolution: this must be the D way to do this.<br>
<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

Current problems: back and popBack not implemented. I&#39;m not sure they<br>
even should be. Doing so would be a tremendous pain the region below the<br>
spine.<br>
<br></blockquote><div><br>Ow.<br>I *guess* it&#39;s doable, but I for sure don&#39;t want to do it.<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

May very well be there are other problems, I don&#39;t know. If anyone finds<br>
any, please let me know.<font color="#888888"></font></blockquote><div><br>Well, I like the way you dealt with popFront.  You length is more costly than mine, but I cheated: I count the numbers of popFronts and substract them from the original length. <br>
<br>Your empty use .length in the foreach loop. You should use .empty instead, I think. And with an infinite range in the mix, the resulting product is infinte also, so you can define your combine to be infinite.<br><br>Then I can give you something to munch over :-)<br>
<br>When one range is infinite, the resulting combination is infinite. What&#39;s sad is that you&#39;ll never &#39;traverse&#39; the infinite range:<br>auto c = combine([0,1,2], cycle([2,3,4]));<br>-&gt;<br>(0,2),(0,3),(0,4),(0,2),(0,3), ...<br>
<br>You never reach the (1,x) (2,x) parts, as it should be seeing how we both defined combinations: iterating on the ranges as if they were digits in a number.<br><br>But there is another way to iterate: diagonally, by cutting successive diagonal slices:<br>
<br>c is:<br>(0,2),(0,3),(0,4),(0,2),...<br>(1,2),(1,3),(1,4),(1,2),...<br>(2,2),(2,3),(2,4),(2,2),...<br>-&gt;<br><br>(0,2),(0,3)(1,2),(0,4),(1,3),(2,2) ... <br><br>It&#39;s even better if all ranges are infinite.<br>I never coded this, but it seems doable for two ranges. Lot thougher for any number of ranges... Pretty obscure, maybe?<br>
<br>btw, I think we should divert this discussion in another thread if you wish to continue: this is bearophile&#39;s Huffman thread, after all.<br><br>  Philippe<br></div></div><br>