package leetcode;

import java.util.function.IntConsumer;

/**
 * https://leetcode.com/problems/print-zero-even-odd/
 */
public class Problem1116 {
    class ZeroEvenOdd {
        private int n;

        public ZeroEvenOdd(int n) {
            this.n = n;
        }

        // printNumber.accept(x) outputs "x", where x is an integer.
        public void zero(IntConsumer printNumber) throws InterruptedException {

        }

        public void even(IntConsumer printNumber) throws InterruptedException {

        }

        public void odd(IntConsumer printNumber) throws InterruptedException {

        }
    }

    public static void main(String[] args) {
        Problem1116 prob = new Problem1116();
    }
}

@@ -12,16 +12,55 @@
 tcode;%0A%0A
+import java.util.concurrent.Semaphore;%0A
 import j
@@ -184,16 +184,31 @@
 6 %7B%0A    
+private static 
 class Ze
@@ -246,321 +246,1056 @@
  n;%0A
-%0A        public ZeroEvenOdd(int n) %7B%0A            this.n = n;%0A        %7D%0A%0A        // printNumber.accept(x) outputs %22x%22, where x is an integer.%0A        public void zero(IntConsumer printNumber) throws InterruptedException %7B%0A%0A        %7D%0A%0A        public void even(IntConsumer printNumber) throws InterruptedException %7B%0A
+        private final Semaphore zeroSempahore = new Semaphore(1);%0A        private final Semaphore oddSempahore = new Semaphore(0);%0A        private final Semaphore evenSempahore = new Semaphore(0);%0A        private boolean odd = true;%0A%0A        public ZeroEvenOdd(int n) %7B%0A            this.n = n;%0A        %7D%0A%0A        // printNumber.accept(x) outputs %22x%22, where x is an integer.%0A        public void zero(IntConsumer printNumber) throws InterruptedException %7B%0A            for (int i = 0; i %3C n; i++) %7B%0A                zeroSempahore.acquire();%0A                printNumber.accept(0);%0A                if (odd) %7B%0A                    oddSempahore.release();%0A                %7D else %7B%0A                    evenSempahore.release();%0A                %7D%0A                odd = !odd;%0A            %7D%0A        %7D%0A%0A        public void even(IntConsumer printNumber) throws InterruptedException %7B%0A            for (int i = 2; i %3C= n; i += 2) %7B%0A                evenSempahore.acquire();%0A                printNumber.accept(i);%0A                zeroSempahore.release();%0A            %7D
 %0A   
@@ -1381,25 +1381,24 @@
 ption %7B%0A
-%0A
         
 %7D%0A    %7D%0A
@@ -1393,107 +1393,189 @@
     
-%7D%0A
     
-%7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1116 prob = new Problem1116();
+for (int i = 1; i %3C= n; i += 2) %7B%0A                oddSempahore.acquire();%0A                printNumber.accept(i);%0A                zeroSempahore.release();%0A            %7D%0A        %7D
 %0A   

Solve problem 1116