SMS Lottery Bet Validator
Description:
Story
You were asked to write a simple validator for a company that is planning to introduce lottery betting via text messages. The same validator will be used for multiple games: e.g. 5 out of 90, 7 out of 35, etc. (N
out of M
)
The text messages should contain exactly N
unique numbers between 1
and M
(both included), separated by a comma (,
) and/or space(s). Any other character makes the bet invalid.
Your task
You receive the game type and the user's text message as input, and you need to check if the bet is valid or not. If it's valid, return the chosen numbers as a list, sorted in increasing order. If it's invalid, return None
, null
, nil
as appropriate to your language.
Note: Leading and trailing spaces will not be tested. Tabs, newlines and other whitespaces are not tested either. Think of a classic Nokia 3310 user for reference :-)
Examples
validate_bet([5, 90], "1 2 3 4 5") --> [1, 2, 3, 4, 5]
validate_bet([5, 90], "5 , 3, 1 4,2") --> [1, 2, 3, 4, 5]
validate_bet([5, 90], "1, 2; 3, 4, 5") --> None / null / nil
validate_bet([5, 90], "1, 2, 3, 4") --> None / null / nil
validate_bet([5, 90], "1, 2, 3, 4, 95") --> None / null / nil
My other katas
If you enjoyed this kata then please try my other katas! :-)
Translations are welcome!
Similar Kata:
Stats:
Created | Aug 28, 2017 |
Published | Sep 9, 2017 |
Warriors Trained | 1762 |
Total Skips | 37 |
Total Code Submissions | 7226 |
Total Times Completed | 818 |
Python Completions | 411 |
C# Completions | 112 |
Ruby Completions | 50 |
Total Stars | 39 |
% of votes with a positive feedback rating | 90% of 188 |
Total "Very Satisfied" Votes | 155 |
Total "Somewhat Satisfied" Votes | 29 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 11 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |