summaryrefslogtreecommitdiff
path: root/progs/bunch_of_tests
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2024-05-28 10:29:13 +0200
committerSanto Cariotti <santo@dcariotti.me>2024-05-28 10:29:13 +0200
commitf05d888a0b621ca4e99e2b0fb6e23c097006fe41 (patch)
treeeebbb2489144112d3288393e354d19375a0aa088 /progs/bunch_of_tests
Init
Diffstat (limited to 'progs/bunch_of_tests')
-rw-r--r--progs/bunch_of_tests101
1 files changed, 101 insertions, 0 deletions
diff --git a/progs/bunch_of_tests b/progs/bunch_of_tests
new file mode 100644
index 0000000..b001761
--- /dev/null
+++ b/progs/bunch_of_tests
@@ -0,0 +1,101 @@
+def coin_change(S, m, n):
+ table = [[0 for x in range(m)] for x in range(n+1)]
+ for i in range(m):
+ table[0][i] = 1
+ for i in range(1, n+1):
+ for j in range(m):
+ x = table[i - S[j]][j] if i-S[j] >= 0 else 0
+ y = table[i][j-1] if j >= 1 else 0
+ table[i][j] = x + y
+ return table[n][m-1]
+
+================
+import re
+def text_match_wordz_middle(text):
+ patterns = '\Bz\B'
+ if re.search(patterns, text):
+ return 'Found a match!'
+ else:
+ return('Not matched!')
+text_match_wordz_middle('ciao')
+
+==============
+
+def max_occurrences(list1):
+ max_val = 0
+ result = list1[0]
+ for i in list1:
+ occu = list1.count(i)
+ if occu > max_val:
+ max_val = occu
+ result = i
+ return result
+
+================
+
+def sort_matrix(M):
+ result = sorted(M, key=sum)
+ return result
+
+=================
+
+def get_ludic(n):
+ ludics = []
+ for i in range(1, n + 1):
+ ludics.append(i)
+ return ludics
+print(get_ludic(a*a))
+
+=================
+
+def adjac(ele, sub = []):
+ if not ele:
+ yield sub
+ else:
+ yield from [ idx for j in range(ele[0] - 1, ele[0] + 2)
+ for idx in adjac(ele[1:], sub + [j])
+ ]
+
+def get_coordinates(test_tup):
+ res = list(adjac(test_tup))
+ return (res)
+
+===================
+
+import heapq
+def heap_sort(iterable):
+ h = []
+ for value in iterable:
+ heapq.heappush(h, value)
+ return [hq.heappop(h) for i in range(len(h))]
+
+
+======================
+
+def get_ludic(n):
+ ludics = []
+ for i in range(1, n + 1):
+ ludics.append(i)
+ index = 1
+ while(index != len(ludics)):
+ first_ludic = ludics[index]
+ remove_index = index + first_ludic
+ while(remove_index < len(ludics)):
+ ludics.remove(ludics[remove_index])
+ remove_index = remove_index + first_ludic - 1
+ index += 1
+ return ludics
+print(get_ludic(a*a))
+
+============================
+
+from collections import defaultdict
+def get_unique(test_list):
+ res = defaultdict(list)
+ for sub in test_list:
+ res[sub[1]].append(sub[0])
+ res = dict(res)
+ res_dict = dict()
+ for key in res:
+ res_dict[key] = len(list(set(res[key])))
+ return (str(res_dict)) \ No newline at end of file