₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,344,467 members, 8,512,069 topics. Date: Monday, 02 November 2026 at 06:40 PM

Toggle theme

Javarules's Posts

Nairaland Forum › Javarules's Profile › Javarules's Posts

1 2 3 4 5 6 7 (of 7 pages)

Programming › Re: Java World: Questions And Solutions (java Only Pls) by javarules(m): 7:25am On Aug 17, 2008
Come join the latest in Java Movememnt, yes a JUG has started in Nigeria and its right here


http://naijadukes.net

All your java problems solved and more,


be there,
Programming › Re: What's Happening Here? by javarules(m): 7:23am On Aug 17, 2008
I dont bliv jack of it

How can Seun's DB be compromised


anyway, I don learn lessons too ooo, on jand, na severals backs ups grin



http://naijadukes.net be there or be squared
Programming › Re: Should A Programmer Marry A Programmer? by javarules(m): 7:17am On Aug 17, 2008
How will u like a lady who sleeps at 1am(at the least), wakes up in d middle of the night(wen both are u are snugging each other) and says honey where is my laptop, hair unkempt, most time always locked up(how did u meet her anyway), acts like a man(a tomboy in most cases)

That is d brief description of what I think a programmer geekress will be

That is something to really think about, but not to worry, we'll hire an house help dts not so smart to take care of the house

and kids

and the car

and d food too

and probably everything else

Even if u marry a geekress, one of u will have to step down from ur geekdom else ur boat will become another titanic, crash is inevitable

ciao I'm outa here
Programming › Re: How Can Java Take Care Of My (future) Needs? by javarules(m): 7:14pm On Aug 13, 2008
What a long post, but I read it. Now let me add to what javalove has just expantiated.

The reason I completed my education is because my family wont let me do otherwise. I started work (employed) when I was in 200L, and ever since den I have been working for one company or the other. The most annoying thing is when I carry some good cash to go pay school fees, money that could buy me quality programming books, pay school fees for some crack head who cant write hello world, yet call themselves prof,, doctors and masters of computer science, its pathetic

I can remeber how many of my lecturers I develop applications for, and yet they smile to the bank on the fees I paid. Today I have worked in several sectors(programming wise) and none of my employers ever requested for the certificate I spent 6 years procurring (plus ASUU strike). My fame always preceeds me. My WORKS say more dn certificates could.

I might not be able to work in a bank(except they change their policy of importing softwares), I might not be able to get some of those bogous govt works(where all they do is sit, jist, gissip, fight and collect salary), but I will always be able to do my thing. I have several contributions to open source software(and still counting), I have several apps that are being used home and abroad(yes abroad), I do what I love everyday and get paid for doing it, If I had not gone to school, believe I would have still achieved what I have achieved today, the only thing I will miss is the people I met on campus.

The truth is you dont have to go to HIGHER INSTITUTION, you can go to any other school but it doesnt have to be a university, dts where we all get it wrong, we allow our parents mentality of "my child is in the university" to get to us. Its time to wake up

Anyway come join us on http://naijadukes.net and find out why we are dukes even if we hate school this much grin

ciao
I am out for now
Programming › Re: Should A Programmer Marry A Programmer? by javarules(m): 7:59pm On Aug 08, 2008
javalove:
@javarules

i no be pikin ooooo so i can read b/w d lines
continue reading btw d lines, seriously, I am begining to think all these is all about folake, say d truth huh
Tech Jobs › Re: Get Your Code Snippets On Www,planetnetbeans.org by javarules(op): 7:33pm On Aug 08, 2008
don't u like to flex your muscles, come on i know u do. lets see how good you are

http://naijadukes.net/jand/index.php/board,9.0.html
Programming › Re: Should A Programmer Marry A Programmer? by javarules(m): 7:32pm On Aug 08, 2008
javalove:
@javarules

what do u mean, that means folake is ugly den?
Please dont bring folake into this, cheesy
And did I mention anything as closely related to the word ugly, please u are drawing your own conclusions, dont put words in my mouth

[quote author=$$Rhino link=topic=154944.msg2629137#msg2629137 date=1218219604]I think it is a bad idea, because programmers don't really have a life, and a husband and wife with no life will only give birth to kids that are geeks, they will be so bored at home, they will go on dates and be talking about coding, how boring cld that get.[/quote]thats very true. Talking coding is d most boring thing. Code should be coded not talked. grin
Programming › Re: Need Help(java Program) by javarules(m): 7:22pm On Aug 08, 2008
import java.util.Random




long seed = 1011001;
Random rand = new Random(seed);
int a = rand.nextInt()
boolean b = rand.nextBoolean()


etc
Programming › Re: Pls How Can Configure Linus {red Hat} by javarules(m): 7:14pm On Aug 08, 2008
U have all spoken well, but the question is too ambigous

How can I configure Red Hat Linux? What I think is how can u install?

If it is install, then if you are a developer DO NOT INSTALL REDHAT

If you are a developer DO NOT INSTALL REDHAT just for emphasis sake

REDHAT is good for what it is good for, a server system. Also note that red-hat is not free, so if u want something similar to readhat that is free consider CentOS. These are good, very good as servers, but as developement machines, I better use something else

If you want to get down and dirty, and u dont mind losing ur data due to improper partitioning, then consider Arch Linux, but seriously,, even I dont use it on my system, I use it only on my VM to test some funky stuffs

My recommendation is d bleeding edge Fedora Linux, I have used Libranet(Debian), tasted Ubuntu(Debian), used SuSE(rpm based), used CentOS(rpm based) and now Fedora(rmp based)

I found Fedora the best of all, as a developer

If you fancy a nice UI, similar to Vista, then try SuSE 11,

How do you install? goto the website of the particular distro you want to install, they always have a detailed how-to-install

ciao
Programming › Re: Java by javarules(m): 7:03pm On Aug 08, 2008
Well,
1 there is a group out there, what we do is try as much to answer your java questions. http://naijadukes.net

2,
logica:
maybe if u tell us what u want the person 2 do for you, u might pique my interest. what do u need?
that might be a piece of advice too, what really do you want?
Programming › Re: Should A Programmer Marry A Programmer? by javarules(m): 6:57pm On Aug 08, 2008
gimbus:
while d guys r thinkin of their compatibility with d female programmers, d real programmer chicks find it hard 2 hook up. sad sad sad
I think I know why

The very pretty ones are always in marketting

The pretty ones are in consulting

The less pretty ones are into Analysis and Designs

The rest are programmers

lol
Tech Jobs › Get Your Code Snippets On Www,planetnetbeans.org by javarules(op): 6:49pm On Aug 08, 2008
Showcase your codes on planetnetbeans.org, and this is no joke. Java and Nigerian Developers, a group of java programmers http://naijadukes.net is hosting a mini code snippet competition. You post your code snippet, come cool things you have just written not more than 10-15 lines and the winner's code snippet goes live on planetnetbeans.org. The competiton is weekly, so if you are a programmer, here's a chance to

teach others
flex your muscles

the first part i dont always like to do, but the second part,

http://naijadukes.net/
Programming › Re: Jand - Java Nigerian Group Launches Web Forum! by javarules(m): 10:13am On Jul 31, 2008
Java Rules, JAND Rules

http://naijadukes.net/jand
Programming › Re: Java Rocks: Java Rules by javarules(op): 5:40pm On Jul 30, 2008
All java lovers, this is a diression but forgive me, the JUG Nigeria has finally kicked off

register and become an automatic member http://naijadukes.net/jand

JAND is d place to be Strictly Naija, Strictly Java
Programming › Re: Nigerian Java Group : Jand by javarules(op): 5:35pm On Jul 30, 2008
[size=24pt]JAND IS HERE FINALLY AND IS HERE TO STAY[/size]

http://naijadukes.net/jand
Programming › Re: Jand - Java Nigerian Group Launches Web Forum! by javarules(m): 5:31pm On Jul 30, 2008
If you do Java, u wont want to miss out of the great movement, this is no joke or cajole, JAND is d place to be, go register now and u will be glad u did

http://naijadukes.net/jand

Strictly Naija, Strictly Java
Programming › Re: Should A Programmer Marry A Programmer? by javarules(m): 6:18pm On Jul 28, 2008
The dinner part na joke now bros

I met a programmer lady(javalove knows about her) and I am planning to take her out to dinner very soon against javalove's wish  grin(u can guess why)

dts why i put that line there

Thinking is part of the job.I have never met a programmer who doesn't think, if u know one please lemme meet him


or her shocked
Programming › Re: Should A Programmer Marry A Programmer? by javarules(m): 5:27pm On Jul 28, 2008
Please javalove stop living in a fool's paradise. If u marry a programmer and it works, believe me its d exception and not the rule. Well its true most of us are exceptional, but our lives are based on rules. u get my point?

If you are a programmer like myself, then this is ur picture

My room is unkempt 75% of the time
I eat out 75% of the time
I dont sleep most times b4 12am and u wont find me in bed most times after 5am
I hate doing things that I can't automate, eg washing/ironing
Whenever I am coding I go into "offline" mode(i.e I am physically there, my mind is somewhere else)
People who meets me in the office always thinks I am an asshole(I laugh with them one minute, I snub them the other, not that I do that on purpose, I have gone to offliine mode lol)
I think think think, before I do(i think more dn I do)

Now if a husband and a wife have these qualities, picture in your mind what kind of home their home will be, what kind of children they will raise, what kind of relationships they will have with other people etc.

Again I will recommend these books,

Why u act the way u do (Tim Lahaye)
The four(or five i cant remember) languages of love (author? cant remember too)

Lastly, its because u have not met a lady that is a techy, if u have met one or two, they are not always the kind of pple dt u can take out for dinner grin

ciao
Programming › Re: Java Rocks: Java Rules by javarules(op): 5:39pm On Jul 22, 2008
reading the first 5 to 10 lines is ok, dt will make u read d rest lol
Programming › Re: Java Rocks: Java Rules by javarules(op): 1:49pm On Jul 21, 2008
yeah i know, doesnt prove jack. but it doesnt have to prove jack, coz dts not what it was meant to prove, it was meant to prove the strenght of a language, two actually dt have stood the test of time

did u see that jruby performs better than ruby? i wonder if its because of the J in it? wink

ciao
Programming › Java Rocks: Java Rules by javarules(op): 12:10pm On Jul 21, 2008
I came upon this post, and i think every java lovers (and java haters too angry ) should read this. The original post is at
http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/   but that page takes a mighty long time to load, s if your con is slow (like mine) then I have taken the pain to copy, paste and make the article a lil bit intelligible for you, u dont have to go to that link  grin

Problem Statement

    Flavius Josephus was a roman historian of Jewish origin. During the Jewish-Roman wars of the first century AD, he was in a cave with fellow soldiers, 40 men in all, surrounded by enemy Roman troops. They decided to commit suicide by standing in a ring and counting off each third man. Each man so designated was to commit suicide…Josephus, not wanting to die, managed to place himself in the position of the last survivor.
    In the general version of the problem, there are n soldiers numbered from 1 to n and each k-th soldier will be eliminated. The count starts from the first soldier. What is the number of the last survivor




Design

I actually changed the design of the solution as compared to the original post. Instead of using the deeply recursive calls as used in the earlier post, I decided to split the logic into two classes, and use loop iteration instead of recursion. It is my belief that we tend to do loop iterations far more frequently than recursions, and the resultant class design having two classes - one to indicate a Chain and one reflecting a Person seemed more appropriate to me.

Logic
The Chain object contains a reference to one person (first) who is but one member in a circular linked list. Each person object has a reference to its previous (prev) and next (next) person in the circle. When the kill loop starts, it sets a threshold (nth). The count starts with 1 from the first person. Each person when asked to shout, checks if the shout count (shout) is less than the threshold (nth). If less, the person just returns an incremented count. If the two are same, the person in effect commits suicide. In doing so the person, updates the next reference of its prev, and prev reference of its next to take himself off the circle and keep the circle consistent, finally returning a shout of 1 (which is what the next person in the list will shout).

The code does not have any comments (sorry!) and all the console outputs have been removed so that the benchmarking activity is not interfered with by the IO overheads.
The results

All the results are as observed on my notebook with the following config
OS : Ubuntu Gutsy Gibbon 7.10
Kernel : 2.6.22-15-generic
CPU : Intel® Core™ Duo CPU T2600 @ 2.16GHz
RAM : 2GB
Language       Version                                                                   Lines of Code   Time per iteration (microseconds)
Java              Sun JDK 1.6.0.03                                                      10186               1.6

C++              4.1.3 20070929 (prerelease)                                             86                                 3
                             (Ubuntu 4.1.2-16ubuntu2)
                             Compiled with optimisation -O3

Ruby              ruby 1.9.0 (2008-04-14 revision 16006)                         63                             114 89
                                   [i686-linux]

ruby 1.8.6              (2007-06-07 patchlevel 36) [i486-linux]                    372                              380

jruby : ruby 1.8.6    (2008-05-28 rev 6586) [i386-jruby1.1.2]                     84                                80

Python                       2.5.1                                                                              41                          225

Jython                          2.2.1 on JRE 1.6.0.03                                               41                               884

Groovy                       Groovy Version: 1.5.6                                                 81                           363
                                      JVM: 1.6.0_03-b05 uncompiled
                                     
                                      Compiled to bytecode and run using java                                            360

UpdateGroovy              Version: 1.6-beta-1 JVM: 1.6.0_03                                                            104

PHP PHP 5.2.3-1ubuntu6.3 (cli)                                                                 85                             593


Updates :

    * Ken suggested syntactic improvements (see comments below) which lead to even faster ruby execution times : jruby : 80 microseconds, ruby 1.9 : 89 microseconds, ruby 1.8.6 : 380 microseconds. The table above has been updated
    * Cato requested a run using Groovy 1.6 beta 1 - have updated the same. Big improvement
    * Tim Fountain in a comment below indicates that on his hardware (core 2 Quad) with Ubuntu Hardy Heron, Ruby 1.8.6 (same version as above) performs somewhat faster (15%) whereas upgraded version of Python and PHP run much faster(63% for python and 83% for ruby). Another difference in config- he is running 64 bit.
          o python - version 2.5.2: - 138 microseconds
          o ruby - 1.8.6 (2007-09-24 patchlevel 111) [x86_64-linux] :321 microseconds
          o PHP - 5.2.4-2ubuntu5.1 with Suhosin-Patch 0.9.6.2 (cli): 323 microseconds.
    * Peter Lupo requested a reduction in line count for Java since the conventional way is to have the opening braces not on a separate independent line. Given the fact that it is a fair comment, I have reduced the line count of java to 86 (didn’t physically change the code - 86 = 101 - 15 opening curly braces).



Summarisation

The following are the results. Given the long code blocks, I am presenting the summarisation first followed by the code.

Note: This can only be treated as one particular benchmark. The results are a little atypical with respect to my general understanding. Advise caution against drawing broad conclusions based on this benchmark alone but would suggest that you could treat this as one data point amongst many. People better versed than me in the details of language runtimes might be able to suggest why some of the results seem surprising or atypical.

    * Java / C++ Rock : The performance of Java and C++ was head and shoulders beyond other languages (nearly 100 times faster). My thought is that while a difference of 10x was only to be expected - this difference was just way too massive
    * Java is faster than C++ : Though I had read about other microbenchmarks reaching the same conclusions, it is the first time I actually ran one where Java was faster. There are many others I have run where C++ beats Java quite handsomely. More importantly - the performance of C++ worsened by almost 40% once I added code which started freeing memory that was being allocated (there’s still a small memory leak in the code - there is no Chain destructor which will clean up first). I would later definitely want to look at the impact of garbage collection in this context, and whether the Java garbage collector simply was much faster than the hand crafted new - delete calls in C++.
    * Ruby 1.9 is twice as fast as Python : While it has been known for a while Ruby 1.9 is much faster than Ruby 1.8.6, heres one more supporting data point. I was expecting ruby 1.9 to give python a run for its performance money. But at least in this particular context it seems to be much much faster.
    * JRuby is faster than Ruby : Even ruby 1.9. Very interesting indeed.
    * Jython still has some catching up to do : Though in the ballpark as the other languages, it was the slowest in the pack.
    * Overhead of dynamism is dominant : I have no idea if JRuby ran much faster because of the java bytecode or because of its implementation (though its performance was not even remotely close to that of Java). However even after I compiled groovy code, to java bytecode, it still ran much slower than python and ruby. It seems the overhead of supporting dynamic constructs is much more dominant than any benefits that one gets out of compilation (whether to java byte code or to intermediate compiled files). I think the argument that because something compiles to java bytecode it is likely to be fast should be looked at a little carefully.
    * PHP stays at the rear end : Though I benchmarked PHP for the first time, I wasn’t completely surprised by the fact that PHP could only manage to be faster than Jython.

Update : There are many comments to this post including those from cwilbur who benchmarks perl using a idiomatic method, Paddy3118 who offers an optimised algorithm for python, and peter lawrey who offers an optimised algorithm for Java. I would like to state that each of their solutions offer superior performance than that what has been described here. However I believe any benchmark comparison should compare apples to apples. Should these contributions be taken into account and be reflected in the table above ? I certainly believe there is a case to do so as an exercise using a different algorithm. However to ensure that it is a fair comparison, one has to modify all the code in all other languages also to reflect the same algorithm. Only then can we get an apple to apples comparison. That is probably an exercise for another post. Is the algorithm I have chosen the fastest - No. However I believe it is a very readable algorithm and if one ignores the IO with networks and databases and files, it is probably close to the kind of code many programmers write (and maintain) on a day to day basis. It has been consistently implemented in all the languages. Readers should be aware that there are algorithms which will deliver much superior performance - but they will also make the performance superior in all the languages (perhaps to slightly differing extents and thus possibly somewhat different results).
The code

For all you who are either interested in running it for yourself or would like to perhaps explore this in more detail, ,  here’s the code. Note that I am not equally competent across all languages. So if you believe there is something that could be more appropriate way to code the same, do post a comment. One of the things I have tried to do is to ensure that the code remains more or less similar across all languages. Also I have used getter - setters or skipped them based on my understanding of the generally accepted convention for users of the language.

Java :
view plaincopy to clipboardprint?

   1. package com.dnene.josephus; 
   2.   
   3. public class Chain 
   4. { 
   5.     private Person first = null; 
   6.       
   7.     public Chain(int size) 
   8.     { 
   9.         Person last = null; 
  10.         Person current = null; 
  11.         for (int i = 0 ; i < size ; i++) 
  12.         { 
  13.             current = new Person(i); 
  14.             if (first == null) first = current;   
  15.             if (last != null) 
  16.             { 
  17.                 last.setNext(current); 
  18.                 current.setPrev(last); 
  19.             } 
  20.             last = current; 
  21.         } 
  22.         first.setPrev(last); 
  23.         last.setNext(first);         
  24.     } 
  25.   
  26.     public Person kill(int nth) 
  27.     { 
  28.         Person current = first; 
  29.         int shout = 1; 
  30.         while(current.getNext() != current) 
  31.         { 
  32.             shout = current.shout(shout, nth); 
  33.             current = current.getNext(); 
  34.         } 
  35.         first = current; 
  36.         return current; 
  37.     } 
  38.       
  39.     public Person getFirst() 
  40.     { 
  41.         return first; 
  42.     } 
  43.     public static void main(String[] args) 
  44.     { 
  45.         int ITER = 100000; 
  46.         long start = System.nanoTime(); 
  47.         for (int i = 0 ; i < ITER ; i++) 
  48.         { 
  49.             Chain chain = new Chain(40); 
  50.             chain.kill(3); 
  51.         } 
  52.         long end = System.nanoTime(); 
  53.         System.out.println("Time per iteration = " + ((end - start) / (ITER )) + " nanoseconds."wink; 
  54.     } 
  55. } 
  56. package com.dnene.josephus; 
  57.   
  58. public class Person 
  59. { 
  60.     int count; 
  61.     private Person prev = null; 
  62.     private Person next = null; 
  63.       
  64.     public Person(int count) 
  65.     { 
  66.         this.count = count; 
  67.     } 
  68.       
  69.     public int shout(int shout, int deadif) 
  70.     { 
  71.         if (shout < deadif) return (shout + 1); 
  72.         this.getPrev().setNext(this.getNext()); 
  73.         this.getNext().setPrev(this.getPrev()); 
  74.         return 1; 
  75.     } 
  76.       
  77.     public int getCount() 
  78.     { 
  79.         return this.count; 
  80.     } 
  81.       
  82.     public Person getPrev() 
  83.     { 
  84.         return prev; 
  85.     } 
  86.   
  87.     public void setPrev(Person prev) 
  88.     { 
  89.         this.prev = prev; 
  90.     } 
  91.   
  92.     public Person getNext() 
  93.     { 
  94.         return next; 
  95.     } 
  96.   
  97.     public void setNext(Person next) 
  98.   
  99.     { 
100.         this.next = next; 
101.     } 
102. } 

view plaincopy to clipboardprint?

   1. package com.dnene.josephus; 
   2.   
   3. public class Chain 
   4. { 
   5.     private Person first = null; 
   6.       
   7.     public Chain(int size) 
   8.     { 
   9.         Person last = null; 
  10.         Person current = null; 
  11.         for (int i = 0 ; i < size ; i++) 
  12.         { 
  13.             current = new Person(i); 
  14.             if (first == null) first = current;   
  15.             if (last != null) 
  16.             { 
  17.                 last.setNext(current); 
  18.                 current.setPrev(last); 
  19.             } 
  20.             last = current; 
  21.         } 
  22.         first.setPrev(last); 
  23.         last.setNext(first);         
  24.     } 
  25.   
  26.     public Person kill(int nth) 
  27.     { 
  28.         Person current = first; 
  29.         int shout = 1; 
  30.         while(current.getNext() != current) 
  31.         { 
  32.             shout = current.shout(shout, nth); 
  33.             current = current.getNext(); 
  34.         } 
  35.         first = current; 
  36.         return current; 
  37.     } 
  38.       
  39.     public Person getFirst() 
  40.     { 
  41.         return first; 
  42.     } 
  43.     public static void main(String[] args) 
  44.     { 
  45.         int ITER = 100000; 
  46.         long start = System.nanoTime(); 
  47.         for (int i = 0 ; i < ITER ; i++) 
  48.         { 
  49.             Chain chain = new Chain(40); 
  50.             chain.kill(3); 
  51.         } 
  52.         long end = System.nanoTime(); 
  53.         System.out.println("Time per iteration = " + ((end - start) / (ITER )) + " nanoseconds."wink; 
  54.     } 
  55. } 
  56. package com.dnene.josephus; 
  57.   
  58. public class Person 
  59. { 
  60.     int count; 
  61.     private Person prev = null; 
  62.     private Person next = null; 
  63.       
  64.     public Person(int count) 
  65.     { 
  66.         this.count = count; 
  67.     } 
  68.       
  69.     public int shout(int shout, int deadif) 
  70.     { 
  71.         if (shout < deadif) return (shout + 1); 
  72.         this.getPrev().setNext(this.getNext()); 
  73.         this.getNext().setPrev(this.getPrev()); 
  74.         return 1; 
  75.     } 
  76.       
  77.     public int getCount() 
  78.     { 
  79.         return this.count; 
  80.     } 
  81.       
  82.     public Person getPrev() 
  83.     { 
  84.         return prev; 
  85.     } 
  86.   
  87.     public void setPrev(Person prev) 
  88.     { 
  89.         this.prev = prev; 
  90.     } 
  91.   
  92.     public Person getNext() 
  93.     { 
  94.         return next; 
  95.     } 
  96.   
  97.     public void setNext(Person next) 
  98.   
  99.     { 
100.         this.next = next; 
101.     } 
102. } 

package com.dnene.josephus;

public class Chain
{
private Person first = null;

public Chain(int size)
{
Person last = null;
Person current = null;
for (int i = 0 ; i < size ; i++)
{
current = new Person(i);
if (first == null) first = current;
if (last != null)
{
last.setNext(current);
current.setPrev(last);
}
last = current;
}
first.setPrev(last);
last.setNext(first);
}

public Person kill(int nth)
{
Person current = first;
int shout = 1;
while(current.getNext() != current)
{
shout = current.shout(shout, nth);
current = current.getNext();
}
first = current;
return current;
}

public Person getFirst()
{
return first;
}
public static void main(String[] args)
{
int ITER = 100000;
long start = System.nanoTime();
for (int i = 0 ; i < ITER ; i++)
{
Chain chain = new Chain(40);
chain.kill(3);
}
long end = System.nanoTime();
System.out.println("Time per iteration = " + ((end - start) / (ITER )) + " nanoseconds."wink;
}
}
package com.dnene.josephus;

public class Person
{
int count;
private Person prev = null;
private Person next = null;

public Person(int count)
{
this.count = count;
}

public int shout(int shout, int deadif)
{
if (shout < deadif) return (shout + 1);
this.getPrev().setNext(this.getNext());
this.getNext().setPrev(this.getPrev());
return 1;
}

public int getCount()
{
return this.count;
}

public Person getPrev()
{
return prev;
}

public void setPrev(Person prev)
{
this.prev = prev;
}

public Person getNext()
{
return next;
}

public void setNext(Person next)

{
this.next = next;
}
}

C++
view plaincopy to clipboardprint?

   1. #include <stdio.h> 
   2. #include <stdlib.h> 
   3. #include <time.h> 
   4. #include <sys/time.h> 
   5.   
   6. class Person 
   7. { 
   8.   
   9.     public: 
  10.   
  11.         Person(int count) : _next(NULL), _prev(NULL) { _count = count; } 
  12.         int shout(int shout, int nth) 
  13.         { 
  14.             if (shout < nth) return (shout + 1); 
  15.             _prev->_next = _next; 
  16.   
  17.   
  18.             _next->_prev = _prev; 
  19.             return 1; 
  20.         } 
  21.         int count() { return _count; } 
  22.         Person* next() { return _next; } 
  23.         void next(Person* person) { this->_next = person ; } 
  24.         Person* prev() { return _prev; } 
  25.         void prev(Person* person) { this->_prev = person; } 
  26.     private: 
  27.         int _count; 
  28.         Person* _next; 
  29.         Person* _prev; 
  30. }; 
  31.   
  32. class Chain 
  33. { 
  34.     public: 
  35.         Chain(int size) : _first(NULL) 
  36.         { 
  37.             Person* current = NULL; 
  38.             Person* last = NULL; 
  39.             for(int i = 0 ; i < size ; i++) 
  40.             { 
  41.                 current = new Person(i); 
  42.                 if (_first == NULL) _first = current; 
  43.                 if (last != NULL) 
  44.                 { 
  45.                     last->next(current); 
  46.                     current->prev(last); 
  47.                 } 
  48.                 last = current; 
  49.             } 
  50.             _first->prev(last); 
  51.             last->next(_first); 
  52.         } 
  53.         Person* kill(int nth) 
  54.         { 
  55.             Person* current = _first; 
  56.             int shout = 1; 
  57.             while(current->next() != current) 
  58.             { 
  59.                 Person* tmp = current; 
  60.                 shout = current->shout(shout,nth); 
  61.                 current = current->next(); 
  62.                 if (shout == 1) 
  63.                 { 
  64.                     delete tmp; 
  65.                 } 
  66.             } 
  67.             _first = current; 
  68.             return current; 
  69.         } 
  70.         Person* first() { return _first; } 
  71.     private: 
  72.         Person* _first; 
  73. }; 
  74.   
  75. int main(int argc, char** argv) 
  76. { 
  77.     int ITER = 1000000; 
  78.     Chain* chain; 
  79.     struct timeval start, end; 
  80.     gettimeofday(&#038;start,NULL); 
  81.     for(int i = 0 ; i < ITER ; i++) 
  82.     { 
  83.         chain = new Chain(40); 
  84.         chain->kill(3); 
  85.         delete chain; 
  86.     } 
  87.     gettimeofday(&#038;end,NULL); 
  88.     fprintf(stdout,"Time per iteration = %d microseconds\n\r", (((end.tv_sec - start.tv_sec) * 1000000) + (end.tv_usec - start.tv_usec)) / ITER); 
  89.     //fprintf(stdout,"Last man standing is %d\n\r", (chain->first()->count() + 1)); 
  90.     return 0; 
  91. } 

view plaincopy to clipboardprint?

   1. #include <stdio.h> 
   2. #include <stdlib.h> 
   3. #include <time.h> 
   4. #include <sys/time.h> 
   5.   
   6. class Person 
   7. { 
   8.   
   9.     public: 
  10.   
  11.         Person(int count) : _next(NULL), _prev(NULL) { _count = count; } 
  12.         int shout(int shout, int nth) 
  13.         { 
  14.             if (shout < nth) return (shout + 1); 
  15.             _prev->_next = _next; 
  16.   
  17.   
  18.             _next->_prev = _prev; 
  19.             return 1; 
  20.         } 
  21.         int count() { return _count; } 
  22.         Person* next() { return _next; } 
  23.         void next(Person* person) { this->_next = person ; } 
  24.         Person* prev() { return _prev; } 
  25.         void prev(Person* person) { this->_prev = person; } 
  26.     private: 
  27.         int _count; 
  28.         Person* _next; 
  29.         Person* _prev; 
  30. }; 
  31.   
  32. class Chain 
  33. { 
  34.     public: 
  35.         Chain(int size) : _first(NULL) 
  36.         { 
  37.             Person* current = NULL; 
  38.             Person* last = NULL; 
  39.             for(int i = 0 ; i < size ; i++) 
  40.             { 
  41.                 current = new Person(i); 
  42.                 if (_first == NULL) _first = current; 
  43.                 if (last != NULL) 
  44.                 { 
  45.                     last->next(current); 
  46.                     current->prev(last); 
  47.                 } 
  48.                 last = current; 
  49.             } 
  50.             _first->prev(last); 
  51.             last->next(_first); 
  52.         } 
  53.         Person* kill(int nth) 
  54.         { 
  55.             Person* current = _first; 
  56.             int shout = 1; 
  57.             while(current->next() != current) 
  58.             { 
  59.                 Person* tmp = current; 
  60.                 shout = current->shout(shout,nth); 
  61.                 current = current->next(); 
  62.                 if (shout == 1) 
  63.                 { 
  64.                     delete tmp; 
  65.                 } 
  66.             } 
  67.             _first = current; 
  68.             return current; 
  69.         } 
  70.         Person* first() { return _first; } 
  71.     private: 
  72.         Person* _first; 
  73. }; 
  74.   
  75. int main(int argc, char** argv) 
  76. { 
  77.     int ITER = 1000000; 
  78.     Chain* chain; 
  79.     struct timeval start, end; 
  80.     gettimeofday(&#038;start,NULL); 
  81.     for(int i = 0 ; i < ITER ; i++) 
  82.     { 
  83.         chain = new Chain(40); 
  84.         chain->kill(3); 
  85.         delete chain; 
  86.     } 
  87.     gettimeofday(&#038;end,NULL); 
  88.     fprintf(stdout,"Time per iteration = %d microseconds\n\r", (((end.tv_sec - start.tv_sec) * 1000000) + (end.tv_usec - start.tv_usec)) / ITER); 
  89.     //fprintf(stdout,"Last man standing is %d\n\r", (chain->first()->count() + 1)); 
  90.     return 0; 
  91. } 

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>

class Person
{

    public:

        Person(int count) : _next(NULL), _prev(NULL) { _count = count; }
        int shout(int shout, int nth)
        {
            if (shout < nth) return (shout + 1);
            _prev->_next = _next;


            _next->_prev = _prev;
            return 1;
        }
        int count() { return _count; }
        Person* next() { return _next; }
        void next(Person* person) { this->_next = person ; }
        Person* prev() { return _prev; }
        void prev(Person* person) { this->_prev = person; }
    private:
        int _count;
        Person* _next;
        Person* _prev;
};

class Chain
{
    public:
        Chain(int size) : _first(NULL)
        {
            Person* current = NULL;
            Person* last = NULL;
            for(int i = 0 ; i < size ; i++)
            {
                current = new Person(i);
                if (_first == NULL) _first = current;
                if (last != NULL)
                {
                    last->next(current);
                    current->prev(last);
                }
                last = current;
            }
            _first->prev(last);
            last->next(_first);
        }
        Person* kill(int nth)
        {
            Person* current = _first;
            int shout = 1;
            while(current->next() != current)
            {
                Person* tmp = current;
                shout = current->shout(shout,nth);
                current = current->next();
                if (shout == 1)
                {
                    delete tmp;
                }
            }
            _first = current;
            return current;
        }
        Person* first() { return _first; }
    private:
        Person* _first;
};

int main(int argc, char** argv)
{
    int ITER = 1000000;
    Chain* chain;
    struct timeval start, end;
    gettimeofday(&#038;start,NULL);
    for(int i = 0 ; i < ITER ; i++)
    {
        chain = new Chain(40);
        chain->kill(3);
        delete chain;
    }
    gettimeofday(&#038;end,NULL);
    fprintf(stdout,"Time per iteration = %d microseconds\n\r", (((end.tv_sec - start.tv_sec) * 1000000) + (end.tv_usec - start.tv_usec)) / ITER);
    //fprintf(stdout,"Last man standing is %d\n\r", (chain->first()->count() + 1));
    return 0;
}

Python
view plaincopy to clipboardprint?

   1. class Person(object): 
   2.     def __init__(self,count): 
   3.         self.count = count; 
   4.         self.prev = None   
   5.   
   6.   
   7.         self.next = None 
   8.     def shout(self,shout,deadif): 
   9.         if (shout < deadif): return (shout + 1) 
  10.         self.prev.next = self.next 
  11.         self.next.prev = self.prev 
  12.         return 1 
  13.   
  14. class Chain(object): 
  15.     def __init__(self,size):   
  16.         self.first = None 
  17.         last = None 
  18.         for i in range(size): 
  19.             current = Person(i) 
  20.             if self.first == None : self.first = current 
  21.             if last != None : 
  22.                 last.next = current 
  23.                 current.prev = last 
  24.             last = current 
  25.         self.first.prev = last 
  26.         last.next = self.first 
  27.     def kill(self,nth): 
  28.         current = self.first 
  29.         shout = 1 
  30.         while current.next != current: 
  31.             shout = current.shout(shout,nth) 
  32.             current = current.next 
  33.         self.first = current 
  34.         return current 
  35.       
  36. import time   
  37. ITER = 100000 
  38. start = time.time() 
  39. for i in range(ITER): 
  40.     chain = Chain(40) 
  41.     chain.kill(3) 
  42. end = time.time() 
  43. print 'Time per iteration = %s microseconds ' % ((end - start) * 1000000 / ITER) 

view plaincopy to clipboardprint?

   1. class Person(object): 
   2.     def __init__(self,count): 
   3.         self.count = count; 
   4.         self.prev = None   
   5.   
   6.   
   7.         self.next = None 
   8.     def shout(self,shout,deadif): 
   9.         if (shout < deadif): return (shout + 1) 
  10.         self.prev.next = self.next 
  11.         self.next.prev = self.prev 
  12.         return 1 
  13.   
  14. class Chain(object): 
  15.     def __init__(self,size):   
  16.         self.first = None 
  17.         last = None 
  18.         for i in range(size): 
  19.             current = Person(i) 
  20.             if self.first == None : self.first = current 
  21.             if last != None : 
  22.                 last.next = current 
  23.                 current.prev = last 
  24.             last = current 
  25.         self.first.prev = last 
  26.         last.next = self.first 
  27.     def kill(self,nth): 
  28.         current = self.first 
  29.         shout = 1 
  30.         while current.next != current: 
  31.             shout = current.shout(shout,nth) 
  32.             current = current.next 
  33.         self.first = current 
  34.         return current 
  35.       
  36. import time   
  37. ITER = 100000 
  38. start = time.time() 
  39. for i in range(ITER): 
  40.     chain = Chain(40) 
  41.     chain.kill(3) 
  42. end = time.time() 
  43. print 'Time per iteration = %s microseconds ' % ((end - start) * 1000000 / ITER) 

class Person(object):
    def __init__(self,count):
        self.count = count;
        self.prev = None


        self.next = None
    def shout(self,shout,deadif):
        if (shout < deadif): return (shout + 1)
        self.prev.next = self.next
        self.next.prev = self.prev
        return 1

class Chain(object):
    def __init__(self,size):
        self.first = None
        last = None
        for i in range(size):
            current = Person(i)
            if self.first == None : self.first = current
            if last != None :
                last.next = current
                current.prev = last
            last = current
        self.first.prev = last
        last.next = self.first
    def kill(self,nth):
        current = self.first
        shout = 1
        while current.next != current:
            shout = current.shout(shout,nth)
            current = current.next
        self.first = current
        return current
   
import time
ITER = 100000
start = time.time()
for i in range(ITER):
    chain = Chain(40)
    chain.kill(3)
end = time.time()
print 'Time per iteration = %s microseconds ' % ((end - start) * 1000000 / ITER)

Ruby
view plaincopy to clipboardprint?

   1. class Person 
   2.     attr_reader :count, :prev, :next 
   3.     attr_writer :count, :prev, :next 
   4.   
   5.     def initialize(count) 
   6.         #puts 'Initializing person : ' + count.to_s() 
   7.         @count = count 
   8.         @prev = nil 
   9.         @next = nil 
  10.     end 
  11.   
  12.     def shout(shout, deadif) 
  13.         if shout < deadif 
  14.             return shout + 1 
  15.         end 
  16.         @prev.next = @next 
  17.         @next.prev = @prev 
  18.         return 1 
  19.     end 
  20. end       
  21.                   
  22. class Chain   
  23.     attr_reader :first 
  24.     attr_writer :first 
  25.       
  26.     def initialize(size) 
  27.         @first = nil 
  28.         last = nil 
  29.         for i in (1, size) 
  30.             current = Person.new(i) 
  31.             if @first == nil 
  32.                 @first = current 
  33.             end 
  34.             if last != nil 
  35.                 last.next = current 
  36.                 current.prev = last 
  37.             end 
  38.             last = current 
  39.         end 
  40.         @first.prev = last 
  41.         last.next = @first 
  42.     end 
  43.   
  44.     def kill(nth) 
  45.         current = @first 
  46.         shout = 1 
  47.         while current.next != current 
  48.             shout = current.shout(shout,nth) 
  49.             current = current.next 
  50.         end 
  51.         @first = current 
  52.         return current 
  53.     end 
  54. end 
  55.   
  56. ITER=100000 
  57. start = Time.now 
  58. ITER.times { |i| 
  59. chain = Chain.new(40) 
  60. chain.kill(3) 
  61. } 
  62. ends = Time.now 
  63. puts 'Time per iteration = ' + ((ends - start) * 1000000 / ITER).to_s() + " microseconds" 

view plaincopy to clipboardprint?

   1. class Person 
   2.     attr_reader :count, :prev, :next 
   3.     attr_writer :count, :prev, :next 
   4.   
   5.     def initialize(count) 
   6.         #puts 'Initializing person : ' + count.to_s() 
   7.         @count = count 
   8.         @prev = nil 
   9.         @next = nil 
  10.     end 
  11.   
  12.     def shout(shout, deadif) 
  13.         if shout < deadif 
  14.             return shout + 1 
  15.         end 
  16.         @prev.next = @next 
  17.         @next.prev = @prev 
  18.         return 1 
  19.     end 
  20. end       
  21.                   
  22. class Chain   
  23.     attr_reader :first 
  24.     attr_writer :first 
  25.       
  26.     def initialize(size) 
  27.         @first = nil 
  28.         last = nil 
  29.         for i in (1, size) 
  30.             current = Person.new(i) 
  31.             if @first == nil 
  32.                 @first = current 
  33.             end 
  34.             if last != nil 
  35.                 last.next = current 
  36.                 current.prev = last 
  37.             end 
  38.             last = current 
  39.         end 
  40.         @first.prev = last 
  41.         last.next = @first 
  42.     end 
  43.   
  44.     def kill(nth) 
  45.         current = @first 
  46.         shout = 1 
  47.         while current.next != current 
  48.             shout = current.shout(shout,nth) 
  49.             current = current.next 
  50.         end 
  51.         @first = current 
  52.         return current 
  53.     end 
  54. end 
  55.   
  56. ITER=100000 
  57. start = Time.now 
  58. ITER.times { |i| 
  59. chain = Chain.new(40) 
  60. chain.kill(3) 
  61. } 
  62. ends = Time.now 
  63. puts 'Time per iteration = ' + ((ends - start) * 1000000 / ITER).to_s() + " microseconds" 

class Person
    attr_reader :count, :prev, :next
    attr_writer :count, :prev, :next

    def initialize(count)
        #puts 'Initializing person : ' + count.to_s()
        @count = count
        @prev = nil
        @next = nil
    end

    def shout(shout, deadif)
        if shout < deadif
            return shout + 1
        end
        @prev.next = @next
        @next.prev = @prev
        return 1
    end
end     
               
class Chain
    attr_reader :first
    attr_writer :first
   
    def initialize(size)
        @first = nil
        last = nil
        for i in (1, size)
            current = Person.new(i)
            if @first == nil
                @first = current
            end
            if last != nil
                last.next = current
                current.prev = last
            end
            last = current
        end
        @first.prev = last
        last.next = @first
    end

    def kill(nth)
        current = @first
        shout = 1
        while current.next != current
            shout = current.shout(shout,nth)
            current = current.next
        end
        @first = current
        return current
    end
end

ITER=100000
start = Time.now
ITER.times { |i|
chain = Chain.new(40)
chain.kill(3)
}
ends = Time.now
puts 'Time per iteration = ' + ((ends - start) * 1000000 / ITER).to_s() + " microseconds"

Groovy
view plaincopy to clipboardprint?

   1. class Chain 
   2. { 
   3.     def size 
   4.     def first 
   5.   
   6.     def init(siz) 
   7.     { 
   8.         def last 
   9.         size = siz 
  10.         for(def i = 0 ; i < siz ; i++) 
  11.         { 
  12.             def current = new Person() 
  13.             current.count = i 
  14.             if (i == 0) first = current 
  15.             if (last != null) 
  16.             { 
  17.                 last.next = current 
  18.             } 
  19.             current.prev = last 
  20.             last = current 
  21.         } 
  22.         first.prev = last 
  23.         last.next = first 
  24.     } 
  25.   
  26.     def kill(nth) 
  27.     { 
  28.         def current = first 
  29.         def shout = 1 
  30.         while(current.next != current) 
  31.         { 
  32.             shout = current.shout(shout,nth) 
  33.             current = current.next 
  34.         } 
  35.         first = current 
  36.     } 
  37. } 
  38.   
  39. class Person 
  40. { 
  41.     def count 
  42.     def prev 
  43.     def next 
  44.   
  45.     def shout(shout,deadif) 
  46.     { 
  47.         if (shout < deadif) 
  48.         { 
  49.             return (shout + 1) 
  50.         } 
  51.         prev.next = next 
  52.         next.prev = prev 
  53.         return 1 
  54.     } 
  55. } 
  56.   
  57. def main(args) 
  58. { 
  59.     println "Starting" 
  60.     def ITER = 100000 
  61.     def start = System.nanoTime() 
  62.     for(def i = 0 ; i < ITER ; i++) 
  63.     { 
  64.         def chain = new Chain() 
  65.         chain.init(40) 
  66.         chain.kill(3) 
  67.     } 
  68.     def end = System.nanoTime() 
  69.     println "Total time = " + ((end - start)/(ITER * 1000)) + " microseconds" 
  70. } 
  71.   
  72. def ITER = 100000 
  73. def start = System.nanoTime() 
  74. for(def i = 0 ; i < ITER ; i++) 
  75. { 
  76.     def chain = new Chain() 
  77.     chain.init(40) 
  78.     chain.kill(3) 
  79. } 
  80. def end = System.nanoTime() 
  81. println "Time per iteration = " + ((end - start)/(ITER * 1000)) + " microseconds" 

view plaincopy to clipboardprint?

   1. class Chain 
   2. { 
   3.     def size 
   4.     def first 
   5.   
   6.     def init(siz) 
   7.     { 
   8.         def last 
   9.         size = siz 
  10.         for(def i = 0 ; i < siz ; i++) 
  11.         { 
  12.             def current = new Person() 
  13.             current.count = i 
  14.             if (i == 0) first = current 
  15.             if (last != null) 
  16.             { 
  17.                 last.next = current 
  18.             } 
  19.             current.prev = last 
  20.             last = current 
  21.         } 
  22.         first.prev = last 
  23.         last.next = first 
  24.     } 
  25.   
  26.     def kill(nth) 
  27.     { 
  28.         def current = first 
  29.         def shout = 1 
  30.         while(current.next != current) 
  31.         { 
  32.             shout = current.shout(shout,nth) 
  33.             current = current.next 
  34.         } 
  35.         first = current 
  36.     } 
  37. } 
  38.   
  39. class Person 
  40. { 
  41.     def count 
  42.     def prev 
  43.     def next 
  44.   
  45.     def shout(shout,deadif) 
  46.     { 
  47.         if (shout < deadif) 
  48.         { 
  49.             return (shout + 1) 
  50.         } 
  51.         prev.next = next 
  52.         next.prev = prev 
  53.         return 1 
  54.     } 
  55. } 
  56.   
  57. def main(args) 
  58. { 
  59.     println "Starting" 
  60.     def ITER = 100000 
  61.     def start = System.nanoTime() 
  62.     for(def i = 0 ; i < ITER ; i++) 
  63.     { 
  64.         def chain = new Chain() 
  65.         chain.init(40) 
  66.         chain.kill(3) 
  67.     } 
  68.     def end = System.nanoTime() 
  69.     println "Total time = " + ((end - start)/(ITER * 1000)) + " microseconds" 
  70. } 
  71.   
  72. def ITER = 100000 
  73. def start = System.nanoTime() 
  74. for(def i = 0 ; i < ITER ; i++) 
  75. { 
  76.     def chain = new Chain() 
  77.     chain.init(40) 
  78.     chain.kill(3) 
  79. } 
  80. def end = System.nanoTime() 
  81. println "Time per iteration = " + ((end - start)/(ITER * 1000)) + " microseconds" 

class Chain
{
    def size
    def first

    def init(siz)
    {
        def last
        size = siz
        for(def i = 0 ; i < siz ; i++)
        {
            def current = new Person()
            current.count = i
            if (i == 0) first = current
            if (last != null)
            {
                last.next = current
            }
            current.prev = last
            last = current
        }
        first.prev = last
        last.next = first
    }

    def kill(nth)
    {
        def current = first
        def shout = 1
        while(current.next != current)
        {
            shout = current.shout(shout,nth)
            current = current.next
        }
        first = current
    }
}

class Person
{
    def count
    def prev
    def next

    def shout(shout,deadif)
    {
        if (shout < deadif)
        {
            return (shout + 1)
        }
        prev.next = next
        next.prev = prev
        return 1
    }
}

def main(args)
{
    println "Starting"
    def ITER = 100000
    def start = System.nanoTime()
    for(def i = 0 ; i < ITER ; i++)
    {
        def chain = new Chain()
        chain.init(40)
        chain.kill(3)
    }
    def end = System.nanoTime()
    println "Total time = " + ((end - start)/(ITER * 1000)) + " microseconds"
}

def ITER = 100000
def start = System.nanoTime()
for(def i = 0 ; i < ITER ; i++)
{
    def chain = new Chain()
    chain.init(40)
    chain.kill(3)
}
def end = System.nanoTime()
println "Time per iteration = " + ((end - start)/(ITER * 1000)) + " microseconds"

PHP
view plaincopy to clipboardprint?

   1. <? 
   2. class Person 
   3. {     
   4.     function __construct($c) 
   5.     {     
   6.         $this->count = $c; 
   7.     }         
   8.   
   9.                   
  10.     function getPrev() 
  11.     {         
  12.         return $this->prev;   
  13.     }             
  14.               
  15.     function setPrev($pr) 
  16.     {     
  17.         $this->prev = $pr; 
  18.     }     
  19.       
  20.     function getNext() 
  21.     { 
  22.         return $this->next; 
  23.     } 
  24.   
  25.     function setNext($nxt) 
  26.     { 
  27.         $this->next = $nxt; 
  28.     } 
  29.   
  30.     function shout($shout, $nth) 
  31.     { 
  32.         if ($shout < $nth) 
  33.         { 
  34.             return $shout + 1; 
  35.         } 
  36.         $this->getPrev()->setNext($this->getNext()); 
  37.         $this->getNext()->setPrev($this->getPrev()); 
  38.         return 1; 
  39.     } 
  40. } 
  41.   
  42. class Chain 
  43. { 
  44.     var $first; 
  45.   
  46.     function __construct($size) 
  47.     { 
  48.         for($i = 0; $i < $size ; $i++) 
  49.         { 
  50.             $current = new Person($i); 
  51.             if ($this->first == null) $this->first = $current; 
  52.             if ($last != null) 
  53.             { 
  54.                 $last->setNext($current); 
  55.                 $current->setPrev($last); 
  56.             } 
  57.             $last = $current; 
  58.         } 
  59.         $this->first->setPrev($last); 
  60.         $last->setNext($this->first); 
  61.     } 
  62.   
  63.     function kill($nth) 
  64.     { 
  65.         $current = $this->first; 
  66.         $shout = 1; 
  67.         while($current->getNext() !== $current) 
  68.         { 
  69.             $shout =  $current->shout($shout,$nth); 
  70.             $current = $current->getNext(); 
  71.         } 
  72.         $this->first = $current; 
  73.     } 
  74. } 
  75.   
  76. $start = microtime(true); 
  77. $ITER = 100000; 
  78. for($i = 0 ; $i < $ITER ; $i++) 
  79. { 
  80.     $chain = new Chain(40); 
  81.     $chain->kill(3); 
  82. } 
  83. $end = microtime(true); 
  84. printf("Time per iteration = %3.2f microseconds\n\r",(($end -  $start) * 1000000 / $ITER)); 
  85. ?> 

view plaincopy to clipboardprint?

   1. <? 
   2. class Person 
   3. {     
   4.     function __construct($c) 
   5.     {     
   6.         $this->count = $c; 
   7.     }         
   8.   
   9.                   
  10.     function getPrev() 
  11.     {         
  12.         return $this->prev;   
  13.     }             
  14.               
  15.     function setPrev($pr) 
  16.     {     
  17.         $this->prev = $pr; 
  18.     }     
  19.       
  20.     function getNext() 
  21.     { 
  22.         return $this->next; 
  23.     } 
  24.   
  25.     function setNext($nxt) 
  26.     { 
  27.         $this->next = $nxt; 
  28.     } 
  29.   
  30.     function shout($shout, $nth) 
  31.     { 
  32.         if ($shout < $nth) 
  33.         { 
  34.             return $shout + 1; 
  35.         } 
  36.         $this->getPrev()->setNext($this->getNext()); 
  37.         $this->getNext()->setPrev($this->getPrev()); 
  38.         return 1; 
  39.     } 
  40. } 
  41.   
  42. class Chain 
  43. { 
  44.     var $first; 
  45.   
  46.     function __construct($size) 
  47.     { 
  48.         for($i = 0; $i < $size ; $i++) 
  49.         { 
  50.             $current = new Person($i); 
  51.             if ($this->first == null) $this->first = $current; 
  52.             if ($last != null) 
  53.             { 
  54.                 $last->setNext($current); 
  55.                 $current->setPrev($last); 
  56.             } 
  57.             $last = $current; 
  58.         } 
  59.         $this->first->setPrev($last); 
  60.         $last->setNext($this->first); 
  61.     } 
  62.   
  63.     function kill($nth) 
  64.     { 
  65.         $current = $this->first; 
  66.         $shout = 1; 
  67.         while($current->getNext() !== $current) 
  68.         { 
  69.             $shout =  $current->shout($shout,$nth); 
  70.             $current = $current->getNext(); 
  71.         } 
  72.         $this->first = $current; 
  73.     } 
  74. } 
  75.   
  76. $start = microtime(true); 
  77. $ITER = 100000; 
  78. for($i = 0 ; $i < $ITER ; $i++) 
  79. { 
  80.     $chain = new Chain(40); 
  81.     $chain->kill(3); 
  82. } 
  83. $end = microtime(true); 
  84. printf("Time per iteration = %3.2f microseconds\n\r",(($end -  $start) * 1000000 / $ITER)); 
  85. ?>
Programming › Re: Defend Your Programming Language by javarules(m): 6:37pm On Jul 10, 2008
@Bossman

I think these debates are good ooooooo, dats the only way you can make a nigerian say something these days grin cheesy just kidding
Programming › Re: [Opinion] B.sc Computer Science In Nigeria? poo! by javarules(m): 6:25pm On Jul 10, 2008
huh where do i begin. U are all right in a way I must admit

@javaprince and all dt are for: I think I will talk to you first. I believe you, the University is a place to be. What with all the people you meet and the courses you take. There are people in my life that I wouldnt have met(and wu av affected my life so positively dt I owe them something) if not for University. Now the question is do we do irrelevant things in school or not? yes we do. Why? I'll tell you. The school is not meant to give you skills alone(like javalove's java skills), the school is also meant to build you in other ways, socially, spiritually and otherwise. I was talking to a group of young programmers in my alma mata and I told them, the reason why you do only two or three programming courses and 5 other "irrelevant courses" is so if you can successfully handle and pass 5 more courses and yet still do well @ programming, then tomoro if youo are put in charge of a company with 5 departments, you will be able to do well at ur core (programming) and still handle the 5 depts well. they all laughed but at least they get the idea. the school is meant to build you in other ways too not just your skills alone. A professor is one who knows a little about much and much about a little.

@javalove and all dat are against: Its a pity though that our educational system have now focused much on the other ways and neglected the basic(skills). Its a shame that if a medical student did not pass MTH 101, he or she is withdrawn from the college! Its a shame that a fine and applied arts students is made to go thru the rigours of BIO 101! all these things are good as addons, but when the core is now neglected and the others are focused on? its a pity.

In conclusion
Our educational system is thus not all that bad. Even if you score them less than average(although I think I score them 50%) at least "eni to gba odo gba mark" u get? what we need is a revisitation of our curriculum and things like that. Its no wonder though because every other sector suffers, not just education, we need to re-evaluate so many things. Rev. Sam Adeyemi said the way they use to prepare roasted corn is still d way they use to prepare it till now! that shiouldnt be. Let young men and young enterpreneurs invest in education, lets start schools and lets set standards for these schools, standards that eventually the public schools will emulate. Its the way forward and not the way backward.

Its true our man Bill dropped out of school, but lets not forget that he went back to complete his degree. Bill is not just a programmer, he is a business man, a graduate from Harvard Business school. That's why I believe M$ is such a successful Business

I am out for now




Java Nigeria Developers, meet the java dukes
Programming › Re: Defend Your Programming Language by javarules(m): 2:32pm On Jul 10, 2008
There are no super programming languages, there are only super programmers,

Having said said that, how can u compare Java with C#? let me ask you a question, your father built a house in 1960, since then he has been doing major and minor renovations on the house, changing this and putting that etcetera, now you build a house a house in 2008, and you compare your house to your father's in Elegance, Style and Design, u must be crazy(so sorry to use that word, but u get the point), C# was build with a major aim in mind, treat the fuckups in Java. I have done both languages and I see the differences clearly, but a seasoned Java programmer wont need to go and learn C# because almost all d additions to C# are in his library, created by himself! Just like your Dad don't need to build a new house just because your own house have a flat screen TV, by pete's name go and buy a flat screen TV and put it in the house. Why, if I have to migrate all my works to C# from Java, by the time I am through, a new language would have come out say F-Cubed that will beat C#, so what will I do then, start migrating? stupidity in the highest level.

I am out for now jare!




Java and Nigerian Developers, meet the java dukes
Programming › Re: Java Has Failed! by javarules(m): 10:43am On Jul 02, 2008
Java has failed? I got only one answer www.java.com, if a language does all that and it has failed, show me a language that does more! ciao
Programming › Re: Why Certification Since Your Clients Are Satisfied: by javarules(m): 12:59pm On Jul 01, 2008
look for job? or job look for me. If u are good, jobs will look for you, u dont need certifications. This is how it goes, a big bang company employs a certified geek, he creates the problem he can't solve it, they call me to come and do the clean up, I came did d clean up and go(after I am some hundreds of thousands richer). Can't remember when last I wrote a CV.

its funny oooo that a programmer will say I am good I am looking for job, he can't be both, if he is both then he needs Pastor Chris grin
Programming › Re: Why Certification Since Your Clients Are Satisfied: by javarules(m): 6:48pm On Jun 30, 2008
javalove:
Programming is no Econs or Banking and Finance where u are required to read your life out.
tell them oooo
Programming › Re: Why Certification Since Your Clients Are Satisfied: by javarules(m): 10:26am On Jun 30, 2008
u avn't heard of 2 cents? how long you've been in this forum, so sorry about it i just tot everyone should know. Its a term we use to simply say a piece of my heart. I don't have a certification and dts because I don't want to, not because I can't pass it. If you have links within Sun Microsystems, ask them if they've ever heard of me.That will give you an idea.

Now I like the part that says develpers can't pass SCJA, they are not to be taken and passed by developers! do I shock you? I bet no. Developers have better things to do with their time than sit down with volumes of books dt they might never need after the certification. Developers, as I know them are people who get jobs done and make customers happy, if you come in to my office brandishing SCJA, I wont employ you on the basis of that. You are not a developer, you are one of the bookish guys.

Now taking it for the fun of it. I have more fun from developing than from sitting down with a certification. If you derive fun from sitting down to write certifications, then good for you. I av not met a developer who derives more fun from anything than developing, if you are one, then I am glad I met you!

I am a mobile application developer, I use java for all other things too, I can't say I am enterprise or web, although I do both at a considerate level, I use them only when my mobile apps need them or when a customer will be happier if I use them.

All in all, u like certifications, take them at least they get you a job.



JAND, a place to be, a community to belong to
Programming › Re: Why Certification Since Your Clients Are Satisfied: by javarules(m): 8:39am On Jun 30, 2008
malone5923:
That because the guy has a scjp certification which is questioned based(you can always get dumps for it) if he was a certified web content developer or a certified java achitect which rerquires you pass three modes that involes assignments and essay to acquire the certificate. In all certification isnt rubbbish if you have a high level certificate. No Offence but I don't thinkl you would even pass the sun certified java architect.
I laugh. this is my 2cents, I dont think I need SCJA to prove my java-abilities, avn't u wondered why we dont av so many of them.
Romance › Re: Why Do Ladies Like Men That Treat 'em Like Crap? by javarules(m): 7:54pm On Jun 26, 2008
make una take am easy on d guy now. its not easy to be a fool oooooo. at least he tried just that his own mumu na grade one. well, at least d guy no come back, dt means he don realise his mumulity.

i am out for now
Programming › Re: Can Not Run My Applet In A Web Browser by javarules(m): 3:22pm On Jun 25, 2008
send ur java and html code lets see
Programming › Re: Why Certification Since Your Clients Are Satisfied: by javarules(m): 2:53pm On Jun 25, 2008
How I hate certifications, some punk came to my office brandishing java certification, he was so unlucky that I was around, so my hrm said I should interview him and get back to him. I asked him just a question and he messed up. But he is Sun Certified Java Programmer, as for me certifications are rubbish things. Several guys out there carry ccna around who can not even crimp a networking cable, this is no fable, i have seen it.

In my company, we do our own certification exam for you, even if you like say you have MCZZ we dont like

my 2cents

1 2 3 4 5 6 7 (of 7 pages)