Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Euclidean algorithm Golf in Perl 6by moritz (Cardinal) |
on Jun 18, 2009 at 16:28 UTC ( [id://772778]=note: print w/replies, xml ) | Need Help?? |
Two simple things you can do (also in Perl 5):
You can get rid of the temporary $t by using list assignment:
Or you can resort to recursion, ignoring your boundaries to the golf court:
For none of these I can see something where Perl 6 really plays its strengths. So maybe something completely else? This might work, but since nobody implements infix:<...> yet, I couldn't test it:
For example for gcd(42, 24) it would produce the list 42, 24, 18, 6. During the next call to the block it the $^x % $^y returns 0, and the block the empty list, ending the creation of the list. The last element is the gcd.
In Section
Seekers of Perl Wisdom
|
|