Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Fun Challenge! (https://forums.graalonline.com/forums/showthread.php?t=50572)

Kristi 01-23-2004 08:18 AM

Fun Challenge!
 
I know this is nerdy but...
Fun Challenge/Contest thing

The Challenge:
Assign the variable "a" with one of the following numbers randomly:
1 2 4 5 7 8 (ie exclude 3 and 6)

I know this is easy, but who can come up with the best/most interesting way?

Assume your condition has been triggered, you need only show anything concerning getting "a" it's random value

send me a Private Message with your solution (as to not give anything away)
I will post the most impressive yada yada tomorrow night =).

I came up with 2 one-liners (only one assignment without loops or conditions), many 2 liners, and many condition then assignments.

http://forums.graal2001.com/forums/images/sendpm.gif

osrs 01-23-2004 03:26 PM

Quote:


Assign the variable "a" with one of the following numbers randomly:
1 2 4 5 7 8 (ie exclude 3 and 6)

Eh?

NPC Code:

if(created) a = int(random(1,8));



:confused:

Hevaricubed 01-23-2004 05:57 PM

that does not exclude 3 and 6.

Kristi 01-23-2004 08:20 PM

Loriel did 2 one liners and a few others

One of his one liners was one that i missed =D

And yes, a few other people came up with stuff but no one liners... they interest me the most hehe
r0bin needs to message me about something common in all of his solutions =p
James (andy0687) and Schoko (JAceves) both had some interesting 2 liners

Rick (Thought) had a good solution that I also did, and Loriel did too.

Keep sending them!

Termina_Owner 01-24-2004 01:38 AM

NPC Code:

a = 3;
while (a != 3 && a != 6) a = int(random(0,8));



Like that?

Kristi 01-24-2004 03:04 AM

Quote:

Originally posted by Termina_Owner
NPC Code:

a = 3;
while (a != 3 && a != 6) a = int(random(0,8));



Like that?

nono keep it private!
and that condition will make that loop run forever XD

Keep sending them in! Send more then one solution if you wish!
Ive gotten quite a lot

Kristi 01-24-2004 08:49 AM

OK here are the results!

My best solution was the best one Schoko came up with
NPC Code:

a = int(int(random(1,7))/7*10);


(Hehe 7 is an interesting number ;D)

My other one liner was only matched by Loriel
Mine:
NPC Code:

a = int(random(0,3)) * 3 + int(random(1,3));


Loriels:
NPC Code:

a = 1 + int(random(0, 2)) + 3 * int(random(0, 3));



Loriel summited this, then Darkshadows_Legend Matched it
NPC Code:

a = strtofloat(#R(1,2,4,5,7,8));



Similiar to that was one Shadowblaze (Zelph_Mystick), adam, and darkshadows_legend did
NPC Code:

a = strtofloat(#e(int(random(0,6)),1,"124578"));



Moving on after the one liners:
Rick (Thought), Loriel, Darkshadows_Legend, r0bin and myself came up with this (which is the most efficient via cpu resources)

NPC Code:

b = {1,2,4,5,7,8};
a = b[int(random(0,6))];



Schoko made these two interesting ones
NPC Code:

while (a % 3 == 0)
a = int(random(1,9));


NPC Code:

a = int(random(3,9));
a = a%3==0?a/3:a;



r0bin came up with a similiar two
NPC Code:

a=int(random(1,9));
while (a==3||a==6)
a=int(random(1,9));


NPC Code:

a=int(random(3,9));
a=a==3||a==6?int(random(1,2)):a;



Loriel did this interesting guy
NPC Code:

a = int(random(0, 6);
a += 1 + int(a / 2);



James (Andy0687) did this one
NPC Code:

tokenize 1 2 4 5 7 8;
a = strtofloat(#t(int(random(0,6)));



Dach did this... not sure if it works but he can fix it if not XD
NPC Code:

a = timevar%9+1;
a = a/3==int(a/3)?a-1:a;



Darkshadows_Legend did this one
NPC Code:

rand = int(random(1,8));
a = (rand in {3,6} ? rand-1:rand);



Xecutor did this which seemed to add extra work XD
NPC Code:

for (i = 1; i <= 8; i ++) {
setstring num#v(i),#v(i);
}
ans = #R(num1,num2,num4,num5,num7,num8);



and ill post Spyders since he sent me the obvious =D
Spyder
NPC Code:

a=int(random(1,7));
if (a==3)
a = 7;
if (a==6)
a = 8;



Do you have an interesting one? Post it =)

Python523 01-24-2004 06:39 PM

wont work till the new engine but
NPC Code:

do {
a=int(random(1,9));
} while (a == 3 || a == 6)


Dach 01-24-2004 07:08 PM

meh, the 9 should have been 8 upon further consideration, but I dun like it anyhow, this is better

NPC Code:

for (i=0;i<8;i++) {
i = (i/3==int(i)/3)?i+1:i;
a = int(random(0,6.9));
while (!save[a]==0) a=(a+1)%7;
save[a]=i;
}
a = save[int(random(0,6.9))];



redundancy is fun :rolleyes:

adam 01-25-2004 04:45 AM

Mine was slightly different from the one you said I did.

perhaps becouse I didn't put in an int() it didn't need to be 0,6 it needed to be 1,7 and it works fine.


Personally I like the #R one the best.
It's simple, it's customizable.
I was gonna do that. I dont know why I didn't.

The first one I wanted to do was the array one, but It took 2 lines so I skipped it.
I love arrays. ;-)

DIABLO2099 01-25-2004 05:50 AM

Quote:

Originally posted by Python523
wont work till the new engine but
NPC Code:

do {
a=int(random(1,9));
} while (a == 3 || a == 6)


Alright, do while loops! :)

GoZelda 01-25-2004 01:37 PM

NPC Code:

a=int(random(0,8));
if (a==3){
a=int(random(0,2));
} else if (a==6){
a=int(random(4,8));
} else {
a=a;
}



Meh...

wonderboysp2p 01-31-2004 07:19 PM

Quote:

Originally posted by Python523
wont work till the new engine but
NPC Code:

do {
a=int(random(1,9));
} while (a == 3 || a == 6)



new engine will be fun


All times are GMT +2. The time now is 09:00 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.