diff --git a/questions/Poker_game.md b/questions/Poker_game.md new file mode 100644 index 0000000..c769c30 --- /dev/null +++ b/questions/Poker_game.md @@ -0,0 +1,7 @@ +# Pick a card + +## Question + +Welcome to **divine**! Here is the problem statement: + +You are playing a poker game and the final round that could cost you millions of dollars is to pick a card from a list of cards which is arranged in ascending order that contains a number that is given to you in the shortest amount of time, which way would you take to pick that card and in the shortest amount of time possible so that you can cash out millions of dollars!!!! \ No newline at end of file diff --git a/util/divine-quest.py b/util/divine-quest.py new file mode 100644 index 0000000..ea83d35 --- /dev/null +++ b/util/divine-quest.py @@ -0,0 +1,18 @@ +def pick_a_card(list_cards, card_number): + mid = len(list_cards)//2 + first_pos = 0 + last_pos = len(list_cards)-1 + + while first_pos <= last_pos: + if list_cards[mid] > card_number: + last_pos = mid + new_cards = list_cards[first_pos,last_pos+1] + if list_cards[mid] == card_number: + return mid + + elif list_cards[mid] < card_number: + first_pos = mid + list_cards = list_cards[first_pos,last_pos+1] + if list_cards[mid] == card_number: + return mid + \ No newline at end of file