[Java] Simple Semaphore Solution - beats 100%
Only two Philosophers can eat at the same time :3\n\n\nclass DiningPhilosophers {\n\n    private Semaphore[] forks = new Semaphore[5];\n    private Semaphore ea
Only two Philosophers can eat at the same time :3\n\n```\nclass DiningPhilosophers {\n\n    private Semaphore[] forks = new Semaphore[5];\n    private Semaphore eatingPeople = new Semaphore(2);\n    \n    public DiningPhilosophers() {\n        for (int i = 0; i < 5; i++){\n            forks[i] = new Semaphore(1);\n        }\n    }\n    \n    // call the run() method of any runnable to execute its code\n    public void wantsToEat(int philosopher,\n                           Runnable pickLeftFork,\n                           Runnable pickRightFork,\n                           Runnable eat,\n                           Runnable putLeftFork,\n                           Runnable putRightFork) throws InterruptedException {\n        \n        Semaphore leftFork = forks[philosopher];\n        Semaphore rightFork = forks[(philosopher+5-1)%5];\n        \n        eatingPeople.acquire();\n        \n        leftFork.acquire();\n        rightFork.acquire();\n        pickLeftFork.run();\n        pickRightFork.run();\n        eat.run();\n        putLeftFork.run();\n        putRightFork.run();\n        leftFork.release();\n        rightFork.release();\n        \n        eatingPeople.release();\n        \n    }\n}\n```
[]