Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #16  
Old 06-14-2008, 08:46 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Programmer View Post
Time: 0.001927852
Aww, mine was 0.008700847 seconds.

Of course, I was trying to make mine inefficient, for some reason ...
__________________
Reply With Quote
  #17  
Old 06-14-2008, 03:14 PM
Programmer Programmer is offline
Coder
Programmer's Avatar
Join Date: Jan 2008
Location: -78.464422, 106.837328
Posts: 449
Programmer has a spectacular aura aboutProgrammer has a spectacular aura about
Send a message via AIM to Programmer Send a message via MSN to Programmer Send a message via Yahoo to Programmer
Quote:
Originally Posted by cbk1994 View Post
Aww, mine was 0.008700847 seconds.

Of course, I was trying to make mine inefficient, for some reason ...
Perhaps too many nested loops?
__________________
- Iᴀɴ Zɪᴍᴍᴇʀᴍᴀɴ
Reply With Quote
  #18  
Old 06-14-2008, 07:50 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by Programmer View Post
Picky, Picky.

PHP Code:
function onCreated()
{
  
this.start timevar2;
  
  
this.incompatability = {
    {
102284},
    {
392126},
    {
12},
    {
34},
    {
56},
    {
78}
  };
  
  
  
this.studentsSelected.clear();
  
this.studentGroups.clear();
  
  
numStudentsSelected 0;
  
// Select students at random
  
for (0100i++)
  {
    
int(random(0400));
    
    if (
this.studentsSelected.index(f) == -1)
    {
      
this.studentsSelected.add(f);
    } else
    {
      
i--; continue;
    }
  }
  
  
// Group them
  
for (0this.studentsSelected.size(); += 2)
  {
    
this.studentGroups.add({this.studentsSelected[i], this.studentsSelected[i+1]});
  }
  
  
// Remove incompatabilities
  
for (050i++)
  {
    
sGroup this.studentGroups[i];
    
    for (
0this.incompatability.size(); a++)
    {
      if ((
sGroup[0] == this.incompatability[a][0] || sGroup[0] == this.incompatability[a][1]) && (sGroup[1] == this.incompatability[a][0] || sGroup[1] == this.incompatability[a][1]))
      {
        echo(
"INCOMPATABILITY: " sGroup);
        
        
// we've found an incompatability, so lets flip this student with the next group
        
sGroup2 this.studentGroups[i+1];
        
        
sGroup[0] = sGroup2[0];
        
        
this.studentGroups[i] = sGroup;
        
this.studentGroups[i+1] = sGroup2;
        
        
i--;
        continue;
      }
    }
  }
  
  
this.end timevar2;
  
  echo(
this.end this.start);
  
  for (
050i++)
  {
    echo(
"Group " @ (i+1) @ ": {" this.studentGroups[i][0] @ ", " this.studentGroups[i][1] @ "}");
  }

Time: 0.001927852
Once again, this failed to perform the task.
Again, let's discuss what we ought to be doing to solve this problem. This is a very difficult problem to solve (HRs idea, don't blame me).
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #19  
Old 06-14-2008, 08:03 PM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Quote:
Originally Posted by Tolnaftate2004 View Post
Today's challenge will include 2 problems:
  1. hard Suppose that you are organizing housing accommodations for a group of four hundred university students. Space is limited and only one hundred of the students will receive places in the dormitory. To complicate matters, the Dean has provided you with a list of pairs of incompatible students, and requested that no pair from this list appear in your final choice.
    The point of this exercise is to GENERATE DISCUSSION. We are not asking you to WRITE the code, merely speculate as to how you might do it. BUT IF YOU FEEL COMPELLED, write the code to accomodate arbitrary lists from the Dean.
  2. easy Solve this problem.
Is it possible for you to write in a little more simple English for me? I don't understand the task quite well, though I'd like to give it a go
__________________
Reply With Quote
  #20  
Old 06-14-2008, 08:20 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Dan View Post
Is it possible for you to write in a little more simple English for me? I don't understand the task quite well, though I'd like to give it a go
1. hard You are putting 400 people in houses. Only 100 people will be able to have a house. You have a list of people that can not be in the same house. 2 people must be in each house. Talk about it, don't script it unless you want to.

Is that a bit better?
__________________
Reply With Quote
  #21  
Old 06-15-2008, 04:49 PM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Not sure if I entirely understood the task, but I suppose this should work?

PHP Code:
function onCreated() {
  
temp.students_incompatible = {{1,2},{3,49}};
  
temp.students_total = new[400];
  
temp.house_list = {};
  
  while (
temp.house_list.size() < 100) {
    
temp.0;
    while (
temp.students_total[temp.i] == 1)
      
temp.++;
    
temp.students_total[temp.i] = 1;
    
temp.temp.i;
    
    
temp.go false;
    while (
temp.students_total[temp.j] == || !temp.go) {
      if ((@ {
temp.1,temp.1}) in temp.students_incompatible) {
        
temp.go false;
        
temp.++;
      }
      else if ((@ {
temp.1,temp.1}) in temp.students_incompatible) {
        
temp.go false;
        
temp.++;
      }
      else if (
temp.students_total[temp.j] == 1)
        
temp.++;
      else
        
temp.go true;
    }
    
temp.students_total[temp.j] = 1;
    
temp.house_list.add({temp.1,temp.1});
  }
  echo(
temp.house_list);

Time: 0.008579015
__________________

Last edited by Dan; 06-15-2008 at 05:07 PM.. Reason: Added time.
Reply With Quote
  #22  
Old 06-15-2008, 05:39 PM
Chompy Chompy is offline
Ż\(ş_o)/Ż
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Uhm, Dan, suppose to be discussion :o
__________________
Reply With Quote
  #23  
Old 06-15-2008, 06:33 PM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Quote:
Originally Posted by Chompy View Post
Uhm, Dan, suppose to be discussion :o
Well then this is how I'd make the groups, lol.
__________________
Reply With Quote
  #24  
Old 06-15-2008, 06:35 PM
Chompy Chompy is offline
Ż\(ş_o)/Ż
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Dan View Post
Well then this is how I'd make the groups, lol.
Try explain it with words instead of code
__________________
Reply With Quote
  #25  
Old 06-15-2008, 09:17 PM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Quote:
Originally Posted by Chompy View Post
Try explain it with words instead of code
I want to know if it does what it should do tho (if I did what was needed).
__________________
Reply With Quote
  #26  
Old 06-16-2008, 07:36 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
You are using very small lists Your algorithms are based on the fact that the list is small. If you took your basic ideas and applied them to more complex or impossible lists, they would run much longer then any of our lifetimes.

By impossible, suppose you were given a list of incompatible students that makes it impossible to come up with 100 students.

Your work is cut out for you
__________________
Reply With Quote
  #27  
Old 06-16-2008, 10:41 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Kristi View Post
If you took your basic ideas and applied them to more complex or impossible lists, they would run much longer then any of our lifetimes.
No, that's why we have a max loop limit
__________________
Reply With Quote
  #28  
Old 06-16-2008, 10:48 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
Quote:
Originally Posted by cbk1994 View Post
No, that's why we have a max loop limit
You are supposed to assume a limit doesn't exist (in graal this can be achieved with a scheduleevent).
__________________
Reply With Quote
  #29  
Old 06-16-2008, 11:03 PM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Quote:
Originally Posted by Kristi View Post
You are supposed to assume a limit doesn't exist (in graal this can be achieved with a scheduleevent).
OK. Good luck to anyone trying, Dan's not going to invest any more time in this Programming Exercise because there's more work to do .
__________________
Reply With Quote
  #30  
Old 06-18-2008, 10:46 PM
Stryke Stryke is offline
Scripter
Join Date: Apr 2008
Posts: 157
Stryke is an unknown quantity at this point
Would this work?

PHP Code:
function onCreated()
{
  
this.start timevar2;
  
this.incompatability = {
                         {
23,46},
                         {
29,44},
                         {
45,96},
                         {
11,77},
                         {
2,32},
                         {
1,12},
                         {
13,69},
                         };
  
this.houselist NULL;
  for(
temp.i=0temp.i<100temp.i++)
  {
    
this.intA 0;
    
this.intB 0;
    while(!
this.intA && !this.intB)
    {
      
this.intA int(random(0,400));
      
this.intB int(random(0,400));
      for(
temp.j=0temp.j<100temp.j++)
      {
        if(
this.intA == this.houselist[temp.j][0])
          
this.int 0;
        else if(
this.intA == this.houselist[temp.j][1])
          
this.int 0;
        else if(
this.intB == this.houselist[temp.j][0])
          
this.int 0;
        else if(
this.intB == this.houselist[temp.j][1])
          
this.int 0;
        if(
this.intA == this.incompatibility[temp.j])
          if(
this.intB == this.incompatibility[temp.j])
            
this.int 0;
        else if(
this.intB == this.incompatibility[temp.j])
          if(
this.intA == this.incompatibility[temp.j])
            
this.int 0;
      }
      if(
this.intA == this.intB)
        
this.int 0;
    }
    
this.houselist.add({this.intA,this.intB});
  }
  
this.end timevar2;
}
savelog2("houseList.txt",this.houselist);
echo(
"Time: " this.end this.start); 
Time: 0.026829004

Damn that's slow compared to others lol
Reply With Quote
Reply

Tags
programming-exercise

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 03:06 PM.


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