Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
43
Task/Even-or-odd/NetRexx/even-or-odd.netrexx
Normal file
43
Task/Even-or-odd/NetRexx/even-or-odd.netrexx
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
say 'Val'.right(5)': mod - ver - pos - bits'
|
||||
say '---'.right(5)': ---- + ---- + ---- + ----'
|
||||
loop nn = -15 to 15 by 3
|
||||
say nn.right(5)':' eo(isEven(nn)) '-' eo(isEven(nn, 'v')) '-' eo(isEven(nn, 'p')) '-' eo(isEven(nn, 'b'))
|
||||
end nn
|
||||
return
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
-- Overloaded method. Default is to use the remainder specialization below
|
||||
method isEven(anInt, meth = 'R') public static returns boolean
|
||||
select case meth.upper().left(1)
|
||||
when 'R' then eo = isEvenRemainder(anInt)
|
||||
when 'V' then eo = isEvenVerify(anInt)
|
||||
when 'P' then eo = isEvenPos(anInt)
|
||||
when 'B' then eo = isEvenBits(anInt)
|
||||
otherwise eo = isEvenRemainder(anInt) -- default
|
||||
end
|
||||
return eo
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method isEvenRemainder(anInt) public static returns boolean
|
||||
return anInt // 2 == 0
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method isEvenVerify(anInt) public static returns boolean
|
||||
return anInt.right(1).verify('02468') == 0
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method isEvenPos(anInt) public static returns boolean
|
||||
return '13579'.pos(anInt.right(1)) == 0
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method isEvenBits(anInt) public static returns boolean
|
||||
return \(anInt.d2x(1).x2b().right(1))
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method eo(state = boolean) public static
|
||||
if state then sv = 'Even'
|
||||
else sv = 'Odd'
|
||||
return sv.left(4)
|
||||
Loading…
Add table
Add a link
Reference in a new issue