Java Solution -- Easy and Faster
Code\n\nclass DiningPhilosophers {\n\n    private Semaphore[] forks = new Semaphore[5];\n\tprivate Lock eaters;\n\t\n\t\n\tpublic DiningPhilosophers() {\n      
# Code\n```\nclass DiningPhilosophers {\n\n    private Semaphore[] forks = new Semaphore[5];\n\tprivate Lock eaters;\n\t\n\t\n\tpublic DiningPhilosophers() {\n        for(int i=0; i<5; i++) {\n        \tforks[i] = new Semaphore(1);\n        }\n        eaters = new ReentrantLock();\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    \t\n    \teaters.lock();\n    \tforks[philosopher].acquire();\n    \tforks[(philosopher+1) %5].acquire();\n    \t\n    \tpickLeftFork.run();\n    \tpickRightFork.run();\n    \t\n    \teat.run();\n    \t\n    \tputLeftFork.run();\n    \tputRightFork.run();\n    \t\n    \tforks[philosopher].release();\n    \tforks[(philosopher + 1) % 5].release();\n    \teaters.unlock();\n    \t\n    \t\n    }\n}\n```
['Java']