Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Programming Exercise #1 (https://forums.graalonline.com/forums/showthread.php?t=77627)

Kristi 11-29-2007 09:07 PM

Quote:

Originally Posted by Tolnaftate2004 (Post 1361203)
The maximum size of the intersect should be the size of the small array as it cannot possibly have more elements in common than there are in the set.

I was half asleep, good point xD
I actually read my post before yours and was about to correct that (does so)

Tolnaftate2004 11-29-2007 10:37 PM

Also, the method you proposed for determining the intersection gives duplicates.

Kristi 11-29-2007 10:54 PM

Quote:

Originally Posted by Tolnaftate2004 (Post 1361302)
Also, the method you proposed for determining the intersection gives duplicates.

>_<
PHP Code:

  temp.intersect = new[smallerarray.size()];

  for(
etemp.largerarray)
   
temp.b.("v"@e) = true;

  for(
esmallerarray)
   if(
temp.b.("v"@e)) {
     
temp.intersect[temp.j] = e;
     
temp.b.("v"@e) = false;
     
temp.j++;
   } 

I should also point out that its O(n+m)

Tolnaftate2004 11-29-2007 11:08 PM

Quote:

Originally Posted by Kristi (Post 1361308)
>_<
PHP Code:

  temp.intersect = new[smallerarray.size()];

  for(
etemp.largerarray)
   
temp.b.("v"@e) = true;

  for(
esmallerarray)
   if(
temp.b.("v"@e)&&!(temp.c.("v"@e))) {
     
temp.intersect[temp.j] = e;
     
temp.c.("v"@e) = true;
     
temp.j++;
   } 


Okay, so why the temp.intersect array now? We can just do:

PHP Code:

  for(esmallerarray)
   if(
temp.b.("v"@e)) 
     
temp.c.("v"@e) = true;

  
temp.intersect temp.c.getdynamicvarnames(); 

I think O(getdynamicvarnames) ~ O(temp.intersect[temp.j++] =), at worst. I suppose the only issue here would be getting the size to optimize the set-making and the eventual substrings. Just some thoughts... >_<

Kristi 11-29-2007 11:11 PM

Quote:

Originally Posted by Tolnaftate2004 (Post 1361311)
Okay, so why the temp.intersect array now?

I changed it to falsify b instead, i guess while you were typing this up.
However, im not sure which would work faster. when i get home and have access to my rc ill find out by averaging the run times :P

creating temp.c set means creating and moving a lot of pointers. it might be faster to assign the intersects directly to the array instead of getting dynamic variable names because of it. Ill report back tonight

xAndrewx 11-30-2007 12:00 AM

whats the use in this? I wouldn't use this in a script... lol

Make a exercise that'll come in handy !!!!

Tolnaftate2004 11-30-2007 12:04 AM

Quote:

Originally Posted by xAndrewx (Post 1361321)
I wouldn't use this in a script... lol

That's not really the point of the thread. We're trying to solve problems as efficiently as possible, which is a skill that will come in handy.

xAndrewx 11-30-2007 12:06 AM

why if you're not intending to use it? i'm asking for you to base your exercises on something that'll come in handy

Tolnaftate2004 11-30-2007 12:13 AM

Quote:

Originally Posted by xAndrewx (Post 1361323)
why if you're not intending to use it?

It's good practice.

Kristi 11-30-2007 12:53 AM

Quote:

Originally Posted by xAndrewx (Post 1361323)
why if you're not intending to use it? i'm asking for you to base your exercises on something that'll come in handy

Mathematical and computational efficiency is the basis of programming

Bell 11-30-2007 01:45 AM

What Hell isn't telling you is he's using Graal to get his teaching degree and using you guys to do his homework for him. ;)

Tigairius 11-30-2007 04:57 AM

Quote:

Originally Posted by Bell (Post 1361343)
What Hell isn't telling you is he's using Graal to get his teaching degree and using you guys to do his homework for him. ;)

Hell Raven? A teacher :( scary...

Kyranki 11-30-2007 05:01 AM

Quote:

Originally Posted by Tigairius (Post 1361405)
Hell Raven? A teacher :( scary...

Hey! I'm a testament to his teaching abilities :<

Tigairius 11-30-2007 05:12 AM

Quote:

Originally Posted by Kyranki (Post 1361408)
Hey! I'm a testament to his teaching abilities :<

Even scarier

Tolnaftate2004 11-30-2007 06:39 AM

Quote:

Originally Posted by Kyranki (Post 1361408)
Hey! I'm a testament to his teaching abilities :<

Where were you in this thread then?! :P
No offense, Hell Raven...


All times are GMT +2. The time now is 04:53 AM.

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