Graal Forums

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

DustyPorViva 03-26-2008 09:43 PM

Dunno but it seems to show up in every single one of these exercises :/

Chompy 03-26-2008 09:44 PM

Quote:

Originally Posted by DustyPorViva (Post 1382501)
Dunno but it seems to show up in every single one of these exercises :/

*points at HR and pfa*

hehe

Tolnaftate2004 03-26-2008 09:49 PM

Quote:

Originally Posted by Inverness (Post 1382499)
What the hell are you talking about?

This is big O notation, it is how we measure the efficiency of algorithms, without being hardware-specific. The O stands for order, which can take 2 meanings:
  1. In mathematics, O(f) is for all terms order f and above. f is usually a function where the parameter is much less than 1 (error terms).
  2. In computer science O(f) is the major factor in determining algorithm efficiency. f is a function of n, which is a whole number.

For example, the quicksort algorithm is O(n log n) [for every item to sort, it takes log base 2 of n loops to find its place].

cbk1994 03-26-2008 10:18 PM

Quote:

Originally Posted by xXziroXx (Post 1382451)
How about making Programming Exercise #4 something that we normal mortals stand a chance at? :whatever:

This isn't really that hard, you could do this! Think about it ;)

EDIT:

I fixed mine, it wins now. It goes something like this:

PHP Code:

function onCreated()
{
  echo( 
"time going in: 12412412412.1241023" );
  
findpatterns();
  echo( 
"finished: 12412412412.124104" );
  echo( 
"elapsed time: .000001" );



Inverness 03-26-2008 10:26 PM

Well, after having this explained to me I'm kinda ticked that this wasn't even pointed out from the start.

If I were to optimize my script I would have used Drakilor's method which for me to do now would just be copying.

Chompy 03-27-2008 12:02 AM

PHP Code:

function findpatterns(string) {
  
temp.time timevar2;
  
temp.out 0;
  
temp.check 0;

  for (
temp.2string.length()/2++) {
    for (
temp.0string.length()/2++) {
      if (
i+j+string.length()-2) continue;
      
temp.letters temp.string.substring(ji);
      
      if (
check.index(letters) > -1) continue;
      if (
letters.length() < 2) continue;
      
      
temp.pos string.positions(letters);
      if (
pos.size() < 2) continue;
      
      
check.add(letters);
      
out.add({letterspos.size()});
    }
  }
  echo(
"Delta Time: "timevar2-time);
  return 
out;



Example1:
PHP Code:

function onCreated() {
  echo(
findpatterns("TAPEREDATAPER"));
}
/*
  output:
  
  Weapon/GUI-script ChompyT added/updated by Chompy
  Delta Time: 0.000427007
  "TA,2","AP,2","PE,2","ER,2","TAP,2","APE,2","PER,2","TAPE,2","APER,2","TAPER,2"
*/ 

Example2:
PHP Code:

function onCreated() {
  echo(
findpatterns("AUGCCCGTAUACGTA"));
}
/*
  output:

  Weapon/GUI-script ChompyT added/updated by Chompy
  Delta Time: 0.000540971
  "AU,2","CC,2","CG,2","GT,2","TA,2","CGT,2","GTA,2","CGTA,2"
*/ 


DrakilorP2P 03-27-2008 01:36 AM

Quote:

Originally Posted by Chompy (Post 1382537)
PHP Code:

  for (temp.2string.length()/2++) { 


Won't that miss the "AAAAAAAAA" pattern that occurs twice in "AAAAAAAAAA"?

Tolnaftate2004 03-27-2008 02:04 AM

Quote:

Originally Posted by Inverness (Post 1382513)
Well, after having this explained to me I'm kinda ticked that this wasn't even pointed out from the start.

This has always been the point of the Programming Exercises. Perhaps you need to think differently to solve this problem by better methods, rather than the obvious...

@Chris, you started your algorithm 355 years into the future? Also you fail at subtracting. :p

e: Here are exact (well, kinda) loop count functions for the algorithms (n=str.length()):
Inverness: http://img258.imageshack.us/img258/2...b9bf3c1nt8.png
Where epsilon (the E) is a number representative of the other loops that lead to 'continue;'. The script could be adjusted slightly to eliminate this term.
DrakilorP2P: http://img87.imageshack.us/img87/353...66d612ekl4.png
It should be pretty obvious where I get the O(n^2) from...

cbk1994 03-27-2008 03:39 AM

Quote:

Originally Posted by Tolnaftate2004 (Post 1382578)
Chris, you started your algorithm 355 years into the future? Also you fail at subtracting. :p

PSHAW

Inverness 03-27-2008 05:17 AM

Quote:

Originally Posted by Tolnaftate2004 (Post 1382578)
This has always been the point of the Programming Exercises.

Very nice of you GSTs to give programming exercises without explaining the point.

You also have yet to point out to others what functions they should be avoiding and why.
Quote:

Originally Posted by Tolnaftate2004 (Post 1382578)
Perhaps you need to think differently to solve this problem by better methods, rather than the obvious...

Like I've said, if your ranking system/method of measuring had been pointed out in the first place then maybe I would have made a script thats better on your ranking system instead of on Graal's.

You need to come down to the level of us mortals.

Tolnaftate2004 03-27-2008 05:34 AM

Quote:

Originally Posted by Inverness (Post 1382636)
Very nice of you GSTs to give programming exercises without explaining the point.

Quote:

Originally Posted by Kristi in Programming Exercise #1 (Post 1359228)
So, there is a lot of help around here dealing with syntax of scripting, but I don't see much discussion on best algorithms. Be this the case, I am going to every so often (when I feel like it) post some mathematically cool problem for you all to help each other solve and break some mental barriers.

...
Remember, the goal is to make this as efficient as possible with graal script.

Quote:

Originally Posted by Inverness (Post 1382636)
You also have yet to point out to others what functions they should be avoiding and why.

Do you want me to rank them or tell you how efficient I think they are? x-x

Quote:

Originally Posted by Inverness (Post 1382636)
Like I've said, if your ranking system/method of measuring had been pointed out in the first place then maybe I would have made a script thats better on your ranking system instead of on Graal's.

The theory behind big-O notation is that it should be an accurate measure of code efficiency regardless of language or hardware. Different servers run the same code in different time. Additionally, though big-O is only an approximation, it is most accurate for LARGE n.

I don't see what you're so upset about, you made a good contribution.

cbk1994 03-27-2008 05:45 AM

I bet I could beat my previous time of 12 seconds by triggering my web server which would use awesome fast PHP to find patterns, then return them to Graal.

Slower than some, but surely faster than 12 seconds?

Inverness 03-27-2008 06:41 AM

I'm upset because you're evaluating based on this big-O thing but didn't state that in the first place and explain it.

Anyhow, if the goal is "to make this as efficient as possible with graal script" then you should be measuring based on time to complete instead of your big-O thing since the hard-coded functions do have a notable speed difference.

DustyPorViva 03-27-2008 06:46 AM

If it's going to be based on time they would all have to be done on one computer instead of us each executing them as our computer speeds can change the time.

Inverness 03-27-2008 06:59 AM

Quote:

Originally Posted by DustyPorViva (Post 1382645)
If it's going to be based on time they would all have to be done on one computer instead of us each executing them as our computer speeds can change the time.

I was assuming pfa would do that?

And could you "pfa" get yourself a new account or put the proper way to address you in your signature or something? I can't go calling you Tolnaftate2004 or a shortened version of it and I'm not sure if I should be calling you "pfa" either and didn't even know about that until the announcement that you became GST.


All times are GMT +2. The time now is 03:33 PM.

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