Skip to content
Closed

mypy #18223

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
10 changes: 10 additions & 0 deletions Dog Pattern
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def dog_pattern():

print(" / \__")
print(" ( @\__")
print("/ o")
print("/ (_____")
print("\ u )")
print(" `----------")

dog_pattern()
44 changes: 44 additions & 0 deletions Merge sort
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os

def merge_sort_files(file_input, file_output):
# Read input file
with open(file_input, 'r') as f:
arr = list(map(int, f.read().split()))

# Sort the array
arr = merge_sort(arr)

# Write sorted data to the output file
with open(file_output, 'w') as f:
f.write(" ".join(map(str, arr)))

def merge_sort(arr):
if len(arr) <= 1:
return arr

mid = len(arr) // 2
left_half = merge_sort(arr[:mid])
right_half = merge_sort(arr[mid:])

return merge(left_half, right_half)

def merge(left, right):
result = []
i = j = 0
while i < len(left) and j < len(right):
if left[i] <= right[j]:
result.append(left[i])
i += 1
else:
result.append(right[j])
j += 1

result.extend(left[i:])
result.extend(right[j:])
return result

# Example usage
input_file = "unsorted.txt"
output_file = "sorted.txt"
merge_sort_files(input_file, output_file)
print(f"Sorted data written to {output_file}")
27 changes: 27 additions & 0 deletions Stack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
def largest_rectangle_area(heights):
stack = []
max_area = 0
index = 0

while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
index += 1

else:
top_of_stack = stack.pop()
area = heights[top_of_stack] * ((index - stack[-1] - 1) if stack else index)

max_area = max(max_area, area)

while stack:
top_of_stack = stack.pop()
area = heights[top_of_stack] * ((index - stack[-1] - 1) if stack else index)
max_area = max(max_area, area)

return max_area


histogram = [2, 1, 5, 6, 2, 3]

print(largest_rectangle_area(histogram))