From f5d39c8681807bccf60483135a6ae448ccb71ae8 Mon Sep 17 00:00:00 2001 From: Drexregion <96681590+Drexregion@users.noreply.github.com> Date: Sat, 21 Oct 2023 15:49:55 +0000 Subject: [PATCH 1/3] Added a new question with a python file --- questions/Poker_game.md | 7 +++++++ util/divine-quest.py | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 questions/Poker_game.md create mode 100644 util/divine-quest.py 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..735f0be --- /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 True: + if list_cards[mid] > card_number: + last_pos = mid + new_cards = list_cards[first_pos,last_pos+1] + if mid == card_number: + return mid + + else: + first_pos = mid + list_cards = list_cards[first_pos,last_pos+1] + if mid == card_number: + return mid + \ No newline at end of file From 30d407e0cb61b32708c47ec3fb4e8519e8009cfa Mon Sep 17 00:00:00 2001 From: Drexregion <96681590+Drexregion@users.noreply.github.com> Date: Sat, 21 Oct 2023 15:56:57 +0000 Subject: [PATCH 2/3] New change in while loop --- util/divine-quest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/divine-quest.py b/util/divine-quest.py index 735f0be..9256d47 100644 --- a/util/divine-quest.py +++ b/util/divine-quest.py @@ -3,7 +3,7 @@ def pick_a_card(list_cards, card_number): first_pos = 0 last_pos = len(list_cards)-1 - while True: + while first_pos <= last_pos: if list_cards[mid] > card_number: last_pos = mid new_cards = list_cards[first_pos,last_pos+1] From 498837b7c7baf84cb839f7395e24362c7d2a9a0a Mon Sep 17 00:00:00 2001 From: Drexregion <96681590+Drexregion@users.noreply.github.com> Date: Sat, 21 Oct 2023 15:59:53 +0000 Subject: [PATCH 3/3] New changes for functionality --- util/divine-quest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/divine-quest.py b/util/divine-quest.py index 9256d47..ea83d35 100644 --- a/util/divine-quest.py +++ b/util/divine-quest.py @@ -7,12 +7,12 @@ def pick_a_card(list_cards, card_number): if list_cards[mid] > card_number: last_pos = mid new_cards = list_cards[first_pos,last_pos+1] - if mid == card_number: + if list_cards[mid] == card_number: return mid - else: + elif list_cards[mid] < card_number: first_pos = mid list_cards = list_cards[first_pos,last_pos+1] - if mid == card_number: + if list_cards[mid] == card_number: return mid \ No newline at end of file