package leetcode;

/**
 * https://leetcode.com/problems/the-dining-philosophers/
 */
public class Problem1226 {
    private static class DiningPhilosophers {
        public DiningPhilosophers() {
        }

        // call the run() method of any runnable to execute its code
        public void wantsToEat(int philosopher,
                               Runnable pickLeftFork,
                               Runnable pickRightFork,
                               Runnable eat,
                               Runnable putLeftFork,
                               Runnable putRightFork) throws InterruptedException {

        }
    }
}

@@ -12,16 +12,56 @@
 tcode;%0A%0A
+import java.util.concurrent.Semaphore;%0A%0A
 /**%0A * h
@@ -204,36 +204,224 @@
    p
-ublic DiningPhilosophers() %7B
+rivate final Semaphore%5B%5D semaphores = new Semaphore%5B5%5D;%0A%0A        public DiningPhilosophers() %7B%0A            for (int i = 0; i %3C semaphores.length; i++) %7B%0A                semaphores%5Bi%5D = new Semaphore(1);%0A            %7D
 %0A   
@@ -836,16 +836,889 @@
 ption %7B%0A
+            Semaphore left = semaphores%5Bphilosopher%5D;%0A            Semaphore right = (philosopher == 0) ? semaphores%5B4%5D : semaphores%5Bphilosopher - 1%5D;%0A%0A            if (philosopher %25 2 == 0) %7B%0A                left.acquire();%0A                pickLeftFork.run();%0A                right.acquire();%0A                pickRightFork.run();%0A            %7D else %7B%0A                right.acquire();%0A                pickRightFork.run();%0A                left.acquire();%0A                pickLeftFork.run();%0A            %7D%0A%0A            eat.run();%0A%0A            if (philosopher %25 2 == 0) %7B%0A                putRightFork.run();%0A                right.release();%0A                putLeftFork.run();%0A                left.release();%0A            %7D else %7B%0A                putLeftFork.run();%0A                left.release();%0A                putRightFork.run();%0A                right.release();%0A            %7D
 %0A       

Solve problem 1226