Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,4 @@
---
category:
- Simple
from: http://rosettacode.org/wiki/Even_or_odd

View file

@ -0,0 +1,13 @@
;Task:
Test whether an integer is even or odd.
There is more than one way to solve this task:
* Use the even and odd predicates, if the language provides them.
* Check the least significant digit. With binary integers, ''i [[bitwise operations|bitwise-and]] 1'' equals 0 [[wikt:iff|iff]] ''i'' is even, or equals 1 iff ''i'' is odd.
* Divide ''i'' by 2. The remainder equals 0 iff ''i'' is even. The remainder equals +1 or -1 iff ''i'' is odd.
* Use modular congruences:
** ''i'' ≡ 0 (mod 2) iff ''i'' is even.
** ''i'' ≡ 1 (mod 2) iff ''i'' is odd.
<br><br>

View file

@ -0,0 +1,2 @@
}:s:|=<:2:x~#:e:=/~%~<:20:~$=<:73:x<:69:~$~$~<:20:~$=^:o:<:65:
x<:76:=$=$~$<:6E:~$<:a:~$^:s:}:o:<:6F:x<:64:x~$~$$<:a:~$^:s:

View file

@ -0,0 +1,5 @@
F is_even(i)
R i % 2 == 0
F is_odd(i)
R i % 2 == 1

View file

@ -0,0 +1,48 @@
.lf evenodd6502.lst
.cr 6502
.tf evenodd6502.obj,ap1
;------------------------------------------------------
; Even or Odd for the 6502 by barrym95838 2014.12.10
; Thanks to sbprojects.com for a very nice assembler!
; The target for this assembly is an Apple II with
; mixed-case output capabilities. Apple IIs like to
; work in '+128' ascii, and this version is tailored
; to that preference.
; Tested and verified on AppleWin 1.20.0.0
;------------------------------------------------------
; Constant Section
;
CharIn = $fd0c ;Specific to the Apple II
CharOut = $fded ;Specific to the Apple II
;------------------------------------------------------
; The main program
;
main ldy #sIntro-sbase
jsr puts ;Print Intro
loop jsr CharIn ;Get a char from stdin
cmp #$83 ;Ctrl-C?
beq done ; yes: end program
jsr CharOut ;Echo char
ldy #sOdd-sbase ;Pre-load odd string
lsr ;LSB of char to carry flag
bcs isodd
ldy #sEven-sbase
isodd jsr puts ;Print appropriate response
beq loop ;Always taken
; Output NUL-terminated string @ offset Y
;
puts lda sbase,y ;Get string char
beq done ;Done if NUL
jsr CharOut ;Output the char
iny ;Point to next char
bne puts ;Loop up to 255 times
done rts ;Return to caller
;------------------------------------------------------
; String Constants (in '+128' ascii, Apple II style)
;
sbase: ;String base address
sIntro .az -"Hit any key (Ctrl-C to quit):",-#13
sEven .az -" is even.",-#13
sOdd .az -" is odd.",-#13
;------------------------------------------------------
.en

View file

@ -0,0 +1,3 @@
BTST D0,#1
BNE isOdd
;else, is even.

View file

@ -0,0 +1,3 @@
AND.B D0,#1
BNE isOdd
;else, is even.

View file

@ -0,0 +1,3 @@
ROR.B D0,#1
BCS isOdd
;else, is even.

View file

@ -0,0 +1,3 @@
ROXR.B D0,#1
BCS isOdd
;else, is even.

View file

@ -0,0 +1,3 @@
LSR.B D0,#1
BCS isOdd
;else, is even.

View file

@ -0,0 +1,3 @@
ASR.B D0,#1
BCS isOdd
;else, is even.

View file

@ -0,0 +1,17 @@
CMDLIN: equ 80h ; Location of CP/M command line argument
puts: equ 9h ; Syscall to print a string
;;; Check if number given on command line is even or odd
org 100h
lxi h,CMDLIN ; Find length of argument
mov a,m
add l ; Look up last character (digit)
mov l,a
mov a,m ; Retrieve low digit
rar ; Rotate low bit into carry flag
mvi c,puts ; Prepare to print string
lxi d,odd ; If carry is set, then the number is odd
jc 5 ; So print 'odd'
lxi d,even ; Otherwise, the number is even
jmp 5 ; So print 'even'
even: db 'Even$' ; Strings
odd: db 'Odd$'

View file

@ -0,0 +1,3 @@
test ax,1
jne isOdd
;else, is even

View file

@ -0,0 +1,3 @@
and ax,1
jne isOdd
;else, is even

View file

@ -0,0 +1,3 @@
ror ax,1
jc isOdd
;else, is even

View file

@ -0,0 +1,3 @@
rcr ax,1
jc isOdd
;else, is even

View file

@ -0,0 +1,3 @@
sar ax,1
jc isOdd
;else, is even

View file

@ -0,0 +1,3 @@
shr ax,1
jc isOdd
;else, is even

View file

@ -0,0 +1,4 @@
: odd? \ n -- boolean
dup 1 n:band 1 n:= ;
: even? \ n -- boolean
odd? not ;

View file

@ -0,0 +1,4 @@
: even? \ n -- f
1 n:band not ;
: odd? \ n -- f
even? not ;

View file

@ -0,0 +1,74 @@
/* ARM assembly AARCH64 Raspberry PI 3B and android arm 64 bits*/
/* program oddEven64.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
/*********************************/
/* Initialized data */
/*********************************/
.data
sMessResultOdd: .asciz " @ is odd (impair) \n"
sMessResultEven: .asciz " @ is even (pair) \n"
szCarriageReturn: .asciz "\n"
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
sZoneConv: .skip 24
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: //entry of program
mov x0,#5
bl testOddEven
mov x0,#12
bl testOddEven
mov x0,#2021
bl testOddEven
100: //standard end of the program
mov x0, #0 //return code
mov x8, #EXIT //request to exit program
svc #0 //perform the system call
qAdrszCarriageReturn: .quad szCarriageReturn
qAdrsMessResultOdd: .quad sMessResultOdd
qAdrsMessResultEven: .quad sMessResultEven
qAdrsZoneConv: .quad sZoneConv
/***************************************************/
/* test if number is odd or even */
/***************************************************/
// x0 contains à number
testOddEven:
stp x1,lr,[sp,-16]! // save registres
tst x0,#1 //test bit 0 to one
beq 1f //if result are all zéro, go to even
ldr x1,qAdrsZoneConv //else display odd message
bl conversion10 //call decimal conversion
ldr x0,qAdrsMessResultOdd
ldr x1,qAdrsZoneConv //insert value conversion in message
bl strInsertAtCharInc
bl affichageMess
b 100f
1:
ldr x1,qAdrsZoneConv
bl conversion10 //call decimal conversion
ldr x0,qAdrsMessResultEven
ldr x1,qAdrsZoneConv //insert conversion in message
bl strInsertAtCharInc
bl affichageMess
100:
ldp x1,lr,[sp],16 // restaur des 2 registres
ret
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"

View file

@ -0,0 +1,11 @@
cl_demo_output=>display(
VALUE string_table(
FOR i = -5 WHILE i < 6 (
COND string(
LET r = i MOD 2 IN
WHEN r = 0 THEN |{ i } is even|
ELSE |{ i } is odd|
)
)
)
).

View file

@ -0,0 +1,8 @@
# Algol 68 has a standard operator: ODD which returns TRUE if its integer #
# operand is odd and FALSE if it is even #
# E.g.: #
INT n;
print( ( "Enter an integer: " ) );
read( ( n ) );
print( ( whole( n, 0 ), " is ", IF ODD n THEN "odd" ELSE "even" FI, newline ) )

View file

@ -0,0 +1,15 @@
BEGIN
% RETURN 1 IF EVEN, OTHERWISE 0 %
INTEGER FUNCTION EVEN(I);
INTEGER I;
BEGIN
EVEN := 1 - (I - 2 * (I / 2));
END;
% TEST THE ROUTINE %
INTEGER K;
FOR K := 1 STEP 3 UNTIL 10 DO
WRITE(K," IS ", IF EVEN(K) = 1 THEN "EVEN" ELSE "ODD");
END

View file

@ -0,0 +1,6 @@
% RETURN 1 IF EVEN, OTHERWISE 0 %
INTEGER FUNCTION EVEN(I);
INTEGER I;
BEGIN
EVEN := (IF I = 2 * (I / 2) THEN 1 ELSE 0);
END;

View file

@ -0,0 +1,8 @@
begin
% the Algol W standard procedure odd returns true if its integer %
% parameter is odd, false if it is even %
for i := 1, 1702, 23, -26
do begin
write( i, " is ", if odd( i ) then "odd" else "even" )
end for_i
end.

View file

@ -0,0 +1,2 @@
odd: {x mod 2}
even: {1 - x mod 2}

View file

@ -0,0 +1,4 @@
2|28
0
2|37
1

View file

@ -0,0 +1,77 @@
/* ARM assembly Raspberry PI or android 32 bits */
/* program oddEven.s */
/* REMARK 1 : this program use routines in a include file
see task Include a file language arm assembly
for the routine affichageMess conversion10
see at end of this program the instruction include */
/* for constantes see task include a file in arm assembly */
/************************************/
/* Constantes */
/************************************/
.include "../constantes.inc"
/*********************************/
/* Initialized data */
/*********************************/
.data
sMessResultOdd: .asciz " @ is odd (impair) \n"
sMessResultEven: .asciz " @ is even (pair) \n"
szCarriageReturn: .asciz "\n"
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
sZoneConv: .skip 24
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: @ entry of program
mov r0,#5
bl testOddEven
mov r0,#12
bl testOddEven
mov r0,#2021
bl testOddEven
100: @ standard end of the program
mov r0, #0 @ return code
mov r7, #EXIT @ request to exit program
svc #0 @ perform the system call
iAdrszCarriageReturn: .int szCarriageReturn
iAdrsMessResultOdd: .int sMessResultOdd
iAdrsMessResultEven: .int sMessResultEven
iAdrsZoneConv: .int sZoneConv
/***************************************************/
/* test if number is odd or even */
/***************************************************/
// r0 contains à number
testOddEven:
push {r2-r8,lr} @ save registers
tst r0,#1 @ test bit 0 to one
beq 1f @ if result are all zéro, go to even
ldr r1,iAdrsZoneConv @ else display odd message
bl conversion10 @ call decimal conversion
ldr r0,iAdrsMessResultOdd
ldr r1,iAdrsZoneConv @ insert value conversion in message
bl strInsertAtCharInc
bl affichageMess
b 100f
1:
ldr r1,iAdrsZoneConv
bl conversion10 @ call decimal conversion
ldr r0,iAdrsMessResultEven
ldr r1,iAdrsZoneConv @ insert conversion in message
bl strInsertAtCharInc
bl affichageMess
100:
pop {r2-r8,lr} @ restaur registers
bx lr @ return
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
.include "../affichage.inc"

View file

@ -0,0 +1,7 @@
function isodd(x) {
return x % 2 != 0
}
function iseven(x) {
return x % 2 == 0
}

View file

@ -0,0 +1,42 @@
PROC OddByAnd(INT v)
IF (v&1)=0 THEN
Print(" even")
ELSE
Print(" odd ")
FI
RETURN
PROC OddByMod(INT v)
;MOD doesn't work properly for negative numbers in Action!
IF v<0 THEN
v=-v
FI
IF v MOD 2=0 THEN
Print(" even")
ELSE
Print(" odd ")
FI
RETURN
PROC OddByDiv(INT v)
INT d
d=(v/2)*2
IF v=d THEN
Print(" even")
ELSE
Print(" odd ")
FI
RETURN
PROC Main()
INT i
FOR i=-4 TO 4
DO
PrintF("%I is",i)
OddByAnd(i)
OddByMod(i)
OddByDiv(i)
PutE()
OD
RETURN

View file

@ -0,0 +1,15 @@
-- Ada has bitwise operators in package Interfaces,
-- but they work with Interfaces.Unsigned_*** types only.
-- Use rem or mod for Integer types, and let the compiler
-- optimize it.
declare
N : Integer := 5;
begin
if N rem 2 = 0 then
Put_Line ("Even number");
elseif N rem 2 /= 0 then
Put_Line ("Odd number");
else
Put_Line ("Something went really wrong!");
end if;
end;

View file

@ -0,0 +1,13 @@
module EvenOrOdd where
open import Data.Bool using (Bool; false; true)
open import Data.Nat using (; zero; suc)
even : Bool
odd : Bool
even zero = true
even (suc n) = odd n
odd zero = false
odd (suc n) = even n

View file

@ -0,0 +1,5 @@
if (x & 1) {
# x is odd
} else {
# x is even
}

View file

@ -0,0 +1,14 @@
set L to {3, 2, 1, 0, -1, -2, -3}
set evens to {}
set odds to {}
repeat with x in L
if (x mod 2 = 0) then
set the end of evens to x's contents
else
set the end of odds to x's contents
end if
end repeat
return {even:evens, odd:odds}

View file

@ -0,0 +1 @@
{even:{2, 0, -2}, odd:{3, 1, -1, -3}}

View file

@ -0,0 +1,67 @@
----------------------- EVEN OR ODD ------------------------
-- even :: Int -> Bool
on even(n)
0 = n mod 2
end even
-- odd :: Int -> Bool
on odd(n)
not even(n)
end odd
--------------------------- TEST ---------------------------
on run
partition(odd, enumFromTo(-6, 6))
--> {{-5, -3, -1, 1, 3, 5}, {-6, -4, -2, 0, 2, 4, 6}}
end run
-------------------- GENERICS FOR TEST ---------------------
-- enumFromTo :: Int -> Int -> [Int]
on enumFromTo(m, n)
if m n then
set lst to {}
repeat with i from m to n
set end of lst to i
end repeat
lst
else
{}
end if
end enumFromTo
-- partition :: (a -> Bool) -> [a] -> ([a], [a])
on partition(p, xs)
tell mReturn(p)
set {ys, zs} to {{}, {}}
repeat with x in xs
set v to contents of x
if |λ|(v) then
set end of ys to v
else
set end of zs to v
end if
end repeat
end tell
{ys, zs}
end partition
-- mReturn :: First-class m => (a -> b) -> m (a -> b)
on mReturn(f)
-- 2nd class handler function lifted into 1st class script wrapper.
if script is class of f then
f
else
script
property |λ| : f
end script
end if
end mReturn

View file

@ -0,0 +1 @@
{{-5, -3, -1, 1, 3, 5}, {-6, -4, -2, 0, 2, 4, 6}}

View file

@ -0,0 +1,4 @@
10 INPUT "ENTER A NUMBER: ";N
20 IF N/2 <> INT(N/2) THEN PRINT "THE NUMBER IS ODD":GOTO 40
30 PRINT "THE NUMBER IS EVEN"
40 END

View file

@ -0,0 +1,32 @@
LISTEN TO ME VERY CAREFULLY isOdd
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE n
GIVE THESE PEOPLE AIR
HEY CHRISTMAS TREE result
YOU SET US UP @I LIED
GET TO THE CHOPPER result
HERE IS MY INVITATION n
I LET HIM GO 2
ENOUGH TALK
I'LL BE BACK result
HASTA LA VISTA, BABY
LISTEN TO ME VERY CAREFULLY showParity
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE n
TALK TO THE HAND n
HEY CHRISTMAS TREE parity
YOU SET US UP @I LIED
GET YOUR A** TO MARS parity
DO IT NOW isOdd n
BECAUSE I'M GOING TO SAY PLEASE parity
TALK TO THE HAND "odd"
BULLS***
TALK TO THE HAND "even"
YOU HAVE NO RESPECT FOR LOGIC
TALK TO THE HAND ""
HASTA LA VISTA, BABY
IT'S SHOWTIME
DO IT NOW showParity 5
DO IT NOW showParity 6
DO IT NOW showParity -11
YOU HAVE BEEN TERMINATED

View file

@ -0,0 +1,4 @@
loop (neg 5)..5 [x][
if? even? x -> print [pad to :string x 4 ": even"]
else -> print [pad to :string x 4 ": odd"]
]

View file

@ -0,0 +1,7 @@
for (int i = 1; i <= 10; ++i) {
if (i % 2 == 0) {
write(string(i), " is even");
} else {
write(string(i), " is odd");
}
}

View file

@ -0,0 +1,5 @@
if ( int & 1 ){
; do odd stuff
}else{
; do even stuff
}

View file

@ -0,0 +1,4 @@
for i = 1 to 10
if (i mod 2) then print i;" is odd" else print i;" is even"
next i
end

View file

@ -0,0 +1,11 @@
IF FNisodd%(14) PRINT "14 is odd" ELSE PRINT "14 is even"
IF FNisodd%(15) PRINT "15 is odd" ELSE PRINT "15 is even"
IF FNisodd#(9876543210#) PRINT "9876543210 is odd" ELSE PRINT "9876543210 is even"
IF FNisodd#(9876543211#) PRINT "9876543211 is odd" ELSE PRINT "9876543211 is even"
END
REM Works for -2^31 <= n% < 2^31
DEF FNisodd%(n%) = (n% AND 1) <> 0
REM Works for -2^53 <= n# <= 2^53
DEF FNisodd#(n#) = n# <> 2 * INT(n# / 2)

View file

@ -0,0 +1,4 @@
odd 2|
!0 odd 12
!1 odd 31

View file

@ -0,0 +1,5 @@
' Even or odd
OPTION MEMTYPE int
SPLIT ARGUMENT$ BY " " TO arg$ SIZE dim
n = IIF$(dim < 2, 0, VAL(arg$[1]))
PRINT n, " is ", IIF$(EVEN(n), "even", "odd")

View file

@ -0,0 +1,14 @@
@echo off
set /p i=Insert number:
::bitwise and
set /a "test1=%i%&1"
::divide last character by 2
set /a test2=%i:~-1%/2
::modulo
set /a test3=%i% %% 2
set test
pause>nul

View file

@ -0,0 +1,8 @@
i = -3
/* Assumes that i is an integer. */
scale = 0
if (i % 2 == 0) "i is even
"
if (i % 2) "i is odd
"

View file

@ -0,0 +1,5 @@
beads 1 program 'Even or odd'
calc main_init
loop across:[-10, -5, 10, 5] val:v
log "{v}\todd:{is_odd(v)}\teven:{is_even(v)}"

View file

@ -0,0 +1 @@
&2%52**"E"+,@

View file

@ -0,0 +1,29 @@
( ( even
=
. @( !arg
: ?
[-2
( 0
| 2
| 4
| 6
| 8
)
)
)
& (odd=.~(even$!arg))
& ( eventest
=
. out
$ (!arg is (even$!arg&|not) even)
)
& ( oddtest
=
. out
$ (!arg is (odd$!arg&|not) odd)
)
& eventest$5556
& oddtest$5556
& eventest$857234098750432987502398457089435
& oddtest$857234098750432987502398457089435
)

View file

@ -0,0 +1,8 @@
,[>,----------] Read until newline
++< Get a 2 and move into position
[->-[>+>>]> Do
[+[-<+>]>+>>] divmod
<<<<<] magic
>[-]<++++++++ Clear and get an 8
[>++++++<-] to get a 48
>[>+<-]>. to get n % 2 to ASCII and print

View file

@ -0,0 +1 @@
,[>,----------]<[--]

View file

@ -0,0 +1 @@
2.%

View file

@ -0,0 +1,9 @@
bool isOdd(int x)
{
return x % 2;
}
bool isEven(int x)
{
return !(x % 2);
}

View file

@ -0,0 +1,17 @@
template < typename T >
constexpr inline bool isEven( const T& v )
{
return isEven( int( v ) );
}
template <>
constexpr inline bool isEven< int >( const int& v )
{
return (v & 1) == 0;
}
template < typename T >
constexpr inline bool isOdd( const T& v )
{
return !isEven(v);
}

View file

@ -0,0 +1,66 @@
namespace RosettaCode
{
using System;
public static class EvenOrOdd
{
public static bool IsEvenBitwise(this int number)
{
return (number & 1) == 0;
}
public static bool IsOddBitwise(this int number)
{
return (number & 1) != 0;
}
public static bool IsEvenRemainder(this int number)
{
int remainder;
Math.DivRem(number, 2, out remainder);
return remainder == 0;
}
public static bool IsOddRemainder(this int number)
{
int remainder;
Math.DivRem(number, 2, out remainder);
return remainder != 0;
}
public static bool IsEvenModulo(this int number)
{
return (number % 2) == 0;
}
public static bool IsOddModulo(this int number)
{
return (number % 2) != 0;
}
}
public class Program
{
public static void Main()
{
int num = 26; //Set this to any integer.
if (num.IsEvenBitwise()) //Replace this with any even function.
{
Console.Write("Even");
}
else
{
Console.Write("Odd");
}
//Prints "Even".
if (num.IsOddBitwise()) //Replace this with any odd function.
{
Console.Write("Odd");
}
else
{
Console.Write("Even");
}
//Prints "Even".
}
}
}

View file

@ -0,0 +1,5 @@
if (x & 1) {
/* x is odd */
} else {
/* or not */
}

View file

@ -0,0 +1,4 @@
mpz_t x;
...
if (mpz_even_p(x)) { /* x is even */ }
if (mpz_odd_p(x)) { /* x is odd */ }

View file

@ -0,0 +1,5 @@
IF FUNCTION REM(Num, 2) = 0
DISPLAY Num " is even."
ELSE
DISPLAY Num " is odd."
END-IF

View file

@ -0,0 +1,6 @@
10 cls
20 for n = 1 to 10
30 print n;
40 if (n and 1) = 1 then print "is odd" else print "is even"
50 next n
60 end

View file

@ -0,0 +1,2 @@
(if (even? some-var) (do-even-stuff))
(if (odd? some-var) (do-odd-stuff))

View file

@ -0,0 +1 @@
isEven = (x) -> !(x%2)

View file

@ -0,0 +1,3 @@
function f(numeric n) {
return n mod 2?"odd":"even"
}

View file

@ -0,0 +1,7 @@
10 rem determine if integer is even or odd
20 print "Enter an integer:";
30 input i%
35 print
40 eo$="even"
50 if (i% and 1)=1 then eo$="odd"
60 print "The number ";i%;"is ";eo$;"."

View file

@ -0,0 +1,2 @@
(if (evenp some-var) (do-even-stuff))
(if (oddp some-other-var) (do-odd-stuff))

View file

@ -0,0 +1,10 @@
;; Project : Even or odd
(defun evenodd (nr)
(cond ((evenp nr) "even")
((oddp nr) "odd")))
(dotimes (n 10)
(if (< n 1) (terpri))
(if (< n 9) (format t "~a" " "))
(write(+ n 1)) (format t "~a" ": ")
(format t "~a" (evenodd (+ n 1))) (terpri))

View file

@ -0,0 +1,53 @@
MODULE EvenOdd;
IMPORT StdLog,Args,Strings;
PROCEDURE BitwiseOdd(i: INTEGER): BOOLEAN;
BEGIN
RETURN 0 IN BITS(i)
END BitwiseOdd;
PROCEDURE Odd(i: INTEGER): BOOLEAN;
BEGIN
RETURN (i MOD 2) # 0
END Odd;
PROCEDURE CongruenceOdd(i: INTEGER): BOOLEAN;
BEGIN
RETURN ((i -1) MOD 2) = 0
END CongruenceOdd;
PROCEDURE Do*;
VAR
p: Args.Params;
i,done,x: INTEGER;
BEGIN
Args.Get(p);
StdLog.String("Builtin function: ");StdLog.Ln;i := 0;
WHILE i < p.argc DO
Strings.StringToInt(p.args[i],x,done);
StdLog.String(p.args[i] + " is:> ");
IF ODD(x) THEN StdLog.String("odd") ELSE StdLog.String("even") END;
StdLog.Ln;INC(i)
END;
StdLog.String("Bitwise: ");StdLog.Ln;i:= 0;
WHILE i < p.argc DO
Strings.StringToInt(p.args[i],x,done);
StdLog.String(p.args[i] + " is:> ");
IF BitwiseOdd(x) THEN StdLog.String("odd") ELSE StdLog.String("even") END;
StdLog.Ln;INC(i)
END;
StdLog.String("Module: ");StdLog.Ln;i := 0;
WHILE i < p.argc DO
Strings.StringToInt(p.args[i],x,done);
StdLog.String(p.args[i] + " is:> ");
IF Odd(x) THEN StdLog.String("odd") ELSE StdLog.String("even") END;
StdLog.Ln;INC(i)
END;
StdLog.String("Congruences: ");StdLog.Ln;i := 0;
WHILE i < p.argc DO
Strings.StringToInt(p.args[i],x,done);
StdLog.String(p.args[i] + " is:> ");
IF CongruenceOdd(x) THEN StdLog.String("odd") ELSE StdLog.String("even") END;
StdLog.Ln;INC(i)
END;
END Do;

View 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)

View file

@ -0,0 +1,6 @@
void main() {
import std.stdio, std.bigint;
foreach (immutable i; -5 .. 6)
writeln(i, " ", i & 1, " ", i % 2, " ", i.BigInt % 2);
}

View file

@ -0,0 +1,8 @@
$! in DCL, for integers, the least significant bit determines the logical value, where 1 is true and 0 is false
$
$ i = -5
$ loop1:
$ if i then $ write sys$output i, " is odd"
$ if .not. i then $ write sys$output i, " is even"
$ i = i + 1
$ if i .le. 6 then $ goto loop1

View file

@ -0,0 +1 @@
var isOdd := Odd(i);

View file

@ -0,0 +1 @@
var isOdd := (i and 1)<>0;

View file

@ -0,0 +1 @@
var isOdd := (i mod 2)=1;

View file

@ -0,0 +1,9 @@
void main() {
for (var i = 1; i <= 10; i++) {
if (i % 2 != 0) {
print("$i is odd");
} else {
print("$i is even");
}
}
}

View file

@ -0,0 +1 @@
[K Sk 0 k 2 % Lk k]

View file

@ -0,0 +1,29 @@
program EvenOdd;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
procedure IsOdd(aValue: Integer);
var
Odd: Boolean;
begin
Odd := aValue and 1 <> 0;
Write(Format('%d is ', [aValue]));
if Odd then
Writeln('odd')
else
Writeln('even');
end;
var
i: Integer;
begin
for i := -5 to 10 do
IsOdd(i);
Readln;
end.

View file

@ -0,0 +1,5 @@
use_namespace(rosettacode)_me();
funct(isEven)_arg(i)_ret()_calc(i%2)_equals(0);
reset_namespace[];

View file

@ -0,0 +1,33 @@
[ Even or odd
===========
A program for the EDSAC
Determines whether the number stored at
address 15@ is even or odd, and prints
'E' or 'O' accordingly
Works with Initial Orders 2 ]
T56K [ load point ]
GK [ base address ]
O11@ [ print letter shift ]
T10@ [ clear accumulator ]
H15@ [ multiplier := n ]
C12@ [ acc +:= mult AND 1 ]
S12@ [ acc -:= 1 ]
G8@ [ branch on negative ]
O14@ [ print 'O' ]
ZF [ halt ]
[ 8 ] O13@ [ print 'E' ]
ZF [ halt ]
[ 10 ] P0F [ used to clear acc ]
[ 11 ] *F [ letter shift character ]
[ 12 ] P0D [ const: 1 ]
[ 13 ] EF [ character 'E' ]
[ 14 ] OF [ character 'O' ]
[ 15 ] P18D [ number to test: 37 ]
EZPF [ branch to load point ]

View file

@ -0,0 +1,20 @@
List evenCheckers = fun[
logic by int i do return i % 2 == 0 end,
logic by int i do return i & 1 == 0 end]
List oddCheckers = fun[
logic by int i do return i % 2 != 0 end,
logic by int i do return i & 1 == 1 end]
writeLine("integer".padStart(10, " ") + "|is_even" + "|is_odd |")
writeLine("----------+-------+-------+")
for each int i in range(-5, 6).append(3141592653)
write((text!i).padStart(10, " ") + "| ")
for each fun isEven in evenCheckers
write(isEven(i) + " ")
end
write("| ")
for each fun isOdd in oddCheckers
write(isOdd(i) + " ")
end
writeLine("|")
end
writeLine("----------+-------+-------+")

View file

@ -0,0 +1,19 @@
PROGRAM ODD_EVEN
! works for -2^15 <= n% < 2^15
FUNCTION ISODD%(N%)
ISODD%=(N% AND 1)<>0
END FUNCTION
! works for -2^38 <= n# <= 2^38
FUNCTION ISODD#(N#)
ISODD#=N#<>2*INT(N#/2)
END FUNCTION
BEGIN
IF ISODD%(14) THEN PRINT("14 is odd") ELSE PRINT("14 is even") END IF
IF ISODD%(15) THEN PRINT("15 is odd") ELSE PRINT("15 is even") END IF
IF ISODD#(9876543210) THEN PRINT("9876543210 is odd") ELSE PRINT("9876543210 is even") END IF
IF ISODD#(9876543211) THEN PRINT("9876543211 is odd") ELSE PRINT("9876543211 is even") END IF
END PROGRAM

View file

@ -0,0 +1,14 @@
--bit testing
if i.bit_and (1) = 0 then
-- i is even
end
--built-in bit testing (uses bit_and)
if i.bit_test (0) then
-- i is odd
end
--integer remainder (modulo)
if i \\ 2 = 0 then
-- i is even
end

View file

@ -0,0 +1,14 @@
defmodule RC do
import Integer
def even_or_odd(n) when is_even(n), do: "#{n} is even"
def even_or_odd(n) , do: "#{n} is odd"
# In second "def", the guard clauses of "is_odd(n)" is unnecessary.
# Another definition way
def even_or_odd2(n) do
if is_even(n), do: "#{n} is even", else: "#{n} is odd"
end
end
Enum.each(-2..3, fn n -> IO.puts RC.even_or_odd(n) end)

View file

@ -0,0 +1 @@
rem(n,2) == 0

View file

@ -0,0 +1,10 @@
(require 'cl-lib)
(defun even-or-odd-p (n)
(if (cl-evenp n) 'even 'odd))
(defun even-or-odd-p (n)
(if (zerop (% n 2)) 'even 'odd))
(message "%d is %s" 3 (even-or-oddp 3))
(message "%d is %s" 2 (even-or-oddp 2))

View file

@ -0,0 +1,13 @@
%% Implemented by Arjun Sunel
-module(even_odd).
-export([main/0]).
main()->
test(8).
test(N) ->
if (N rem 2)==1 ->
io:format("odd\n");
true ->
io:format("even\n")
end.

View file

@ -0,0 +1,13 @@
%% Implemented by Arjun Sunel
-module(even_odd2).
-export([main/0]).
main()->
test(10).
test(N) ->
if (N band 1)==1 ->
io:format("odd\n");
true ->
io:format("even\n")
end.

View file

@ -0,0 +1,5 @@
include std/math.e
for i = 1 to 10 do
? {i, is_even(i)}
end for

View file

@ -0,0 +1,2 @@
=MOD(33;2)
=MOD(18;2)

View file

@ -0,0 +1,2 @@
=ISEVEN(33)
=ISEVEN(18)

View file

@ -0,0 +1,2 @@
=ISODD(33)
=ISODD(18)

View file

@ -0,0 +1,2 @@
let isEven x =
x &&& 1 = 0

View file

@ -0,0 +1,2 @@
let isEven x =
x % 2 = 0

View file

@ -0,0 +1,4 @@
<v"Please enter a number:"a
>l0)?!vo v < v o<
^ >i:a=?v>i:a=?v$a*+^>"The number is even."ar>l0=?!^>
> >2%0=?^"The number is odd."ar ^

View file

@ -0,0 +1,4 @@
: odd? ( n -- ? ) 1 and ;
: even? ( n -- ? ) odd? 0= ;
\ Every value not equal to zero is considered true. Only zero is considered false.

View file

@ -0,0 +1,78 @@
!-*- mode: compilation; default-directory: "/tmp/" -*-
!Compilation started at Tue May 21 20:22:56
!
!a=./f && make $a && OMP_NUM_THREADS=2 $a < unixdict.txt
!gfortran -std=f2008 -Wall -ffree-form -fall-intrinsics f.f08 -o f
! n odd even
!-6 F T
!-5 T F
!-4 F T
!-3 T F
!-2 F T
!-1 T F
! 0 F T
! 1 T F
! 2 F T
! 3 T F
! 4 F T
! 5 T F
! 6 F T
! -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 n
! F T F T F T F T F T F T F odd
! T F T F T F T F T F T F T even
!
!Compilation finished at Tue May 21 20:22:56
module bit0parity
interface odd
module procedure odd_scalar, odd_list
end interface
interface even
module procedure even_scalar, even_list
end interface
contains
logical function odd_scalar(a)
implicit none
integer, intent(in) :: a
odd_scalar = btest(a, 0)
end function odd_scalar
logical function even_scalar(a)
implicit none
integer, intent(in) :: a
even_scalar = .not. odd_scalar(a)
end function even_scalar
function odd_list(a) result(rv)
implicit none
integer, dimension(:), intent(in) :: a
logical, dimension(size(a)) :: rv
rv = btest(a, 0)
end function odd_list
function even_list(a) result(rv)
implicit none
integer, dimension(:), intent(in) :: a
logical, dimension(size(a)) :: rv
rv = .not. odd_list(a)
end function even_list
end module bit0parity
program oe
use bit0parity
implicit none
integer :: i
integer, dimension(13) :: j
write(6,'(a2,2a8)') 'n', 'odd', 'even'
write(6, '(i2,2l5)') (i, odd_scalar(i), even_scalar(i), i=-6,6)
do i=-6, 6
j(i+7) = i
end do
write(6, '((13i3),a8/(13l3),a8/(13l3),a8)') j, 'n', odd(j), 'odd', even(j), 'even'
end program oe

View file

@ -0,0 +1,19 @@
' FB 1.05.0 Win64
Dim n As Integer
Do
Print "Enter an integer or 0 to finish : ";
Input "", n
If n = 0 Then
Exit Do
ElseIf n Mod 2 = 0 Then
Print "Your number is even"
Print
Else
Print "Your number is odd"
Print
End if
Loop
End

View file

@ -0,0 +1,2 @@
isEven[x is isInteger] := getBit[x,0] == 0
isOdd[x is isInteger] := getBit[x,0] == 1

View file

@ -0,0 +1 @@
fun main(x: int): bool = (x & 1) == 0

Some files were not shown because too many files have changed in this diff Show more