Bulls and Cows
Description:
In this kata you will try to recreate a simple code-breaking game. It is called "Bulls and Cows". The rules are quite simple:
The computer generates a secret number consisting of 4 distinct digits. Then the player, in 8 turns, tries to guess the number. As a result he receives from the computer the number of matches. If the matching digits are in their right positions, they are "bulls", if in different positions, they are "cows".
To implement this you will use:
1)a constructor (int) - initiates the game, receives a number and then sets it as the secret number.
2)and a function "compare with (int)" - compares the given and the secret numbers and then returns a String formated as "X bull/bulls and Y cow/cows".
However, there are some notes:
1)if the given number matches the secret number instead of returning "4 bulls and 0 cows", return "You win!". Any next attempts to play the game (even with invalid numbers) should return "You already won!"
2)if the amount of turns in this game is more than 8 (invalid turns are not counted) the returned String should be "Sorry, you're out of turns!".
3)After checking the turns you should validate the given number. If it does not correspond to the conditions you should throw an exception :
IllegalArgumentException
Similar Kata:
Stats:
Created | Nov 6, 2018 |
Published | Nov 13, 2018 |
Warriors Trained | 1512 |
Total Skips | 18 |
Total Code Submissions | 4097 |
Total Times Completed | 437 |
Java Completions | 188 |
Python Completions | 258 |
Total Stars | 30 |
% of votes with a positive feedback rating | 84% of 126 |
Total "Very Satisfied" Votes | 94 |
Total "Somewhat Satisfied" Votes | 24 |
Total "Not Satisfied" Votes | 8 |
Total Rank Assessments | 4 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 7 kyu |
Lowest Assessed Rank | 8 kyu |