ID:190290
 
I was bored, so I made a couple of procs for people to use.. (I think this fits in this forum, if not, please move it)
proc
iseven(n as num)
var/list/evens = list("0","2","4","6","8")
var/numtext = num2text(n)
if(evens.Find(copytext(numtext,length(numtext),length(numtext)+1))
return 1
isodd(n as num)
var/list/evens = list("1","3","5","7","9")
var/numtext = num2text(n)
if(evens.Find(copytext(numtext,length(numtext),length(numtext)+1))
return 1


isodd() could also just be achieved by doing;
if(!iseven(number))

But, eh..

These procs can be useful for team making, to evenly distribute the members..
var/team_red
var/team_blue
mob/var/team
proc
Assign_Team(mob/M as mob)
if(isodd(team_red))
team_red++
M.team = "Red"
else
team_blue++
M.team = "Blue"


What does everyone think? Useful, or waste of forum space?

~>Volte
Handy snippet
And thank me for teaching him that only the last number in a whole number make it odd/even, thank me!
And now my versions! =P

> proc
> iseven(n as num)
> return !(n%2)

> isodd(n as num)
> return n%2
>
These procs can be useful for team making, to evenly distribute the members..
var/team_red
> var/team_blue
> mob/var/team
> proc
> Assign_Team(mob/M as mob)
> if(isodd(team_red))
> team_red++
> M.team = "Red"
> else
> team_blue++
> M.team = "Blue"
>
As team_red starts at 0 (which is even), nobody will ever be put on the red team. =)
In response to Crispy
Hey, gimme a break! It's almost 3 AM! :]

I'm sure people would catch that before they use it, anyway. So... Hah! :]

Another note, would that 'version' of yours actually work?
It would seem if I did <nobr><code>if(iseven(5))</code></ nobr> I believe it would return 1, indicating 5 is an even number.

~>Volte
In response to Volte
5/2 == 2 with a remainder of 1. !1 == 0, so iseven(5) would return zero.

Good try, but no cigar. =P
In response to Crispy
Why don't you just test it instead of sitting there arguing about the concept? The results tend to be more reliable.
In response to Crispy
Crispy wrote:
5/2 == 2 with a remainder of 1. !1 == 0, so iseven(5) would return zero.

Good try, but no cigar. =P

Strange..
mob
verb
check(n as num)
usr << n%2

I entered 5, and it returned 1.

~>Volte
In response to Jp
I just proved it mathematically, but if you insist...

(tests it, comes back)

Works exactly as I said. So there! =P
In response to Volte
Tsk, tsk... that's <code>!(n%2)</code> rather than <code>n%2</code>

Read more carefully next time! =P
In response to Crispy
Crispy wrote:
Tsk, tsk... that's <code>!(n%2)</code> rather than <code>n%2</code>

Read more carefully next time! =P

Gaah. My mistake. Around 2 AM, my eyes start their trip towards failure. :]


~>Volte
In response to Volte
Volte wrote:
Gaah. My mistake. Around 2 AM, my eyes start their trip towards failure. :]

I can understand that. =)
In response to Crispy
You didn't prove it mathematicly. there were no = signs, no divides or pluses or multiplies, not even a measly diagram! How can that be maths!
In response to Crispy
Crispy wrote:
And now my versions! =P

> > proc
> > iseven(n as num)
> > return !(n%2)
>
> > isodd(n as num)
> > return n%2

Back to the subject.. I tried finding a mathmatical equasion to figure it out. I knew it was something REALLY short, but eh, I'm not the MOST mathmatically inclined person to live. Math is one of my subjects that I just don't get, nor like.

~>Volte
In response to Volte
You forgot to close your dm tag mr.
How about

proc/IsOdd(num)
{
return(num & 1)
}

Much faster and shorter :). Even better than with the modulus.
In response to Theodis
Question: Why do you put the
{
}
in all of the code ive seen from you?
In response to Jotdaniel
Jotdaniel wrote:
Question: Why do you put the
{
}
in all of the code ive seen from you?

I program in C++ too and it gets confusing going back and forth so I just stick with what works for both.
In response to Theodis
O ok, I see.
In response to Nadrew
Thats what...3rd grade math though?
Page: 1 2