object for deciding wether input is odd or prime number
Is there an objetc that sends out 0 or 1 wether input is odd or prime?
Do you mean odd or even?
odd/even is dead easy: mask low order bit is one way, or do an integer divide by two and multiply back to see if you get the same number. Tim's presumably using one of these (haven't looked at his patch yet).
Prime isn't quite so easy, but there are a couple of objects to help. If you check out MaxObjects.com (try ) you'll find some objects that ought to suit your purposes. You may need to patch a bit around them to get what you need.
Never mind, my answer is the same as the patch above:
[% 2] gives 0 for odd, 1 for even numbers.
Yeah, modulo is in my post. Here's a pointless way of doing it manually because I'm bored :)
expr (((($i1+1)/2)*2)-$i1) - pretty much what Peter said
0 even
1 odd
found this .js on the forum, can't recall who. brute-force way of determining primes (spits out factors), still plenty fast:
function msg_int(v)
{
while (v%2==0)
{
outlet(0,2);
v/=2;
}
var i=3;
while (i*i
{
if (v%i==0)
{
v/=i;
outlet(0,i);
}
else i+=2;
}
if (v>1) outlet(0,v);
}