@@ -0,0 +1,1285 @@
+package coding4fun;%0A%0A/**%0A * Generate a unique ID with a length of 4 that consists of letters a, b, c, and d.%0A *%0A * For example:%0A * %3Cpre%3E%0A * aaaa%0A * aaab%0A * aaac%0A * aaad%0A * aaba%0A * %3C/pre%3E%0A */%0Apublic class Problem50 %7B%0A    private static class Id %7B%0A        private static char%5B%5D CHARS = new char%5B%5D%7B'a', 'b', 'c', 'd'%7D;%0A        private static int MAX = 255; // (3 * 4**3) + (3 * 4**2) + (3 * 4**1) + (3 * 4**0)%0A        private int id;%0A%0A        public String generate() %7B%0A            if (id == MAX) %7B // reset it%0A                id = 0;%0A            %7D%0A            int i = id;%0A            StringBuilder sb = new StringBuilder();%0A            while (i %3E 0) %7B%0A                int idx = i %25 CHARS.length;%0A                i = i / CHARS.length;%0A                sb.append(CHARS%5Bidx%5D);%0A            %7D%0A            id++;%0A            return pad(sb).reverse().toString();%0A        %7D%0A%0A        private static StringBuilder pad(StringBuilder sb) %7B%0A            int size = sb.length();%0A            for (int i = 0; i %3C CHARS.length - size; i++) %7B%0A                sb.append(CHARS%5B0%5D);%0A            %7D%0A            return sb;%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Id id = new Id();%0A        for (int i = 0; i %3C 5; i++) %7B%0A            System.out.println(id.generate());%0A        %7D%0A    %7D%0A%7D%0A

Add problem 50