Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions 02_05/quicksort.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


4 changes: 3 additions & 1 deletion 02_06/fibonacci.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
34 changes: 29 additions & 5 deletions 03_06/number_placement_algorithm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import random

PUZZLE_SIZE = 10
PUZZLE_SIZE = 5

# Create random puzzle
# random.sample ensures no duplicates
Expand All @@ -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
Expand All @@ -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))
Expand Down
9 changes: 9 additions & 0 deletions 03_06/test.py
Original file line number Diff line number Diff line change
@@ -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))
24 changes: 23 additions & 1 deletion 05_05/ransom_note_stub.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down