From 5cab41dde46fbed333b23a64e6fe017a78f7f17c Mon Sep 17 00:00:00 2001
From: SHRI171981 <164859992+SHRI171981@users.noreply.github.com>
Date: Wed, 8 Jan 2025 02:30:46 +0530
Subject: [PATCH] Added the files
---
...tion_type_and_modify_check_suffix.py.jinja | 75 +++++++++
q1-int_with_decimal.md | 127 +++++++++++++++
q2-odd_even_difference.md | 126 +++++++++++++++
q3-dot_product.md | 149 ++++++++++++++++++
q4-pairs_less_than_pair.md | 146 +++++++++++++++++
5 files changed, 623 insertions(+)
create mode 100644 function_type_and_modify_check_suffix.py.jinja
create mode 100644 q1-int_with_decimal.md
create mode 100644 q2-odd_even_difference.md
create mode 100644 q3-dot_product.md
create mode 100644 q4-pairs_less_than_pair.md
diff --git a/function_type_and_modify_check_suffix.py.jinja b/function_type_and_modify_check_suffix.py.jinja
new file mode 100644
index 0000000..056fa5e
--- /dev/null
+++ b/function_type_and_modify_check_suffix.py.jinja
@@ -0,0 +1,75 @@
+from copy import deepcopy
+
+{% raw %}
+def order_repr(d):
+ '''Print in lexicographical order of repr if dict and set'''
+ if isinstance(d,dict):
+ d = sorted(d.items(), key=lambda x:order_repr(x[0]) )
+ return f"{{{', '.join(f'{order_repr(k)}: {order_repr(v)}' for k,v in d)}}}"
+ elif isinstance(d,set):
+ return f"{{{', '.join(map(order_repr,sorted(d, key=order_repr)))}}}"
+ else:
+ return repr(d)
+{% endraw %}
+
+def order_print(d):
+ print(order_repr(d))
+
+
+import traceback
+def except_wrap(func):
+ def inner_func(*args,**kwargs):
+ try:
+ func(*args,**kwargs)
+ except AssertionError as e:
+ print(e)
+ except Exception as e:
+ traceback.print_exception(e,limit=-1, file=sys.stdout)
+ return inner_func
+
+
+def assert_equal(actual_out, expected_out, show=True):
+ assert expected_out is None or actual_out is not None,\
+ "No output returned.\nAre you returning the output? It seems like you are not returning anything."
+ assert actual_out == expected_out and type(actual_out) == type(expected_out),\
+ (
+ 'Your output does not match expected output.\n'
+ f'Expected ouput (type: {type(expected_out).__name__}):\n{order_repr(expected_out)}\n'
+ f'Your output (type: {type(actual_out).__name__}):\n{order_repr(actual_out)}'
+ )
+ if show:
+ order_print(actual_out)
+
+is_equal = except_wrap(assert_equal)
+
+@except_wrap
+def modify_check(func, in_obj, expected, should_modify=True):
+ in_obj_old = deepcopy(in_obj)
+ actual_out = func(in_obj)
+ if should_modify:
+ assert in_obj_old == expected or in_obj != in_obj_old,\
+ (
+ f'Input {type(in_obj).__name__} is not modified. You should modify the input {type(in_obj).__name__}.\n'
+ f'Original ({type(in_obj).__name__}):\n{order_repr(in_obj)}\n'
+ f'Expected modification:\n{order_repr(expected)}'
+ )
+ assert in_obj == expected,\
+ (
+ f'Incorrect modifcation of the input {type(in_obj).__name__}.\n'
+ f'Expected modification:\n{order_repr(expected)}\n'
+ f'Your modification:\n{order_repr(in_obj)}'
+ )
+ order_print(in_obj)
+ else:
+ assert_equal(actual_out, expected,show=False)
+ assert in_obj_old == in_obj,\
+ (
+ f'Input {type(in_obj).__name__} is modified. You shouldn\'t modify the input {type(in_obj).__name__}.\n'
+ f'Original input ({type(in_obj).__name__}):\n{order_repr(in_obj_old)}\n'
+ f'Your modification:\n{order_repr(in_obj)}'
+ )
+ order_print(actual_out)
+
+import sys
+exec(sys.stdin.read())
+
diff --git a/q1-int_with_decimal.md b/q1-int_with_decimal.md
new file mode 100644
index 0000000..f70072a
--- /dev/null
+++ b/q1-int_with_decimal.md
@@ -0,0 +1,127 @@
+---
+title: Integer with decimal
+---
+
+# Problem Statement
+
+Given an integer `n`, return the digits of absolute value of `n` separated by `.`
+
+**Example**
+```py3
+integer_sep_decimal(123) # 1.2.3
+integer_sep_decimal(-105) # 1.0.5
+integer_sep_decimal(1) # 1
+```
+
+# Solution
+
+```py3 test.py -r 'python test.py'
+
+# some prefix
+
+
+def integer_sep_decimal(n: int) -> str:
+ '''
+ Given an integer, return the digits separated by '.'
+
+ Arguments:
+ n: int - an integer
+
+ Return: str - string separated by '.'
+ '''
+ ...
+ return '.'.join(str(abs(n)))
+ test = ...'test' #tests
+
+
+# some suffix
+
+
+{% include '../function_type_and_modify_check_suffix.py.jinja' %}
+
+```
+
+# Public Test Cases
+
+## Input 1
+
+```
+is_equal(
+ integer_sep_decimal(123),
+ '1.2.3'
+)
+```
+
+## Output 1
+
+```
+'1.2.3'
+```
+
+## Input 2
+
+```
+is_equal(
+ integer_sep_decimal(-105),
+ '1.0.5'
+)
+```
+
+## Output 2
+
+```
+'1.0.5'
+```
+
+## Input 3
+
+```
+is_equal(
+ integer_sep_decimal(1),
+ '1'
+)
+```
+
+## Output 3
+
+```
+'1'
+```
+
+# Private Test Cases
+
+## Input 1
+
+```
+n = 0
+is_equal(
+ integer_sep_decimal(n),
+ '0'
+)
+
+n = -1
+is_equal(
+ integer_sep_decimal(n),
+ '1'
+)
+
+n = 100
+is_equal(
+ integer_sep_decimal(n),
+ '1.0.0'
+)
+n = 1729
+is_equal(
+ integer_sep_decimal(n),
+ '1.7.2.9'
+)
+```
+
+## Output 1
+
+```
+'0'
+'1'
+'1.0.0'
+'1.7.2.9'
+```
\ No newline at end of file
diff --git a/q2-odd_even_difference.md b/q2-odd_even_difference.md
new file mode 100644
index 0000000..1bb66f9
--- /dev/null
+++ b/q2-odd_even_difference.md
@@ -0,0 +1,126 @@
+---
+title: odd even difference
+---
+
+# Problem Statement
+
+Given a list of two or more integers `L`, return the absolute difference of average of elements at odd indices and even indices
+**Example**
+```py3
+odd_even_difference([1,2,3,4]) # 2
+odd_even_difference([-1,0,5]) # 4
+odd_even_difference([0,0,0,0]) # 0
+```
+
+# Solution
+
+```py3 test.py -r 'python test.py'
+
+# some prefix
+
+
+def odd_even_difference(L: list) -> int:
+ '''
+ Given an list of two or more integers, return the absolute difference of average of elements at odd indices and even indices
+
+ Arguments:
+ L: list - a list of integers
+
+ Return: int - difference of elements
+ '''
+ ...
+ return abs((sum(L[::2])/len(L[::2])) - (sum(L[1::2])/len(L[1::2])))
+ test = ...'test' #tests
+
+
+# some suffix
+
+
+{% include '../function_type_and_modify_check_suffix.py.jinja' %}
+
+```
+
+# Public Test Cases
+
+## Input 1
+
+```
+is_equal(
+ odd_even_difference([1,2,3,4]),
+ 1
+)
+```
+
+## Output 1
+
+```
+1
+```
+
+## Input 2
+
+```
+is_equal(
+ odd_even_difference([-1,0,5]),
+ 2
+)
+```
+
+## Output 2
+
+```
+2
+```
+
+## Input 3
+
+```
+is_equal(
+ odd_even_difference([0,0,0,0]),
+ 0
+)
+```
+
+## Output 3
+
+```
+0
+```
+
+# Private Test Cases
+
+## Input 1
+
+```
+L = [1,7,2,9]
+is_equal(
+ odd_even_difference(L),
+ 6.5
+)
+
+L = [-1,0,1,0]
+is_equal(
+ odd_even_difference(L),
+ 0
+)
+
+L = [-1,1]
+is_equal(
+ odd_even_difference(L),
+ 2
+)
+
+L = [1,1]
+is_equal(
+ odd_even_difference(L),
+ 0
+)
+```
+
+## Output 1
+
+```
+6.5
+0
+2
+0
\ No newline at end of file
diff --git a/q3-dot_product.md b/q3-dot_product.md
new file mode 100644
index 0000000..37ffdde
--- /dev/null
+++ b/q3-dot_product.md
@@ -0,0 +1,149 @@
+---
+title: dot_product
+---
+
+# Problem Statement
+
+Given two lists of integers `L1` and `L2`, return the dot product of the lists.
+
+The first line of the input is list1 of integers separated by spaces
+The second line of the input is list2 of integers separated by spaces
+
+**Example**
+```py3
+dot_product([1,2,3,4],[5,6,7,8]) # 70
+dot_product([1,2],[0,0]) # 0
+dot_product([1,-1,0],[0,1,1],4) # -1
+```
+
+# Solution
+
+```py3 test.py -r 'python test.py'
+
+# some prefix
+
+
+def dot_product(L1: list,L2: list) -> int:
+ '''
+ Given two lists of integers `L1` and `L2`, return the dot product of the lists.
+
+ Arguments:
+ L1: list - a list of integers
+ L2: list - a list of integers
+
+ Return: int - dot product of the lists
+ '''
+ ...
+
+ dot = 0
+ for i in range(len(L1)):
+ dot += L1[i]*L2[i]
+ return dot
+
+ test = ...'test' #tests
+
+
+# Driver code
+l1 = list(map(int, input().split()))
+l2 = list(map(int, input().split()))
+print(dot_product(l1,l2))
+
+
+{% include '../function_type_and_modify_check_suffix.py.jinja' %}
+
+```
+
+# Public Test Cases
+
+## Input 1
+
+```
+1 2 3 4
+5 6 7 8
+```
+
+## Output 1
+
+```
+70
+```
+
+## Input 2
+
+```
+1 2
+0 0
+```
+
+## Output 2
+
+```
+0
+```
+
+## Input 3
+
+```
+1 -1 0
+0 1 1
+```
+
+## Output 3
+
+```
+-1
+```
+
+# Private Test Cases
+
+## Input 1
+
+```
+0 0
+0 0
+```
+
+## Output 1
+
+```
+0
+```
+
+## Input 2
+
+```
+1 7
+2 9
+```
+
+## Output 2
+
+```
+65
+```
+
+## Input 3
+
+```
+1 0
+0 1
+```
+
+## Output 3
+
+```
+0
+```
+
+## Input 4
+
+```
+100 50
+20 10
+```
+
+## Output 4
+
+```
+2500
+```
\ No newline at end of file
diff --git a/q4-pairs_less_than_pair.md b/q4-pairs_less_than_pair.md
new file mode 100644
index 0000000..bcd8fd4
--- /dev/null
+++ b/q4-pairs_less_than_pair.md
@@ -0,0 +1,146 @@
+---
+title: pairs less than pair
+---
+
+# Problem Statement
+You are given a list of 2D points, represented as pairs (x, y) in a string with random spacing, and a reference point (xr, yr). A point (xi, yi) is considered strictly less than (xr, yr) if both xi < xr and yi < yr.
+
+Write a program to count how many points in the list are strictly less than the reference point and return these points as a list.
+
+**Example**
+```py3
+pairs_less_than("[(4,5 ) , (-1, -2) ,(1,1)] ",(1,2)) # 1 -> (-1,-2)
+pairs_less_than("[ ( 4 ,5 ) , ( -1,-2) , ( 1,1 ) , ( 2,3), ( 6 , 7 )]", (2,3)) # 2 -> (-1,-2),(1,1)
+pairs_less_than("[ (3,4),( 5 ,6) , (0, 0 ), ( -2 , -1) ,( 7 ,8 ) ] ", (4,-4)) # 0
+```
+
+# Solution
+
+```py3 test.py -r 'python test.py'
+
+# some prefix
+
+
+def pairs_less_than(s: string,p: tuple) -> int:
+ '''
+ You are given a list of 2D points, represented as pairs (x, y) in a string with random spacing, and a reference point (xr, yr). A point (xi, yi) is considered strictly less than (xr, yr) if both xi < xr and yi < yr.
+
+ Write a program to count how many points in the list are strictly less than the reference point and return these points as a list.
+
+ Arguments:
+ s: list - a string having a list of integer tuples
+ p: tuple - reference point
+
+ Return: int - count of pairs less than p
+ '''
+ ...
+
+ s = s.replace(' ','')
+ s = s.replace('[','')
+ s = s.replace(']','')
+ s = s.replace('(','')
+ s = s.replace(')','')
+ s = s.replace(',',' ')
+ L = list(map(int,s.split()))
+ M = []
+ for i in range(0,len(L),2):
+ M.append(tuple(L[i:i+2]))
+ count = 0
+ for i in M:
+ if i[0] < p[0] and i[1] < p[1]:
+ count+=1
+ return count
+
+ test = ...'test' #tests
+
+
+# some suffix
+
+
+{% include '../function_type_and_modify_check_suffix.py.jinja' %}
+
+```
+
+# Public Test Cases
+
+## Input 1
+
+```
+is_equal(
+ pairs_less_than("[(4,5 ) , (-1, -2) ,(1,1)] ",(1,2)),
+ 1
+)
+```
+
+## Output 1
+
+```
+1
+```
+
+## Input 2
+
+```
+is_equal(
+ pairs_less_than("[ ( 4 ,5 ) , ( -1,-2) , ( 1,1 ) , ( 2,3), ( 6 , 7 )]", (2,3)),
+ 2
+)
+```
+
+## Output 2
+
+```
+2
+```
+
+## Input 3
+
+```
+is_equal(
+ pairs_less_than("[ (3,4),( 5 ,6) , (0, 0 ), ( -2 , -1) ,( 7 ,8 ) ] ", (4,-4)),
+ 0
+)
+```
+
+## Output 3
+
+```
+0
+```
+
+# Private Test Cases
+
+## Input 1
+
+```
+L = "[ ( 2,2 ),( 1,1 ),( 3,4 ) ,(0 ,0 ) , ( 5 ,5)] "
+p = (2,3)
+is_equal(
+ pairs_less_than(L,p),
+ 3
+)
+
+L = "[ (8, 9), ( 2,3 ),( 6 , 5),( -1,-1) , (10 ,12 ) ]"
+p = (11,13)
+
+is_equal(
+ pairs_less_than(L,p),
+ 5
+)
+
+L = "[(1,1)]"
+p = (2,3)
+
+is_equal(
+ pairs_less_than(L,p),
+ 1
+)
+
+```
+
+## Output 1
+
+```
+3
+5
+1
\ No newline at end of file