Even or odd: Difference between revisions

m
 
(5 intermediate revisions by 4 users not shown)
Line 1,253:
 
Outputs E if even, O if odd.
 
=={{header|Binary Lambda Calculus}}==
In lambda calculus, the oddness of a given church numeral n can be computed as n applications of <code>not</code> to <code>false</code>: <code>\n. n (\b\x\y. b y x) (\x\y.y)</code>, which in BLC is
 
<pre>00 01 01 10 0000000101111010110 000010</pre>
 
To compute the evenness, one need only replace <code>false</code> by <code>true</code>, i.e. replace the final 0 bit by 10.
 
=={{header|BQN}}==
Line 1,766 ⟶ 1,773:
Modulo:
<syntaxhighlight lang="delphi">var isOdd := (i mod 2)=1;</syntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
a = 13
if a mod 2 = 0
print a & " is even"
else
print a & " is odd"
.
</syntaxhighlight>
 
=={{header|EDSAC order code}}==
Line 4,178 ⟶ 4,195:
return true
}</syntaxhighlight>
=={{header|Swift}}==
<syntaxhighlight lang="swift">
// Swift has Int.isMultiple(of:Int) -> Bool
 
var isEven: (_:Int) -> Bool = {$0.isMultiple(of: 2)}
</syntaxhighlight>
 
=={{header|Symsyn}}==
Line 4,361 ⟶ 4,384:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var isEven1 = Fn.new { |i| i & 1 == 0 }
56

edits