Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

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,8 @@
# Algol 68 has a standard operator: ODD which returns TRUE if it's 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

@ -1,6 +1,3 @@
bool isEven(int Value){
if((x % 2) == 0){
return true;
}
return false;
bool isEven(int x) {
return x % 2;
}

View file

@ -0,0 +1,5 @@
<Cfif i MOD 2 eq 0>
She's even
<Cfelse>
He's odd
</cfif>

View file

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

View file

@ -0,0 +1,3 @@
function isEven( i ) {
return (i & 1) === 0;
}

View file

@ -0,0 +1,8 @@
define(`even', `ifelse(eval(`$1'%2),0,True,False)')
define(`odd', `ifelse(eval(`$1'%2),0,False,True)')
even(13)
even(8)
odd(5)
odd(0)

View file

@ -0,0 +1,8 @@
EvenOrOdd := proc( x::integer )
if x mod 2 = 0 then
print("Even"):
else
print("Odd"):
end if:
end proc:
EvenOrOdd(9);

View file

@ -0,0 +1,2 @@
(odd? 1)
(even? 2)

View file

@ -0,0 +1,9 @@
// Using the modulo operator
even: func (n: Int) -> Bool {
(n % 2) == 0
}
// Using bitwise and
odd: func (n: Int) -> Bool {
(n & 1) == 1
}

View file

@ -2,30 +2,28 @@
numeric digits 1000 /*handle most big 'uns from the CL*/
parse arg x _ . /*get arg(s) from the command line*/
if x=='' then call terr 'no input'
if _\=='' | arg()\==1 then call terr 'too many arguments:' arg(1)
if \datatype(x,'N') then call terr x "isn't numeric"
if \datatype(x,'W') then call terr x "isn't an integer"
y=abs(x) /*just in case X is negative, */
/*(modulus of neg # might be -1), */
/*══════════════════════════════════════════════════════════════════════*/
say center('test using modulo method',40,'')
if _\=='' | arg()\==1 then call terr 'too many arguments: ' arg(1)
if \datatype(x,'N') then call terr x " isn't numeric"
if \datatype(x,'W') then call terr x " isn't an integer"
y=abs(x)/1 /*just in case X is negative, */
/*(remainder of neg # might be -1)*/
/*══════════════════════════════════════════════════*/
say center('test using remainder)method',40,'')
if y//2 then say x 'is odd'
else say x 'is even'
/*══════════════════════════════════════════════════════════════════════*/
/*══════════════════════════════════════════════════*/
say; say center('test rightmost digit for evenness',40,'')
_=right(y,1)
if pos(_,02468)==0 then say x 'is odd'
else say x 'is even'
/*══════════════════════════════════════════════════════════════════════*/
/*══════════════════════════════════════════════════*/
say; say center('test rightmost digit for oddness',40,'')
if pos(right(y,1),13579)==0 then say x 'is even'
else say x 'is odd'
/*══════════════════════════════════════════════════════════════════════*/
/*══════════════════════════════════════════════════*/
say; say center('test rightmost (binary) bit',40,'')
/*Note: some REXX's don't have a D2B bif.*/
if right(x2b(d2x(y)),1) then say x 'is odd'
else say x 'is even'
/*══════════════════════════════════════════════════════════════════════*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────TERR subroutine─────────────────────*/
terr: say; say '***error!***'; say; say arg(1); say; exit 13

View file

@ -0,0 +1,2 @@
let isodd = |x: int| x & 1 == 1;
let iseven = |x: int| x & 1 == 0;

View file

@ -0,0 +1,2 @@
let isodd = |x: int| x % 2 == 1;
let iseven = |x: int| x % 2 == 0;