Anonymous user
Greatest common divisor: Difference between revisions
no edit summary
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
No edit summary |
||
Line 2,110:
{{VI snippet}}<br/>
[[File:LabVIEW Greatest common divisor.png]]
=={{header|Lambdatalk}}==
<lang scheme>
{def gcd
{lambda {:a :b}
{if {= :b 0}
then :a
else {gcd :b {% :a :b}}}}}
-> gcd
{gcd 12 3}
-> 3
{gcd 123 122}
-> 1
{S.map {gcd 123} {S.serie 1 30}}
-> 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3
A simpler one if a and b are greater than zero
{def GCD
{lambda {:a :b}
{if {= :a :b}
then :a
else {if {> :a :b}
then {GCD {- :a :b} :b}
else {GCD :a {- :b :a}}}}}}
-> GCD
{S.map {GCD 123} {S.serie 1 30}}
-> 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3
</lang>
=={{header|LFE}}==
|