Java simple and clear
\nclass DiningPhilosophers {\n\n    private Semaphore[] forks = new Semaphore[5];\n    \n    public DiningPhilosophers() {\n        for(int i = 0; i < 5; i++) {
```\nclass DiningPhilosophers {\n\n    private Semaphore[] forks = new Semaphore[5];\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 rightFork = forks[philosopher];\n        Semaphore leftFork = forks[(philosopher + 1) % 5];\n        \n        rightFork.acquire();\n        pickRightFork.run();\n        \n        leftFork.acquire();\n        pickLeftFork.run();\n        \n        eat.run();\n        \n        putLeftFork.run();\n        leftFork.release();\n        \n        putRightFork.run();\n        rightFork.release();\n    }\n}\n```
[]