Java Sweet Short Solution
\nclass DiningPhilosophers {\n\n    Semaphore[] sem = new Semaphore[5];\n    Object obj = new Object();\n    \n    public DiningPhilosophers() {\n        for (i
```\nclass DiningPhilosophers {\n\n    Semaphore[] sem = new Semaphore[5];\n    Object obj = new Object();\n    \n    public DiningPhilosophers() {\n        for (int i = 0 ; i <=4 ; i++) {\n            sem[i] = new Semaphore(1);\n        }\n    }\n\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\n        sem[philosopher].acquire();\n        sem[(philosopher+1)%5].acquire();\n        \n\t\t// Here only if we have picked up both forks.\n        pickLeftFork.run();\n        pickRightFork.run();\n        eat.run();\n        putLeftFork.run();\n        putRightFork.run();\n        \n\t\t// Release both forks.\n        sem[philosopher].release();\n        sem[(philosopher+1)%5].release();\n\n    }\n}\n```
[]