Java Code Challenge is a new regular segment taking the best challenge from Reddit's dailyprogrammer. Things are a little different here as we're focused on Java. A working solution is not enough; we're looking for the cleanest Java code with tests. 3rd party libraries are welcome but if you can do it without it will be easier for others to comprehend.
If you can fit your solution in the comments then go for it, but preferably put your answer in GitHub and link in the comments. Next week we'll be sharing the best solutions and sharing the best code practices we see! This challenge should be a good opportunity to flex your Java 8 muscles.
Scrabble is a popular word game where players remove tiles with letters on them from a bag and use them to create words on a board. The total number of tiles, as well as the frequency of each letter, does not change between games.
For this challenge, we will be using the tile set from the English edition, which has 100 tiles total. Here's a reference for the distribution and point value of each tile.
Each tile will be represented by the letter that appears on it, with the exception that blank tiles are represented by underscores
The tiles already in play are inputted as an uppercase string. For example, if 14 tiles have been removed from the bag and are in play, you would be given an input like this:
You should output the tiles that are left in the bag. The list should be in descending order of the quantity of each tile left in the bag, skipping over amounts that have no tiles.
In cases where more than one letter has the same quantity remaining, output those letters in alphabetical order, with blank tiles at the end.
10: E 9: I 8: A 7: O 5: N, R, T 4: D, L, U 3: G, S 2: F, H, P, V, W 1: B, C, J, K, M, Q, Y, Z, _ 0: X
If more tiles have been removed from the bag than possible, such as 3
Qs, you should give a helpful error message instead of printing the list.
Invalid input. More Q's have been taken from the bag than possible.
10: E 7: A, I 6: N, O 5: T 4: D, L, R 3: S, U 2: B, C, F, G, M, V, Y 1: H, J, K, P, W, X, Z, _ 0: Q
11: E 9: A, I 6: R 5: N, O 4: D, S, T, U 3: G, L 2: B, C, H, M, P, V, W, Y, _ 1: K, X 0: F, J, Q, Z
Invalid input. More X's have been taken from the bag than possible.