From 1978fe0dbd8ed7ce00a98175bc253dadf626b8f2 Mon Sep 17 00:00:00 2001 From: vigneshnagaraju Date: Thu, 4 Jun 2026 00:19:25 +0000 Subject: [PATCH 1/2] Initial commit From 641a75d95e25782249755efc18f79d4f77169ced Mon Sep 17 00:00:00 2001 From: vigneshnagaraju Date: Thu, 4 Jun 2026 00:19:25 +0000 Subject: [PATCH 2/2] Pending changes exported from your codespace --- 02_05/quicksort.py | 7 +++--- 02_06/fibonacci.py | 4 +++- 03_06/number_placement_algorithm.py | 34 ++++++++++++++++++++++++----- 03_06/test.py | 9 ++++++++ 05_05/ransom_note_stub.py | 24 +++++++++++++++++++- 5 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 03_06/test.py diff --git a/02_05/quicksort.py b/02_05/quicksort.py index a610bfa..24cb86a 100644 --- a/02_05/quicksort.py +++ b/02_05/quicksort.py @@ -26,11 +26,12 @@ def quicksort_verbose(arr): data = [3, 1, 4, 2] -# print(quicksort(data)) -# print(quicksort_verbose(data)) +#print(quicksort(data)) +#print(quicksort_verbose(data)) # What about data with duplicates? data = [1, 6, 5, 5, 2, 6, 1] -print(quicksort(data)) +#print(quicksort(data)) +print(quicksort_verbose(data)) diff --git a/02_06/fibonacci.py b/02_06/fibonacci.py index daa8197..e8c146c 100644 --- a/02_06/fibonacci.py +++ b/02_06/fibonacci.py @@ -1,5 +1,7 @@ def fibonacci_recursive(n): - pass + if n<2: + return n + return fibonacci_recursive(n-1)+ fibonacci_recursive(n-2) for i in range(8): diff --git a/03_06/number_placement_algorithm.py b/03_06/number_placement_algorithm.py index 5eeec43..f3c140f 100644 --- a/03_06/number_placement_algorithm.py +++ b/03_06/number_placement_algorithm.py @@ -1,6 +1,6 @@ import random -PUZZLE_SIZE = 10 +PUZZLE_SIZE = 5 # Create random puzzle # random.sample ensures no duplicates @@ -11,13 +11,13 @@ for i in range(PUZZLE_SIZE - 1): puzzle_symbols.append(">" if random.random() < .5 else "<") -# print(puzzle_nums) -# print(puzzle_symbols) +print(f"Puzzle numbers: {puzzle_nums}") +print(f"Puzzle symbols: {puzzle_symbols}") # Sort puzzle numbers first # Use largest remaining if greater than, smallest remaining if less than sorted_puzzle_nums = sorted(puzzle_nums, reverse=True) - +print(f"desending order: {sorted_puzzle_nums}") # Vars for the "two pointer" method high = 0 low = PUZZLE_SIZE - 1 @@ -28,7 +28,31 @@ # Your code goes here # Iterate through the inequalities and apply solution algorithm to populate solution_values # You may need to add the last value outside the loop -pass +# for symbol in puzzle_symbols: +# if symbol == '>': +# max_num= max(sorted_puzzle_nums) +# print(max_num) +# solution_values.append(max_num) +# sorted_puzzle_nums.remove(max_num) +# if symbol =='<': +# min_num= min(sorted_puzzle_nums) +# print(min_num) +# solution_values.append(min_num) +# sorted_puzzle_nums.remove(min_num) +# # --- ADD THIS LINE HERE (aligned with the 'for' statement) --- +# solution_values.append(sorted_puzzle_nums[0]) +# print(f"sortedpuzzles: {solution_values} ") + + +for symbol in puzzle_symbols: + if symbol == '>': + solution_values.append(sorted_puzzle_nums[high]) + high+=1 + if symbol == '<': + solution_values.append(sorted_puzzle_nums[low]) + low-=1 +solution_values.append(sorted_puzzle_nums[high]) +print(f"sorted puzzle: {solution_values}") # Convert solution_values to list of strings solution_values = list(map(str, solution_values)) diff --git a/03_06/test.py b/03_06/test.py new file mode 100644 index 0000000..4fff9e9 --- /dev/null +++ b/03_06/test.py @@ -0,0 +1,9 @@ +def numberpuzzle(arr): + + left = [x for x in arr if x < pivot] + middle = [x for x in arr if x == pivot] + right = [x for x in arr if x > pivot] + return quicksort(left) + middle + quicksort(right) + +data=[9,7,4,3,2] +print(numberpuzzle(data)) \ No newline at end of file diff --git a/05_05/ransom_note_stub.py b/05_05/ransom_note_stub.py index 41f6478..064356c 100644 --- a/05_05/ransom_note_stub.py +++ b/05_05/ransom_note_stub.py @@ -1,8 +1,30 @@ + # for word in magazine: + # for word2 in note: + # if word== word2: + # print(word) + # return True + # return False + def ransom_note(magazine, note): - pass + # Step 1: Build the hash table + word_counts = {} + for word in magazine: + word_counts[word] = word_counts.get(word, 0) + 1 + print(f"magazine Word : {word_counts[word]}") + + # Step 2: Verify the note words + for word in note: + if word not in word_counts or word_counts[word] == 0: + return False + word_counts[word] -= 1 # Use up one word + print(f"verify words: {word_counts[word]}") + + return True + magazine = "give me one grand today night".split() +#print(magazine) note = "give one grand today".split() assert ransom_note(magazine, note) is True