From 37689b78ec73436b333d22b5dccf07b0b3b0fb17 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 1 Dec 2023 21:39:56 +0530 Subject: [PATCH 01/42] Create C_HariVignesh18_Cricmeter.c --- December 01/C_HariVignesh18_Cricmeter.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 December 01/C_HariVignesh18_Cricmeter.c diff --git a/December 01/C_HariVignesh18_Cricmeter.c b/December 01/C_HariVignesh18_Cricmeter.c new file mode 100644 index 0000000..f841b37 --- /dev/null +++ b/December 01/C_HariVignesh18_Cricmeter.c @@ -0,0 +1,20 @@ +#include +int main(){ + int n,s,a[100]; + int max; + int i; + scanf("%d",&n); + for(i = 0;i < n;i++){ + scanf("%d",&a[i]); + s = s + a[i]; + } + max = a[0]; + int ind = 0; + for(i = 1;imax){ + max = a[i]; + ind = i; + } + } + printf("%d\n%d",s,ind); +} From 2bd410d4df3f2f878a99f005e43a5f472277c6d9 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Sat, 2 Dec 2023 13:34:37 +0530 Subject: [PATCH 02/42] Python_HariVignesh18_Shopper's Choice.py --- .../Python_HariVignesh18_Shopper's Choice.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 December 02 /Python_HariVignesh18_Shopper's Choice.py diff --git a/December 02 /Python_HariVignesh18_Shopper's Choice.py b/December 02 /Python_HariVignesh18_Shopper's Choice.py new file mode 100644 index 0000000..a55fb96 --- /dev/null +++ b/December 02 /Python_HariVignesh18_Shopper's Choice.py @@ -0,0 +1,13 @@ +a = list(map(int,input().split())) +b = [] +for i in a: + if i not in b: + b.append(i) +c = [] +for i in b: + count = 0 + for j in a: + if i == j: + count += 1 + c.append(count) +print(c) From 0d59bfbab23aaf97ea6d80130c222be2663542a2 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Sat, 2 Dec 2023 13:35:40 +0530 Subject: [PATCH 03/42] C_HariVignesh18_Cricmetrics.c --- ...{C_HariVignesh18_Cricmeter.c => C_HariVignesh18_Cricmetrics.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename December 01/{C_HariVignesh18_Cricmeter.c => C_HariVignesh18_Cricmetrics.c} (100%) diff --git a/December 01/C_HariVignesh18_Cricmeter.c b/December 01/C_HariVignesh18_Cricmetrics.c similarity index 100% rename from December 01/C_HariVignesh18_Cricmeter.c rename to December 01/C_HariVignesh18_Cricmetrics.c From 02d1da143b1e9ba77f8b1f32c8c09b2cbfa27d8d Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Sat, 2 Dec 2023 20:57:06 +0530 Subject: [PATCH 04/42] python3_HariVignesh18_Shopper's Choice.py --- ...pper's Choice.py => python3_HariVignesh18_Shopper's Choice.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename December 02 /{Python_HariVignesh18_Shopper's Choice.py => python3_HariVignesh18_Shopper's Choice.py} (100%) diff --git a/December 02 /Python_HariVignesh18_Shopper's Choice.py b/December 02 /python3_HariVignesh18_Shopper's Choice.py similarity index 100% rename from December 02 /Python_HariVignesh18_Shopper's Choice.py rename to December 02 /python3_HariVignesh18_Shopper's Choice.py From 22b5ae459a7ba49eab8edf51cab43d94b0b389b6 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Sun, 3 Dec 2023 11:14:10 +0530 Subject: [PATCH 05/42] Create C_HariVignesh18_Sunburnt.c --- December 03/C_HariVignesh18_Sunburnt.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 December 03/C_HariVignesh18_Sunburnt.c diff --git a/December 03/C_HariVignesh18_Sunburnt.c b/December 03/C_HariVignesh18_Sunburnt.c new file mode 100644 index 0000000..7c203ca --- /dev/null +++ b/December 03/C_HariVignesh18_Sunburnt.c @@ -0,0 +1,16 @@ +#include +int main() +{ + int n,a[100]; + scanf("%d",&n); + for(int i = 0;i < n; i++){ + scanf("%d",&a[i]); + } + int b = 1; + for(int i = 1;i < n; i++){ + if(a[i]>a[i-1]){ + b += 1; + } + } + printf("%d",b); +} From b1880ecf35f8ce44e05d02fd7d292aa52b9f654b Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Sun, 3 Dec 2023 11:20:38 +0530 Subject: [PATCH 06/42] C_HariVignesh18_Sunburnt.c --- December 03/C_HariVignesh18_Sunburnt.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/December 03/C_HariVignesh18_Sunburnt.c b/December 03/C_HariVignesh18_Sunburnt.c index 7c203ca..4471bd9 100644 --- a/December 03/C_HariVignesh18_Sunburnt.c +++ b/December 03/C_HariVignesh18_Sunburnt.c @@ -6,10 +6,17 @@ int main() for(int i = 0;i < n; i++){ scanf("%d",&a[i]); } - int b = 1; - for(int i = 1;i < n; i++){ - if(a[i]>a[i-1]){ - b += 1; + int b = 0; + for(int i = 0;i < n; i++){ + int s = 0; + for(int j = 0;j < i;j++){ + if(a[j]>=a[i]){ + s = 1; + break; + } + } + if(s == 0){ + b+=1; } } printf("%d",b); From 936454e6ee54e554751c156d86c377807822e903 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Mon, 4 Dec 2023 18:17:48 +0530 Subject: [PATCH 07/42] Create python3_HariVignesh18_Mirror Magic.py --- December 04/python3_HariVignesh18_Mirror Magic.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 December 04/python3_HariVignesh18_Mirror Magic.py diff --git a/December 04/python3_HariVignesh18_Mirror Magic.py b/December 04/python3_HariVignesh18_Mirror Magic.py new file mode 100644 index 0000000..d3a1aae --- /dev/null +++ b/December 04/python3_HariVignesh18_Mirror Magic.py @@ -0,0 +1,12 @@ +a = input() +b = "" +for i in range(0,len(a)-1): + for j in range(i+2,len(a)+1): + sub = a[i:j] + if sub == sub[::-1]: + if len(b)!= "" or len(b) > len(sub): + b = sub +if b!="": + print(b) +else: + print("Error") From dd774f5a3e915d20931415e1840fa4adc4da46a1 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Tue, 5 Dec 2023 17:44:55 +0530 Subject: [PATCH 08/42] Create python3_HariVignesh18_PeakyBlinders.py --- December 05/python3_HariVignesh18_PeakyBlinders.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 December 05/python3_HariVignesh18_PeakyBlinders.py diff --git a/December 05/python3_HariVignesh18_PeakyBlinders.py b/December 05/python3_HariVignesh18_PeakyBlinders.py new file mode 100644 index 0000000..cb3055d --- /dev/null +++ b/December 05/python3_HariVignesh18_PeakyBlinders.py @@ -0,0 +1,12 @@ +a = [int(i) for i in input().split()] +c = 0 +s = 0 +for i in a: + s += i + c += 1 +b = s/c +s = 0 +for i in a: + if i >= b: + s += i +print(s) From 3e1b72ea774abffc5ea1083eae400262640633d0 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Wed, 6 Dec 2023 10:28:44 +0530 Subject: [PATCH 09/42] Create python3_HariVignesh18_TheLostAlgorithmScrolls.py --- ...n3_HariVignesh18_TheLostAlgorithmScrolls.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 December 06/python3_HariVignesh18_TheLostAlgorithmScrolls.py diff --git a/December 06/python3_HariVignesh18_TheLostAlgorithmScrolls.py b/December 06/python3_HariVignesh18_TheLostAlgorithmScrolls.py new file mode 100644 index 0000000..641aab4 --- /dev/null +++ b/December 06/python3_HariVignesh18_TheLostAlgorithmScrolls.py @@ -0,0 +1,18 @@ +s = input().split() +ans = [] +for i in range(0,len(s)-1): + if len(s[i]) == len(s[i+1]): + f = 0 + a = s[i] + b = s[i+1] + for i in range(0,len(s[i])): + if a[i] != b[i]: + f += 1 + if f == 1: + if a not in ans: + ans.append(a) + ans.append(b) +if ans != []: + print(ans) +else: + print("No Valid Chain.") From 49af224dd04298f7c8876e88e1fee8a10a03595a Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Thu, 7 Dec 2023 10:49:54 +0530 Subject: [PATCH 10/42] Create python3_HariVignesh18_BabyBlocks.py --- December 07/python3_HariVignesh18_BabyBlocks.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 December 07/python3_HariVignesh18_BabyBlocks.py diff --git a/December 07/python3_HariVignesh18_BabyBlocks.py b/December 07/python3_HariVignesh18_BabyBlocks.py new file mode 100644 index 0000000..e124d9f --- /dev/null +++ b/December 07/python3_HariVignesh18_BabyBlocks.py @@ -0,0 +1,13 @@ +def rectangleInCircle(width ,height ,radius): + diagSquare = (width**2 + height**2) + diagonal = diagSquare**0.5 + if diagonal > radius*2: + return False + else: + return True +a = [int(i) for i in input().split()] +ans = rectangleInCircle(a[0] , a[1], a[2]) +if ans == True: + print("True") +else: + print("False") From 0d28224300695ab94c39b82a7d0f9ab894d2473c Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:40:10 +0530 Subject: [PATCH 11/42] Create python3_HariVignesh18_TheEnchantedForest.py --- ...ython3_HariVignesh18_TheEnchantedForest.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 December 08/python3_HariVignesh18_TheEnchantedForest.py diff --git a/December 08/python3_HariVignesh18_TheEnchantedForest.py b/December 08/python3_HariVignesh18_TheEnchantedForest.py new file mode 100644 index 0000000..6064d93 --- /dev/null +++ b/December 08/python3_HariVignesh18_TheEnchantedForest.py @@ -0,0 +1,23 @@ +def find_path(n): + ans = [[0]*n for _ in range(n)] + c = 0 + i = 0 + j = n//2 + for k in range(1,(n*n)+1): + ans [i][j] = k + i -= 1 + j += 1 + c += 1 + if c == n: + i += 2 + j -= 1 + c = 0 + else: + if j == n: + j -= n + elif i < 0: + i += n + for row in ans: + print(*row) +n = int(input()) +find_path(n) From 3af8c81d27460e1c02125ee93b95c568100a3560 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Sat, 9 Dec 2023 10:39:38 +0530 Subject: [PATCH 12/42] Create python3_HariVignesh18_Camels_In_A_String.py --- December 09/python3_HariVignesh18_Camels_In_A_String.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 December 09/python3_HariVignesh18_Camels_In_A_String.py diff --git a/December 09/python3_HariVignesh18_Camels_In_A_String.py b/December 09/python3_HariVignesh18_Camels_In_A_String.py new file mode 100644 index 0000000..7113711 --- /dev/null +++ b/December 09/python3_HariVignesh18_Camels_In_A_String.py @@ -0,0 +1,6 @@ +s = input() +c = 1 +for i in s: + if ord(i)>64 and ord(i)<91: + c += 1 +print(c) From b8541a6f45c3b98f2b9163143d01a1512fb5fcb7 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Mon, 11 Dec 2023 12:15:45 +0530 Subject: [PATCH 13/42] Create python3_HariVignesh18_coderOfConversions.py --- .../python3_HariVignesh18_coderOfConversions.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 December 11/python3_HariVignesh18_coderOfConversions.py diff --git a/December 11/python3_HariVignesh18_coderOfConversions.py b/December 11/python3_HariVignesh18_coderOfConversions.py new file mode 100644 index 0000000..e5dc65a --- /dev/null +++ b/December 11/python3_HariVignesh18_coderOfConversions.py @@ -0,0 +1,12 @@ +def decToBinary(n): + s = n[0] + n[1] + binaryNum = [0] * s; + i = 0; + while (s > 0): + binaryNum[i] = s % 2; + s = int(s / 2); + i += 1; + for j in range(i - 1, -1, -1): + print(binaryNum[j], end = ""); +n = [int(i) for i in input().split()] +decToBinary(n); From 0bf12da3094d56df030f66514624eebc33a1d572 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Tue, 12 Dec 2023 13:06:16 +0530 Subject: [PATCH 14/42] Create python3_HariVignesh18_forgotPassword.py --- .../python3_HariVignesh18_forgotPassword.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 December 10/python3_HariVignesh18_forgotPassword.py diff --git a/December 10/python3_HariVignesh18_forgotPassword.py b/December 10/python3_HariVignesh18_forgotPassword.py new file mode 100644 index 0000000..dc0daa9 --- /dev/null +++ b/December 10/python3_HariVignesh18_forgotPassword.py @@ -0,0 +1,19 @@ +a = ['Shivansh Kumar','Ragul Gupta'] +query = input().split() +b = ['1','2','3','4','5','6','7','8','9','0'] +c = [0]*2 +j = 0 +cl = 0 +for i in query[1]: + if i in b: + if cl == 0: + c[j] += int(i) + else: + c[j] = c[j]*10 + int(i) + cl += 1 + if i not in b: + if cl > 0: + j += 1 + cl = 0 +for i in a: + print(i[c[0]-1:c[0]+c[1]-1]) From ce259b13ebd324bdca56f516cb9fe844de64bee3 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Tue, 12 Dec 2023 13:30:39 +0530 Subject: [PATCH 15/42] Create python3_HariVignesh18_theHeist.py --- December 12/python3_HariVignesh18_theHeist.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 December 12/python3_HariVignesh18_theHeist.py diff --git a/December 12/python3_HariVignesh18_theHeist.py b/December 12/python3_HariVignesh18_theHeist.py new file mode 100644 index 0000000..1e6198b --- /dev/null +++ b/December 12/python3_HariVignesh18_theHeist.py @@ -0,0 +1,26 @@ +def find(box): + target = 'Gold' + l = 0 + r = len(box)-1 + while l<=r: + mid = (l+r)//2 + if box[mid] == target: + return True + elif box[mid] < target: + l = mid+1 + else: + r = mid-1 + return False + +box1 = input().split() +box2 = input().split() +box3 = input().split() +box1.sort() +box2.sort() +box3.sort() +if find(box1): + print("Box1 contains the Gold") +elif find(box2): + print("Box2 contains the Gold") +else: + print("Box3 contains the Gold") From 51d4d519d39d38043c8a77f06a82e1104ad4fc77 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Wed, 13 Dec 2023 22:41:04 +0530 Subject: [PATCH 16/42] Create python3_HariVignesh18_CallCipher.py --- December 13/python3_HariVignesh18_CallCipher.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 December 13/python3_HariVignesh18_CallCipher.py diff --git a/December 13/python3_HariVignesh18_CallCipher.py b/December 13/python3_HariVignesh18_CallCipher.py new file mode 100644 index 0000000..2cba944 --- /dev/null +++ b/December 13/python3_HariVignesh18_CallCipher.py @@ -0,0 +1,11 @@ +def textToNum(s): + my_dict = {"A": 2, "B": 2, "C": 2,"D": 3, "E": 3, "F": 3,"G": 4, "H": 4, "I": 4,"J": 5, "K": 5, "L": 5,"M": 6, "N": 6, "O": 6,"P": 7, "Q": 7, "R": 7, "S": 7,"T": 8, "U": 8, "V": 8,"W": 9, "X": 9, "Y": 9, "Z": 9} + ans = "" + for i in s: + if i in my_dict: + ans += str(my_dict[i]) + else: + ans += i + return ans +s = input() +print(textToNum(s)) From 78bda77e05b15b1ac8ea4b7bd5c84389b3589a26 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 15 Dec 2023 18:33:43 +0530 Subject: [PATCH 17/42] Create python3_HariVignesh18_SubsequenceSorcery.py --- December 15/python3_HariVignesh18_SubsequenceSorcery.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 December 15/python3_HariVignesh18_SubsequenceSorcery.py diff --git a/December 15/python3_HariVignesh18_SubsequenceSorcery.py b/December 15/python3_HariVignesh18_SubsequenceSorcery.py new file mode 100644 index 0000000..d032ec8 --- /dev/null +++ b/December 15/python3_HariVignesh18_SubsequenceSorcery.py @@ -0,0 +1,9 @@ +from itertools import combinations +a = input() +ans = [] +for i in range(1,len(a)+1): + b = combinations(a,i) + for i in b: + if i not in ans: + ans.append(i) +print(len(ans)+1) From 51929c24b421787c57600199b648425153292707 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 15 Dec 2023 18:34:35 +0530 Subject: [PATCH 18/42] Delete December 02 directory --- December 02/.gitignore | 231 ----------------------------------------- 1 file changed, 231 deletions(-) delete mode 100644 December 02/.gitignore diff --git a/December 02/.gitignore b/December 02/.gitignore deleted file mode 100644 index 8e0ca25..0000000 --- a/December 02/.gitignore +++ /dev/null @@ -1,231 +0,0 @@ -# gitignore file for "A December of Algorithms 2023" -# visit https://github.com/SVCE-ACM/A-December-of-Algorithms -# Written individually to adjust for the needs of the problem - -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# node.js -/node_modules -package-lock.json - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -Pipfile.lock -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -# Files and directories created by pub -.dart_tool/ -.packages -build/ -# If you're building an application, you may want to check-in your pubspec.lock -pubspec.lock - -# Directory created by dartdoc -# If you don't generate documentation locally you can remove this line. -doc/api/ - -# Avoid committing generated Javascript files: -*.dart.js -*.info.json # Produced by the --dump-info flag. -*.js # When generated by dart2js. Don't specify *.js if your - # project includes source files written in JavaScript. -*.js_ -*.js.deps -*.js.map - -# Prerequisites -*.d - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app - -# Executables -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex - -# Debug files -*.dSYM/ -*.su -*.idb -*.pdb - -# Kernel Module Compile Results -*.mod* -*.cmd -.tmp_versions/ -modules.order -Module.symvers -Mkfile.old -dkms.conf From ab08782a51c9c7d7dd822571e0f57f7762643d83 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Mon, 18 Dec 2023 18:26:00 +0530 Subject: [PATCH 19/42] Create c++_HariVignesh18_CallOfJustice.cpp --- .../c++_HariVignesh18_CallOfJustice.cpp | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 December 14/c++_HariVignesh18_CallOfJustice.cpp diff --git a/December 14/c++_HariVignesh18_CallOfJustice.cpp b/December 14/c++_HariVignesh18_CallOfJustice.cpp new file mode 100644 index 0000000..333e611 --- /dev/null +++ b/December 14/c++_HariVignesh18_CallOfJustice.cpp @@ -0,0 +1,82 @@ +#include +#include + +using namespace std; + +class TreeNode { +public: + int value; + TreeNode* left; + TreeNode* right; + + TreeNode(int val) : value(val), left(nullptr), right(nullptr) {} +}; + +void findKDistanceNodes(TreeNode* root, int target, int k, vector& result) { + if (!root) + return; + + if (k == 0) { + result.push_back(root->value); + return; + } + + // Recur on the left subtree + findKDistanceNodes(root->left, target, k - 1, result); + + // Recur on the right subtree + findKDistanceNodes(root->right, target, k - 1, result); +} + +int findTarget(TreeNode* root, int target, int k, vector& result) { + if (!root) + return -1; + + if (root->value == target) { + findKDistanceNodes(root, target, k, result); + return 0; + } + + int leftDistance = findTarget(root->left, target, k, result); + if (leftDistance >= 0) { + if (leftDistance + 1 == k) + result.push_back(root->value); + + findKDistanceNodes(root->right, target, k - leftDistance - 2, result); + return leftDistance + 1; + } + + int rightDistance = findTarget(root->right, target, k, result); + if (rightDistance >= 0) { + if (rightDistance + 1 == k) + result.push_back(root->value); + + findKDistanceNodes(root->left, target, k - rightDistance - 2, result); + return rightDistance + 1; + } + + return -1; +} + +int main() { + TreeNode* root = new TreeNode(14); + root->left = new TreeNode(7); + root->right = new TreeNode(20); + root->right->right = new TreeNode(30); + root->left->left = new TreeNode(4); + root->left->right = new TreeNode(3); + root->left->right->left = new TreeNode(2); + root->left->right->left->left = new TreeNode(1); + root->left->right->left->right = new TreeNode(4); + + int targetNode = 7; + int kDistance = 3; + + vector output; + findTarget(root, targetNode, kDistance, output); + sort(output.begin(),output.end()); + for (int node : output) { + cout << " " << node; + } + return 0; +} From c90c79dfca5c90b73e327efad00a72e642796a80 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Mon, 18 Dec 2023 18:38:47 +0530 Subject: [PATCH 20/42] Create c++_HariVignesh18_BookshelfDilemma.cpp --- .../c++_HariVignesh18_BookshelfDilemma.cpp | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 December 17/c++_HariVignesh18_BookshelfDilemma.cpp diff --git a/December 17/c++_HariVignesh18_BookshelfDilemma.cpp b/December 17/c++_HariVignesh18_BookshelfDilemma.cpp new file mode 100644 index 0000000..43a7a79 --- /dev/null +++ b/December 17/c++_HariVignesh18_BookshelfDilemma.cpp @@ -0,0 +1,88 @@ +#include +using namespace std; + +struct Node { + int data; + struct Node* next; +}; + +void removeLoop(struct Node*, struct Node*); + +int detectAndRemoveLoop(struct Node* list) +{ + struct Node *slow_p = list, *fast_p = list; + + while (slow_p && fast_p && fast_p->next) { + slow_p = slow_p->next; + fast_p = fast_p->next->next; + + if (slow_p == fast_p) { + removeLoop(slow_p, list); + + return 1; + } + } + + return 0; +} + +void removeLoop(struct Node* loop_node, struct Node* head) +{ + struct Node* ptr1 = loop_node; + struct Node* ptr2 = loop_node; + + unsigned int k = 1, i; + while (ptr1->next != ptr2) { + ptr1 = ptr1->next; + k++; + } + + ptr1 = head; + + ptr2 = head; + for (i = 0; i < k; i++) + ptr2 = ptr2->next; + + while (ptr2 != ptr1) { + ptr1 = ptr1->next; + ptr2 = ptr2->next; + } + + while (ptr2->next != ptr1) + ptr2 = ptr2->next; + + ptr2->next = NULL; +} + +void printList(struct Node* node) +{ + + while (node != NULL) { + cout << node->data << " "; + node = node->next; + } +} + +struct Node* newNode(int key) +{ + struct Node* temp = new Node(); + temp->data = key; + temp->next = NULL; + return temp; +} + +int main() +{ + struct Node* head = newNode(1); + head->next = newNode(2); + head->next->next = newNode(3); + head->next->next->next = newNode(4); + head->next->next->next->next = newNode(5); + + head->next->next->next->next->next = head->next; + + detectAndRemoveLoop(head); + + printList(head); + return 0; +} From fc8ee10b06ac89159252b5aad350d7bdca043b42 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 17:05:23 +0530 Subject: [PATCH 21/42] Create python3_HariVignesh18_OutbreaksDynamics.py --- python3_HariVignesh18_OutbreaksDynamics.py | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 python3_HariVignesh18_OutbreaksDynamics.py diff --git a/python3_HariVignesh18_OutbreaksDynamics.py b/python3_HariVignesh18_OutbreaksDynamics.py new file mode 100644 index 0000000..f1b2e7f --- /dev/null +++ b/python3_HariVignesh18_OutbreaksDynamics.py @@ -0,0 +1,35 @@ +from collections import deque +def min_infection_time(grid): + rows, cols = len(grid), len(grid[0]) + humans = 0 + zombies = deque() + for i in range(rows): + for j in range(cols): + if grid[i][j] == 1: + zombies.append((i, j)) + elif grid[i][j] == 0: + humans += 1 + time = 0 + directions = [(0, 1), (0, -1), (1, 0), (-1, 0)] + while humans > 0 and zombies: + time += 1 + for _ in range(len(zombies)): + x, y = zombies.popleft() + for dx, dy in directions: + nx, ny = x + dx, y + dy + if 0 <= nx < rows and 0 <= ny < cols: + if grid[nx][ny] == 0: + humans -= 1 + grid[nx][ny] = 1 + zombies.append((nx, ny)) + + return time if humans == 0 else -1 +grid = [ + [1, 0, 1, 1, 0], + [0, 0, 0, 1, 1], + [1, 0, 1, 1, 1], + [1, 0, -1, 0, 0], + [1, 1, 0, 0, 1] +] +a = min_infection_time(grid) +print(a) From 5a10d6a7a8570499e79f5491825f98b67ac5d972 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 17:07:15 +0530 Subject: [PATCH 22/42] Delete python3_HariVignesh18_OutbreaksDynamics.py --- python3_HariVignesh18_OutbreaksDynamics.py | 35 ---------------------- 1 file changed, 35 deletions(-) delete mode 100644 python3_HariVignesh18_OutbreaksDynamics.py diff --git a/python3_HariVignesh18_OutbreaksDynamics.py b/python3_HariVignesh18_OutbreaksDynamics.py deleted file mode 100644 index f1b2e7f..0000000 --- a/python3_HariVignesh18_OutbreaksDynamics.py +++ /dev/null @@ -1,35 +0,0 @@ -from collections import deque -def min_infection_time(grid): - rows, cols = len(grid), len(grid[0]) - humans = 0 - zombies = deque() - for i in range(rows): - for j in range(cols): - if grid[i][j] == 1: - zombies.append((i, j)) - elif grid[i][j] == 0: - humans += 1 - time = 0 - directions = [(0, 1), (0, -1), (1, 0), (-1, 0)] - while humans > 0 and zombies: - time += 1 - for _ in range(len(zombies)): - x, y = zombies.popleft() - for dx, dy in directions: - nx, ny = x + dx, y + dy - if 0 <= nx < rows and 0 <= ny < cols: - if grid[nx][ny] == 0: - humans -= 1 - grid[nx][ny] = 1 - zombies.append((nx, ny)) - - return time if humans == 0 else -1 -grid = [ - [1, 0, 1, 1, 0], - [0, 0, 0, 1, 1], - [1, 0, 1, 1, 1], - [1, 0, -1, 0, 0], - [1, 1, 0, 0, 1] -] -a = min_infection_time(grid) -print(a) From d2db1db091ebb86079d03c019d49a3da039c9e56 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 17:08:56 +0530 Subject: [PATCH 23/42] Create python3_HariVignesh18_OutbreakDynamics.py --- .../python3_HariVignesh18_OutbreakDynamics.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 December 16/python3_HariVignesh18_OutbreakDynamics.py diff --git a/December 16/python3_HariVignesh18_OutbreakDynamics.py b/December 16/python3_HariVignesh18_OutbreakDynamics.py new file mode 100644 index 0000000..f1b2e7f --- /dev/null +++ b/December 16/python3_HariVignesh18_OutbreakDynamics.py @@ -0,0 +1,35 @@ +from collections import deque +def min_infection_time(grid): + rows, cols = len(grid), len(grid[0]) + humans = 0 + zombies = deque() + for i in range(rows): + for j in range(cols): + if grid[i][j] == 1: + zombies.append((i, j)) + elif grid[i][j] == 0: + humans += 1 + time = 0 + directions = [(0, 1), (0, -1), (1, 0), (-1, 0)] + while humans > 0 and zombies: + time += 1 + for _ in range(len(zombies)): + x, y = zombies.popleft() + for dx, dy in directions: + nx, ny = x + dx, y + dy + if 0 <= nx < rows and 0 <= ny < cols: + if grid[nx][ny] == 0: + humans -= 1 + grid[nx][ny] = 1 + zombies.append((nx, ny)) + + return time if humans == 0 else -1 +grid = [ + [1, 0, 1, 1, 0], + [0, 0, 0, 1, 1], + [1, 0, 1, 1, 1], + [1, 0, -1, 0, 0], + [1, 1, 0, 0, 1] +] +a = min_infection_time(grid) +print(a) From 1d48d642de28a2c49fc0b19db8136a5a8a1f5e01 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 17:36:55 +0530 Subject: [PATCH 24/42] Create python3_HariVignesh18_RottenOranges.py --- .../python3_HariVignesh18_RottenOranges.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 December 22/python3_HariVignesh18_RottenOranges.py diff --git a/December 22/python3_HariVignesh18_RottenOranges.py b/December 22/python3_HariVignesh18_RottenOranges.py new file mode 100644 index 0000000..a485e72 --- /dev/null +++ b/December 22/python3_HariVignesh18_RottenOranges.py @@ -0,0 +1,32 @@ +from collections import deque +def rottime(grid): + if not grid or not grid[0]: + return 0 + rows, cols = len(grid), len(grid[0]) + f, q = 0, deque() + for i in range(rows): + for j in range(cols): + if grid[i][j] == 1: + f+=1 + elif grid[i][j] == 2: + q.append((i, j, 0)) + if f==0: + return 0 + + d=[(-1, 0), (1, 0), (0, -1), (0, 1)] + t=0 + + while q: + i,j,t=q.popleft() + + for di,dj in d: + ni,nj=i+di,j+dj + + if 0 <= ni < rows and 0 <= nj < cols and grid[ni][nj] == 1: + grid[ni][nj] = 2 + f -= 1 + q.append((ni, nj, t + 1)) + + return t if f == 0 else -1 +grid=[[2, 2, 0, 1]] +print(rottime(grid)) From 0f2db74b6834cee4909acc363a06a27a150eadc9 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 18:13:18 +0530 Subject: [PATCH 25/42] Create python3_HariVignesh18_Dominoes.py --- December 23/python3_HariVignesh18_Dominoes.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 December 23/python3_HariVignesh18_Dominoes.py diff --git a/December 23/python3_HariVignesh18_Dominoes.py b/December 23/python3_HariVignesh18_Dominoes.py new file mode 100644 index 0000000..270ccc4 --- /dev/null +++ b/December 23/python3_HariVignesh18_Dominoes.py @@ -0,0 +1,32 @@ +def min_rotation_time(n, dominos): + upper_sum = 0 + lower_sum = 0 + rotation_count = 0 + + for domino in dominos: + upper_sum += domino[0] + lower_sum += domino[1] + + if upper_sum % 2 == 0 and lower_sum % 2 == 0: + return 0 + + if upper_sum % 2 != lower_sum % 2: + return -1 + + for i in range(n): + if dominos[i][0] % 2 != dominos[i][1] % 2: + if upper_sum % 2 == 1 and dominos[i][0] % 2 == 1: + rotation_count += 1 + upper_sum -= 1 + lower_sum += 1 + elif lower_sum % 2 == 1 and dominos[i][1] % 2 == 1: + rotation_count += 1 + upper_sum += 1 + lower_sum -= 1 + + return rotation_count + +n = 3 +dominos = [(4,2),(6,4)] +result = min_rotation_time(n, dominos) +print(result) From af4d6f84f709f51ed2c342ccb65af16981433eb6 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 18:23:53 +0530 Subject: [PATCH 26/42] Create python3_HariVignesh18_HarmonyHurdle.py --- .../python3_HariVignesh18_HarmonyHurdle.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 December 25/python3_HariVignesh18_HarmonyHurdle.py diff --git a/December 25/python3_HariVignesh18_HarmonyHurdle.py b/December 25/python3_HariVignesh18_HarmonyHurdle.py new file mode 100644 index 0000000..2e5b0b6 --- /dev/null +++ b/December 25/python3_HariVignesh18_HarmonyHurdle.py @@ -0,0 +1,38 @@ +from collections import defaultdict, deque + +def min_time_to_complete_tasks(tasks, dependencies): + graph = defaultdict(list) + in_degree = {task: 0 for task in tasks} + + for i, deps in enumerate(dependencies): + for dep in deps: + graph[dep].append(i + 1) + in_degree[i + 1] += 1 + + top_order = [] + queue = deque([task for task, degree in in_degree.items() if degree == 0]) + + while queue: + current_task = queue.popleft() + top_order.append(current_task) + + for neighbor in graph[current_task]: + in_degree[neighbor] -= 1 + if in_degree[neighbor] == 0: + queue.append(neighbor) + + min_time = 0 + time_to_complete = {task: 0 for task in tasks} + + for task in top_order: + for neighbor in graph[task]: + time_to_complete[neighbor] = max(time_to_complete[neighbor], time_to_complete[task] + 1) + min_time = max(min_time, time_to_complete[neighbor]) + + return min_time + +tasks = [1, 2, 3, 4, 5] +dependencies = [[], [1], [2], [3], [4, 1]] + +result = min_time_to_complete_tasks(tasks, dependencies) +print(result) From bf47481c9e76e1ae0b03d9864ae8b14c30e92eb5 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 18:36:02 +0530 Subject: [PATCH 27/42] Create python3_HarVignesh_CircleOfEndurance.py --- .../python3_HarVignesh_CircleOfEndurance.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 December 27/python3_HarVignesh_CircleOfEndurance.py diff --git a/December 27/python3_HarVignesh_CircleOfEndurance.py b/December 27/python3_HarVignesh_CircleOfEndurance.py new file mode 100644 index 0000000..2c60f6e --- /dev/null +++ b/December 27/python3_HarVignesh_CircleOfEndurance.py @@ -0,0 +1,25 @@ +def find_starting_point(N, petrol, distance): + start = 0 + petrol_in_tank = 0 + total_petrol = 0 + total_distance = 0 + + for i in range(N): + petrol_in_tank = petrol[i] - distance[i] + total_petrol += petrol[i] + total_distance += distance[i] + + if petrol_in_tank < 0: + start_point += 1 + petrol_in_tank = 0 + return start + +N1 = 4 +petrol1 = [4, 6, 7, 4] +distance1 = [6, 5, 3, 5] +print(find_starting_point(N1, petrol1, distance1)) + +N2 = 5 +petrol2 = [2, 3, 7, 4, 5] +distance2 = [6, 5, 3, 5, 3] +print(find_starting_point(N2, petrol2, distance2)) From 8cc5c31e21cd438977c28b2397e100c80e973d4b Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 18:53:03 +0530 Subject: [PATCH 28/42] Create python3_HariVignesh8_TheSellingGame.py --- .../python3_HariVignesh8_TheSellingGame.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 December 28/python3_HariVignesh8_TheSellingGame.py diff --git a/December 28/python3_HariVignesh8_TheSellingGame.py b/December 28/python3_HariVignesh8_TheSellingGame.py new file mode 100644 index 0000000..c591e0b --- /dev/null +++ b/December 28/python3_HariVignesh8_TheSellingGame.py @@ -0,0 +1,33 @@ +def max_gadgets_sold(x, z, items, clients): + items.sort(key=lambda item: (item['m'], -item['n']), reverse=True) + clients.sort(key=lambda client: client['k']) + + gadgets_sold = 0 + sold_items = set() + + for client in clients: + for i, item in enumerate(items): + if i not in sold_items and item['m'] > client['k'] and item['n'] <= client['r']: + gadgets_sold += 1 + sold_items.add(i) + break + + return gadgets_sold + +# Example usage: +x = 3 +z = 3 +items = [ + {'k': 10, 'r': 100, 'm': 5, 'n': 110}, # Item 0 + {'k': 9, 'r': 200, 'm': 2, 'n': 200}, # Item 1 + {'k': 20, 'r': 300, 'm': 30, 'n': 300} # Item 2 +] + +clients = [ + {'k': 5, 'r': 110}, # Client 0 + {'k': 9, 'r': 500}, # Client 1 + {'k': 20, 'r': 400}, # Client 2 +] + +result = max_gadgets_sold(x, z, items, clients) +print(result) From b306ab213c317533cc0e6c4c623da7e6549be336 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 18:57:51 +0530 Subject: [PATCH 29/42] Create C++_HariVignesh18_PhantomCycle.cpp --- .../C++_HariVignesh18_PhantomCycle.cpp | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 December 26/C++_HariVignesh18_PhantomCycle.cpp diff --git a/December 26/C++_HariVignesh18_PhantomCycle.cpp b/December 26/C++_HariVignesh18_PhantomCycle.cpp new file mode 100644 index 0000000..c73e90a --- /dev/null +++ b/December 26/C++_HariVignesh18_PhantomCycle.cpp @@ -0,0 +1,56 @@ +#include +using namespace std; +struct node +{ + int val; + struct node *next; +}; +struct node *head = NULL; + +bool detectLoop(Node* head) + { + Node* temp = head; + map v; + while(temp!=NULL){ + if(v[temp]!=true){ + v[temp] = true; + temp = temp->next;} + else{ + return true; + } + } + return false; +} +void insert(struct node *head, int val) +{ + struct node *nn = malloc(sizeof(struct node)); + nn->val=val; + nn->next=NULL; + if(head==NULL){ + head=nn; + } + else + { + struct node *t=head; + while(t->next!=NULL) + { + t=t->next; + } + t->next=nn; + } +} + +int main(){ + int n,e; + cin>>n; + for(int i=0; i>e; + insert(head,e); + } + if(detectLoop(head)){ + cout << "Cycle Found"; + } + else{ + cout << "No Cycle Found"; + } +} From a080de1af214dc9582a5bcb99eeed3d583ec4a4d Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 21:17:41 +0530 Subject: [PATCH 30/42] Create python3_HariVignesh18_RiddleMeThis.py --- December 21/python3_HariVignesh18_RiddleMeThis.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 December 21/python3_HariVignesh18_RiddleMeThis.py diff --git a/December 21/python3_HariVignesh18_RiddleMeThis.py b/December 21/python3_HariVignesh18_RiddleMeThis.py new file mode 100644 index 0000000..021d0ea --- /dev/null +++ b/December 21/python3_HariVignesh18_RiddleMeThis.py @@ -0,0 +1,9 @@ +s = "RQHODQTLATCTQ" +ans = "" +for i in s: + a = ord(i) + a = a-25 + if a < 65: + a +=26 + ans += chr(a) +print(ans) From 6fd9ddc187b34c8d5420713d5213c6cc66f83123 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 21:25:54 +0530 Subject: [PATCH 31/42] Create python3_HariVignesh18_GoldenRuleViolation --- December 24/python3_HariVignesh18_GoldenRuleViolation | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 December 24/python3_HariVignesh18_GoldenRuleViolation diff --git a/December 24/python3_HariVignesh18_GoldenRuleViolation b/December 24/python3_HariVignesh18_GoldenRuleViolation new file mode 100644 index 0000000..5c236a9 --- /dev/null +++ b/December 24/python3_HariVignesh18_GoldenRuleViolation @@ -0,0 +1,9 @@ +a = [int(i) for i in input().split()] +b = a.copy() +count = 0 +for i in range(0,len(a)): + c = b[:i+1] + for j in c: + if j > a[i]: + count += 1 +print(count) From fad41c142c4bed7ccc8490e61f5c6591d9b612c5 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 21:47:16 +0530 Subject: [PATCH 32/42] Create python3_HariVignesh18_CartesianWalkValidator.py --- ...n3_HariVignesh18_CartesianWalkValidator.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 December 29/python3_HariVignesh18_CartesianWalkValidator.py diff --git a/December 29/python3_HariVignesh18_CartesianWalkValidator.py b/December 29/python3_HariVignesh18_CartesianWalkValidator.py new file mode 100644 index 0000000..ad028d8 --- /dev/null +++ b/December 29/python3_HariVignesh18_CartesianWalkValidator.py @@ -0,0 +1,23 @@ +def find_path(path): + b = [0, 0] + c = 0 + for i in path: + c += 1 + if i == 'n': + b = [b[0], b[1] + 1] + elif i == 'e': + b = [b[0] + 1, b[1]] + elif i == 's': + b = [b[0], b[1] - 1] + else: + b = [b[0] - 1, b[1]] + if c == 10: + if b == [0,0]: + print("True") + else: + print("False") + else: + print("False") + +path = input().split() +find_path(path) From d8a7b1f91b72fbf50940934aee5b77a764193388 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 22:21:37 +0530 Subject: [PATCH 33/42] Update C++_HariVignesh18_PhantomCycle.cpp --- December 26/C++_HariVignesh18_PhantomCycle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/December 26/C++_HariVignesh18_PhantomCycle.cpp b/December 26/C++_HariVignesh18_PhantomCycle.cpp index c73e90a..faaab07 100644 --- a/December 26/C++_HariVignesh18_PhantomCycle.cpp +++ b/December 26/C++_HariVignesh18_PhantomCycle.cpp @@ -1,4 +1,4 @@ -#include +#include using namespace std; struct node { From 35be1ac14aefcc409b8f122102b7e53df6c7e114 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 22:25:55 +0530 Subject: [PATCH 34/42] Update C++_HariVignesh18_PhantomCycle.cpp --- December 26/C++_HariVignesh18_PhantomCycle.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/December 26/C++_HariVignesh18_PhantomCycle.cpp b/December 26/C++_HariVignesh18_PhantomCycle.cpp index faaab07..f8d8f2f 100644 --- a/December 26/C++_HariVignesh18_PhantomCycle.cpp +++ b/December 26/C++_HariVignesh18_PhantomCycle.cpp @@ -1,4 +1,5 @@ #include +#include using namespace std; struct node { From d62b4bd2916ab1f76143702503fec7a060306493 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 22:32:00 +0530 Subject: [PATCH 35/42] Update C++_HariVignesh18_PhantomCycle.cpp --- .../C++_HariVignesh18_PhantomCycle.cpp | 79 ++++++++++--------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/December 26/C++_HariVignesh18_PhantomCycle.cpp b/December 26/C++_HariVignesh18_PhantomCycle.cpp index f8d8f2f..b2fd282 100644 --- a/December 26/C++_HariVignesh18_PhantomCycle.cpp +++ b/December 26/C++_HariVignesh18_PhantomCycle.cpp @@ -1,6 +1,7 @@ #include #include using namespace std; + struct node { int val; @@ -8,50 +9,52 @@ struct node }; struct node *head = NULL; -bool detectLoop(Node* head) - { - Node* temp = head; - map v; - while(temp!=NULL){ - if(v[temp]!=true){ +bool detectLoop(struct node* head) +{ + struct node* temp = head; + map v; + while(temp!=NULL){ + if(v[temp]!=true){ v[temp] = true; - temp = temp->next;} - else{ - return true; - } + temp = temp->next; + } + else{ + return true; } - return false; + } + return false; } -void insert(struct node *head, int val) + +void insert(int val) { - struct node *nn = malloc(sizeof(struct node)); - nn->val=val; - nn->next=NULL; - if(head==NULL){ - head=nn; - } - else - { - struct node *t=head; - while(t->next!=NULL) - { - t=t->next; + struct node *nn = new struct node; + nn->val = val; + nn->next = NULL; + if (head == NULL) { + head = nn; + } else { + struct node *t = head; + while (t->next != NULL) { + t = t->next; } - t->next=nn; + t->next = nn; } } -int main(){ - int n,e; - cin>>n; - for(int i=0; i>e; - insert(head,e); - } - if(detectLoop(head)){ - cout << "Cycle Found"; - } - else{ - cout << "No Cycle Found"; - } +int main() { + int n, e; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> e; + insert(e); + } + // Adding a Loop + head->next->next->next = head; + if (detectLoop(head)) { + cout << "Cycle Found"; + } else { + cout << "No Cycle Found"; + } + + return 0; } From ea5b563eb19c338da24e9653ac2bc9f1d436a339 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 22:56:40 +0530 Subject: [PATCH 36/42] Create C++_HariVignesh18_SymbolicSum.cpp --- C++_HariVignesh18_SymbolicSum.cpp | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 C++_HariVignesh18_SymbolicSum.cpp diff --git a/C++_HariVignesh18_SymbolicSum.cpp b/C++_HariVignesh18_SymbolicSum.cpp new file mode 100644 index 0000000..d2e6a0d --- /dev/null +++ b/C++_HariVignesh18_SymbolicSum.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +using namespace std; + +int symbolicSum(const string& sequence) { + stack> st; + + int mul = 1; + long long sum = 0; + + for (char ch : sequence) { + if (isdigit(ch)) { + sum += ch - '0'; + } else if (ch == 'X') { + st.push({sum, mul}); + sum = 0; + mul = 1; + } else if (ch == ' ') { + continue; + } else { + mul = ch - '0'; + } + } + + long long symbolicSum = 0; + + while (!st.empty()) { + auto top = st.top(); + st.pop(); + + symbolicSum += top.first * top.second; + } + + return symbolicSum; +} + +int main() { + string s_seq = "X5 2 X3 7 X2 5 6"; + + int r = symbolicSum(s_seq); + cout << "Symbolic Sum: " << r << endl; + + return 0; +} From 1713f19a89875c811da9a25ffe509981a4fe51e8 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 23:15:31 +0530 Subject: [PATCH 37/42] Create python3_HariVignesh_TreasureHuntInTheIsles,py --- ...hon3_HariVignesh_TreasureHuntInTheIsles,py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 December 20/python3_HariVignesh_TreasureHuntInTheIsles,py diff --git a/December 20/python3_HariVignesh_TreasureHuntInTheIsles,py b/December 20/python3_HariVignesh_TreasureHuntInTheIsles,py new file mode 100644 index 0000000..116fb91 --- /dev/null +++ b/December 20/python3_HariVignesh_TreasureHuntInTheIsles,py @@ -0,0 +1,22 @@ +import heapq +def hunt(g, s, e): + q = [(0, s, [s])] + while q: + tw, cc, pf = heapq.heappop(q) + if cc == e: + return pf + for n, w in g.get(cc, {}).items(): + tnw = tw + w + heapq.heappush(q, (tnw, n, pf + [n])) + return [] + +graph = { + 'Cave_A': {'Cave_B': 3, 'Cave_C': 5}, + 'Cave_B': {'Cave_D': 7, 'Cave_E': 1}, + 'Cave_C': {'Cave_D': 3}, + 'Cave_D': {'Cave_E': 5}, + 'Cave_E': {} +} +start_cave2 = 'Cave_A' +end_cave2 = 'Cave_E' +print(hunt(graph, start_cave2, end_cave2)) From 605242711d91a638c6eda6efbd76a30b4ef03d14 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 23:18:48 +0530 Subject: [PATCH 38/42] Delete C++_HariVignesh18_SymbolicSum.cpp --- C++_HariVignesh18_SymbolicSum.cpp | 45 ------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 C++_HariVignesh18_SymbolicSum.cpp diff --git a/C++_HariVignesh18_SymbolicSum.cpp b/C++_HariVignesh18_SymbolicSum.cpp deleted file mode 100644 index d2e6a0d..0000000 --- a/C++_HariVignesh18_SymbolicSum.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include -using namespace std; - -int symbolicSum(const string& sequence) { - stack> st; - - int mul = 1; - long long sum = 0; - - for (char ch : sequence) { - if (isdigit(ch)) { - sum += ch - '0'; - } else if (ch == 'X') { - st.push({sum, mul}); - sum = 0; - mul = 1; - } else if (ch == ' ') { - continue; - } else { - mul = ch - '0'; - } - } - - long long symbolicSum = 0; - - while (!st.empty()) { - auto top = st.top(); - st.pop(); - - symbolicSum += top.first * top.second; - } - - return symbolicSum; -} - -int main() { - string s_seq = "X5 2 X3 7 X2 5 6"; - - int r = symbolicSum(s_seq); - cout << "Symbolic Sum: " << r << endl; - - return 0; -} From 67e2e08668c86bac9cd04972a73209192e28f27c Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 23:20:12 +0530 Subject: [PATCH 39/42] Create C++_HariVignesh18_SymbolicSum.cpp --- December 19/C++_HariVignesh18_SymbolicSum.cpp | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 December 19/C++_HariVignesh18_SymbolicSum.cpp diff --git a/December 19/C++_HariVignesh18_SymbolicSum.cpp b/December 19/C++_HariVignesh18_SymbolicSum.cpp new file mode 100644 index 0000000..d2e6a0d --- /dev/null +++ b/December 19/C++_HariVignesh18_SymbolicSum.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +using namespace std; + +int symbolicSum(const string& sequence) { + stack> st; + + int mul = 1; + long long sum = 0; + + for (char ch : sequence) { + if (isdigit(ch)) { + sum += ch - '0'; + } else if (ch == 'X') { + st.push({sum, mul}); + sum = 0; + mul = 1; + } else if (ch == ' ') { + continue; + } else { + mul = ch - '0'; + } + } + + long long symbolicSum = 0; + + while (!st.empty()) { + auto top = st.top(); + st.pop(); + + symbolicSum += top.first * top.second; + } + + return symbolicSum; +} + +int main() { + string s_seq = "X5 2 X3 7 X2 5 6"; + + int r = symbolicSum(s_seq); + cout << "Symbolic Sum: " << r << endl; + + return 0; +} From 28db15bc14b800d9b0ecdc835d37df486bb4fb6f Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Fri, 29 Dec 2023 23:37:49 +0530 Subject: [PATCH 40/42] Create python3_HariVignesh18_ It'sChristmasSeason,py --- ...hon3_HariVignesh18_ It'sChristmasSeason,py | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 December 18/python3_HariVignesh18_ It'sChristmasSeason,py diff --git a/December 18/python3_HariVignesh18_ It'sChristmasSeason,py b/December 18/python3_HariVignesh18_ It'sChristmasSeason,py new file mode 100644 index 0000000..a1c28db --- /dev/null +++ b/December 18/python3_HariVignesh18_ It'sChristmasSeason,py @@ -0,0 +1,87 @@ +import sys +sys.setrecursionlimit(10 ** 6) +N = 100000 +l=[] +MOD = 10 ** 9 + 7 +f = [0] * (N + 1) +invf = [0] * (N + 1) + +def dfs(node, p, g, a, x): + for c in g[node]: + if c != p: + dfs(c, node, g, a, x) + a[node] += a[c] + if a[node] >= x: + a[node] -= x + +def powmod(a, b, mod): + res = 1 + a %= mod + while b: + if b & 1: + res = res * a % mod + a = a * a % mod + b >>= 1 + return res + +def cn(u, v, MOD): + if u > v: + return 0 + if u == v: + return 1 + if u == 1 or u + 1 == v: + return v + return f[v] * invf[u] % MOD * invf[v - u] % MOD + +def dfs_count(node, p, g, a): + cnt = 1 if a[node] == 0 else 0 + for c in g[node]: + if c != p: + cnt += dfs_count(c, node, g, a) + return cnt + +def solve(): + global N, MOD, f, invf + n, x = map(int, input().split()) + a = list(map(int, input().split())) + a = [ai % x for ai in a] + g = [[] for _ in range(n)] + for _ in range(n - 1): + u, v = map(int, input().split()) + u -= 1 + v -= 1 + g[u].append(v) + g[v].append(u) + + dfs(0, -1, g, a, x) + + if a[0] != 0: + print(' '.join(['0'] * n)) + return + + result = [1] + cnt = dfs_count(0, -1, g, a) + + for i in range(2, n + 1): + result.append(cn(i - 1, cnt - 1, MOD)) + + l.append(list(''.join(map(str,result)))) + +f[0] = 1 + +for i in range(1, N + 1): + f[i] = f[i - 1] * i % MOD + +invf[N] = powmod(f[N], MOD - 2, MOD) + +for i in range(N, 0, -1): + invf[i - 1] = invf[i] * i % MOD + +t = int(input()) + +for _ in range(t): + solve() +for i in l: + for j in i: + print(int(j),end=" ") + print() From 484f3dc15537dbf0416e4a62fc4083572cb6f183 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Sun, 7 Jan 2024 10:35:32 +0530 Subject: [PATCH 41/42] Create python3_HariVignesh18_TreeInversions.py --- .../python3_HariVignesh18_TreeInversions.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 December 30/python3_HariVignesh18_TreeInversions.py diff --git a/December 30/python3_HariVignesh18_TreeInversions.py b/December 30/python3_HariVignesh18_TreeInversions.py new file mode 100644 index 0000000..b120c6a --- /dev/null +++ b/December 30/python3_HariVignesh18_TreeInversions.py @@ -0,0 +1,43 @@ +def dfs(node, parent, colors, tree, in_count, out_count, depth): + in_count[node] = [0] * depth + out_count[node] = [0] * depth + in_count[node][colors[node] - 1] = 1 + + for child in tree[node]: + if child == parent: + continue + dfs(child, node, colors, tree, in_count, out_count, depth) + for i in range(depth): + in_count[node][i] += in_count[child][i] + out_count[node][i] += out_count[child][i] + out_count[node][colors[node] - 1] += 1 + +def solve_queries(tree, in_count, out_count, depth, queries): + result = [] + for query in queries: + x, y = query + x -= 1 + y -= 1 + total_inversions = 0 + for i in range(depth): + total_inversions += abs(in_count[x][i] - in_count[y][i]) + abs(out_count[x][i] - out_count[y][i]) + result.append(total_inversions // 2) + return result + +T = int(input()) +for _ in range(T): + N, Q = map(int, input().split()) + colors = list(map(int, input().split())) + tree = {i: [] for i in range(N)} + for _ in range(N - 1): + X, Y = map(int, input().split()) + tree[X - 1].append(Y - 1) + tree[Y - 1].append(X - 1) + in_count = {} + out_count = {} + dfs(0, -1, colors, tree, in_count, out_count, max(colors)) + queries = [tuple(map(int, input().split())) for _ in range(Q)] + result = solve_queries(tree, in_count, out_count, max(colors), queries) + + for res in result: + print(res) From df3f3f292f2fd69567139abd30d492d4959aa560 Mon Sep 17 00:00:00 2001 From: Hari Vignesh <131291876+HariVignesh18@users.noreply.github.com> Date: Sun, 7 Jan 2024 10:36:43 +0530 Subject: [PATCH 42/42] Create python3_HariVignesh18_NQueens.py --- December 31/python3_HariVignesh18_NQueens.py | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 December 31/python3_HariVignesh18_NQueens.py diff --git a/December 31/python3_HariVignesh18_NQueens.py b/December 31/python3_HariVignesh18_NQueens.py new file mode 100644 index 0000000..88f3061 --- /dev/null +++ b/December 31/python3_HariVignesh18_NQueens.py @@ -0,0 +1,25 @@ +def is_safe(board, row, col, N): + for i in range(row): + if board[i] == col or board[i] - i == col - row or board[i] + i == col + row: + return False + return True + +def solve_nqueens(board, row, N, solutions): + if row == N: + solutions.append(tuple(board[:])) + else: + for col in range(N): + if is_safe(board, row, col, N): + board[row] = col + solve_nqueens(board, row + 1, N, solutions) + +def print_solutions(N): + board = [-1] * N + solutions = [] + solve_nqueens(board, 0, N, solutions) + + for solution in solutions: + print(" ".join(f"({i + 1}, {solution[i] + 1})" for i in range(N))) + +N = int(input()) +print_solutions(N)