Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
30
Task/Even-or-odd/Crystal/even-or-odd.crystal
Normal file
30
Task/Even-or-odd/Crystal/even-or-odd.crystal
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#Using bitwise shift
|
||||
def isEven_bShift(n)
|
||||
n == ((n >> 1) << 1)
|
||||
end
|
||||
def isOdd_bShift(n)
|
||||
n != ((n >> 1) << 1)
|
||||
end
|
||||
#Using modulo operator
|
||||
def isEven_mod(n)
|
||||
(n % 2) == 0
|
||||
end
|
||||
def isOdd_mod(n)
|
||||
(n % 2) != 0
|
||||
end
|
||||
# Using bitwise "and"
|
||||
def isEven_bAnd(n)
|
||||
(n & 1) == 0
|
||||
end
|
||||
def isOdd_bAnd(n)
|
||||
(n & 1) != 0
|
||||
end
|
||||
|
||||
puts isEven_bShift(7)
|
||||
puts isOdd_bShift(7)
|
||||
|
||||
puts isEven_mod(12)
|
||||
puts isOdd_mod(12)
|
||||
|
||||
puts isEven_bAnd(21)
|
||||
puts isOdd_bAnd(21)
|
||||
Loading…
Add table
Add a link
Reference in a new issue