From 3f0fbede4e582ee7fbfa486c198b0ac59c122a5f Mon Sep 17 00:00:00 2001 From: Jeswindany <120293717+Jeswindany@users.noreply.github.com> Date: Sat, 2 Dec 2023 17:11:43 +0530 Subject: [PATCH 01/66] Add files via upload --- December 01/C++_Jeswindany_Cricmetric.c++ | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 December 01/C++_Jeswindany_Cricmetric.c++ diff --git a/December 01/C++_Jeswindany_Cricmetric.c++ b/December 01/C++_Jeswindany_Cricmetric.c++ new file mode 100644 index 0000000..59c903c --- /dev/null +++ b/December 01/C++_Jeswindany_Cricmetric.c++ @@ -0,0 +1,17 @@ +#include +using namespace std; + +int main(){ + int n; + cin >> n; + int runs[n], total = 0, highest = 0; + for (int i = 0; i> runs[i]; + total += runs[i]; + if(runs[i]>runs[highest]){ + highest = i; + } + } + cout << total << endl; + cout << highest << endl; +} \ No newline at end of file From 19a03c0feb7ed956c6493e2527ca0afe75d55801 Mon Sep 17 00:00:00 2001 From: Jeswindany <120293717+Jeswindany@users.noreply.github.com> Date: Sat, 2 Dec 2023 17:19:05 +0530 Subject: [PATCH 02/66] Add files via upload --- December 02/python3_Jeswindany_Shoppers_Choice.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 December 02/python3_Jeswindany_Shoppers_Choice.py diff --git a/December 02/python3_Jeswindany_Shoppers_Choice.py b/December 02/python3_Jeswindany_Shoppers_Choice.py new file mode 100644 index 0000000..f0766fb --- /dev/null +++ b/December 02/python3_Jeswindany_Shoppers_Choice.py @@ -0,0 +1,8 @@ +sales = [int(i) for i in input().split()] +visited = [] +frequency = [] +for i in sales: + if i not in visited: + visited.append(i) + frequency.append(sales.count(i)) +print(frequency) From 6d1191734a3b08a85716aed2cca959f0969e0fb4 Mon Sep 17 00:00:00 2001 From: Jeswindany <120293717+Jeswindany@users.noreply.github.com> Date: Sat, 2 Dec 2023 17:20:47 +0530 Subject: [PATCH 03/66] Moving source code to December 02 file --- .../python3_Jeswindany_Shoppers_Choice.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {December 02 => December 02 }/python3_Jeswindany_Shoppers_Choice.py (100%) diff --git a/December 02/python3_Jeswindany_Shoppers_Choice.py b/December 02 /python3_Jeswindany_Shoppers_Choice.py similarity index 100% rename from December 02/python3_Jeswindany_Shoppers_Choice.py rename to December 02 /python3_Jeswindany_Shoppers_Choice.py From 4db573bafc0e4d557607d591badddf099a90e3ac Mon Sep 17 00:00:00 2001 From: Jeswindany <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 3 Dec 2023 10:30:20 +0530 Subject: [PATCH 04/66] Add files via upload --- December 03/C++_Jeswindany_Sunburnt.c++ | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 December 03/C++_Jeswindany_Sunburnt.c++ diff --git a/December 03/C++_Jeswindany_Sunburnt.c++ b/December 03/C++_Jeswindany_Sunburnt.c++ new file mode 100644 index 0000000..41f7966 --- /dev/null +++ b/December 03/C++_Jeswindany_Sunburnt.c++ @@ -0,0 +1,24 @@ +#include +using namespace std; + +int main(){ + int n; + cin >> n; + int h[n]; + for(int i=0; i> h[i]; + } + int c = 0, f; + for(int i=0; i h[i]){ + f = 0; + break; + } + } + if(f == 1) + c++; + } + cout << c; +} \ No newline at end of file From 92e918455eb704b8980f2d884838596a8736f932 Mon Sep 17 00:00:00 2001 From: Jeswindany <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 3 Dec 2023 10:34:03 +0530 Subject: [PATCH 05/66] Update C++_Jeswindany_Sunburnt.c++ --- December 03/C++_Jeswindany_Sunburnt.c++ | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/December 03/C++_Jeswindany_Sunburnt.c++ b/December 03/C++_Jeswindany_Sunburnt.c++ index 41f7966..ad40309 100644 --- a/December 03/C++_Jeswindany_Sunburnt.c++ +++ b/December 03/C++_Jeswindany_Sunburnt.c++ @@ -12,7 +12,7 @@ int main(){ for(int i=0; i h[i]){ + if(h[j] >= h[i]){ f = 0; break; } @@ -21,4 +21,4 @@ int main(){ c++; } cout << c; -} \ No newline at end of file +} From 6177d3cb20869de58abb32fa3ba8d8b09b91c15c Mon Sep 17 00:00:00 2001 From: Jeswindany <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 5 Dec 2023 09:49:01 +0530 Subject: [PATCH 06/66] Add files via upload --- December 04/python3_Jeswindany_MirrorMagic.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 December 04/python3_Jeswindany_MirrorMagic.py diff --git a/December 04/python3_Jeswindany_MirrorMagic.py b/December 04/python3_Jeswindany_MirrorMagic.py new file mode 100644 index 0000000..2dd34b5 --- /dev/null +++ b/December 04/python3_Jeswindany_MirrorMagic.py @@ -0,0 +1,22 @@ +def substrings(s): + substrings = [] + n = len(s) + + for i in range(n): + for j in range(i + 1, n + 1): + substrings.append(s[i:j]) + return substrings + +def palindrome(s): + return s == s[::-1] + +word = input() +sub = substrings(word) +sub.sort(key = str.__len__) +for i in range(len(word), len(sub)): + if(palindrome(sub[i].casefold())): + res = sub[i] + break +else: + res = "Error" +print(res) \ No newline at end of file From 6b68645494e81d051085943de673eca516d77d25 Mon Sep 17 00:00:00 2001 From: Jeswindany <120293717+Jeswindany@users.noreply.github.com> Date: Wed, 6 Dec 2023 11:56:58 +0530 Subject: [PATCH 07/66] Add files via upload --- December 05/python3_Jeswindany_PeakyBlinders.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 December 05/python3_Jeswindany_PeakyBlinders.py diff --git a/December 05/python3_Jeswindany_PeakyBlinders.py b/December 05/python3_Jeswindany_PeakyBlinders.py new file mode 100644 index 0000000..0321117 --- /dev/null +++ b/December 05/python3_Jeswindany_PeakyBlinders.py @@ -0,0 +1,7 @@ +loot = [int(i) for i in input().split()] +avg = sum(loot)/len(loot) +res_sum = 0 +for i in loot: + if(i>=avg): + res_sum += i +print(res_sum) \ No newline at end of file From 0053be6b3a9a32415ffe9d2863bb9c22cb7752b7 Mon Sep 17 00:00:00 2001 From: Jeswindany <120293717+Jeswindany@users.noreply.github.com> Date: Thu, 7 Dec 2023 15:13:48 +0530 Subject: [PATCH 08/66] Add files via upload --- December 07/C++_Jeswindany_BabyBlocks.c++ | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 December 07/C++_Jeswindany_BabyBlocks.c++ diff --git a/December 07/C++_Jeswindany_BabyBlocks.c++ b/December 07/C++_Jeswindany_BabyBlocks.c++ new file mode 100644 index 0000000..3f11186 --- /dev/null +++ b/December 07/C++_Jeswindany_BabyBlocks.c++ @@ -0,0 +1,18 @@ +#include +#include +using namespace std; + +void rectangleInCircle(double w,double h,double r){ + double diag = sqrt((w*w)+(h*h)); + if(diag>(2*r)) + cout << "false" << endl; + else + cout << "true" << endl; +} + +int main(){ + double w, h, r; + cin >> w >> h >> r; + rectangleInCircle(w,h,r); + return 0; +} \ No newline at end of file From 7f93b623bdec96ba1c95d777abfcdaf5368437b6 Mon Sep 17 00:00:00 2001 From: Jeswindany <120293717+Jeswindany@users.noreply.github.com> Date: Thu, 7 Dec 2023 16:45:26 +0530 Subject: [PATCH 09/66] Add files via upload --- ...hon3_Jeswindany_TheLostAlgorithmScrolls.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py diff --git a/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py b/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py new file mode 100644 index 0000000..da47bc9 --- /dev/null +++ b/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py @@ -0,0 +1,36 @@ +def link(a, b): + if(len(a) == len(b) and len(set(a)^set(b))==2): + return True + return False + +words = input().split() +d = {} +f = 0 +for i in words: + d[i] = [] + for j in words: + if(i!=j and link(i,j)): + d[i].append(j) + f += 1 + +if f == 0: + print("No valid chain") + +else: + res = [] + for i in words: + if d[i] != []: + start = i + res.append(i) + break + while(1): + if(d[start] == []): + break + for i in d[start]: + if i not in res: + res.append(i) + start = i + break + else: + break + print(res) \ No newline at end of file From 7819621b17aaba28efc0df1cda8b2151843de43a Mon Sep 17 00:00:00 2001 From: Jeswindany <120293717+Jeswindany@users.noreply.github.com> Date: Thu, 7 Dec 2023 17:53:07 +0530 Subject: [PATCH 10/66] Delete December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py --- ...hon3_Jeswindany_TheLostAlgorithmScrolls.py | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py diff --git a/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py b/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py deleted file mode 100644 index da47bc9..0000000 --- a/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py +++ /dev/null @@ -1,36 +0,0 @@ -def link(a, b): - if(len(a) == len(b) and len(set(a)^set(b))==2): - return True - return False - -words = input().split() -d = {} -f = 0 -for i in words: - d[i] = [] - for j in words: - if(i!=j and link(i,j)): - d[i].append(j) - f += 1 - -if f == 0: - print("No valid chain") - -else: - res = [] - for i in words: - if d[i] != []: - start = i - res.append(i) - break - while(1): - if(d[start] == []): - break - for i in d[start]: - if i not in res: - res.append(i) - start = i - break - else: - break - print(res) \ No newline at end of file From 6351135c9efcf3d1786cb6f491bf02201b5584b0 Mon Sep 17 00:00:00 2001 From: Jeswindany <120293717+Jeswindany@users.noreply.github.com> Date: Thu, 7 Dec 2023 17:53:26 +0530 Subject: [PATCH 11/66] Add files via upload --- ...hon3_Jeswindany_TheLostAlgorithmScrolls.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py diff --git a/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py b/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py new file mode 100644 index 0000000..fec7f1a --- /dev/null +++ b/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py @@ -0,0 +1,32 @@ +def link(a, b): + if(len(a) == len(b) and len(set(a)^set(b))==2): + return True + elif((a in b) or (b in a)): + return True + return False + +words = input().split() +start = "" +res = [] +for i in words: + for j in words: + if(i!=j and link(i,j)): + start = i + res.append(i) + break + if(start != ""): + break + +if start == "": + print("No valid chain") +else: + while(1): + for i in words: + if(i!=start and link(start,i) and (i not in res)): + start = i + res.append(i) + break + else: + break + print(res) + From e67f5ac41a646e22766f235f38d9425ccf7e24b4 Mon Sep 17 00:00:00 2001 From: Jeswindany <120293717+Jeswindany@users.noreply.github.com> Date: Thu, 7 Dec 2023 18:06:52 +0530 Subject: [PATCH 12/66] Update python3_Jeswindany_TheLostAlgorithmScrolls.py --- .../python3_Jeswindany_TheLostAlgorithmScrolls.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py b/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py index fec7f1a..36e95f0 100644 --- a/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py +++ b/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py @@ -1,8 +1,14 @@ def link(a, b): - if(len(a) == len(b) and len(set(a)^set(b))==2): - return True - elif((a in b) or (b in a)): - return True + if(len(a) == len(b)): + c = 0 + for i in range(len(a)): + if(a[i] != b[i]): + c+=1 + if(c == 1): + return True + elif(abs(len(a) - len(b)) == 1): + if((a in b) or (b in a)): + return True return False words = input().split() @@ -29,4 +35,3 @@ def link(a, b): else: break print(res) - From 2b729996d6f0d11edb2cb49045a5936732ee38e9 Mon Sep 17 00:00:00 2001 From: Jeswindany <120293717+Jeswindany@users.noreply.github.com> Date: Fri, 8 Dec 2023 11:17:46 +0530 Subject: [PATCH 13/66] Add files via upload --- .../C++_Jeswindany_TheEnchantedForest.c++ | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 December 08/C++_Jeswindany_TheEnchantedForest.c++ diff --git a/December 08/C++_Jeswindany_TheEnchantedForest.c++ b/December 08/C++_Jeswindany_TheEnchantedForest.c++ new file mode 100644 index 0000000..efae596 --- /dev/null +++ b/December 08/C++_Jeswindany_TheEnchantedForest.c++ @@ -0,0 +1,46 @@ +#include +#include +using namespace std; + +void magicsquare(int n){ + int sqr[n][n]; + memset(sqr, 0, sizeof(sqr)); + int i = n/2; + int j = n-1; + + for(int num = 1; num <= n*n;){ + if(i == -1 && j == n){ + i = 0; + j = n-2; + } + else{ + if(j == n) + j = 0; + if(i < 0) + i = n-1; + } + if(sqr[i][j]){ + i += 1; + j -= 2; + continue; + } + else{ + sqr[i][j] = num++; + } + i--; + j++; + } + + for (i = 0; i> n; + magicsquare(n); +} \ No newline at end of file From 91cd77b745c54e881919d16a9e3473c54d246d05 Mon Sep 17 00:00:00 2001 From: Jeswindany <120293717+Jeswindany@users.noreply.github.com> Date: Fri, 8 Dec 2023 11:20:02 +0530 Subject: [PATCH 14/66] Update C++_Jeswindany_TheEnchantedForest.c++ --- December 08/C++_Jeswindany_TheEnchantedForest.c++ | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/December 08/C++_Jeswindany_TheEnchantedForest.c++ b/December 08/C++_Jeswindany_TheEnchantedForest.c++ index efae596..8cd65f5 100644 --- a/December 08/C++_Jeswindany_TheEnchantedForest.c++ +++ b/December 08/C++_Jeswindany_TheEnchantedForest.c++ @@ -43,4 +43,5 @@ int main(){ int n; cin >> n; magicsquare(n); -} \ No newline at end of file + return 0; +} From b630cdf3d53e29df3442c45d17a3962e9f7b57be Mon Sep 17 00:00:00 2001 From: Jeswindany <120293717+Jeswindany@users.noreply.github.com> Date: Fri, 8 Dec 2023 11:33:54 +0530 Subject: [PATCH 15/66] Update C++_Jeswindany_TheEnchantedForest.c++ --- December 08/C++_Jeswindany_TheEnchantedForest.c++ | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/December 08/C++_Jeswindany_TheEnchantedForest.c++ b/December 08/C++_Jeswindany_TheEnchantedForest.c++ index 8cd65f5..066a51f 100644 --- a/December 08/C++_Jeswindany_TheEnchantedForest.c++ +++ b/December 08/C++_Jeswindany_TheEnchantedForest.c++ @@ -2,7 +2,7 @@ #include using namespace std; -void magicsquare(int n){ +void find_path(int n){ int sqr[n][n]; memset(sqr, 0, sizeof(sqr)); int i = n/2; @@ -42,6 +42,6 @@ void magicsquare(int n){ int main(){ int n; cin >> n; - magicsquare(n); + find_path(n); return 0; } From be62b8ef50df95c24418951dd21eff76f090f393 Mon Sep 17 00:00:00 2001 From: Jeswindany <120293717+Jeswindany@users.noreply.github.com> Date: Sat, 9 Dec 2023 11:34:14 +0530 Subject: [PATCH 16/66] Add files via upload --- December 09/C++_Jeswindany_camelsOnAString.c++ | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 December 09/C++_Jeswindany_camelsOnAString.c++ diff --git a/December 09/C++_Jeswindany_camelsOnAString.c++ b/December 09/C++_Jeswindany_camelsOnAString.c++ new file mode 100644 index 0000000..002af27 --- /dev/null +++ b/December 09/C++_Jeswindany_camelsOnAString.c++ @@ -0,0 +1,16 @@ +#include +#include +using namespace std; + +int main(){ + string text; + cin >> text; + int c = 1; + for(int i = 0; i=65 && text[i] <= 90){ + c += 1; + } + } + cout << c; + return 0; +} \ No newline at end of file From 8c2c0802ec1b723cd8499a6def5ee4647a388685 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Mon, 11 Dec 2023 10:16:41 +0530 Subject: [PATCH 17/66] Add python3_Jeswindany_CoderOfConversions.py --- December 11/python3_Jeswindany_CoderOfConversions.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 December 11/python3_Jeswindany_CoderOfConversions.py diff --git a/December 11/python3_Jeswindany_CoderOfConversions.py b/December 11/python3_Jeswindany_CoderOfConversions.py new file mode 100644 index 0000000..f533f8a --- /dev/null +++ b/December 11/python3_Jeswindany_CoderOfConversions.py @@ -0,0 +1,5 @@ +def binsum(a,b): + return bin(a+b)[2:] + +a,b = [int(i) for i in input().split()] +print(binsum(a,b)) \ No newline at end of file From a797800def75b8bcee8af8031f04246640fab10e Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:47:01 +0530 Subject: [PATCH 18/66] Add python3_Jeswindany_ForgotPassword.py --- December 10/python3_Jeswindany_ForgotPassword.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 December 10/python3_Jeswindany_ForgotPassword.py diff --git a/December 10/python3_Jeswindany_ForgotPassword.py b/December 10/python3_Jeswindany_ForgotPassword.py new file mode 100644 index 0000000..469bfa1 --- /dev/null +++ b/December 10/python3_Jeswindany_ForgotPassword.py @@ -0,0 +1,9 @@ +def substring(name, a, b): + return name[a-1:a+b-1] + +data = [[100, "Shivnash Kumar"],[110,"Ragul Gupta"]] + +a,b= [int(i) for i in input().split()] + +for i,j in data: + print(substring(j,a,b)) \ No newline at end of file From 27557a3798deab538ec32078f3d3cbf6d57f3ec6 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:47:50 +0530 Subject: [PATCH 19/66] Add C++_Jeswindany_Cricmetric.c++ --- December 01/C++_Jeswindany_Cricmetric.c++ | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/December 01/C++_Jeswindany_Cricmetric.c++ b/December 01/C++_Jeswindany_Cricmetric.c++ index 59c903c..79da1fd 100644 --- a/December 01/C++_Jeswindany_Cricmetric.c++ +++ b/December 01/C++_Jeswindany_Cricmetric.c++ @@ -14,4 +14,4 @@ int main(){ } cout << total << endl; cout << highest << endl; -} \ No newline at end of file +} From 0eded3c367fc406731e4f10c3e4be7f3515c7df2 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:48:25 +0530 Subject: [PATCH 20/66] Add python3_Jeswindany_Shoppers_Choice.py From 56783ce33632add3b45f1b03d949e37753937654 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:50:34 +0530 Subject: [PATCH 21/66] Add python3_Jeswindany_Shoppers_Choice.py --- .../python3_Jeswindany_Shoppers_Choice.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {December 02 => December 02}/python3_Jeswindany_Shoppers_Choice.py (100%) diff --git a/December 02 /python3_Jeswindany_Shoppers_Choice.py b/December 02/python3_Jeswindany_Shoppers_Choice.py similarity index 100% rename from December 02 /python3_Jeswindany_Shoppers_Choice.py rename to December 02/python3_Jeswindany_Shoppers_Choice.py From 149e5074a61b4cce465eb78b4b6853a7ab226455 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:51:11 +0530 Subject: [PATCH 22/66] Add C++_Jeswindany_Sunburnt.c++ From ddafdb0e368783c63caa050aef60bea9cac18e45 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:51:42 +0530 Subject: [PATCH 23/66] Add C++_Jeswindany_Sunburnt.c++ From 10b2986c1ab646633f7e9a71b5ef6111775b1cb6 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:52:15 +0530 Subject: [PATCH 24/66] Add python3_Jeswindany_MirrorMagic.py --- December 04/python3_Jeswindany_MirrorMagic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/December 04/python3_Jeswindany_MirrorMagic.py b/December 04/python3_Jeswindany_MirrorMagic.py index 2dd34b5..61339b3 100644 --- a/December 04/python3_Jeswindany_MirrorMagic.py +++ b/December 04/python3_Jeswindany_MirrorMagic.py @@ -19,4 +19,4 @@ def palindrome(s): break else: res = "Error" -print(res) \ No newline at end of file +print(res) From 843c4bcb3c9f38da10ddf928c7d0aa9ca128c462 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:52:38 +0530 Subject: [PATCH 25/66] Add python3_Jeswindany_PeakyBlinders.py --- December 05/python3_Jeswindany_PeakyBlinders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/December 05/python3_Jeswindany_PeakyBlinders.py b/December 05/python3_Jeswindany_PeakyBlinders.py index 0321117..8f022cb 100644 --- a/December 05/python3_Jeswindany_PeakyBlinders.py +++ b/December 05/python3_Jeswindany_PeakyBlinders.py @@ -4,4 +4,4 @@ for i in loot: if(i>=avg): res_sum += i -print(res_sum) \ No newline at end of file +print(res_sum) From aceb589c860d2dca6de3d1b90464d3db8b30f055 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:53:09 +0530 Subject: [PATCH 26/66] Add python3_Jeswindany_TheLostAlgorithmScrolls.py From aff51df21e9340dc4e3c746b234631745dea42cb Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:53:40 +0530 Subject: [PATCH 27/66] Add python3_Jeswindany_TheLostAlgorithmScrolls.py From a785930148f451090d90d68d6e24e12ca652ad65 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:54:14 +0530 Subject: [PATCH 28/66] Add C++_Jeswindany_BabyBlocks.c++ --- December 07/C++_Jeswindany_BabyBlocks.c++ | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/December 07/C++_Jeswindany_BabyBlocks.c++ b/December 07/C++_Jeswindany_BabyBlocks.c++ index 3f11186..4fc301c 100644 --- a/December 07/C++_Jeswindany_BabyBlocks.c++ +++ b/December 07/C++_Jeswindany_BabyBlocks.c++ @@ -15,4 +15,4 @@ int main(){ cin >> w >> h >> r; rectangleInCircle(w,h,r); return 0; -} \ No newline at end of file +} From 7533c64e4feb9694b241bc6b243fc3343fcb09fd Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:54:40 +0530 Subject: [PATCH 29/66] Add C++_Jeswindany_TheEnchantedForest.c++ From 1788d02f73d2ebf3704ae37cddd0b2f70af5024a Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:55:04 +0530 Subject: [PATCH 30/66] Add C++_Jeswindany_camelsOnAString.c++ --- December 09/C++_Jeswindany_camelsOnAString.c++ | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/December 09/C++_Jeswindany_camelsOnAString.c++ b/December 09/C++_Jeswindany_camelsOnAString.c++ index 002af27..76ba373 100644 --- a/December 09/C++_Jeswindany_camelsOnAString.c++ +++ b/December 09/C++_Jeswindany_camelsOnAString.c++ @@ -13,4 +13,4 @@ int main(){ } cout << c; return 0; -} \ No newline at end of file +} From 4de8a450dd81fcdd4827e8a1553c3ded5562d999 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:55:54 +0530 Subject: [PATCH 31/66] Add C++_Jeswindany_TheEnchantedForest.c++ --- December 08/C++_Jeswindany_TheEnchantedForest.c++ | 1 + 1 file changed, 1 insertion(+) diff --git a/December 08/C++_Jeswindany_TheEnchantedForest.c++ b/December 08/C++_Jeswindany_TheEnchantedForest.c++ index 066a51f..753131e 100644 --- a/December 08/C++_Jeswindany_TheEnchantedForest.c++ +++ b/December 08/C++_Jeswindany_TheEnchantedForest.c++ @@ -2,6 +2,7 @@ #include using namespace std; + void find_path(int n){ int sqr[n][n]; memset(sqr, 0, sizeof(sqr)); From 86e088ec0a170e81b71b067ae1b3b1e3306c061f Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:57:09 +0530 Subject: [PATCH 32/66] Add python3_Jeswindany_TheLostAlgorithmScrolls.py --- December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py | 1 - 1 file changed, 1 deletion(-) diff --git a/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py b/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py index 36e95f0..fc0904d 100644 --- a/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py +++ b/December 06/python3_Jeswindany_TheLostAlgorithmScrolls.py @@ -22,7 +22,6 @@ def link(a, b): break if(start != ""): break - if start == "": print("No valid chain") else: From 257b9e26c35bcf340a84a21ac9703a003fd37271 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:57:34 +0530 Subject: [PATCH 33/66] Add C++_Jeswindany_Sunburnt.c++ --- December 03/C++_Jeswindany_Sunburnt.c++ | 1 - 1 file changed, 1 deletion(-) diff --git a/December 03/C++_Jeswindany_Sunburnt.c++ b/December 03/C++_Jeswindany_Sunburnt.c++ index ad40309..36a3529 100644 --- a/December 03/C++_Jeswindany_Sunburnt.c++ +++ b/December 03/C++_Jeswindany_Sunburnt.c++ @@ -1,6 +1,5 @@ #include using namespace std; - int main(){ int n; cin >> n; From eb52dd2c97d0598c1c9f79c3e26a9a986125e639 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Tue, 12 Dec 2023 18:05:34 +0530 Subject: [PATCH 34/66] Add python3_Jeswindany_TheHeist.py --- December 12/python3_Jeswindany_TheHeist.py | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 December 12/python3_Jeswindany_TheHeist.py diff --git a/December 12/python3_Jeswindany_TheHeist.py b/December 12/python3_Jeswindany_TheHeist.py new file mode 100644 index 0000000..d5fab2d --- /dev/null +++ b/December 12/python3_Jeswindany_TheHeist.py @@ -0,0 +1,25 @@ +def binarySearch(box): + l = 0 + h = len(box) - 1 + while(l <= h): + m = (l+h)//2 + if(box[m].lower() == "gold"): + return 1 + elif(box[m].lower() < "gold"): + l = m+1 + elif(box[m].lower() > "gold"): + h = m-1 + return 0 + +box1 = sorted([i.lower() for i in input().split()]) +box2 = sorted([i.lower() for i in input().split()]) +box3 = sorted([i.lower() for i in input().split()]) + +if(binarySearch(box1)): + print("Box1 Contains the Gold") +elif(binarySearch(box2)): + print("Box2 Contains the Gold") +elif(binarySearch(box3)): + print("Box3 Contains the Gold") +else: + print("Gold not Found") \ No newline at end of file From 5414c2dfa63def0ab9651c54f2f2c8eec1f80b0b Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Wed, 13 Dec 2023 18:33:22 +0530 Subject: [PATCH 35/66] Add C++_Jeswindany_CallCipher.c++ --- December 13/C++_Jeswindany_CallCipher.c++ | 58 +++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 December 13/C++_Jeswindany_CallCipher.c++ diff --git a/December 13/C++_Jeswindany_CallCipher.c++ b/December 13/C++_Jeswindany_CallCipher.c++ new file mode 100644 index 0000000..a8d8da5 --- /dev/null +++ b/December 13/C++_Jeswindany_CallCipher.c++ @@ -0,0 +1,58 @@ +#include + +#include +using namespace std; + +int textToNum(char c){ + switch(c){ + case 65: + case 66: + case 67: + return 2; + case 68: + case 69: + case 70: + return 3; + case 71: + case 72: + case 73: + return 4; + case 74: + case 75: + case 76: + return 5; + case 77: + case 78: + case 79: + return 6; + case 80: + case 81: + case 82: + case 83: + return 7; + case 84: + case 85: + case 86: + return 8; + case 87: + case 88: + case 89: + case 90: + return 9; + } +} + +int main(){ + string S; + cin >> S; + for (char i: S){ + if(i>=65 && i<=90) + cout << textToNum(i); + else if(i>=97 && i<=122) + cout << textToNum(toupper(i)); + else + cout << i; + } + cout << endl; + return 0; +} \ No newline at end of file From e147ab7699df713eea10bdc3379672ef526f547e Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Wed, 13 Dec 2023 18:45:27 +0530 Subject: [PATCH 36/66] Add python3_Jeswindany_ForgotPassword.py --- December 10/python3_Jeswindany_ForgotPassword.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/December 10/python3_Jeswindany_ForgotPassword.py b/December 10/python3_Jeswindany_ForgotPassword.py index 469bfa1..7f30bb5 100644 --- a/December 10/python3_Jeswindany_ForgotPassword.py +++ b/December 10/python3_Jeswindany_ForgotPassword.py @@ -1,9 +1,12 @@ +import re + def substring(name, a, b): return name[a-1:a+b-1] data = [[100, "Shivnash Kumar"],[110,"Ragul Gupta"]] -a,b= [int(i) for i in input().split()] +ind = re.findall('\d+',input()) +a,b= [int(i) for i in ind] for i,j in data: - print(substring(j,a,b)) \ No newline at end of file + print(substring(j,a,b)) From 74b52ada2aef4f950a979c5684165efae0124b27 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 24 Dec 2023 09:35:33 +0530 Subject: [PATCH 37/66] Add files via upload --- .../C++_Jeswindany_GoldenRuleViolation.c++ | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 December 24/C++_Jeswindany_GoldenRuleViolation.c++ diff --git a/December 24/C++_Jeswindany_GoldenRuleViolation.c++ b/December 24/C++_Jeswindany_GoldenRuleViolation.c++ new file mode 100644 index 0000000..b17c9a3 --- /dev/null +++ b/December 24/C++_Jeswindany_GoldenRuleViolation.c++ @@ -0,0 +1,32 @@ +#include +using namespace std; + +void swap(int &a, int &b){ + a = a+b; + b = a-b; + a = a-b; +} + +int bubbleSort(int arr[], int n){ + int c = 0; + for (int i = 0; i arr[j+1]){ + swap(arr[j],arr[j+1]); + c++; + } + } + } + return c; +} + +int main(){ + int n; + cin >> n; + int arr[n]; + for (int i = 0; i> arr[i]; + int count = bubbleSort(arr, n); + cout << count << endl; + return 0; +} \ No newline at end of file From eaeb7bc7af5e0bee2f71a0b48ae6479bb577c186 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 24 Dec 2023 09:36:37 +0530 Subject: [PATCH 38/66] Add C++_Jeswindany_GoldenRuleViolation.c++ --- December 24/C++_Jeswindany_GoldenRuleViolation.c++ | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/December 24/C++_Jeswindany_GoldenRuleViolation.c++ b/December 24/C++_Jeswindany_GoldenRuleViolation.c++ index b17c9a3..518c0b9 100644 --- a/December 24/C++_Jeswindany_GoldenRuleViolation.c++ +++ b/December 24/C++_Jeswindany_GoldenRuleViolation.c++ @@ -29,4 +29,4 @@ int main(){ int count = bubbleSort(arr, n); cout << count << endl; return 0; -} \ No newline at end of file +} From 8310976672c40bcec2045fe13c90367f0eb119e1 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Fri, 29 Dec 2023 10:35:32 +0530 Subject: [PATCH 39/66] Add Python_JeswinDany_CartesianWalkValidator.py --- ...ython_JeswinDany_CartesianWalkValidator.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 December 29/Python_JeswinDany_CartesianWalkValidator.py diff --git a/December 29/Python_JeswinDany_CartesianWalkValidator.py b/December 29/Python_JeswinDany_CartesianWalkValidator.py new file mode 100644 index 0000000..03e39c4 --- /dev/null +++ b/December 29/Python_JeswinDany_CartesianWalkValidator.py @@ -0,0 +1,24 @@ +directions = input().split() + +def CartesianWalkValidator(directions): + + if(len(directions) == 10): + initial = [0,0] + for i in directions: + if i == 'n': + initial[1] += 1 + elif i == 'e': + initial[0] += 1 + elif i == 'w': + initial[0] -= 1 + elif i == 's': + initial[1] -= 1 + if initial == [0,0]: + return True + else: + return False + + else: + return False + +print(CartesianWalkValidator(directions)) \ No newline at end of file From 8384074768fbc776bdd7a0dbfc6f90644f7500e0 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Fri, 29 Dec 2023 19:54:02 +0530 Subject: [PATCH 40/66] Add C++_Jeswindany_CallOfJustice.c++ --- December 14/C++_Jeswindany_CallOfJustice.c++ | 74 ++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 December 14/C++_Jeswindany_CallOfJustice.c++ diff --git a/December 14/C++_Jeswindany_CallOfJustice.c++ b/December 14/C++_Jeswindany_CallOfJustice.c++ new file mode 100644 index 0000000..438e06f --- /dev/null +++ b/December 14/C++_Jeswindany_CallOfJustice.c++ @@ -0,0 +1,74 @@ +#include +#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; + } + + findKDistanceNodes(root->left, target, k - 1, result); + 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(17); + root->left = new TreeNode(8); + root->right = new TreeNode(27); + root->left->left = new TreeNode(4); + root->left->right = new TreeNode(14); + root->left->right->left = new TreeNode(10); + root->left->right->right = new TreeNode(16); + int targetNode = 8; + int kDistance = 2; + vector output; + findTarget(root, targetNode, kDistance, output); + sort(output.begin(),output.end()); + for (int node : output) { + cout << node << " "; + } + cout << endl; + return 0; +} \ No newline at end of file From 27108f66bb735d86f8645330a95469e8739acebc Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Fri, 29 Dec 2023 19:55:19 +0530 Subject: [PATCH 41/66] Add files via upload --- December 15/python3_Jeswindany_SubsequenceSorcery.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 December 15/python3_Jeswindany_SubsequenceSorcery.py diff --git a/December 15/python3_Jeswindany_SubsequenceSorcery.py b/December 15/python3_Jeswindany_SubsequenceSorcery.py new file mode 100644 index 0000000..bdf0979 --- /dev/null +++ b/December 15/python3_Jeswindany_SubsequenceSorcery.py @@ -0,0 +1,12 @@ +def subsequence(s, sub, substr = ""): + if(len(s) == 0): + sub.append(substr) + return + subsequence(s[:-1], sub, substr + s[-1]) + subsequence(s[:-1], sub, substr) + return + +s = input() +sub = [] +subsequence(s, sub) +print(len(set(sub))) \ No newline at end of file From 493114ddc12b8102047cf898a9981c90b0a1b46e Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Fri, 29 Dec 2023 19:56:00 +0530 Subject: [PATCH 42/66] Add python3_Jeswindany_SubsequenceSorcery.py --- December 15/python3_Jeswindany_SubsequenceSorcery.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/December 15/python3_Jeswindany_SubsequenceSorcery.py b/December 15/python3_Jeswindany_SubsequenceSorcery.py index bdf0979..7169bc2 100644 --- a/December 15/python3_Jeswindany_SubsequenceSorcery.py +++ b/December 15/python3_Jeswindany_SubsequenceSorcery.py @@ -9,4 +9,5 @@ def subsequence(s, sub, substr = ""): s = input() sub = [] subsequence(s, sub) -print(len(set(sub))) \ No newline at end of file + +print(len(set(sub))) From db16a567e32ff142d8c73e77f960d82b0414d391 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Fri, 29 Dec 2023 19:59:01 +0530 Subject: [PATCH 43/66] Add Python3_Jeswindany_OutbreakDynamics.py --- .../Python3_Jeswindany_OutbreakDynamics.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 December 16/Python3_Jeswindany_OutbreakDynamics.py diff --git a/December 16/Python3_Jeswindany_OutbreakDynamics.py b/December 16/Python3_Jeswindany_OutbreakDynamics.py new file mode 100644 index 0000000..052b672 --- /dev/null +++ b/December 16/Python3_Jeswindany_OutbreakDynamics.py @@ -0,0 +1,37 @@ +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) \ No newline at end of file From 0eb32180e70531bda1e156e1abadeac46166a75d Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Fri, 29 Dec 2023 20:10:43 +0530 Subject: [PATCH 44/66] Add C++_JeswinDany_BookshelfDilemma.c++ --- .../C++_JeswinDany_BookshelfDilemma.c++ | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 December 17/C++_JeswinDany_BookshelfDilemma.c++ diff --git a/December 17/C++_JeswinDany_BookshelfDilemma.c++ b/December 17/C++_JeswinDany_BookshelfDilemma.c++ new file mode 100644 index 0000000..7b72c26 --- /dev/null +++ b/December 17/C++_JeswinDany_BookshelfDilemma.c++ @@ -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; +} \ No newline at end of file From f407199b98c6a68a591963140208508c15aa92e9 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Fri, 29 Dec 2023 20:46:06 +0530 Subject: [PATCH 45/66] Add C++_Jeswindany_RiddleMeThis.c++ --- December 21/C++_Jeswindany_RiddleMeThis.c++ | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 December 21/C++_Jeswindany_RiddleMeThis.c++ diff --git a/December 21/C++_Jeswindany_RiddleMeThis.c++ b/December 21/C++_Jeswindany_RiddleMeThis.c++ new file mode 100644 index 0000000..e2addc3 --- /dev/null +++ b/December 21/C++_Jeswindany_RiddleMeThis.c++ @@ -0,0 +1,21 @@ +#include +using namespace std; + +#include + +int main(){ + string S; + cout << "Code: "; + cin >> S; + cout << "Shift: "; + int shift; + cin >> shift; + for (int i=0; S[i]!='\0'; i++){ + char tmp = S[i]-(shift%26); + if(tmp < 65) + tmp = 90-(64-tmp); + cout << tmp; + } + cout << endl; + return 0; +} \ No newline at end of file From 7252ab01e9e8a9f99bde140cfecb71b1d349d66e Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Fri, 29 Dec 2023 20:51:07 +0530 Subject: [PATCH 46/66] Add Python_Jeswindany_HarmonyHurdle.py --- .../Python_Jeswindany_HarmonyHurdle.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 December 25/Python_Jeswindany_HarmonyHurdle.py diff --git a/December 25/Python_Jeswindany_HarmonyHurdle.py b/December 25/Python_Jeswindany_HarmonyHurdle.py new file mode 100644 index 0000000..f46eafa --- /dev/null +++ b/December 25/Python_Jeswindany_HarmonyHurdle.py @@ -0,0 +1,25 @@ +tasks = [1, 2, 3, 4, 5] +dependancies = [[], [1], [2], [3], [4,1]] +d = {} +c = 0 +t = 0 + +for i in range(len(tasks)): + d[tasks[i]] = dependancies[i] + +while(d): + t += 1 + l = [] + for i in d: + if d[i] == []: + l.append(i) + for i in l: + d.pop(i) + for i in d: + for j in d[i]: + if j in l: + d[i].remove(j) + print(d) + +print(t) + \ No newline at end of file From 0b71b7d060351acb6731076b43b0530fad3c2c88 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Fri, 29 Dec 2023 20:53:44 +0530 Subject: [PATCH 47/66] Add Python_Jeswindany_HarmonyHurdle.py --- December 25/Python_Jeswindany_HarmonyHurdle.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/December 25/Python_Jeswindany_HarmonyHurdle.py b/December 25/Python_Jeswindany_HarmonyHurdle.py index f46eafa..e878fff 100644 --- a/December 25/Python_Jeswindany_HarmonyHurdle.py +++ b/December 25/Python_Jeswindany_HarmonyHurdle.py @@ -19,7 +19,5 @@ for j in d[i]: if j in l: d[i].remove(j) - print(d) - print(t) - \ No newline at end of file + From b8fcdc598a98318ee309ab1a04daed57b951c7e2 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Fri, 29 Dec 2023 21:02:55 +0530 Subject: [PATCH 48/66] Add C++_Jeswindany_ThePhantomCycle.c++ --- .../C++_Jeswindany_ThePhantomCycle.c++ | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 December 26/C++_Jeswindany_ThePhantomCycle.c++ diff --git a/December 26/C++_Jeswindany_ThePhantomCycle.c++ b/December 26/C++_Jeswindany_ThePhantomCycle.c++ new file mode 100644 index 0000000..66ceecd --- /dev/null +++ b/December 26/C++_Jeswindany_ThePhantomCycle.c++ @@ -0,0 +1,60 @@ +#include +#include +using namespace std; + +struct node +{ + int val; + struct node *next; +}; +struct node *head = NULL; + +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; + } + } + return false; +} + +void insert(int val) +{ + 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; + } +} + +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->next->next = head; + if (detectLoop(head)) { + cout << "Cycle Found"; + } else { + cout << "No Cycle Found"; + } + + return 0; +} From 0ac2143c3c33b494125a1f1913b89026f1a11c06 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Fri, 29 Dec 2023 21:51:37 +0530 Subject: [PATCH 49/66] Add C++_Jeswindany_CircleOfEndurance.c++ --- .../C++_Jeswindany_CircleOfEndurance.c++ | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 December 27/C++_Jeswindany_CircleOfEndurance.c++ diff --git a/December 27/C++_Jeswindany_CircleOfEndurance.c++ b/December 27/C++_Jeswindany_CircleOfEndurance.c++ new file mode 100644 index 0000000..b47137f --- /dev/null +++ b/December 27/C++_Jeswindany_CircleOfEndurance.c++ @@ -0,0 +1,36 @@ +#include +using namespace std; + +int main(){ + int n; + cout << "N = "; + cin >> n; + int petrol[n]; + cout << "Petrol = "; + for (int i = 0; i < n; i++) + cin >> petrol[i]; + int distance[n]; + cout << "Distance = "; + for (int i = 0; i < n; i++) + cin >> distance[i]; + for (int i = 0; i < n; i++){ + if(petrol[i] >= distance[i]){ + int pos = i, tank = petrol[i]-distance[i]; + pos = (pos+1)%n; + while(pos != i){ + tank += petrol[pos]; + if (distance[pos] > tank){ + break; + } + tank -= distance[pos]; + pos = (pos+1)%n; + } + if (pos == i){ + cout << i+1; + return 0; + } + } + } + cout << -1; + return 0; +} \ No newline at end of file From 5ccc5f6f74567189bb0607f6bcc0ebe20dcc4216 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 31 Dec 2023 11:34:06 +0530 Subject: [PATCH 50/66] Add Python_Jeswindany_TheSellingGame.py --- .../Python_Jeswindany_TheSellingGame.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 December 28/Python_Jeswindany_TheSellingGame.py diff --git a/December 28/Python_Jeswindany_TheSellingGame.py b/December 28/Python_Jeswindany_TheSellingGame.py new file mode 100644 index 0000000..67dc358 --- /dev/null +++ b/December 28/Python_Jeswindany_TheSellingGame.py @@ -0,0 +1,32 @@ +def max_gadgets_sold(x, z, items, clients): + items.sort(key=lambda item: item['m'], 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 + +x = 3 +z = 3 +items = [ + {'k': 10, 'r': 100, 'm': 5, 'n': 110}, + {'k': 9, 'r': 200, 'm': 2, 'n': 200}, + {'k': 20, 'r': 300, 'm': 30, 'n': 300} +] + +clients = [ + {'k': 5, 'r': 110}, + {'k': 9, 'r': 500}, + {'k': 20, 'r': 400}, +] + +result = max_gadgets_sold(x, z, items, clients) +print(result) From 979ee416ed488bc361957c78d0494922dd8431c9 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 31 Dec 2023 11:38:21 +0530 Subject: [PATCH 51/66] Add C++_Jeswindany_Cricmetric.cpp --- ...++_Jeswindany_Cricmetric.c++ => C++_Jeswindany_Cricmetric.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename December 01/{C++_Jeswindany_Cricmetric.c++ => C++_Jeswindany_Cricmetric.cpp} (100%) diff --git a/December 01/C++_Jeswindany_Cricmetric.c++ b/December 01/C++_Jeswindany_Cricmetric.cpp similarity index 100% rename from December 01/C++_Jeswindany_Cricmetric.c++ rename to December 01/C++_Jeswindany_Cricmetric.cpp From b53d15a09bbdd6b2674c3b9c6ca717ba6ee48583 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 31 Dec 2023 11:38:46 +0530 Subject: [PATCH 52/66] Add C++_Jeswindany_Sunburnt.cpp --- .../{C++_Jeswindany_Sunburnt.c++ => C++_Jeswindany_Sunburnt.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename December 03/{C++_Jeswindany_Sunburnt.c++ => C++_Jeswindany_Sunburnt.cpp} (100%) diff --git a/December 03/C++_Jeswindany_Sunburnt.c++ b/December 03/C++_Jeswindany_Sunburnt.cpp similarity index 100% rename from December 03/C++_Jeswindany_Sunburnt.c++ rename to December 03/C++_Jeswindany_Sunburnt.cpp From b0e60b992d0a3e3cb86ec8494356c0f591b7530a Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 31 Dec 2023 11:39:22 +0530 Subject: [PATCH 53/66] Add C++_Jeswindany_BabyBlocks.cpp --- ...++_Jeswindany_BabyBlocks.c++ => C++_Jeswindany_BabyBlocks.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename December 07/{C++_Jeswindany_BabyBlocks.c++ => C++_Jeswindany_BabyBlocks.cpp} (100%) diff --git a/December 07/C++_Jeswindany_BabyBlocks.c++ b/December 07/C++_Jeswindany_BabyBlocks.cpp similarity index 100% rename from December 07/C++_Jeswindany_BabyBlocks.c++ rename to December 07/C++_Jeswindany_BabyBlocks.cpp From bbcdf1b913d4e78050b7d1b77a70bf555ec1b9cb Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 31 Dec 2023 11:39:42 +0530 Subject: [PATCH 54/66] Add C++_Jeswindany_TheEnchantedForest.cpp --- ...eEnchantedForest.c++ => C++_Jeswindany_TheEnchantedForest.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename December 08/{C++_Jeswindany_TheEnchantedForest.c++ => C++_Jeswindany_TheEnchantedForest.cpp} (100%) diff --git a/December 08/C++_Jeswindany_TheEnchantedForest.c++ b/December 08/C++_Jeswindany_TheEnchantedForest.cpp similarity index 100% rename from December 08/C++_Jeswindany_TheEnchantedForest.c++ rename to December 08/C++_Jeswindany_TheEnchantedForest.cpp From c4dca0f3c3cffda670b32ea87e44acd050da92ae Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 31 Dec 2023 11:40:16 +0530 Subject: [PATCH 55/66] Add C++_Jeswindany_camelsOnAString.cpp --- ...any_camelsOnAString.c++ => C++_Jeswindany_camelsOnAString.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename December 09/{C++_Jeswindany_camelsOnAString.c++ => C++_Jeswindany_camelsOnAString.cpp} (100%) diff --git a/December 09/C++_Jeswindany_camelsOnAString.c++ b/December 09/C++_Jeswindany_camelsOnAString.cpp similarity index 100% rename from December 09/C++_Jeswindany_camelsOnAString.c++ rename to December 09/C++_Jeswindany_camelsOnAString.cpp From 057f3f81f8e11e7ccbcc3cfeda273e573354d7b9 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 31 Dec 2023 11:40:40 +0530 Subject: [PATCH 56/66] Update and rename C++_Jeswindany_CallCipher.c++ to C++_Jeswindany_CallCipher.cpp --- ..._Jeswindany_CallCipher.c++ => C++_Jeswindany_CallCipher.cpp} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename December 13/{C++_Jeswindany_CallCipher.c++ => C++_Jeswindany_CallCipher.cpp} (94%) diff --git a/December 13/C++_Jeswindany_CallCipher.c++ b/December 13/C++_Jeswindany_CallCipher.cpp similarity index 94% rename from December 13/C++_Jeswindany_CallCipher.c++ rename to December 13/C++_Jeswindany_CallCipher.cpp index a8d8da5..9e974e4 100644 --- a/December 13/C++_Jeswindany_CallCipher.c++ +++ b/December 13/C++_Jeswindany_CallCipher.cpp @@ -55,4 +55,4 @@ int main(){ } cout << endl; return 0; -} \ No newline at end of file +} From bcfa193e5e1a4a54d69aaecad9729ef52cdceb33 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 31 Dec 2023 11:41:03 +0530 Subject: [PATCH 57/66] Add C++_Jeswindany_CallCipher.cpp --- December 13/C++_Jeswindany_CallCipher.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/December 13/C++_Jeswindany_CallCipher.cpp b/December 13/C++_Jeswindany_CallCipher.cpp index 9e974e4..32766a9 100644 --- a/December 13/C++_Jeswindany_CallCipher.cpp +++ b/December 13/C++_Jeswindany_CallCipher.cpp @@ -1,5 +1,4 @@ #include - #include using namespace std; From 557f5bf2ec4d0a3e1379eff7cc3f7608d62ac6ba Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 31 Dec 2023 11:41:25 +0530 Subject: [PATCH 58/66] Add C++_Jeswindany_CallOfJustice.cpp --- ...ndany_CallOfJustice.c++ => C++_Jeswindany_CallOfJustice.cpp} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename December 14/{C++_Jeswindany_CallOfJustice.c++ => C++_Jeswindany_CallOfJustice.cpp} (96%) diff --git a/December 14/C++_Jeswindany_CallOfJustice.c++ b/December 14/C++_Jeswindany_CallOfJustice.cpp similarity index 96% rename from December 14/C++_Jeswindany_CallOfJustice.c++ rename to December 14/C++_Jeswindany_CallOfJustice.cpp index 438e06f..d4df719 100644 --- a/December 14/C++_Jeswindany_CallOfJustice.c++ +++ b/December 14/C++_Jeswindany_CallOfJustice.cpp @@ -71,4 +71,4 @@ int main() { } cout << endl; return 0; -} \ No newline at end of file +} From f3b29d9a7098953f13430b0f987aa5a08979b1a6 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 31 Dec 2023 11:42:01 +0530 Subject: [PATCH 59/66] Add C++_JeswinDany_BookshelfDilemma.cpp --- ...BookshelfDilemma.c++ => C++_JeswinDany_BookshelfDilemma.cpp} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename December 17/{C++_JeswinDany_BookshelfDilemma.c++ => C++_JeswinDany_BookshelfDilemma.cpp} (93%) diff --git a/December 17/C++_JeswinDany_BookshelfDilemma.c++ b/December 17/C++_JeswinDany_BookshelfDilemma.cpp similarity index 93% rename from December 17/C++_JeswinDany_BookshelfDilemma.c++ rename to December 17/C++_JeswinDany_BookshelfDilemma.cpp index 7b72c26..9515b45 100644 --- a/December 17/C++_JeswinDany_BookshelfDilemma.c++ +++ b/December 17/C++_JeswinDany_BookshelfDilemma.cpp @@ -85,4 +85,4 @@ int main() printList(head); return 0; -} \ No newline at end of file +} From 41b388b3bc0ac65829eeef3b5cbd68aa50178a01 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 31 Dec 2023 11:45:29 +0530 Subject: [PATCH 60/66] Add C++_Jeswindany_ItsChristmasSeason.cpp --- .../C++_Jeswindany_ItsChristmasSeason.cpp | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 December 18/C++_Jeswindany_ItsChristmasSeason.cpp diff --git a/December 18/C++_Jeswindany_ItsChristmasSeason.cpp b/December 18/C++_Jeswindany_ItsChristmasSeason.cpp new file mode 100644 index 0000000..1d6f079 --- /dev/null +++ b/December 18/C++_Jeswindany_ItsChristmasSeason.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +using namespace std; + +const int MOD = 1e9 + 7; + +struct Node { + int value; + vector children; +}; + +void dfs(int node, int currSum, int X, vector& tree, vector>& dp) { + currSum = (currSum + tree[node].value) % X; + dp[node][currSum]++; + + for (int child : tree[node].children) { + dfs(child, currSum, X, tree, dp); + + for (auto it = dp[child].begin(); it != dp[child].end(); ++it) { + int remainder = (it->first + currSum) % X; + dp[node][remainder] = (dp[node][remainder] + it->second) % MOD; + } + } +} + +vector countGoodCuttings(int N, int X, vector& values, vector>& edges) { + vector tree(N); + vector> dp(N); + + for (int i = 0; i < N; ++i) { + tree[i].value = values[i]; + } + + for (const auto& edge : edges) { + int u = edge[0], v = edge[1]; + tree[u].children.push_back(v); + } + + dfs(0, 0, X, tree, dp); + vector result(N); + for (int i = 0; i < N; ++i) { + result[i] = dp[0][i % X]; + } + + return result; +} + +int main() { + int N, X; + cin >> N >> X; + + vector values(N); + for (int i = 0; i < N; ++i) { + cin >> values[i]; + } + + vector> edges(N - 1, vector(2)); + for (int i = 0; i < N - 1; ++i) { + cin >> edges[i][0] >> edges[i][1]; + } + + vector counts = countGoodCuttings(N, X, values, edges); + + for (int i = 0; i < N; ++i) { + cout << counts[i] << " "; + } + + return 0; +} \ No newline at end of file From 089e837c2f861dd3dffa10682023ee9bc2e7cf8f Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 31 Dec 2023 11:48:52 +0530 Subject: [PATCH 61/66] Add C++_Jeswindany_SymbolicSum.cpp --- December 19/C++_Jeswindany_SymbolicSum.cpp | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 December 19/C++_Jeswindany_SymbolicSum.cpp diff --git a/December 19/C++_Jeswindany_SymbolicSum.cpp b/December 19/C++_Jeswindany_SymbolicSum.cpp new file mode 100644 index 0000000..c09f445 --- /dev/null +++ b/December 19/C++_Jeswindany_SymbolicSum.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +using namespace std; + +int symbolicSum(const string& sequence) { + stack> stk; + + int multiplier = 1; + long long sum = 0; + + for (char ch : sequence) { + if (isdigit(ch)) { + sum += ch - '0'; + } else if (ch == 'X') { + stk.push({sum, multiplier}); + sum = 0; + multiplier = 1; + } else if (ch == ' ') { + continue; + } else { + multiplier = ch - '0'; + } + } + + long long symbolicSum = 0; + + while (!stk.empty()) { + auto top = stk.top(); + stk.pop(); + + symbolicSum += top.first * top.second; + } + + return symbolicSum; +} + +int main() { + string sequence = "1 X 2 X 3 X2"; + + int result = symbolicSum(sequence); + cout << result << endl; + + return 0; +} \ No newline at end of file From 38eeaee755f961a90cb072ebcedb206e2a9c9404 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 31 Dec 2023 11:56:33 +0530 Subject: [PATCH 62/66] Add Python_Jeswindany_TreasureHuntInTheIsles.py --- ...ython_Jeswindany_TreasureHuntInTheIsles.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 December 20/Python_Jeswindany_TreasureHuntInTheIsles.py diff --git a/December 20/Python_Jeswindany_TreasureHuntInTheIsles.py b/December 20/Python_Jeswindany_TreasureHuntInTheIsles.py new file mode 100644 index 0000000..8ee28a1 --- /dev/null +++ b/December 20/Python_Jeswindany_TreasureHuntInTheIsles.py @@ -0,0 +1,22 @@ +import heapq +def hunt(graph, start, end): + l = [(0, start, [start])] + while l: + a, b, c = heapq.heappop(l) + if b == end: + return c + for i, j in graph.get(b, {}).items(): + t = a + j + heapq.heappush(l, (t, i, c + [i])) + 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_cave = 'Cave_A' +end_cave = 'Cave_E' +print(hunt(graph, start_cave, end_cave)) \ No newline at end of file From c7173dd30ce0d5f5cc0c2039ec087721a280ed92 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 31 Dec 2023 12:06:42 +0530 Subject: [PATCH 63/66] Add C++_Jeswindany_RottenOranges.cpp --- December 22/C++_Jeswindany_RottenOranges.cpp | 68 ++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 December 22/C++_Jeswindany_RottenOranges.cpp diff --git a/December 22/C++_Jeswindany_RottenOranges.cpp b/December 22/C++_Jeswindany_RottenOranges.cpp new file mode 100644 index 0000000..c7640b1 --- /dev/null +++ b/December 22/C++_Jeswindany_RottenOranges.cpp @@ -0,0 +1,68 @@ +#include +#include +#include + +using namespace std; + +int orangesRotting(vector>& grid) { + int rows = grid.size(); + int cols = grid[0].size(); + + queue> rotten; + int freshOranges = 0; + int time = 0; + + for (int i = 0; i < rows; ++i) { + for (int j = 0; j < cols; ++j) { + if (grid[i][j] == 1) { + ++freshOranges; + } else if (grid[i][j] == 2) { + rotten.push({i, j}); + } + } + } + + vector> directions = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; + + while (!rotten.empty() && freshOranges > 0) { + int size = rotten.size(); + for (int i = 0; i < size; ++i) { + int x = rotten.front().first; + int y = rotten.front().second; + rotten.pop(); + + for (const auto& dir : directions) { + int newX = x + dir.first; + int newY = y + dir.second; + + if (newX >= 0 && newX < rows && newY >= 0 && newY < cols && + grid[newX][newY] == 1) { + grid[newX][newY] = 2; + rotten.push({newX, newY}); + --freshOranges; + } + } + } + if (!rotten.empty()) { + ++time; + } + } + + return (freshOranges == 0) ? time : -1; +} + +int main() { + int n, m; + cin >> n >> m; + + vector> grid(n, vector(m)); + + for (int i = 0; i < n; ++i) { + for (int j = 0; j < m; ++j) { + cin >> grid[i][j]; + } + } + + cout << orangesRotting(grid); + return 0; +} \ No newline at end of file From 381786417a924ff41c9a53d0975630cc4181bedf Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Sun, 31 Dec 2023 12:14:31 +0530 Subject: [PATCH 64/66] Add Python_Jeswindany_Dominoes.py --- December 23/Python_Jeswindany_Dominoes.py | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 December 23/Python_Jeswindany_Dominoes.py diff --git a/December 23/Python_Jeswindany_Dominoes.py b/December 23/Python_Jeswindany_Dominoes.py new file mode 100644 index 0000000..2a398c5 --- /dev/null +++ b/December 23/Python_Jeswindany_Dominoes.py @@ -0,0 +1,35 @@ +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 = int(input()) +dominos = [] +for i in range(n): + dominos.append(tuple(int(i) for i in input().split())) + +result = min_rotation_time(n, dominos) +print(result) \ No newline at end of file From f88eca687ebd4c06226eac4392470fa717914634 Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Mon, 1 Jan 2024 10:54:58 +0530 Subject: [PATCH 65/66] Add Python_Jeswindany_NQueens.py --- December 31/Python_Jeswindany_NQueens.py | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 December 31/Python_Jeswindany_NQueens.py diff --git a/December 31/Python_Jeswindany_NQueens.py b/December 31/Python_Jeswindany_NQueens.py new file mode 100644 index 0000000..133d1e1 --- /dev/null +++ b/December 31/Python_Jeswindany_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) From 8c92a18a11adf4ad0a003f65833059ca8d94a9fc Mon Sep 17 00:00:00 2001 From: Jeswin Paul Dany D <120293717+Jeswindany@users.noreply.github.com> Date: Mon, 1 Jan 2024 11:04:12 +0530 Subject: [PATCH 66/66] Add Python_Jeswindany_TreeInversions.py --- .../Python_Jeswindany_TreeInversions.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 December 30/Python_Jeswindany_TreeInversions.py diff --git a/December 30/Python_Jeswindany_TreeInversions.py b/December 30/Python_Jeswindany_TreeInversions.py new file mode 100644 index 0000000..e87d13e --- /dev/null +++ b/December 30/Python_Jeswindany_TreeInversions.py @@ -0,0 +1,51 @@ +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) # Divide by 2 to avoid double counting + 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)