6 kyu

SMS Lottery Bet Validator

411 of 818anter69

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!

Algorithms

Stats:

CreatedAug 28, 2017
PublishedSep 9, 2017
Warriors Trained1762
Total Skips37
Total Code Submissions7226
Total Times Completed818
Python Completions411
C# Completions112
Ruby Completions50
Total Stars39
% of votes with a positive feedback rating90% of 188
Total "Very Satisfied" Votes155
Total "Somewhat Satisfied" Votes29
Total "Not Satisfied" Votes4
Total Rank Assessments11
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • anter69 Avatar
  • ZozoFouchtra Avatar
  • Axesilo Avatar
  • hobovsky Avatar
  • dfhwze Avatar
Ad