$iseven - $isodd

By FLCL on Oct 26, 2007

$iseven returning $true if the string is even.
$isodd returning $true if the string is odd.

/*
    $iseven & $isodd checks if the number is odd or even. 
     If the number is even it returns $true, (and for $isodd) if the number is odd it returns $true.

    ; Syntax:
        $iseven(string)
        $isodd(string)
    ; Shoutouts:

        Olliegod & jaytea - helped me simplify a horribly written code. Thanks guys.

*/

alias iseven return $iif(2 // $1,$true,$false)
alias isodd return $iif(!$iseven($1),$true,$false)
/* 
    $iseven & $isodd created by FLCL
        Unauthorized editing/redistribution of this script is forbidden.
*/

Comments

Sign in to comment.
Korvin   -  Oct 27, 2007

thats why i smiley faced =D

 Respond  
FLCL   -  Oct 27, 2007

Should look a bit better now, thanks jaytea and Olliegod.

 Respond  
FLCL   -  Oct 27, 2007

there\'s lots of ways to accomplish this, FLCL\'s methods are probably amongst the worst i\'ve seen (sorry, just seems like you\'ve copied techniques without understanding them at all :P), here\'s quite possibly the shortest method:

Nope. I fully understand this snippet. I guess it\'s just my habit to over complicate things with $regex. I am going to reduce the code a bit more right now. Hopefully it won\'t be as bad as it was before.

I\'ll probably go with something similar to $iif(2 // $1) as you pointed out jaytea.

 Respond  
jaytea   -  Oct 27, 2007

oh duh, return $isodd($calc(1+$1)) for iseven is one character shorter haha

 Respond  
jaytea   -  Oct 27, 2007

not quite Olliegod :P $1 // 2 checks $1 is a factor of 2. you want the reverse, 2 // $1

there\'s lots of ways to accomplish this, FLCL\'s methods are probably amongst the worst i\'ve seen (sorry, just seems like you\'ve copied techniques without understanding them at all :P), here\'s quite possibly the shortest method:

alias iseven return $isodd($calc($1 -1))
alias isodd return $istok(1,$and($1,1),0)

there\'s a lot of other conditions you can use to check $1 is odd/even :P

if ($1 & 1) ; odd
if ($1 !& 1) ; even

if (1 \\\\ $calc($1 / 2)) ; odd
if (1 // $calc($1 / 2)) ; even

if ($calc($1 % 2)) ; odd
if (!$calc($1 % 2)) ; even

if ($1 == $or($1,1)) ; odd
if ($1 != $or($1,1)) ; even

and the list goes on :P

 Respond  
Olliegod   -  Oct 27, 2007

This could be achieved much easier by using the // and \\ if operators. For example:

 alias iseven return $iif($1 // 2,$true,$false)
 Respond  
Korvin   -  Oct 26, 2007

=p

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.