Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-23-2004, 08:18 AM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
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.

__________________

Last edited by Kristi; 01-23-2004 at 08:54 AM..
Reply With Quote
  #2  
Old 01-23-2004, 03:26 PM
osrs osrs is offline
Graalian since 1998
osrs's Avatar
Join Date: Mar 2002
Location: Brazil
Posts: 2,724
osrs is on a distinguished road
Send a message via ICQ to osrs Send a message via AIM to osrs Send a message via MSN to osrs Send a message via Yahoo to osrs
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));



__________________
"Ability is what you are capable of doing. Motivation determines what you do. Attitude determines how well you do it."
Facebook: facebook.com/raysilvadotnet /
Reply With Quote
  #3  
Old 01-23-2004, 05:57 PM
Hevaricubed Hevaricubed is offline
Registered User
Join Date: Aug 2003
Posts: 262
Hevaricubed is on a distinguished road
Send a message via AIM to Hevaricubed Send a message via Yahoo to Hevaricubed
that does not exclude 3 and 6.
__________________
Reply With Quote
  #4  
Old 01-23-2004, 08:20 PM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
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!
__________________
Reply With Quote
  #5  
Old 01-24-2004, 01:38 AM
Termina_Owner Termina_Owner is offline
Registered User
Join Date: Oct 2003
Posts: 175
Termina_Owner is on a distinguished road
NPC Code:

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



Like that?
__________________
- Rance Vicious
Reply With Quote
  #6  
Old 01-24-2004, 03:04 AM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
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
__________________
Reply With Quote
  #7  
Old 01-24-2004, 08:49 AM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
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 =)
__________________

Last edited by Kristi; 01-24-2004 at 09:11 AM..
Reply With Quote
  #8  
Old 01-24-2004, 06:39 PM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
wont work till the new engine but
NPC Code:

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

Reply With Quote
  #9  
Old 01-24-2004, 07:08 PM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
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
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial
Reply With Quote
  #10  
Old 01-25-2004, 04:45 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura about
Send a message via AIM to adam
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. ;-)
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #11  
Old 01-25-2004, 05:50 AM
DIABLO2099 DIABLO2099 is offline
Registered User
Join Date: Sep 2002
Location: New York
Posts: 290
DIABLO2099 is on a distinguished road
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!
__________________
-Former UnholyNation Server Manager.

Call me Xecutor.
Reply With Quote
  #12  
Old 01-25-2004, 01:37 PM
GoZelda GoZelda is offline
Mister 1,000,000
GoZelda's Avatar
Join Date: Jan 2003
Location: Brussels, capital of Europe.
Posts: 5,396
GoZelda will become famous soon enough
Send a message via AIM to GoZelda Send a message via MSN to GoZelda
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...
__________________

Quote:
Originally Posted by Lance
stefan is satan
I am the best.
[URL removed]Music or aural pollution?
Reply With Quote
  #13  
Old 01-31-2004, 07:19 PM
wonderboysp2p wonderboysp2p is offline
Registered User
wonderboysp2p's Avatar
Join Date: Sep 2002
Location: -Wonderboy
Posts: 537
wonderboysp2p is on a distinguished road
Send a message via AIM to wonderboysp2p
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
__________________

we are the llama FORUms!!!EWQ Ce13d5423f23!! 2e1 @$6tgv3uy65!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:27 PM.


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