Hi Joe,<br><br><div class="gmail_quote">On Mon, Mar 19, 2012 at 01:44, Joe Gilray <span dir="ltr"><<a href="mailto:jgilray@gmail.com">jgilray@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi, I created the following code from some scheme I found on ProjectEuler.net (problem #9):<div><br><div><div>(define (right-triangle? a b c)</div><div> (= (+ (* a a) (* b b)) (* c c)))</div></div></div></blockquote><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>-snip-<br> </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>Thoughts?</div></div><div><br></div></blockquote><div><br></div><div>When I saw your code it made me think of a good chance to use for*.</div>
<div><br></div><div>This is what I got:</div><div><br></div><div><br></div><div><font face="'courier new', monospace">(define (pythagorean-triple/alt n)</font></div><div><font face="'courier new', monospace"> (for*/first ([a (in-range 1 n)]</font></div>
<div><font face="'courier new', monospace"> [b (in-range a n)]</font></div><div><font face="'courier new', monospace"> [c (in-value (- n a b))]</font></div><div><font face="'courier new', monospace"> #:when (right-triangle? a b c))</font></div>
<div><font face="'courier new', monospace"> (list a b c))) </font></div></div><div><br></div><div><br></div><div>The cool thing is that this is my first use of <a href="http://docs.racket-lang.org/reference/sequences.html#(def._((lib._racket/private/base..rkt)._in-value))">in-value</a>, and the docs say that "<span style="background-color:rgb(255,255,255);font-family:serif;text-align:left;font-size:medium">This form is mostly useful for </span><span class="RktSym" style="background-color:rgb(255,255,255);font-family:monospace;color:rgb(38,38,128);text-align:left"><a href="http://docs.racket-lang.org/reference/let.html#(form._((lib._racket/private/letstx-scheme..rkt)._let))" class="RktStxLink" style="text-decoration:none;color:black">let</a></span><span style="background-color:rgb(255,255,255);font-family:serif;text-align:left;font-size:medium">-like bindings in forms such as </span><span class="RktSym" style="background-color:rgb(255,255,255);font-family:monospace;color:rgb(38,38,128);text-align:left"><a href="http://docs.racket-lang.org/reference/for.html#(form._((lib._racket/private/base..rkt)._for*/list))" class="RktStxLink" style="text-decoration:none;color:black">for*/list</a></span><span style="background-color:rgb(255,255,255);font-family:serif;text-align:left;font-size:medium">.</span>"!</div>
<div><br></div><div>One more nice thing about using <i>for </i>is that the loop becomes bounded (I got infinite running programs when I ran your code with bad input n).</div><div><br></div><div><br></div><div>[]'s</div>
<div><br>Rodolfo</div>