Skip to content

Commit 19403f6

Browse files
9 v2
1 parent 6af0049 commit 19403f6

File tree

9 files changed

+452
-0
lines changed

9 files changed

+452
-0
lines changed

125_Valid Palindrome/sol2.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Input: s = "A man, a plan, a canal: Panama"
2+
# Output: true
3+
# Explanation: "amanaplanacanalpanama" is a palindrome.
4+
5+
6+
s = "A man, a plan, a canal: Panama"
7+
8+
def pol(string):
9+
ar = ''
10+
11+
for i in string:
12+
if i.isalpha() or i.isnumeric():
13+
ar += i.lower()
14+
15+
print(ar)
16+
17+
po1, po2 = 0, len(ar) - 1
18+
19+
while po1 < po2:
20+
if ar[po1] == ar[po2]:
21+
po1 += 1
22+
po2 -= 1
23+
else:
24+
return False
25+
return True
26+
27+
28+
print(pol(s))

9_Palindrome Number/v2.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#Example 1:
2+
#
3+
# Input: x = 121
4+
# Output: true
5+
# Explanation: 121 reads as 121 from left to right and from right to left.
6+
# Example 2:
7+
8+
x = 121
9+
10+
11+
12+
def polindrome(number) -> bool:
13+
if number < 0:
14+
return False
15+
elif 0 < number < 10:
16+
return False
17+
18+
l_number = [i for i in str(number)]
19+
20+
21+
po1, po2 = 0, len(l_number) - 1
22+
23+
while po1 < po2:
24+
if l_number[po1] == l_number[po2]:
25+
po1 +=1
26+
po2 -=1
27+
else:
28+
return False
29+
return True
30+
31+
32+
print(polindrome(x))

RAG/rag_schema.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import matplotlib.pyplot as plt
2+
import matplotlib.patches as mpatches
3+
4+
# Create figure and axis
5+
fig, ax = plt.subplots(figsize=(10, 8))
6+
7+
# Remove the axis
8+
ax.axis('off')
9+
10+
# Define box properties
11+
box_style = dict(boxstyle="round,pad=0.3", edgecolor="black", facecolor="lightblue")
12+
13+
# Define the positions of the boxes
14+
positions = {
15+
"User Query": (0.5, 0.9),
16+
"Retriever": (0.5, 0.75),
17+
"Retriever Embeds Query": (0.5, 0.6),
18+
"Search Documents/Chunks": (0.5, 0.45),
19+
"Retrieve Top-K Relevant Chunks": (0.5, 0.3),
20+
"Pass Chunks to Generator": (0.5, 0.15),
21+
"Generate Final Response": (0.5, 0.05)
22+
}
23+
24+
# Create the boxes
25+
for text, pos in positions.items():
26+
ax.text(pos[0], pos[1], text, ha="center", va="center", bbox=box_style, fontsize=12)
27+
28+
# Create the arrows
29+
arrow_props = dict(facecolor='black', shrink=0.05)
30+
for i in range(len(positions) - 1):
31+
start_pos = list(positions.values())[i]
32+
end_pos = list(positions.values())[i + 1]
33+
ax.annotate('', xy=end_pos, xytext=start_pos, arrowprops=dict(arrowstyle="->", lw=1.5))
34+
35+
# Display the flowchart
36+
plt.title("Flowchart for RAG Model", fontsize=14)
37+
plt.show()

hacker_rank/lc.py

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# ###1
2+
# if __name__ == '__main__':
3+
# # x = int(input())
4+
# # y = int(input())
5+
# # z = int(input())
6+
# # n = int(input())
7+
#
8+
# ## all cases
9+
# def all_cases(x=1, y=1, z=2) -> []:
10+
# all_cases = []
11+
#
12+
# cases = [[i,j,k] for i in range(0,x+1) for j in range(0, y+1) for k in range(0,z+1)]
13+
# return cases
14+
#
15+
#
16+
# ## cases where it's not equal to n
17+
#
18+
# def equal_cases(cases, n=3):
19+
# equal_cases = [i for i in cases if i[1]+i[2]+i[0]==n]
20+
#
21+
#
22+
# return equal_cases
23+
#
24+
#
25+
# # print(equal_cases(all_cases(x, y, z), 3))
26+
# print(equal_cases(all_cases()))
27+
28+
#2 second lowest
29+
30+
31+
# students = [['Harry', 37.21], ['Berry', 37.21], ['Tina', 37.2], ['Akriti', 41], ['Harsh', 39]]
32+
#
33+
#
34+
# ### need to print second lowest, if there are 2 grades print them alphabetically
35+
#
36+
# highest = students[0][1]
37+
# runner = float('inf')
38+
#
39+
# for i in range(1, len(students)):
40+
# if students[i][1] < highest:
41+
# runner = highest
42+
# highest = students[i][1]
43+
# elif students[i][1] < runner and students[i][1] != highest:
44+
# runner = students[i][1]
45+
#
46+
# print(runner)
47+
#
48+
# selected = [i for i in range(0,len(students)) if students[i][1] == runner]
49+
# ready = []
50+
#
51+
# for i in selected:
52+
# ready.append(students[i])
53+
#
54+
# ready.sort()
55+
#
56+
#
57+
#
58+
#
59+
60+
###3
61+
62+
string = 'Banana'
63+
vowels = ['a', 'e', 'i', 'o', 'u']
64+
consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z']
65+
66+
67+
68+
def count_stuart(string):
69+
words = []
70+
71+
for po1 in range(len(string)):
72+
if string[po1].lower() in consonants:
73+
for po2 in range(po1 + 1, len(string)+ 1):
74+
words.append(string[po1:po2])
75+
76+
score_dict = {word : words.count(word) for word in words}
77+
total_points = 0
78+
79+
for k,v in score_dict.items():
80+
total_points += v
81+
82+
return total_points
83+
84+
def count_kevin(string):
85+
words = []
86+
87+
for po1 in range(len(string)):
88+
if string[po1].lower() in vowels:
89+
for po2 in range(po1 + 1, len(string) + 1):
90+
words.append(string[po1:po2])
91+
92+
score_dict = {word: words.count(word) for word in words}
93+
total_points = 0
94+
95+
for k, v in score_dict.items():
96+
total_points += v
97+
98+
return total_points
99+
100+
def minion_game(string) -> str:
101+
kevin = count_kevin(string)
102+
stuart = count_stuart(string)
103+
result = ''
104+
if kevin > stuart:
105+
result = f'Kevin {kevin}'
106+
elif stuart > kevin:
107+
result = f'Stuart {stuart}'
108+
else:
109+
result = 'Draw'
110+
111+
return result
112+
113+
114+
print(minion_game(string))
115+
116+
117+
118+
119+
120+
121+
122+
123+
124+
125+
126+
127+
128+
129+
130+
131+
132+
133+
134+
135+

internship.py

Whitespace-only changes.

linkedList_practise.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# singly linked list
2+
from turtledemo.penrose import start
3+
4+
5+
class Node:
6+
def __init__(self, data):
7+
self.data = data
8+
self.next = None
9+
10+
class LinkedList:
11+
def __init__(self):
12+
self.head = None
13+
14+
def insertion_at_the_beginning(self, data):
15+
new_node = Node(data)
16+
new_node.next = self.head
17+
self.head = new_node
18+
19+
def insertion_at_the_end(self, data):
20+
new_node = Node(data)
21+
22+
if not self.head:
23+
self.head = new_node
24+
return
25+
26+
last_checked = self.head
27+
28+
while last_checked.next:
29+
last_checked = last_checked.next
30+
31+
last_checked.next = new_node
32+
33+
34+
35+
def printing_list(self):
36+
if not self.head:
37+
print("LList is empty")
38+
return
39+
40+
current_read = self.head
41+
while current_read:
42+
print(current_read.data, end=" -> ")
43+
current_read = current_read.next
44+
print("None")
45+
46+
47+
48+
49+
llist = LinkedList()
50+
51+
llist.printing_list()
52+
llist.insertion_at_the_beginning(1)
53+
llist.insertion_at_the_end(10)
54+
llist.insertion_at_the_beginning(12)
55+
llist.printing_list()
56+
57+
58+

linked_list/linkedlist.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from debugpy.common.timestamp import current
2+
3+
4+
class Node:
5+
def __init__(self, hold_value):
6+
7+
self.data = hold_value ##Data field
8+
self.next = None ##next mode
9+
10+
class LinkedList:
11+
def __init__(self):
12+
self.head = None
13+
14+
def append(self, data):
15+
new_node = Node(data) # calling Node class with passing data
16+
17+
if self.head is None: # if empty, setting up a head llist
18+
self.head = new_node
19+
else: ## when the List Isn't Empty
20+
last = self.head # We need to find the last node in the list (the one where next is None). So we start at the head (the first node).
21+
while last.next: # loop to keep moving to the next node, while not finding None node
22+
last = last.next
23+
last.next = new_node
24+
25+
def print(self):
26+
current = self.head
27+
28+
while current:
29+
print(current.data, end=" -> ")
30+
current = current.next
31+
print("None")
32+
33+
def lenght(self):
34+
current = self.head
35+
counter = 0
36+
37+
while current:
38+
counter += 1
39+
current = current.next
40+
return counter
41+
42+
def searchforvalue(self, value):
43+
current = self.head
44+
45+
while current:
46+
if current.data == value:
47+
return "Found"
48+
else:
49+
current = current.next
50+
return "Not found"
51+
52+
def insertatthebeginning(self, value):
53+
insert_node = Node(value)
54+
55+
if self.head is None:
56+
self.head = insert_node
57+
else:
58+
insert_node.next = self.head
59+
self.head = insert_node
60+
61+
62+
63+
64+
ll = LinkedList()
65+
ll.append(5)
66+
ll.insertatthebeginning(1)
67+
ll.append(10)
68+
ll.print()
69+

0 commit comments

Comments
 (0)