From 0f4a8bdedb8c587b50db4855ce8bbb01783ea267 Mon Sep 17 00:00:00 2001 From: GREEDnim Date: Thu, 1 Dec 2022 22:06:58 +0530 Subject: [PATCH 001/408] day 1-completed --- December - 01/GREEDnim_day1_java.java | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 December - 01/GREEDnim_day1_java.java diff --git a/December - 01/GREEDnim_day1_java.java b/December - 01/GREEDnim_day1_java.java new file mode 100644 index 0000000..f5fa007 --- /dev/null +++ b/December - 01/GREEDnim_day1_java.java @@ -0,0 +1,36 @@ + +import java.util.Arrays; +import java.util.Scanner; + +public class GREEDnim_day1_java { + public static void main(String[] args) { + // Assuming the input format as follows + // first line : no of words + // for the next n lines , space seperates hexadecimal values as a string + // eg + // 1st line : 2 + // 2nd line :49 6E 76 61 64 65 + // 3rd line : 4D 69 6C 69 74 61 72 79 + Scanner in=new Scanner(System.in); + StringBuilder ans= new StringBuilder(); + int noOfWords=0; + noOfWords=Integer.parseInt(in.nextLine()); + + for(int i=0;i Date: Thu, 1 Dec 2022 22:19:07 +0530 Subject: [PATCH 002/408] in split() , found regex is more useful than normal space --- December - 01/GREEDnim_day1_java.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/December - 01/GREEDnim_day1_java.java b/December - 01/GREEDnim_day1_java.java index f5fa007..7a97d55 100644 --- a/December - 01/GREEDnim_day1_java.java +++ b/December - 01/GREEDnim_day1_java.java @@ -14,14 +14,16 @@ public static void main(String[] args) { Scanner in=new Scanner(System.in); StringBuilder ans= new StringBuilder(); int noOfWords=0; - noOfWords=Integer.parseInt(in.nextLine()); + noOfWords=Integer.parseInt(in.nextLine().strip()); for(int i=0;i Date: Thu, 1 Dec 2022 18:48:55 -0800 Subject: [PATCH 003/408] day-2 completed --- December - 02/GREEDnim_day2_java.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 December - 02/GREEDnim_day2_java.java diff --git a/December - 02/GREEDnim_day2_java.java b/December - 02/GREEDnim_day2_java.java new file mode 100644 index 0000000..3416b87 --- /dev/null +++ b/December - 02/GREEDnim_day2_java.java @@ -0,0 +1,15 @@ +package acm; + +import java.util.Scanner; + +public class GREEDnim_day2_java { + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + String input =in.next(); + + int indexOfFirstLetter=input.length()-4; + String ans=input.substring(indexOfFirstLetter,indexOfFirstLetter+2)+input.substring(0,indexOfFirstLetter); + System.out.println(ans); + + } +} From ad8845f22e95b7e2b0c73ef84b54ba522dcd3cb7 Mon Sep 17 00:00:00 2001 From: SIVADHAS S <84082104+GREEDnim@users.noreply.github.com> Date: Thu, 1 Dec 2022 18:49:14 -0800 Subject: [PATCH 004/408] Update GREEDnim_day2_java.java --- December - 02/GREEDnim_day2_java.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/December - 02/GREEDnim_day2_java.java b/December - 02/GREEDnim_day2_java.java index 3416b87..f4051a4 100644 --- a/December - 02/GREEDnim_day2_java.java +++ b/December - 02/GREEDnim_day2_java.java @@ -1,4 +1,4 @@ -package acm; + import java.util.Scanner; From 3e0d0396fa67c41e305a76c859a76493bb105a57 Mon Sep 17 00:00:00 2001 From: Sahitya A <113616944+abc123-ux@users.noreply.github.com> Date: Fri, 2 Dec 2022 22:40:54 +0530 Subject: [PATCH 005/408] updated dec 1 --- December - 01/.gitignore | 223 +++++---------------------------------- 1 file changed, 24 insertions(+), 199 deletions(-) diff --git a/December - 01/.gitignore b/December - 01/.gitignore index ac6d3a2..87a7c80 100644 --- a/December - 01/.gitignore +++ b/December - 01/.gitignore @@ -1,182 +1,30 @@ -# gitignore file for "A December of Algorithms 2022" -# 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 +#code +#include +using namespace std; +string convert_ASCII(string hex){ + string ascii = ""; + for (size_t i = 0; i < hex.length(); i += 2) + { + string part = hex.substr(i, 2); + char ch = stoul(part, nullptr, 16); + ascii += ch; + } + return ascii; +} +int main() +{ + string hex; + cout<<"enter the hex"; + cin>>hex; + cout<<"entered string is\n"< Date: Sat, 3 Dec 2022 12:37:40 +0530 Subject: [PATCH 006/408] init day 1 --- December - 01/kotlin_nijuyonkadesu.kt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 December - 01/kotlin_nijuyonkadesu.kt diff --git a/December - 01/kotlin_nijuyonkadesu.kt b/December - 01/kotlin_nijuyonkadesu.kt new file mode 100644 index 0000000..588019d --- /dev/null +++ b/December - 01/kotlin_nijuyonkadesu.kt @@ -0,0 +1,3 @@ +fun main(){ + println("hello") +} From b3d9c52009a8e838aed1fff1611859cd0302608b Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Sat, 3 Dec 2022 14:45:04 +0530 Subject: [PATCH 007/408] string to hex to string conversion - hardcoded --- December - 01/cpp_nijuyonkadesu.cpp | 43 +++++++++++++++++++++++++++ December - 01/kotlin_nijuyonkadesu.kt | 3 -- 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 December - 01/cpp_nijuyonkadesu.cpp delete mode 100644 December - 01/kotlin_nijuyonkadesu.kt diff --git a/December - 01/cpp_nijuyonkadesu.cpp b/December - 01/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..5df26a8 --- /dev/null +++ b/December - 01/cpp_nijuyonkadesu.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include + +void tokenize(std::string const &str, const char delim, + std::vector &out) +{ + size_t start; + size_t end =0 ; + size_t n = str.length(); + + while ((start = str.find_first_not_of(delim, end)) != std::string::npos) + { + end = str.find(delim, start); + out.push_back(str.substr(start, end - start)); + } +} + +int main() +{ + std::string output; + std::string s = "4D,69,6C,69,74,61,72,79"; + const char delim = ','; + + std::vector out; + tokenize(s, delim, out); + +// for (auto &s: out) { +// std::cout << s << std::endl; +// } + + for (auto &s: out) { + uint32_t chr = 0; + std::stringstream ss; + ss << std::hex<>chr; + output.push_back(static_cast(chr)); + } + std::cout< Date: Sat, 3 Dec 2022 16:23:52 +0530 Subject: [PATCH 008/408] question 3 added --- December - 03/GREEDnim_day3_java.java | 81 +++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 December - 03/GREEDnim_day3_java.java diff --git a/December - 03/GREEDnim_day3_java.java b/December - 03/GREEDnim_day3_java.java new file mode 100644 index 0000000..8556801 --- /dev/null +++ b/December - 03/GREEDnim_day3_java.java @@ -0,0 +1,81 @@ + +import java.util.Arrays; +import java.util.Scanner; + +public class GREEDnim_day3_java { + + public static void main(String[] args) + { + char[][]input=getInput(); + char[][]ans=minesweeper(input); + for(char[] arr:ans) + { + System.out.println(Arrays.toString(arr)); + } + + + + } + public static char[][] getInput() + { + Scanner in=new Scanner(System.in); + int rows=in.nextInt(); + char[][] input=new char[rows][rows]; + for(int i=0;i=0 && k=0 && arr[row-1][k]!='#') + { + int val = arr[row - 1][k] + 1; + arr[row - 1][k] = (char)val; + } + if(arr[row][k]!='#') + { + int val = arr[row][k] + 1; + arr[row ][k] = (char)val; + } + if(row+1 Date: Sun, 4 Dec 2022 08:55:42 +0530 Subject: [PATCH 009/408] day 4 completed (dynamic sliding window) --- December - 04/GREEDnim_day4_java.java | 55 +++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 December - 04/GREEDnim_day4_java.java diff --git a/December - 04/GREEDnim_day4_java.java b/December - 04/GREEDnim_day4_java.java new file mode 100644 index 0000000..fbb9a10 --- /dev/null +++ b/December - 04/GREEDnim_day4_java.java @@ -0,0 +1,55 @@ + + +import java.util.Arrays; +import java.util.Scanner; + +public class GREEDnim_day4_java { + + public static void main(String[] args) { + + // getting input; + Scanner in=new Scanner(System.in); + System.out.print("No of Days : "); + int days=in.nextInt(); + System.out.println( "Given stock market change values:"); + int[] inp=new int[days]; + for(int i=0;icurSum) + { + curSum=inp[i]; + curStartIndex=i; + } + else + { + curSum+=inp[i]; + } + curEndIndex=i; + if(curSum>maxSum) + { + maxSum=curSum; + maxStartIndex=curStartIndex; + maxEndIndex=curEndIndex; + } + } + System.out.println("Profited value : "+maxSum); + System.out.println( "proposed day to sell: Day: "+ (maxStartIndex+1) +" to Day : "+(maxEndIndex+1)); + System.out.println("stock market change values :" +Arrays.toString(Arrays.copyOfRange(inp,maxStartIndex,maxEndIndex+1))); + + + + } +} From 5aac88095e3fea48ff748a138bf2608786614608 Mon Sep 17 00:00:00 2001 From: SIVADHAS S <84082104+GREEDnim@users.noreply.github.com> Date: Sat, 3 Dec 2022 19:55:41 -0800 Subject: [PATCH 010/408] kadanes algorithm --- December - 04/GREEDnim_day4_java.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/December - 04/GREEDnim_day4_java.java b/December - 04/GREEDnim_day4_java.java index fbb9a10..1ced3ad 100644 --- a/December - 04/GREEDnim_day4_java.java +++ b/December - 04/GREEDnim_day4_java.java @@ -17,18 +17,20 @@ public static void main(String[] args) { { inp[i]=in.nextInt(); } + + // kadanes algorithm int maxSum=Integer.MIN_VALUE; - int maxStartIndex=0; - int maxEndIndex=0; + int maxStartIndex=Integer.MIN_VALUE; + int maxEndIndex=Integer.MIN_VALUE; - int curSum=0; - int curStartIndex=0; - int curEndIndex=0; + int curSum=Integer.MIN_VALUE; + int curStartIndex=Integer.MIN_VALUE; + int curEndIndex=Integer.MIN_VALUE; System.out.println(Arrays.toString(inp)); for(int i=0;icurSum) + if(curSum<=0 && inp[i]>curSum) { curSum=inp[i]; curStartIndex=i; From 3262bf7fa21eb3dc02a37e3afb257212239b447a Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Sun, 4 Dec 2022 21:46:46 +0530 Subject: [PATCH 011/408] secret language problem naive ans --- December - 02/cpp_nijuyonkadesu.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 December - 02/cpp_nijuyonkadesu.cpp diff --git a/December - 02/cpp_nijuyonkadesu.cpp b/December - 02/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..db6a298 --- /dev/null +++ b/December - 02/cpp_nijuyonkadesu.cpp @@ -0,0 +1,23 @@ +#include +#include +#include + +using namespace std; +void secret(string &msg) { + msg.pop_back(); + msg.pop_back(); + msg.insert(0, 1, msg[msg.length()-1]); + msg.insert(0, 1, msg[msg.length()-2]); + // ^ size of string + // ^ pos + msg.pop_back(); + msg.pop_back(); +} + +int main(){ + string msg; + cin>>msg; + secret(msg); + cout< Date: Sun, 4 Dec 2022 22:47:12 +0530 Subject: [PATCH 012/408] updated dec -02 --- December - 02/.gitignore | 215 +++------------------------------------ 1 file changed, 16 insertions(+), 199 deletions(-) diff --git a/December - 02/.gitignore b/December - 02/.gitignore index ac6d3a2..7338e97 100644 --- a/December - 02/.gitignore +++ b/December - 02/.gitignore @@ -1,179 +1,3 @@ -# gitignore file for "A December of Algorithms 2022" -# 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 @@ -206,26 +30,19 @@ doc/api/ *.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 +#include +#include +using namespace std; +int main() +{ + string ae="ae"; + string x; + char first,sec; + cout<<"enter a string"; + getline(cin,x); + first=x[0]; + sec=x[1]; + cout< Date: Mon, 5 Dec 2022 18:16:18 +0530 Subject: [PATCH 013/408] minesweep brute force --- December - 03/cpp_nijuyonkadesu.cpp | 87 +++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 December - 03/cpp_nijuyonkadesu.cpp diff --git a/December - 03/cpp_nijuyonkadesu.cpp b/December - 03/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..a3ec1af --- /dev/null +++ b/December - 03/cpp_nijuyonkadesu.cpp @@ -0,0 +1,87 @@ +#include +#include +using namespace std; +bool yLow(int y) { + return y>=0; +} +bool yHigh(int y, int size) { + return y=0; +} +bool xHigh(int x, int size) { + return x> &arr) { + int n = arr.size(); + for(int i=0; i>n; + // Create char matrix, default value is 0 + vector> arr(n, vector (n, '0')); + char inp; + + for(int i=0; i>inp; + if(inp == '#') + arr[i][j]=inp; + } + } + + minesweep(arr); + + for(int i=0; i Date: Mon, 5 Dec 2022 19:02:35 +0530 Subject: [PATCH 014/408] price and income --- December - 05/GREEDnim_day5_java.java | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 December - 05/GREEDnim_day5_java.java diff --git a/December - 05/GREEDnim_day5_java.java b/December - 05/GREEDnim_day5_java.java new file mode 100644 index 0000000..1672b40 --- /dev/null +++ b/December - 05/GREEDnim_day5_java.java @@ -0,0 +1,29 @@ +package acm; + +import java.util.Scanner; + +public class GREEDnim_day5_java { + + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + System.out.print("IF INCOME :"); + int income=in.nextInt(); + + int fuelPrize=75; + double amountSpent=0; + for(int i=1;i<32;i++) + { + + if(i%3==0) fuelPrize+=3; + if(i%5==0) fuelPrize-=2; + + amountSpent+=(fuelPrize*2); + + } + double tenPercentOfIncome= (10.0/100.0)*income; + System.out.println("If EXPENSE = "+amountSpent +" "+tenPercentOfIncome); + if(amountSpent>tenPercentOfIncome) System.out.println("EXPENDITURE EXCEEDING LIMIT"); + else System.out.println("EXPENDITURE WITHIN LIMIT"); + + } +} From 2bffa224d4c38defcbccb592f0216b6521e1e6c3 Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Mon, 5 Dec 2022 22:18:02 +0530 Subject: [PATCH 015/408] max sub array using kadane's alog --- December - 04/cpp_nijuyonkadesu.cpp | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 December - 04/cpp_nijuyonkadesu.cpp diff --git a/December - 04/cpp_nijuyonkadesu.cpp b/December - 04/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..cf08bc2 --- /dev/null +++ b/December - 04/cpp_nijuyonkadesu.cpp @@ -0,0 +1,40 @@ +#include +#include +#include + +using namespace std; + +vector maxProfit(vector &history) { + int days = history.size(); + int start=0, end; + int localMax = 0, overallMax = INT_MIN; // -infinity + for (int i=0; i overallMax) { + overallMax = localMax; + end = i; + } + } + vector result { overallMax, start, end }; + return result; +} + +int main(){ + int days; + cin>>days; + vector history(days); + for(int i=0; i>history[i]; + + vector result = maxProfit(history); + cout<<"Max profit: "<< result[0]; + cout<<"\n Proposed days to sell "< Date: Tue, 6 Dec 2022 17:58:34 +0530 Subject: [PATCH 016/408] day 6 (swapped) --- December - 06/GREEDnim_day6_java.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 December - 06/GREEDnim_day6_java.java diff --git a/December - 06/GREEDnim_day6_java.java b/December - 06/GREEDnim_day6_java.java new file mode 100644 index 0000000..84e6f5c --- /dev/null +++ b/December - 06/GREEDnim_day6_java.java @@ -0,0 +1,20 @@ +package acm; + +import java.util.Scanner; + +public class GREEDnim_day6_java +{ + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + int pos=in.nextInt(); + + // why do we need this array? we only need two numbers. + int[]arr=new int[pos]; + for (int i = 0; i < pos; i++) { + arr[i]=in.nextInt(); + } + + if(arr[pos-1]>=arr[0]) System.out.println("PLAYER 2 WINS"); + else System.out.println("PLAYER 1 WINS"); + } +} From bacfe39be9b26fed4518781676683207243f6f99 Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Wed, 7 Dec 2022 19:10:01 +0530 Subject: [PATCH 017/408] misspend problem with simple loop --- December - 05/cpp_nijuyonkadesu.cpp | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 December - 05/cpp_nijuyonkadesu.cpp diff --git a/December - 05/cpp_nijuyonkadesu.cpp b/December - 05/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..aa34105 --- /dev/null +++ b/December - 05/cpp_nijuyonkadesu.cpp @@ -0,0 +1,33 @@ +#include + +using namespace std; + +void alertOnCrossThreshold(){ + cout<<"\nEXPENDITURE EXCEEDING LIMIT\n"; +} + +unsigned long int monthlyExpenditure(unsigned long int &price) { + unsigned long int expenditure = 0; + unsigned long int todayPrice=0; + + for(int i=1; i<=31; i++){ + todayPrice = price; + if(i%3==0) todayPrice+=3; + if(i%5==0) todayPrice-=2; + + expenditure+=(2*todayPrice); + } + if(50000/10>price; + unsigned long int expenditure = monthlyExpenditure(price); + + cout<<"Expenditure="< Date: Wed, 7 Dec 2022 19:43:41 +0530 Subject: [PATCH 018/408] day 5 updated --- December - 03/GREEDnim_day3_java.java | 23 +++++++++-------------- December - 05/GREEDnim_day5_java.java | 17 +++++++++++------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/December - 03/GREEDnim_day3_java.java b/December - 03/GREEDnim_day3_java.java index 8556801..3ef05ec 100644 --- a/December - 03/GREEDnim_day3_java.java +++ b/December - 03/GREEDnim_day3_java.java @@ -51,31 +51,26 @@ public static void makeChanges(char[][]arr,int row,int col) { arr[row][col]='#'; int i=0; - for(int k=col-1;i<3;i++) //for prev row + for(int k=col-1;i<3;i++) //for each column { - if(k>=0 && k=0 && arr[row-1][k]!='#') + if (k >= 0 && k < arr[0].length) { + if (row - 1 >= 0 && arr[row - 1][k] != '#') // for prev row { int val = arr[row - 1][k] + 1; - arr[row - 1][k] = (char)val; + arr[row - 1][k] = (char) val; } - if(arr[row][k]!='#') + if (arr[row][k] != '#') // for cur row { int val = arr[row][k] + 1; - arr[row ][k] = (char)val; + arr[row][k] = (char) val; } - if(row+1 Date: Wed, 7 Dec 2022 21:01:49 +0530 Subject: [PATCH 019/408] Swapped game using vectors --- December - 06/cpp_nijuyonkadesu.cpp | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 December - 06/cpp_nijuyonkadesu.cpp diff --git a/December - 06/cpp_nijuyonkadesu.cpp b/December - 06/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..6d9f100 --- /dev/null +++ b/December - 06/cpp_nijuyonkadesu.cpp @@ -0,0 +1,52 @@ +#include +#include +#include + +using namespace std; + +int gameLoop(vector&); + +int main(){ + // get size + int n; + cin>>n; + vector playground(n, 0); + + for(auto it=playground.begin(); it>*it; + } + cout<<"\nPlayer "< &playground){ + int position=0; + int winner=0; + do{ + cout<<"Player 01: "; + cin>>position; + (*playground.begin()--); + if(--(*playground.begin())==0){ + winner = 1; + break; + } + + iter_swap(playground.begin(), playground.begin()+position); + + cout<<"Player 02: "; + cin>>position; + if(--(*playground.begin())==0){ + winner = 2; + break; + } + + iter_swap(playground.begin(), playground.begin()+position); + }while(1); + + for(auto i: playground) + cout< Date: Wed, 7 Dec 2022 21:08:30 +0530 Subject: [PATCH 020/408] updated dec -07 --- December - 07/.gitignore | 155 ++++++++++++--------------------------- 1 file changed, 46 insertions(+), 109 deletions(-) diff --git a/December - 07/.gitignore b/December - 07/.gitignore index ac6d3a2..f8e3d49 100644 --- a/December - 07/.gitignore +++ b/December - 07/.gitignore @@ -1,7 +1,3 @@ -# gitignore file for "A December of Algorithms 2022" -# 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] @@ -10,10 +6,6 @@ __pycache__/ # C extensions *.so -# node.js -/node_modules -package-lock.json - # Distribution / packaging .Python build/ @@ -41,6 +33,45 @@ MANIFEST *.manifest *.spec +#code +class Solution(object): + def exist(self, board, word): + n =len(board) + m = len(board[0]) + for i in range(n): + for j in range(m): + if word[0] == board[i][j]: + if self.find(board,word,i,j): + return True + return False + def find(self, board,word,row,col,i=0): + if i== len(word): + return True + if row>= len(board) or row <0 or col >=len(board[0]) or col<0 or word[i]!=board[row][col]: + return False + board[row][col] = '*' + res = self.find(board,word,row+1,col,i+1) or self.find(board,word,row-1,col,i+1) or self.find(board,word,row,col+1,i+1) or self.find(board,word,row,col-1,i+1) + board[row][col] = word[i] + return res +ob1 = Solution() +word1=input("enter the word") +print(ob1.exist([ + ['A','S','S','E','R','T','I','V','E','N','E','S','S','L','J'], + ['C','P','O','G','O','O','D','P','O','S','I','T','I','V','E'], + ['O','P','E','N','B','M','U','R','E','W','O','P','R','P','S'], + ['M','E','D','I','A','T','I','O','N','E','L','D','I','O','G'], + ['M','A','A','S','R','E','G','J','E','W','I','N','W','I','N'], + ['U','C','I','A','E','M','O','E','E','C','S','K','E','N','I'], + ['N','E','M','R','S','H','A','C','D','V','T','W','T','T','L'], + ['I','T','E','H','O','T','L','T','S','T','E','R','A','O','E'], + ['C','A','S','P','L','G','L','S','I','U','N','E','R','F','E'], + ['A','I','S','A','U','S','Y','T','O','I','S','E','V','F','S'], + ['T','T','A','R','T','D','O','C','E','N','P','P','I','H','D'], + ['I','O','G','A','I','G','U','P','Y','M','G','O','O','E','E'], + ['O','G','E','P','O','A','F','P','Q','I','E','N','O','W','A'], + ['N','E','C','O','N','F','L','I','C','T','S','D','C','E','R'], + ['F','N','H','T','C','A','T','N','O','C','E','Y','E','B','T']],word1)) +#code # Installer logs pip-log.txt pip-delete-this-directory.txt @@ -93,7 +124,13 @@ ipython_config.py .python-version # pipenv -Pipfile.lock +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff @@ -129,103 +166,3 @@ 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 6c8769f14b083985a735f1d96adbdbf19b36dd96 Mon Sep 17 00:00:00 2001 From: GREEDnim Date: Wed, 7 Dec 2022 22:33:10 +0530 Subject: [PATCH 021/408] day 7 - recursive search --- December - 07/GREEDnim_day7_java.java | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 December - 07/GREEDnim_day7_java.java diff --git a/December - 07/GREEDnim_day7_java.java b/December - 07/GREEDnim_day7_java.java new file mode 100644 index 0000000..ae54c22 --- /dev/null +++ b/December - 07/GREEDnim_day7_java.java @@ -0,0 +1,50 @@ +package acm; + +import java.util.Scanner; + +public class GREEDnim_day7_java { + + static char[][] grid; + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + grid=new char[15][15]; + String a="ASSERTIVENESSLJCFOGOODPOSITIVEOPENBMUREW0PRPSMEDIATIONELDIOGMAASREGJEWINWINUCIAEMOEECSKENINEMRSHACDVTWTTLITEHOTLTSTERAOECASPLGLSIUNERFEAISAUSYTPOISEVFTTARTTDOCENPPIHIOGAIGUPYMGOOEEOGEPOAFPQIENOWANECONFLICTSDCERFNHTCATNOCEYEBT"; +// System.out.println(a.length()); + int index=0; + for(int i=0;i<15;i++) + { + for(int j=0;j<15;j++) + { + grid[i][j]=a.charAt(index++); +// System.out.print(grid[i][j]); + } +// System.out.println(); + } + String inp=in.next(); + boolean done=false; + for(int i=0;i<15;i++) + { + for(int j=0;j<15;j++) + { + if(grid[i][j]==inp.charAt(0)) + { + + done=findWord(inp,1,i+0,j+1) || findWord(inp,1,i+1,j+0); +// System.out.println(i+" "+j+" "+done); + if(done) break; + } + } + if(done) break; + } + if(done) System.out.println("FOUND"); + else System.out.println("NOT FOUND"); + + } + public static boolean findWord(String s,int index,int row,int col) + { + if(index==s.length()) return true; + char c=s.charAt(index); + if( row>=15 || col>=15 || c!=grid[row][col]) return false; + return findWord(s,index+1,row+1,col) || findWord(s,index+1,row,col+1); + } +} From f502891add99c21effb01121ca3bdb38ad3dc3ff Mon Sep 17 00:00:00 2001 From: GREEDnim Date: Wed, 7 Dec 2022 23:20:34 +0530 Subject: [PATCH 022/408] works of both directions on both axis (recursive-backtracking) --- December - 07/GREEDnim_day7_java.java | 36 ++++++++++++++++----------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/December - 07/GREEDnim_day7_java.java b/December - 07/GREEDnim_day7_java.java index ae54c22..7e2e0e9 100644 --- a/December - 07/GREEDnim_day7_java.java +++ b/December - 07/GREEDnim_day7_java.java @@ -5,22 +5,18 @@ public class GREEDnim_day7_java { static char[][] grid; + static boolean[][] checker; public static void main(String[] args) { Scanner in=new Scanner(System.in); + String inp=in.next(); grid=new char[15][15]; - String a="ASSERTIVENESSLJCFOGOODPOSITIVEOPENBMUREW0PRPSMEDIATIONELDIOGMAASREGJEWINWINUCIAEMOEECSKENINEMRSHACDVTWTTLITEHOTLTSTERAOECASPLGLSIUNERFEAISAUSYTPOISEVFTTARTTDOCENPPIHIOGAIGUPYMGOOEEOGEPOAFPQIENOWANECONFLICTSDCERFNHTCATNOCEYEBT"; -// System.out.println(a.length()); + checker=new boolean[15][15]; + String a="ASSERTIVENESSLJCFOGOODPOSITIVEOPENBMUREWOPRPSMEDIATIONELDIOGMAASREGJEWINWINUCIAEMOEECSKENINEMRSHACDVTWTTLITEHOTLTSTERAOECASPLGLSIUNERFEAISAUSYTPOISEVFTTARTTDOCENPPIHIOGAIGUPYMGOOEEOGEPOAFPQIENOWANECONFLICTSDCERFNHTCATNOCEYEBT"; int index=0; for(int i=0;i<15;i++) { - for(int j=0;j<15;j++) - { - grid[i][j]=a.charAt(index++); -// System.out.print(grid[i][j]); - } -// System.out.println(); + for(int j=0;j<15;j++) grid[i][j]=a.charAt(index++); } - String inp=in.next(); boolean done=false; for(int i=0;i<15;i++) { @@ -28,9 +24,7 @@ public static void main(String[] args) { { if(grid[i][j]==inp.charAt(0)) { - - done=findWord(inp,1,i+0,j+1) || findWord(inp,1,i+1,j+0); -// System.out.println(i+" "+j+" "+done); + done=findWord(inp,1,i,j+1,1)||findWord(inp,1,i,j-1,1)||findWord(inp,1,i+1,j,0)||findWord(inp,1,i-1,j,0); if(done) break; } } @@ -40,11 +34,23 @@ public static void main(String[] args) { else System.out.println("NOT FOUND"); } - public static boolean findWord(String s,int index,int row,int col) + public static boolean findWord(String s,int index,int row,int col,int axis) { + if(index==s.length()) return true; char c=s.charAt(index); - if( row>=15 || col>=15 || c!=grid[row][col]) return false; - return findWord(s,index+1,row+1,col) || findWord(s,index+1,row,col+1); + if( row>=15 || col>=15 || row<0|| col<0 || c!=grid[row][col] || checker[row][col]) return false; + checker[row][col]=true; + boolean ans; + if(axis==0) + { + ans=findWord(s,index+1,row+1,col,0)||findWord(s,index+1,row-1,col,0); + } + else{ + ans=findWord(s,index+1,row,col+1,1)||findWord(s,index+1,row,col-1,1); + } + checker[row][col]=false; + return ans; } } +//COMMUNICATION \ No newline at end of file From 70b513cde5ba3459bcad4366c6edc90e57866371 Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Thu, 8 Dec 2022 01:07:49 +0530 Subject: [PATCH 023/408] word map with random values --- December - 07/cpp_nijuyonkadesu.cpp | 83 +++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 December - 07/cpp_nijuyonkadesu.cpp diff --git a/December - 07/cpp_nijuyonkadesu.cpp b/December - 07/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..89c93d8 --- /dev/null +++ b/December - 07/cpp_nijuyonkadesu.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include +#include + +using namespace std; + +void fillRandomCharacters(vector>&, int); +bool searchForWord(vector>&, int, string); + +int main(){ + vector> wordpool; + int rows=15; + fillRandomCharacters(wordpool, rows); + for(auto row: wordpool){ + for(int i=0; i>query; + + if(searchForWord(wordpool, rows, query)) + cout<<"FOUND\n"; + else + cout<<"NOT FOUND\n"; + + return 0; +} + +bool searchForWord(vector> &wordpool, int rows, string key){ + // points to a letter in key + int letter_ptr_horizontal=0; + int letter_ptr_vertical=0; + + for(int i=0; i> &wordpool, int rows){ + // create an instance of an engine, which generate seed for Mersenne twister engine. + // std::random_device generates non-deterministic random int + random_device rnd_device; + + // Specify the engine and distribution. + mt19937 mersenne_engine {rnd_device()}; + uniform_int_distribution dist {65, 90}; + + // [captured]() {..} is lambda function in cpp + auto gen = [&dist, &mersenne_engine](){ + return static_cast(dist(mersenne_engine)); + }; + + vector vec(rows); + for(int i=0;i Date: Thu, 8 Dec 2022 07:56:03 +0530 Subject: [PATCH 024/408] found out the words can also be of different axis and different direction --- December - 07/GREEDnim_day7_java.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/December - 07/GREEDnim_day7_java.java b/December - 07/GREEDnim_day7_java.java index 7e2e0e9..c5ea0c9 100644 --- a/December - 07/GREEDnim_day7_java.java +++ b/December - 07/GREEDnim_day7_java.java @@ -24,7 +24,7 @@ public static void main(String[] args) { { if(grid[i][j]==inp.charAt(0)) { - done=findWord(inp,1,i,j+1,1)||findWord(inp,1,i,j-1,1)||findWord(inp,1,i+1,j,0)||findWord(inp,1,i-1,j,0); + done=findWord(inp,0,i,j); if(done) break; } } @@ -34,7 +34,7 @@ public static void main(String[] args) { else System.out.println("NOT FOUND"); } - public static boolean findWord(String s,int index,int row,int col,int axis) + public static boolean findWord(String s,int index,int row,int col) { if(index==s.length()) return true; @@ -42,13 +42,7 @@ public static boolean findWord(String s,int index,int row,int col,int axis) if( row>=15 || col>=15 || row<0|| col<0 || c!=grid[row][col] || checker[row][col]) return false; checker[row][col]=true; boolean ans; - if(axis==0) - { - ans=findWord(s,index+1,row+1,col,0)||findWord(s,index+1,row-1,col,0); - } - else{ - ans=findWord(s,index+1,row,col+1,1)||findWord(s,index+1,row,col-1,1); - } + ans=findWord(s,index+1,row+1,col)||findWord(s,index+1,row-1, col)||findWord(s,index+1,row,col+1)||findWord(s,index+1,row,col-1); checker[row][col]=false; return ans; } From 6f23c20e5375a61fe6f3386779c6cc1d3dece11f Mon Sep 17 00:00:00 2001 From: Sahitya A <113616944+abc123-ux@users.noreply.github.com> Date: Thu, 8 Dec 2022 21:18:31 +0530 Subject: [PATCH 025/408] updated dec-08 --- December - 08/.gitignore | 120 +++++---------------------------------- 1 file changed, 14 insertions(+), 106 deletions(-) diff --git a/December - 08/.gitignore b/December - 08/.gitignore index ac6d3a2..6661619 100644 --- a/December - 08/.gitignore +++ b/December - 08/.gitignore @@ -1,7 +1,3 @@ -# gitignore file for "A December of Algorithms 2022" -# 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] @@ -10,10 +6,6 @@ __pycache__/ # C extensions *.so -# node.js -/node_modules -package-lock.json - # Distribution / packaging .Python build/ @@ -93,7 +85,13 @@ ipython_config.py .python-version # pipenv -Pipfile.lock +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff @@ -130,102 +128,12 @@ 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 +def solve(s): + s = list(s) + for i in range(0, len(s)-1, 2): + s[i], s[i+1] = s[i+1], s[i] -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* + return ''.join(s) -# 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 +s = input("enter string") +print(solve(s)) From 73f24be021068e3984074c3d2f297823d3d0711a Mon Sep 17 00:00:00 2001 From: GREEDnim Date: Thu, 8 Dec 2022 22:19:26 +0530 Subject: [PATCH 026/408] day 8 added , swapping characters --- December - 07/GREEDnim_day7_java.java | 3 ++- December - 08/GREEDnim_day8_java.java | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 December - 08/GREEDnim_day8_java.java diff --git a/December - 07/GREEDnim_day7_java.java b/December - 07/GREEDnim_day7_java.java index c5ea0c9..d749cae 100644 --- a/December - 07/GREEDnim_day7_java.java +++ b/December - 07/GREEDnim_day7_java.java @@ -45,6 +45,7 @@ public static boolean findWord(String s,int index,int row,int col) ans=findWord(s,index+1,row+1,col)||findWord(s,index+1,row-1, col)||findWord(s,index+1,row,col+1)||findWord(s,index+1,row,col-1); checker[row][col]=false; return ans; + } } -//COMMUNICATION \ No newline at end of file + diff --git a/December - 08/GREEDnim_day8_java.java b/December - 08/GREEDnim_day8_java.java new file mode 100644 index 0000000..3c7ab1f --- /dev/null +++ b/December - 08/GREEDnim_day8_java.java @@ -0,0 +1,18 @@ +package acm; + +import java.util.Scanner; + +public class GREEDnim_day8_java { + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + StringBuilder inp=new StringBuilder(in.next()); + for(int i=0;i+1 Date: Thu, 8 Dec 2022 22:20:58 +0530 Subject: [PATCH 027/408] day 7 added , backtracking --- December - 07/GREEDnim_day7_java.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/December - 07/GREEDnim_day7_java.java b/December - 07/GREEDnim_day7_java.java index d749cae..91b5966 100644 --- a/December - 07/GREEDnim_day7_java.java +++ b/December - 07/GREEDnim_day7_java.java @@ -36,16 +36,14 @@ public static void main(String[] args) { } public static boolean findWord(String s,int index,int row,int col) { - if(index==s.length()) return true; char c=s.charAt(index); if( row>=15 || col>=15 || row<0|| col<0 || c!=grid[row][col] || checker[row][col]) return false; checker[row][col]=true; boolean ans; - ans=findWord(s,index+1,row+1,col)||findWord(s,index+1,row-1, col)||findWord(s,index+1,row,col+1)||findWord(s,index+1,row,col-1); + ans=findWord(s,index+1,row+1,col)||findWord(s,index+1,row-1, col)||findWord(s,index+1,row,col+1)||findWord(s,index+1,row,col-1); checker[row][col]=false; return ans; - } } From 0aaeda75ae498cad2fbf43dd68a55a6042a6a68a Mon Sep 17 00:00:00 2001 From: Sahitya A <113616944+abc123-ux@users.noreply.github.com> Date: Fri, 9 Dec 2022 12:22:14 +0530 Subject: [PATCH 028/408] updated dec-09 code is at the end(line 131-line 152) --- December - 09/.gitignore | 139 +++++++++------------------------------ 1 file changed, 30 insertions(+), 109 deletions(-) diff --git a/December - 09/.gitignore b/December - 09/.gitignore index ac6d3a2..f065d19 100644 --- a/December - 09/.gitignore +++ b/December - 09/.gitignore @@ -1,7 +1,3 @@ -# gitignore file for "A December of Algorithms 2022" -# 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] @@ -10,10 +6,6 @@ __pycache__/ # C extensions *.so -# node.js -/node_modules -package-lock.json - # Distribution / packaging .Python build/ @@ -93,7 +85,13 @@ ipython_config.py .python-version # pipenv -Pipfile.lock +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff @@ -129,103 +127,26 @@ 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 +#code +n=int(input("enter the number of words")) +string1=input("enter sentence") +print(string1) +s=string1.split() +print(s) +max=len(s[0]) +for i in range (n): + if len(s[i])>max: + max=len(s[i]) +print(max) +for i in range (n): + if(len(s[i])%2!=0 and len(s[i])==max) : + c=0 + print(s[i]) + print("winner") + break + else: + c=1 + +if c==1: + print("better luck next time") +#code From e522f2f00cea1877960ecd2317e128866197cce0 Mon Sep 17 00:00:00 2001 From: GREEDnim Date: Fri, 9 Dec 2022 16:16:00 +0530 Subject: [PATCH 029/408] day 9 added, max string length odd --- December - 09/GREEDnim_day9_java.java | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 December - 09/GREEDnim_day9_java.java diff --git a/December - 09/GREEDnim_day9_java.java b/December - 09/GREEDnim_day9_java.java new file mode 100644 index 0000000..0018fc7 --- /dev/null +++ b/December - 09/GREEDnim_day9_java.java @@ -0,0 +1,29 @@ +package acm; + +import java.util.Scanner; + +public class GREEDnim_day9_java { + + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + int size=in.nextInt(); + String[] inp=new String[size]; + int maxLength=0; + int ans=-1; + for(int i=0;i maxLength) + { + maxLength=inp[i].length(); + ans=i; + } + } + } + if(ans==-1) System.out.println("Better luck next time"); + System.out.println(inp[ans]); + } +} From 5a0bb6ddb5b7f7c21bbb7f65dbef772cbf67c6af Mon Sep 17 00:00:00 2001 From: sruthi-v04 <119495356+sruthi-v04@users.noreply.github.com> Date: Sat, 10 Dec 2022 18:27:30 +0530 Subject: [PATCH 030/408] Update README.md --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index 1d6ac56..436ac1b 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Check out our FAQ for more information. - [**December 8 - Aptitude Check!**](#december-8---aptitude-check) - [**December 9 - Kochouseph Konundrum!**](#december-9---kochouseph-konundrum) - [**December 10 - Play with words**](#december-10---play-with-words) + - [**December 11 - Monkey jump**](#december-11---monkey-jump) - [**FAQ**](#faq) @@ -620,6 +621,39 @@ S contains only lowercase Latin characters, i.e, the characters {a,b,c…….z} - [String in Java](https://www.geeksforgeeks.org/strings-in-java/) ---- +### December 11 - Monkey jump +#### Problem Statement + +A list is provided with a sequence of characters ‘_’ and ‘~’ in it Eg = [‘_’,’_’,’~’,’_’]. The character ‘_’ represents land and the character ‘~’ represents water. A monkey can move 1 step or 2 steps at a time. Another list is provided which contains the step that the monkey took Eg[1,1,2,1,2]. Whenever the monkey touches the water. The game is over and the score must be returned. Calculate the Jumps the monkey took before touching the water's surface. + +

+ +Input 1: + +[‘’_’,’~’,’_’,’_’,’_’,’_’,’~’,’_’,’_’,’~’,’_’,’~’] + +Output 1: + +Score = 8 + +Input 2: + +[‘’_’,’~’,’_’,’~’,’_’,’_’,’~’,’_’,’_’,’~’,’_’,’~’] + +Output 2: + +Score =2 + + +Explanation : + +The input is a combination of ‘ _’ and ‘~’ representing land and water respectively. +2 jumps indicate, for example, initially being on position 1 and ending up on position 3 without landing on position 2 in between. + +Monkey takes two jumps as first move and three single jumps as next moves. But after taking two jumps the monkey touches the water . +The jump sequence: [2,1,1,1,2,1,1,1,1] +So the total jump count is 8. + FAQ ====== From 6466f67a779236d1ccb2c4f04738567d8dffe2e8 Mon Sep 17 00:00:00 2001 From: GREEDnim Date: Sat, 10 Dec 2022 18:36:09 +0530 Subject: [PATCH 031/408] day 10 - vowels - hashSet --- December - 10/GREEDnim_day10_java.java | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 December - 10/GREEDnim_day10_java.java diff --git a/December - 10/GREEDnim_day10_java.java b/December - 10/GREEDnim_day10_java.java new file mode 100644 index 0000000..38fc97a --- /dev/null +++ b/December - 10/GREEDnim_day10_java.java @@ -0,0 +1,35 @@ +package acm; + +import java.util.HashSet; +import java.util.Scanner; + +public class GREEDnim_day10_java { + public static void main(String[] args) { + HashSetvowels=new HashSet<>(); + char[] vow={'a','e','i','o','u'}; + for(char e:vow) vowels.add(e); + Scanner in=new Scanner(System.in); + int t=in.nextInt(); + + for(int j=0;j=4) + { + flag=true; + break; + } + } + if(flag) System.out.println("NO"); + else System.out.println("YES"); + } + + } +} From e0e952ff1e2f11141c7ee3afafab1b47d4cebed3 Mon Sep 17 00:00:00 2001 From: sruthi-v04 <119495356+sruthi-v04@users.noreply.github.com> Date: Sat, 10 Dec 2022 18:45:40 +0530 Subject: [PATCH 032/408] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 436ac1b..982967d 100644 --- a/README.md +++ b/README.md @@ -626,8 +626,9 @@ S contains only lowercase Latin characters, i.e, the characters {a,b,c…….z} A list is provided with a sequence of characters ‘_’ and ‘~’ in it Eg = [‘_’,’_’,’~’,’_’]. The character ‘_’ represents land and the character ‘~’ represents water. A monkey can move 1 step or 2 steps at a time. Another list is provided which contains the step that the monkey took Eg[1,1,2,1,2]. Whenever the monkey touches the water. The game is over and the score must be returned. Calculate the Jumps the monkey took before touching the water's surface. -

+

+ Input 1: [‘’_’,’~’,’_’,’_’,’_’,’_’,’~’,’_’,’_’,’~’,’_’,’~’] From 87fc211db708a167289f23c266aacec3e5a97319 Mon Sep 17 00:00:00 2001 From: sruthi-v04 <119495356+sruthi-v04@users.noreply.github.com> Date: Sat, 10 Dec 2022 20:12:52 +0530 Subject: [PATCH 033/408] Update README.md --- README.md | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 982967d..a2dc4d5 100644 --- a/README.md +++ b/README.md @@ -621,41 +621,67 @@ S contains only lowercase Latin characters, i.e, the characters {a,b,c…….z} - [String in Java](https://www.geeksforgeeks.org/strings-in-java/) ---- + + ### December 11 - Monkey jump #### Problem Statement -A list is provided with a sequence of characters ‘_’ and ‘~’ in it Eg = [‘_’,’_’,’~’,’_’]. The character ‘_’ represents land and the character ‘~’ represents water. A monkey can move 1 step or 2 steps at a time. Another list is provided which contains the step that the monkey took Eg[1,1,2,1,2]. Whenever the monkey touches the water. The game is over and the score must be returned. Calculate the Jumps the monkey took before touching the water's surface. - -

+A list is provided with a sequence of characters ‘_ _’ and ‘~’ in it Eg = [‘_’,’_’,’~’,’_’]. The character ‘_’ represents land and the character ‘~’ represents water. A monkey can move 1 step or 2 steps at a time. Another list is provided which contains the step that the monkey took Eg[1,1,2,1,2]. Whenever the monkey touches the water. The game is over and the score must be returned. Calculate the Jumps the monkey took before touching the water's surface. +

+ + #### Sample Input/Output + +``` Input 1: -[‘’_’,’~’,’_’,’_’,’_’,’_’,’~’,’_’,’_’,’~’,’_’,’~’] +[‘_’,’~’,’_’,’_’,’_’,’_’,’~’,’_’,’_’,’~’,’_’,’~’] + Output 1: -Score = 8 +Score =8 Input 2: -[‘’_’,’~’,’_’,’~’,’_’,’_’,’~’,’_’,’_’,’~’,’_’,’~’] +[‘_’,’~’,’_’,’~’,’_’,’_’,’~’,’_’,’_’,’~’,’_’,’~’] Output 2: Score =2 + ``` + +#### Explanation: -Explanation : + ``` -The input is a combination of ‘ _’ and ‘~’ representing land and water respectively. +The input is a combination of ‘_’ and ‘~’ representing land and water respectively. 2 jumps indicate, for example, initially being on position 1 and ending up on position 3 without landing on position 2 in between. Monkey takes two jumps as first move and three single jumps as next moves. But after taking two jumps the monkey touches the water . The jump sequence: [2,1,1,1,2,1,1,1,1] So the total jump count is 8. +``` + +- **References** +- [Looping in C](https://www.tutorialspoint.com/cprogramming/c_loops.htm) +- [Looping in C++](https://www.programiz.com/cpp-programming/for-loop) +- [Looping in Java](https://www.geeksforgeeks.org/loops-in-java/) +- [Looping in Python](https://www.w3schools.com/python/python_for_loops.asp) +- [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) +- [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) +- [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + +---- + + + + + FAQ ====== From 664d1e50131ea97b577774478fcc893183c5dd77 Mon Sep 17 00:00:00 2001 From: Dhruv Rawat <89683914+yesdhruv@users.noreply.github.com> Date: Sat, 10 Dec 2022 17:31:38 +0000 Subject: [PATCH 034/408] added William Butcher's Mission --- December - 01/c++_Dhruv.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 December - 01/c++_Dhruv.cpp diff --git a/December - 01/c++_Dhruv.cpp b/December - 01/c++_Dhruv.cpp new file mode 100644 index 0000000..c4bbe63 --- /dev/null +++ b/December - 01/c++_Dhruv.cpp @@ -0,0 +1,22 @@ +#include + +int main(){ + int t; + cin>>t; + + while(t--){ + vectorv; // v= { 56, 6F, 75, 67, 68, 74} + int n= v.size(); + + string res=""; + + for(int i=0;i Date: Sat, 10 Dec 2022 23:22:47 +0530 Subject: [PATCH 035/408] First push with the folders and assets. --- December - 11/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 11/.gitignore diff --git a/December - 11/.gitignore b/December - 11/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 11/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 70c20bfeb2104552adfd1ed468626c3d9f58798c Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sat, 10 Dec 2022 23:35:02 +0530 Subject: [PATCH 036/408] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a2dc4d5..fd56e83 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # A-December-of-Algorithms-2022

-

header

+

header

+ +

Welcome to A December of Algorithms (2022). From 40c0781f03d5ee042925af65126508d3027c0f27 Mon Sep 17 00:00:00 2001 From: Dhruv Rawat <89683914+yesdhruv@users.noreply.github.com> Date: Sat, 10 Dec 2022 18:07:50 +0000 Subject: [PATCH 037/408] added The Secret Language --- December - 02/C++_Dhruv.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 December - 02/C++_Dhruv.cpp diff --git a/December - 02/C++_Dhruv.cpp b/December - 02/C++_Dhruv.cpp new file mode 100644 index 0000000..9446c41 --- /dev/null +++ b/December - 02/C++_Dhruv.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; +int main(){ + + string s; + cin>>s; + + int n = s.length();//kipediawiae + + string removing_lastTwo = s.substr(0,n-2);// eliminating last two words + // kipediawi + // updating the length + n = removing_lastTwo.size(); + + string getting_ogWords = removing_lastTwo.substr(n-2,2);//wi + + string lastTime_removing = removing_lastTwo.substr(0,n-2);//kipedia + + + string og = getting_ogWords+lastTime_removing;//wikipedia + cout< Date: Sun, 11 Dec 2022 00:48:34 +0530 Subject: [PATCH 038/408] Aptitude chk and guess game --- December - 08/cpp_nijuyonkadesu.cpp | 15 +++++++++++++++ December - 09/cpp_nijuyonkadesu.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 December - 08/cpp_nijuyonkadesu.cpp create mode 100644 December - 09/cpp_nijuyonkadesu.cpp diff --git a/December - 08/cpp_nijuyonkadesu.cpp b/December - 08/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..3d2e101 --- /dev/null +++ b/December - 08/cpp_nijuyonkadesu.cpp @@ -0,0 +1,15 @@ +#include +#include + +using namespace std; + +int main() { + string msg; + int i=0; + cin>>msg; + do{ + swap(msg[i], msg[i+1]); + i+=2; + } while (i+2 +#include + +using namespace std; + +int main() { + int n, myChoiceLength = -1; + int length; + + string myChoice = "Better Luck Next Time"; + cin>>n; + + string word; + + for(int i=0; i>word; + length = word.length(); + if(word.length()%2!=0 && length > myChoiceLength) { + myChoiceLength = word.length(); + myChoice = word; + } + } + cout< Date: Sun, 11 Dec 2022 12:10:59 +0530 Subject: [PATCH 039/408] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fd56e83..92a66fd 100644 --- a/README.md +++ b/README.md @@ -628,10 +628,10 @@ S contains only lowercase Latin characters, i.e, the characters {a,b,c…….z} ### December 11 - Monkey jump #### Problem Statement -A list is provided with a sequence of characters ‘_ _’ and ‘~’ in it Eg = [‘_’,’_’,’~’,’_’]. The character ‘_’ represents land and the character ‘~’ represents water. A monkey can move 1 step or 2 steps at a time. Another list is provided which contains the step that the monkey took Eg[1,1,2,1,2]. Whenever the monkey touches the water. The game is over and the score must be returned. Calculate the Jumps the monkey took before touching the water's surface. +A list is provided with a sequence of characters . The character ‘_’ represents land and the character ‘~’ represents water. A monkey can move 1 step or 2 steps at a time. Another list is provided which contains the step that the monkey took Eg[1,1,2,1,2]. Whenever the monkey touches the water. The game is over and the score must be returned. Calculate the Jumps the monkey took before touching the water's surface.

- + #### Sample Input/Output From 8ff810ffa1898af8115825522a6bf18c3e030f75 Mon Sep 17 00:00:00 2001 From: ABIPRAVI Date: Sun, 11 Dec 2022 13:31:48 +0530 Subject: [PATCH 040/408] Day 1-4 4(File Only) --- .../Praveen Kumar/praveen_python3.py | 29 ++++ .../Praveen Kumar/praveen_python3.py | 8 + .../Praveen Kumar/praveen_python3.py | 141 ++++++++++++++++++ .../Praveen Kumar/praveen_python3.py | 0 4 files changed, 178 insertions(+) create mode 100644 December - 01/Praveen Kumar/praveen_python3.py create mode 100644 December - 02/Praveen Kumar/praveen_python3.py create mode 100644 December - 03/Praveen Kumar/praveen_python3.py create mode 100644 December - 04/Praveen Kumar/praveen_python3.py diff --git a/December - 01/Praveen Kumar/praveen_python3.py b/December - 01/Praveen Kumar/praveen_python3.py new file mode 100644 index 0000000..18b8d05 --- /dev/null +++ b/December - 01/Praveen Kumar/praveen_python3.py @@ -0,0 +1,29 @@ +n = int(input()) +s = [] + +for x in range(n): + l = input() + s.append(l) + +answer = [] + +for x in range(len(s)): + mm = s[x].split(', ') + string = "" + for m in mm: + string = string + chr(int(m, 16)) + print(string) + + +# Sample Input and outputs +# ----> Input 1: +# 1 +# 56, 6F, 75, 67, 68, 74 +# Vought + +# ------> Input 2: +# 2 +# 49, 6E, 76, 61, 64, 65 +# 4D, 69, 6C, 69, 74, 61, 72, 79 +# Invade +# Military \ No newline at end of file diff --git a/December - 02/Praveen Kumar/praveen_python3.py b/December - 02/Praveen Kumar/praveen_python3.py new file mode 100644 index 0000000..e622477 --- /dev/null +++ b/December - 02/Praveen Kumar/praveen_python3.py @@ -0,0 +1,8 @@ +n = input() +n = n[::-1] +n = n[2:] +l = n[1::-1] +n = n[2:] +n = n[::-1] +n = l + n +print(n) \ No newline at end of file diff --git a/December - 03/Praveen Kumar/praveen_python3.py b/December - 03/Praveen Kumar/praveen_python3.py new file mode 100644 index 0000000..d2c7b43 --- /dev/null +++ b/December - 03/Praveen Kumar/praveen_python3.py @@ -0,0 +1,141 @@ +n = int(input()) + +array = [] + +for x in range(0, n): + l = input() + l = l.replace('-', '0').split(' ') + l = l[:5] + array.append(l) + +for x in range(0, n): + for x1 in range(0,n): + if array[x][x1] == '#': + if ((x==0) and (x1==0)): + if array[x][x1+1] != '#': + array[x][x1+1] = int(array[x][x1+1]) + 1 + if array[x+1][x1+1] != '#': + array[x+1][x1+1] = int(array[x+1][x1+1]) + 1 + if array[x+1][x1] != '#': + array[x+1][x1] = int(array[x+1][x1]) + 1 + elif x1 == 0: + if array[x-1][x1] != '#': + array[x-1][x1] = int(array[x-1][x1]) + 1 + if array[x-1][x1+1] != '#': + array[x-1][x1+1] = int(array[x-1][x1+1]) + 1 + if array[x][x+1] != '#': + array[x][x1+1] = int(array[x][x1+1]) + 1 + if array[x+1][x1+1] != '#': + array[x+1][x1+1] = int(array[x+1][x1+1]) + 1 + if array[x+1][x1] != '#': + array[x+1][x1] = int(array[x+1][x1]) + 1 + elif ((x == n-1) and (x1== 0)): + if array[x-1][x1] != '#': + array[x-1][x1] = int(array[x-1][x1]) + 1 + if array[x-1][x1+1] != '#': + array[x-1][x1+1] = int(array[x-1][x1+1]) + 1 + if array[x][x+1] != '#': + array[x][x1+1] = int(array[x][x1+1]) + 1 + elif ((x == 0) and (x1== n-1)): + if array[x+1][x1] != '#': + array[x+1][x1] = int(array[x+1][x1]) + 1 + if array[x+1][x1-1] != '#': + array[x+1][x1-1] = int(array[x+1][x1-1]) + 1 + if array[x][x1-1] != '#': + array[x][x1-1] = int(array[x][x1-1]) + 1 + elif ((x == n-1) and (x1== n-1)): + if array[x-1][x1] != '#': + array[x-1][x1] = int(array[x-1][x1]) + 1 + if array[x-1][x1-1] != '#': + array[x-1][x1-1] = int(array[x-1][x1-1]) + 1 + if array[x][x1-1] != '#': + array[x][x1-1] = int(array[x][x1-1]) + 1 + elif ((x != 0) and (x1== n-1)): + if array[x+1][x1] != '#': + array[x+1][x1] = int(array[x+1][x1]) + 1 + if array[x+1][x1-1] != '#': + array[x+1][x1-1] = int(array[x+1][x1-1]) + 1 + if array[x][x1-1] != '#': + array[x][x1-1] = int(array[x][x1-1]) + 1 + if array[x-1][x1] != '#': + array[x-1][x1] = int(array[x-1][x1]) + 1 + if array[x-1][x1-1] != '#': + array[x-1][x1-1] = int(array[x-1][x1-1]) + 1 + elif ((x ==0) and (x1 !=0)): + if array[x][x1-1] != '#': + array[x][x1-1] = int(array[x][x1-1]) + 1 + if array[x+1][x1-1] != '#': + array[x+1][x1-1] = int(array[x+1][x1-1]) + 1 + if array[x][x1+1] != '#': + array[x][x1+1] = int(array[x][x1+1]) + 1 + if array[x+1][x1+1] != '#': + array[x+1][x1+1] = int(array[x+1][x1+1]) + 1 + if array[x+1][x1] != '#': + array[x+1][x1] = int(array[x+1][x1]) + 1 + elif ((x == n-1) and (x1 !=0)): + if array[x][x1-1] != '#': + array[x][x1-1] = int(array[x][x1-1]) + 1 + if array[x-1][x1-1] != '#': + array[x-1][x1-1] = int(array[x-1][x1-1]) + 1 + if array[x][x1+1] != '#': + array[x][x1+1] = int(array[x][x1+1]) + 1 + if array[x-1][x1+1] != '#': + array[x-1][x1+1] = int(array[x-1][x1+1]) + 1 + if array[x-1][x1] != '#': + array[x-1][x1] = int(array[x-1][x1]) + 1 + + + elif (x != 0 and x1!=0): + if array[x][x1-1] != '#': + array[x][x1-1] = int(array[x][x1-1]) + 1 + if array[x-1][x1-1] != '#': + array[x-1][x1-1] = int(array[x-1][x1-1]) + 1 + if array[x-1][x1+1] != '#': + array[x-1][x1+1] = int(array[x-1][x1+1]) + 1 + if array[x-1][x1] != '#': + array[x-1][x1] = int(array[x-1][x1]) + 1 + if array[x+1][x1-1] != '#': + array[x+1][x1-1] = int(array[x+1][x1-1]) + 1 + if array[x][x1+1] != '#': + array[x][x1+1] = int(array[x][x1+1]) + 1 + if array[x+1][x1] != '#': + array[x+1][x1] = int(array[x+1][x1]) + 1 + if array[x+1][x1+1] != '#': + array[x+1][x1+1] = int(array[x+1][x1+1]) + 1 + +for x in range(n): + for x1 in range(n): + array[x][x1] = str(array[x][x1]) + +for x in range(n): + print(array[x]) + +# input samle case1: + +# 5 +# - - - - - +# - - - - - +# - - # - - +# - - - - - +# - - - - - + +# output: +# ['0', '0', '0', '0', '0'] +# ['0', '1', '1', '1', '0'] +# ['0', '1', '#', '1', '0'] +# ['0', '1', '1', '1', '0'] +# ['0', '0', '0', '0', '0'] + +# 5 +# - # - - # +# - - - - - +# - - # - - +# - # - - # +# - # - - # + +# output +# ['1', '#', '1', '1', '#'] +# ['1', '2', '2', '2', '1'] +# ['1', '2', '#', '2', '1'] +# ['2', '#', '3', '3', '#'] +# ['2', '#', '2', '2', '#'] \ No newline at end of file diff --git a/December - 04/Praveen Kumar/praveen_python3.py b/December - 04/Praveen Kumar/praveen_python3.py new file mode 100644 index 0000000..e69de29 From 3c5af282f63eb1717a3630903bc38552414a5034 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sun, 11 Dec 2022 15:03:54 +0530 Subject: [PATCH 041/408] Update README.md --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 92a66fd..e356844 100644 --- a/README.md +++ b/README.md @@ -628,7 +628,7 @@ S contains only lowercase Latin characters, i.e, the characters {a,b,c…….z} ### December 11 - Monkey jump #### Problem Statement -A list is provided with a sequence of characters . The character ‘_’ represents land and the character ‘~’ represents water. A monkey can move 1 step or 2 steps at a time. Another list is provided which contains the step that the monkey took Eg[1,1,2,1,2]. Whenever the monkey touches the water. The game is over and the score must be returned. Calculate the Jumps the monkey took before touching the water's surface. +A list is provided with a sequence of characters . The character ‘_’ represents land and the character ‘~’ represents water. A monkey can move 1 step or 2 steps at a time. Another list provided here contains the step that the monkey took Eg[1,1,2,1,2]. Whenever the monkey touches the water. The game is over and the score must be returned. Calculate the Jumps the monkey took before touching the water's surface.

@@ -640,6 +640,7 @@ Input 1: [‘_’,’~’,’_’,’_’,’_’,’_’,’~’,’_’,’_’,’~’,’_’,’~’] +[2,1,1,1,2,1,1,1,1] Output 1: @@ -649,9 +650,10 @@ Input 2: [‘_’,’~’,’_’,’~’,’_’,’_’,’~’,’_’,’_’,’~’,’_’,’~’] -Output 2: +[2,2,1,2,1,1,2,1,1] -Score =2 +Output 2: +Score =3 ``` @@ -659,12 +661,12 @@ Score =2 ``` -The input is a combination of ‘_’ and ‘~’ representing land and water respectively. -2 jumps indicate, for example, initially being on position 1 and ending up on position 3 without landing on position 2 in between. +The first line of input is a combination of ‘_’ and ‘~’ representing land and water respectively. +The second line of input ia a combination of 2's and 1's, 2 steps indicate, for example, initially being on position 1 and ending up on position 3 without landing on position 2 in between. -Monkey takes two jumps as first move and three single jumps as next moves. But after taking two jumps the monkey touches the water . +Monkey takes two steps in a single jump as first move and three single steps as the next 3 moves/jumps. But after taking two steps the monkey touches the water . The jump sequence: [2,1,1,1,2,1,1,1,1] -So the total jump count is 8. +Since in the 9th jump the monkey touches water, the total jump count before he touches the water is 8. ``` From 2e8b0eb8093557ebbcfe9a62bc8952334c553d5a Mon Sep 17 00:00:00 2001 From: Dhruv Rawat <89683914+yesdhruv@users.noreply.github.com> Date: Sun, 11 Dec 2022 09:45:30 +0000 Subject: [PATCH 042/408] added Industry --- December - 04/C++_Dhruv.cpp | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 December - 04/C++_Dhruv.cpp diff --git a/December - 04/C++_Dhruv.cpp b/December - 04/C++_Dhruv.cpp new file mode 100644 index 0000000..f6fba8e --- /dev/null +++ b/December - 04/C++_Dhruv.cpp @@ -0,0 +1,39 @@ +#include +using namespace std; + +int main() { + int days; + cin>>days; + vectorv(days); + for(auto& num :v)cin>>num; + + + int max_sum=INT_MIN; + int curr_sum =0; + int first_day=0,last_day; + + for(int i=0;imax_sum){ + max_sum = curr_sum; + last_day=i; + } + + if(curr_sum<0){ + curr_sum=0; + first_day = i+1; + } + + } + + vectoralldays; + for(int i=first_day ;i<=last_day;i++){ + alldays.push_back(v[i]); + } + cout<<"Max profit: "< Date: Sun, 11 Dec 2022 10:00:52 +0000 Subject: [PATCH 043/408] =?UTF-8?q?Don=E2=80=99t=20let=20Mason=20misspend!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- December - 05/C++_Dhruv.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 December - 05/C++_Dhruv.cpp diff --git a/December - 05/C++_Dhruv.cpp b/December - 05/C++_Dhruv.cpp new file mode 100644 index 0000000..98e4965 --- /dev/null +++ b/December - 05/C++_Dhruv.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +int main() { + + int fuel_price; + cin>>fuel_price; + int og_income ; + cin>>og_income; + int income = og_income/10; // 10% of income + int expense; + for(int i=1;i<=31;i++){ + int og_price = fuel_price; + if(i%3==0){ + og_price+=3; + expense+=2*og_price; + } + else if(i%5==0){ + og_price-=2; + expense+=2*og_price; + } + else{ + expense+=2*og_price; + } + } + (expense>income)?cout<<"EXPENDITURE EXCEEDING LIMIT":cout<<"EXPENDITURE WITHIN LIMIT"; +} From 3ddefa4a9045cdd8c8b6ea599fe5224754990121 Mon Sep 17 00:00:00 2001 From: Dhruv Rawat <89683914+yesdhruv@users.noreply.github.com> Date: Sun, 11 Dec 2022 14:03:25 +0000 Subject: [PATCH 044/408] added Swapped --- December - 06/C++_Dhruv.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 December - 06/C++_Dhruv.cpp diff --git a/December - 06/C++_Dhruv.cpp b/December - 06/C++_Dhruv.cpp new file mode 100644 index 0000000..120ca3a --- /dev/null +++ b/December - 06/C++_Dhruv.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +int main() { +// Position=3 +// Set of numbers: 5 4 4 +// Player going first: Tanika + int size;cin>>size; + int pos;cin>>pos; + vectorv(size); + for(auto &x:v)cin>>x; + + int first_value = v[0]; + int pos_value = v[pos-1]; + + int count; + while(first_value>0){ + swap(--first_value,v[pos-1]); + count++; + } + (count%2==0)?cout<<"Tanika ":cout<<" Bob "; + + return 0; +} From 59c7d8f2503be5a8eb53defd0c00498d9adf244c Mon Sep 17 00:00:00 2001 From: sreevathsan22 <113821083+sreevathsan22@users.noreply.github.com> Date: Sun, 11 Dec 2022 20:47:41 +0530 Subject: [PATCH 045/408] Update README.md --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index fd56e83..e7fb1bb 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Check out our FAQ for more information. - [**December 9 - Kochouseph Konundrum!**](#december-9---kochouseph-konundrum) - [**December 10 - Play with words**](#december-10---play-with-words) - [**December 11 - Monkey jump**](#december-11---monkey-jump) + - [**December 12 - Shez in a Maze!**](#december-12---shez-in-a-maze) - [**FAQ**](#faq) @@ -679,8 +680,39 @@ So the total jump count is 8. ---- +### December 12 - Shez in a Maze! +#### Problem Statement +Shez went to an interesting maze where she was given 500 coins. The rule of the maze is when you choose a path in a maze you need to drop the amount indicated on the path and successfully reach the end. +The winner is declared based on the amount you have spent. The person who has spent the least amount will be the winner. +Can you help her win the maze? +The cost of the path will be in a NxN matrix and the current path is indicated by path[i][j], from the current path you can either travel up, down, front or back. + Note that the start of the maze is the top most left corner and the destination is the bottom most right corner. + +

+ +#### Sample Input/Output +``` +INPUT 1: Path = { {9,4,9,9}, {6,7,6,4}, {8,3,3,7}, {7,4,9,10} } + +OUTPUT 1: The minimum cost is 43 +``` +``` +INPUT 2: Path = { {8,3,9}, {2,6,4}, {8,3,1}} +OUTPUT 2: The minimum cost is 43 +``` +#### Explanation: +``` +9 4 9 9 +6 7 6 4 +8 3 3 7 +7 4 9 10 +Minimum cost = 9 + 4 + 7 + 3 + 3 + 7 + 10 = 43 +So here we see that from the start point Shez can take 3 paths which are of costs 4,7,6 respectively. Of these 3 paths the one with cost 4 is the path with minimum cost. Now from 4 she can either take a path of cost 9 or 7 (Remember you can move only up, down, front, back and no diagonal movement is allowed) so she takes the path with cost 7. +From 7 she has 4 options; paths of costs 6,6,3,4 (Taking path 4 is not advisable since that is from where we came to path 7) so now she takes path with cost 3 and then from this position 3 she can either take paths 8,7,3,4; the minimum cost is 3 so she proceeds in the path with cost 3. Following this logic she finishes the maze with spending a minimum amount of 43 units. +``` +---- From d271b58d8b6fff01c0e25acf8119ee81a0288fdf Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sun, 11 Dec 2022 22:10:37 +0530 Subject: [PATCH 046/408] Update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e7fb1bb..be17f04 100644 --- a/README.md +++ b/README.md @@ -708,8 +708,13 @@ OUTPUT 2: The minimum cost is 43 8 3 3 7 7 4 9 10 Minimum cost = 9 + 4 + 7 + 3 + 3 + 7 + 10 = 43 -So here we see that from the start point Shez can take 3 paths which are of costs 4,7,6 respectively. Of these 3 paths the one with cost 4 is the path with minimum cost. Now from 4 she can either take a path of cost 9 or 7 (Remember you can move only up, down, front, back and no diagonal movement is allowed) so she takes the path with cost 7. +So here we see that from the start point Shez can take 3 paths which are of costs 4,7,6 respectively. + +Of these 3 paths the one with cost 4 is the path with minimum cost. + +Now from 4 she can either take a path of cost 9 or 7 (Remember you can move only up, down, front, back and no diagonal movement is allowed) so she takes the path with cost 7. From 7 she has 4 options; paths of costs 6,6,3,4 (Taking path 4 is not advisable since that is from where we came to path 7) so now she takes path with cost 3 and then from this position 3 she can either take paths 8,7,3,4; the minimum cost is 3 so she proceeds in the path with cost 3. Following this logic she finishes the maze with spending a minimum amount of 43 units. + ``` ---- From 4076ab59d9cce9a172b4a12fe84c9825afbc4d69 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sun, 11 Dec 2022 22:20:59 +0530 Subject: [PATCH 047/408] Update README.md --- README.md | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index be17f04..59173c0 100644 --- a/README.md +++ b/README.md @@ -683,26 +683,48 @@ So the total jump count is 8. ### December 12 - Shez in a Maze! #### Problem Statement Shez went to an interesting maze where she was given 500 coins. The rule of the maze is when you choose a path in a maze you need to drop the amount indicated on the path and successfully reach the end. -The winner is declared based on the amount you have spent. The person who has spent the least amount will be the winner. + +The winner is declared based on the amount you have spent. The person who has spent the least amount will be the winner. + Can you help her win the maze? + The cost of the path will be in a NxN matrix and the current path is indicated by path[i][j], from the current path you can either travel up, down, front or back. - Note that the start of the maze is the top most left corner and the destination is the bottom most right corner. + +Note that the start of the maze is the top most left corner and the destination is the bottom most right corner.

#### Sample Input/Output ``` -INPUT 1: Path = { {9,4,9,9}, {6,7,6,4}, {8,3,3,7}, {7,4,9,10} } +INPUT 1: + +4 +Path = { {9,4,9,9}, {6,7,6,4}, {8,3,3,7}, {7,4,9,10} } + +OUTPUT 1: -OUTPUT 1: The minimum cost is 43 +path_taken={9,4,3,3,7,10} +The minimum coins dropped is 43 ``` ``` -INPUT 2: Path = { {8,3,9}, {2,6,4}, {8,3,1}} +INPUT 2: -OUTPUT 2: The minimum cost is 43 +3 +Path = { {8,3,9}, {2,6,4}, {8,3,1}} + +OUTPUT 2: + +path_taken={8,2,6,3,1} +The minimum coins dropped is 20 ``` #### Explanation: ``` + +The first line of input is the size of the NxN matrix. +The next line of input is an NxN matrix where each element represents the number of coins you need to drop at that position. + +The output is a path_taken matrix and the minimum coins dropped amount. + 9 4 9 9 6 7 6 4 8 3 3 7 From daa264820ec8abc6184f887ba41d4b37a054370d Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sun, 11 Dec 2022 22:25:04 +0530 Subject: [PATCH 048/408] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e356844..582afc0 100644 --- a/README.md +++ b/README.md @@ -628,7 +628,7 @@ S contains only lowercase Latin characters, i.e, the characters {a,b,c…….z} ### December 11 - Monkey jump #### Problem Statement -A list is provided with a sequence of characters . The character ‘_’ represents land and the character ‘~’ represents water. A monkey can move 1 step or 2 steps at a time. Another list provided here contains the step that the monkey took Eg[1,1,2,1,2]. Whenever the monkey touches the water. The game is over and the score must be returned. Calculate the Jumps the monkey took before touching the water's surface. +A list is provided with a sequence of characters . The character ‘_’ represents land and the character ‘~’ represents water. A monkey can move 1 step or 2 steps in a single jump. Another list provided here contains the step that the monkey took Eg[1,1,2,1,2]. Whenever the monkey touches the water. The game is over and the score must be returned. Calculate the jumps the monkey took before touching the water.

@@ -665,8 +665,8 @@ The first line of input is a combination of ‘_’ and ‘~’ representing lan The second line of input ia a combination of 2's and 1's, 2 steps indicate, for example, initially being on position 1 and ending up on position 3 without landing on position 2 in between. Monkey takes two steps in a single jump as first move and three single steps as the next 3 moves/jumps. But after taking two steps the monkey touches the water . -The jump sequence: [2,1,1,1,2,1,1,1,1] -Since in the 9th jump the monkey touches water, the total jump count before he touches the water is 8. +Given the jump sequence: [2,1,1,1,2,1,1,1,1] +Since in the 9th jump the monkey touches water, the total jump count before he touches the water is 8 and thus the score is 8. ``` From 32707639bbfcb5543c63ea18353f054096fb0d7f Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sun, 11 Dec 2022 22:55:35 +0530 Subject: [PATCH 049/408] First push with the folders and assets. --- December - 12/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 12/.gitignore diff --git a/December - 12/.gitignore b/December - 12/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 12/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 20113d7dd773b99f1f7b1779b17db690b9f35038 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sun, 11 Dec 2022 22:57:02 +0530 Subject: [PATCH 050/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 15b7ab3..7e30345 100644 --- a/README.md +++ b/README.md @@ -705,7 +705,7 @@ Path = { {9,4,9,9}, {6,7,6,4}, {8,3,3,7}, {7,4,9,10} } OUTPUT 1: -path_taken={9,4,3,3,7,10} +path_taken={9,4,7,3,3,7,10} The minimum coins dropped is 43 ``` ``` From 345d846fd7f9d3a84f5b6dd5d0ef43b41fb21adf Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Mon, 12 Dec 2022 09:16:57 +0530 Subject: [PATCH 051/408] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7e30345..89d61ce 100644 --- a/README.md +++ b/README.md @@ -641,7 +641,7 @@ Input 1: [‘_’,’~’,’_’,’_’,’_’,’_’,’~’,’_’,’_’,’~’,’_’,’~’] -[2,1,1,1,2,1,1,1,1] +[2,1,1,1,2,1,1,2,1] Output 1: @@ -651,7 +651,7 @@ Input 2: [‘_’,’~’,’_’,’~’,’_’,’_’,’~’,’_’,’_’,’~’,’_’,’~’] -[2,2,1,2,1,1,2,1,1] +[2,2,1,1,1,1,2,1,1] Output 2: Score =3 @@ -666,7 +666,7 @@ The first line of input is a combination of ‘_’ and ‘~’ representing lan The second line of input ia a combination of 2's and 1's, 2 steps indicate, for example, initially being on position 1 and ending up on position 3 without landing on position 2 in between. Monkey takes two steps in a single jump as first move and three single steps as the next 3 moves/jumps. But after taking two steps the monkey touches the water . -Given the jump sequence: [2,1,1,1,2,1,1,1,1] +Given the jump sequence: [2,1,1,1,2,1,1,2,1] Since in the 9th jump the monkey touches water, the total jump count before he touches the water is 8 and thus the score is 8. ``` From 76510860fa4992dc6e5a38e8f57f09a74f441152 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Mon, 12 Dec 2022 09:24:12 +0530 Subject: [PATCH 052/408] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 89d61ce..7acfadc 100644 --- a/README.md +++ b/README.md @@ -641,11 +641,11 @@ Input 1: [‘_’,’~’,’_’,’_’,’_’,’_’,’~’,’_’,’_’,’~’,’_’,’~’] -[2,1,1,1,2,1,1,2,1] +[2,1,1,1,2,1,2,1] Output 1: -Score =8 +Score =7 Input 2: @@ -665,9 +665,9 @@ Score =3 The first line of input is a combination of ‘_’ and ‘~’ representing land and water respectively. The second line of input ia a combination of 2's and 1's, 2 steps indicate, for example, initially being on position 1 and ending up on position 3 without landing on position 2 in between. -Monkey takes two steps in a single jump as first move and three single steps as the next 3 moves/jumps. But after taking two steps the monkey touches the water . -Given the jump sequence: [2,1,1,1,2,1,1,2,1] -Since in the 9th jump the monkey touches water, the total jump count before he touches the water is 8 and thus the score is 8. +Monkey takes two steps in a single jump as first move and three single steps as the next 3 moves/jumps, another 2 jumps, 1 jump and another 2 jumps. +Given the jump sequence: [2,1,1,1,2,1,2,1] +Since in the 8th jump the monkey touches water, the total jump count before he touches the water is 7 and thus the score is 7. ``` From 0cee4c2cf0d90b910a0fcdb5ae138ded63b1ea3b Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Mon, 12 Dec 2022 12:26:58 +0530 Subject: [PATCH 053/408] December 1 - William Butcher's Mission --- December - 01/Java_souvikpal2000.java | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 December - 01/Java_souvikpal2000.java diff --git a/December - 01/Java_souvikpal2000.java b/December - 01/Java_souvikpal2000.java new file mode 100644 index 0000000..0486397 --- /dev/null +++ b/December - 01/Java_souvikpal2000.java @@ -0,0 +1,36 @@ +import java.io.*; +public class Java_souvikpal2000{ + public static void main(String args[]) throws IOException{ + InputStreamReader isr=new InputStreamReader(System.in); + BufferedReader br=new BufferedReader(isr); + + System.out.println("Input : "); + int n = Integer.parseInt(br.readLine()); + + String[] hexStrArray = new String[n]; + String[] actualStrArray = new String[n]; + int i = 0; + while(i Date: Mon, 12 Dec 2022 19:49:34 +0530 Subject: [PATCH 054/408] Update README.md --- README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/README.md b/README.md index 59173c0..4744f80 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ Check out our FAQ for more information. - [**December 10 - Play with words**](#december-10---play-with-words) - [**December 11 - Monkey jump**](#december-11---monkey-jump) - [**December 12 - Shez in a Maze!**](#december-12---shez-in-a-maze) + - [**December 13 - The Labyrinth**](#december-13---the-labyrinth) - [**FAQ**](#faq) @@ -740,7 +741,64 @@ From 7 she has 4 options; paths of costs 6,6,3,4 (Taking path 4 is not advisable ``` ---- +### December 13 - The Labyrinth +#### Problem Statement +In Ancient Greek mythology, the Labyrinth was an intricate maze constructed by the master inventor Daedalus as per the orders of King Minos of Crete. +Many heroes from afar contended to escape the maze and overpower the ferocious beast Minotaur, but none succeeded in their attempts except for one, the great Theseus of Athens. +Imagine a modern-world Labyrinth similar to an N*N binary matrix of blocks such that: +- The starting point is the upper leftmost block +- The endpoint is the lower rightmost block +- Dead ends are represented by 0 +- A clear path is represented by 1 + +Help Theseus escape this Labyrinth if he can only move forward and backwards throughout his quest. + + +

+ + + +#### Sample Input/Output +``` +INPUT: +{1,0,0,0} +{1,1,0,1} +{0,1,0,0} +{1,1,1,1} + + +OUTPUT: +{1,0,0,0} +{1,1,0,0} +{0,1,0,0} +{0,1,1,1} + +``` +``` +INPUT: +{1,1,1,0} +{1,0,1,1} +{0,1,0,1} +{0,1,1,1} + + +OUTPUT: +{1,1,1,0} +{0,0,1,1} +{0,0,0,1} +{0,0,0,1} + +``` +#### Explanation: +``` + +In the given samples, the input matrix specifies the structure of the maze in which 0's represent the dead ends, and 1's represent the clear blocks. +After computing a path to the destination, the output matrix represents the path to the destination block using 1’s. + +``` + +---- FAQ From 3733c4fef6f995e478d3099cbb559bdbd46ea1fe Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Mon, 12 Dec 2022 22:34:42 +0530 Subject: [PATCH 055/408] First push with the folders and assets. --- December - 13/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 13/.gitignore diff --git a/December - 13/.gitignore b/December - 13/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 13/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 569a77688e2bf660df6a5fd4599431b75f310648 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Mon, 12 Dec 2022 22:37:34 +0530 Subject: [PATCH 056/408] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4744f80..1f417ea 100644 --- a/README.md +++ b/README.md @@ -762,6 +762,7 @@ Help Theseus escape this Labyrinth if he can only move forward and backwards thr #### Sample Input/Output ``` INPUT: +4 {1,0,0,0} {1,1,0,1} {0,1,0,0} @@ -777,6 +778,7 @@ OUTPUT: ``` ``` INPUT: +4 {1,1,1,0} {1,0,1,1} {0,1,0,1} @@ -792,7 +794,7 @@ OUTPUT: ``` #### Explanation: ``` - +The first line of input is the size of the N*N matrix. In the given samples, the input matrix specifies the structure of the maze in which 0's represent the dead ends, and 1's represent the clear blocks. After computing a path to the destination, the output matrix represents the path to the destination block using 1’s. From 76570afa5f82242cbbeb6388c26daad94488d294 Mon Sep 17 00:00:00 2001 From: Dhruv Rawat <89683914+yesdhruv@users.noreply.github.com> Date: Mon, 12 Dec 2022 18:21:28 +0000 Subject: [PATCH 057/408] added aptitude check --- December - 08/C++_Dhruv.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 December - 08/C++_Dhruv.cpp diff --git a/December - 08/C++_Dhruv.cpp b/December - 08/C++_Dhruv.cpp new file mode 100644 index 0000000..aa9b5b8 --- /dev/null +++ b/December - 08/C++_Dhruv.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; + +int main() { + // DEMOCRACY -> ED OM RC CA Y + string input ; + cin>>input; + int n = size(input); + for(int i=0;i Date: Mon, 12 Dec 2022 18:34:21 +0000 Subject: [PATCH 058/408] added dec 9 problem --- December - 09/C++_Dhruv.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 December - 09/C++_Dhruv.cpp diff --git a/December - 09/C++_Dhruv.cpp b/December - 09/C++_Dhruv.cpp new file mode 100644 index 0000000..a6ba2fd --- /dev/null +++ b/December - 09/C++_Dhruv.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; + +int main() { + int n;cin>>n; + vector input(n) ; + + for(auto &x:input)cin>>x; + int max_len=INT_MIN; + + string word; + for(auto e:input){ + int len = e.size(); + if(size(e)%2!=0) + { + max_len = max(len,max_len); + + } + else + continue; + } + for(auto e:input ){ + if(size(e)==max_len){ + word = e; + break; + + } + } + if(max_len==INT_MIN) + cout<<"Better Luck Next Time"; + else + cout< Date: Tue, 13 Dec 2022 00:08:53 +0530 Subject: [PATCH 059/408] Dec1 --- December - 01/python3_lakshmeeee_dec1.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 December - 01/python3_lakshmeeee_dec1.py diff --git a/December - 01/python3_lakshmeeee_dec1.py b/December - 01/python3_lakshmeeee_dec1.py new file mode 100644 index 0000000..e15b879 --- /dev/null +++ b/December - 01/python3_lakshmeeee_dec1.py @@ -0,0 +1,9 @@ +code = [ "56", "6F", "75", "67", "68", "74"] +# code = input().split(',[]') +# print(code) +sr = "" +for i in code: + ch = chr(int(i, 16)) + sr+=ch +print(sr) + From 4f90fd69c788d9a56755b0a8a210dc6c226ee47a Mon Sep 17 00:00:00 2001 From: Lakshmi Sruthi K Date: Tue, 13 Dec 2022 00:20:49 +0530 Subject: [PATCH 060/408] all --- December - 01/python3_lakshmeeee_dec1.py | 9 ---- December - 02/Python3_lakshmeeee.py | 4 ++ December - 04/Python3_lakshmeeee.py | 53 ++++++++++++++++++++ December - 05/Python3_lakshmeeee.py | 19 +++++++ December - 06/Python3_lakshmeeee.py | 21 ++++++++ December - 07/Python3_lakshmeeee.py | 63 ++++++++++++++++++++++++ December - 08/Python3_lakshmeeee.py | 12 +++++ December - 09/Python3_lakshmeeee.py | 20 ++++++++ December - 10/Python3_lakshmeeee.py | 26 ++++++++++ December - 11/Python3_lakshmeeee.py | 14 ++++++ December - 12/Python3_lakshmeeee.py | 38 ++++++++++++++ 11 files changed, 270 insertions(+), 9 deletions(-) delete mode 100644 December - 01/python3_lakshmeeee_dec1.py create mode 100644 December - 02/Python3_lakshmeeee.py create mode 100644 December - 04/Python3_lakshmeeee.py create mode 100644 December - 05/Python3_lakshmeeee.py create mode 100644 December - 06/Python3_lakshmeeee.py create mode 100644 December - 07/Python3_lakshmeeee.py create mode 100644 December - 08/Python3_lakshmeeee.py create mode 100644 December - 09/Python3_lakshmeeee.py create mode 100644 December - 10/Python3_lakshmeeee.py create mode 100644 December - 11/Python3_lakshmeeee.py create mode 100644 December - 12/Python3_lakshmeeee.py diff --git a/December - 01/python3_lakshmeeee_dec1.py b/December - 01/python3_lakshmeeee_dec1.py deleted file mode 100644 index e15b879..0000000 --- a/December - 01/python3_lakshmeeee_dec1.py +++ /dev/null @@ -1,9 +0,0 @@ -code = [ "56", "6F", "75", "67", "68", "74"] -# code = input().split(',[]') -# print(code) -sr = "" -for i in code: - ch = chr(int(i, 16)) - sr+=ch -print(sr) - diff --git a/December - 02/Python3_lakshmeeee.py b/December - 02/Python3_lakshmeeee.py new file mode 100644 index 0000000..b85a109 --- /dev/null +++ b/December - 02/Python3_lakshmeeee.py @@ -0,0 +1,4 @@ +code = input() +c="" +c+= code[len(code)-4:len(code)-2]+code[:len(code)-4] +print(c) \ No newline at end of file diff --git a/December - 04/Python3_lakshmeeee.py b/December - 04/Python3_lakshmeeee.py new file mode 100644 index 0000000..1b36e55 --- /dev/null +++ b/December - 04/Python3_lakshmeeee.py @@ -0,0 +1,53 @@ +def max_crossing_subarray(a, low, mid, high): + left_sum = -10000 + sum = 0 + max_left = -1 + for i in range(mid,low-1,-1): + sum+=a[i] + if (sum>left_sum): + left_sum = sum + max_left = i + + right_sum = -10000 + sum = 0 + max_right = -1 + for i in range(mid+1,high+1): + sum+=a[i] + if (sum>right_sum): + right_sum = sum + max_right = i + #print('FMCS(a,{},{},{}): {},{},{}'.format(low,mid,high,max_left,max_right, left_sum+right_sum)) + return(max_left,max_right, left_sum+right_sum) + +def max_subarray(a,low,high): + if high==low: + return(low,high,a[low]) + else: + mid = (low+high)//2 + + #print('\nFMS-left(a,{},{})'.format(low,mid)) + left_low, left_high, left_sum = max_subarray(a, low, mid) + + #print('\nFMS-right(a,{},{})'.format(mid+1,high)) + right_low, right_high, right_sum = max_subarray(a, mid+1, high) + + #print('\nFMCS(a,{},{},{})'.format(low,mid,high)) + cross_low, cross_high, cross_sum = max_crossing_subarray(a, low, mid, high) + + if (left_sum>=right_sum and left_sum>=cross_sum): + return (left_low, left_high, left_sum) + + elif (right_sum>=left_sum and right_sum>=cross_sum): + return (right_low, right_high, right_sum) + + else: + return (cross_low, cross_high, cross_sum) + + +arr = [5,4,-1,7,8] +#arr = [-5,20,-18,52,12,-8,-4] + +n = len(arr) + +max_left, max_right, max_sum = max_subarray(arr, 0, n-1) +print("Profit Value: {}\nProposed days to sell: Day: {} to Day: {}\nStock market Change Values: {}".format(max_sum, max_left+1, max_right+1, arr[max_left:max_right+1])) diff --git a/December - 05/Python3_lakshmeeee.py b/December - 05/Python3_lakshmeeee.py new file mode 100644 index 0000000..180b88e --- /dev/null +++ b/December - 05/Python3_lakshmeeee.py @@ -0,0 +1,19 @@ +income = 50000 +x = int(input()) +y=x +total=0 + +for i in range(1,32): + x=y + if(i%3==0): + x+=3 + if(i%5==0): + x-=2 + total+=2*x + +print('Expenditure = ',total) +if(total>income/10): + print("EXPENDITURE EXCEEDING LIMIT") +else: + print("EXPENDITURE WITHIN LIMIT") + \ No newline at end of file diff --git a/December - 06/Python3_lakshmeeee.py b/December - 06/Python3_lakshmeeee.py new file mode 100644 index 0000000..8983104 --- /dev/null +++ b/December - 06/Python3_lakshmeeee.py @@ -0,0 +1,21 @@ +n=[int(x) for x in input().split()] +pos = int(input())-1 +turn_str = input() +if turn_str=="Tanika": + turn=0 +elif turn_str=="Bob": + turn=1 + +while(n[0]!=0): + turn+=1 + if(turn>1): + turn=0 + temp = n[pos] + n[pos] = n[0]-1 + n[0] = n[pos] + print(n) + +if turn==1: + print("Tanika wins the game!\nBob loses the game!") +else: + print("Bob wins the game!\nTanika loses the game!") \ No newline at end of file diff --git a/December - 07/Python3_lakshmeeee.py b/December - 07/Python3_lakshmeeee.py new file mode 100644 index 0000000..6ce7170 --- /dev/null +++ b/December - 07/Python3_lakshmeeee.py @@ -0,0 +1,63 @@ +crossword = [ 'ASSERTIVENESSLJ', +'CFOGOODPOSITIVE', +'OPENBMUREWOPRPS', +'MEDIATIONELDIOG', +'MAASREGJEWINWIN', +'UCIAEMOEECSKENI', +'NEMRSHACDVTWTTL', +'ITEHOTLTSTERAOE', +'CASPLGLSIUNERFE', +'AISAUSYTPOISEVF', +'TTARTTDOCENPPIH', +'IOGAIGUPYMGOOEE', +'OGEPOAFPQIENOWA', +'NECONFLICTSDCER', +'FNHTCATNOCEYEBT'] + +# word = 'DOCUMENT' +# word = 'MEDIATION' +word = input() +flag=0 + +for r in range(14): + if(flag==2): + break + for c in range(14): + if(flag)==2: + break + if crossword[r][c]==word[0]: + flag=0 + if crossword[r][c+1]==word[1]: + h=c+1 + for j in word[2:]: + h+=1 + if h==15: + flag=1 + break + elif(crossword[r][h])!=j: + flag=1 + break + # print(crossword[r][h]) + if flag==0: + flag=2 + flag-0 + if crossword[r+1][c]==word[1]: + k=r+1 + for j in word[2:]: + k+=1 + if k==15: + flag=1 + break + elif(crossword[k][c])!=j: + flag=1 + break + # print(crossword[k][c]) + if flag==0: + flag=2 + if flag==2: + print('Found') + +if(flag!=2): + print('Not Found') + + \ No newline at end of file diff --git a/December - 08/Python3_lakshmeeee.py b/December - 08/Python3_lakshmeeee.py new file mode 100644 index 0000000..b1fb912 --- /dev/null +++ b/December - 08/Python3_lakshmeeee.py @@ -0,0 +1,12 @@ +codelist = input() +# codelist = "DEMOCRACY" +code = list(codelist) +#print(code) + +for i in range(len(code)): + if (i+1)%2==0: + temp = code[i] + code[i]=code[i-1] + code[i-1]=temp +#print(code) +print(''.join(code)) \ No newline at end of file diff --git a/December - 09/Python3_lakshmeeee.py b/December - 09/Python3_lakshmeeee.py new file mode 100644 index 0000000..e37c31a --- /dev/null +++ b/December - 09/Python3_lakshmeeee.py @@ -0,0 +1,20 @@ +n = int(input()) +l = [str(x) for x in input().split()] +# l = ["Helloe", "Good", "Morninge", "Welcomee", "youe"] +length=[] + +for i in range(len(l)): + length.append(len(l[i])) + +m = max(length) +pos=-1 + +for i in range(len(length)): + if length[i]==m and length[i]%2!=0: + pos=i + break + +if(pos==-1): + print("Better luck next time") +else: + print(l[pos]) \ No newline at end of file diff --git a/December - 10/Python3_lakshmeeee.py b/December - 10/Python3_lakshmeeee.py new file mode 100644 index 0000000..e4464fa --- /dev/null +++ b/December - 10/Python3_lakshmeeee.py @@ -0,0 +1,26 @@ +nw = int(input()) +words = [] + +for i in range(nw*2): + word = input() + if (i+1)%2==0: + words.append(word) + +print(words) + +vowels = ['a', 'e', 'i', 'o', 'u'] + +for word in words: + c=0 + + for letter in word: + if letter not in vowels: + c+=1 + else: + c=0 + + if c==4: + print('NO') + break + if c<4: + print('YES') diff --git a/December - 11/Python3_lakshmeeee.py b/December - 11/Python3_lakshmeeee.py new file mode 100644 index 0000000..3056380 --- /dev/null +++ b/December - 11/Python3_lakshmeeee.py @@ -0,0 +1,14 @@ +# envi = ['_','~','_','_','_','_','~','_','_','~','_','~'] +# jumps = [2,1,1,1,2,1,2,1] +envi = ['_','~','_','~','_','_','~','_','_','~','_','~'] +jumps = [2,2,1,1,1,1,2,1,1] +# envi = [str(x) for x in input().split(',')] +# jumps = [int(x) for x in input().split(',')] +pos=0 + +for i in range(len(jumps)): + pos+=jumps[i] + if envi[pos]=='~': + print('Score =',i) + break + diff --git a/December - 12/Python3_lakshmeeee.py b/December - 12/Python3_lakshmeeee.py new file mode 100644 index 0000000..0d0af90 --- /dev/null +++ b/December - 12/Python3_lakshmeeee.py @@ -0,0 +1,38 @@ +# n=4 +# path = [ [9,4,9,9], [6,7,6,4], [8,3,3,7], [7,4,9,10] ] +n=int(input()) +path=[] +for i in range(n): + path.append([int(x) for x in input().split(',')]) + +''' +9 4 9 9 +6 7 6 4 +8 3 3 7 +7 4 9 10 +''' + +i,j=0,0 +cost=path[i][j] +# print(cost) + +while(i!=n-1 and j!=n-1): + if (i+1)!=n and (j+1)!=n: + if path[i][j+1] Date: Tue, 13 Dec 2022 00:23:01 +0530 Subject: [PATCH 061/408] Till 12 --- December - 01/Python3_lakshmeeee.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 December - 01/Python3_lakshmeeee.py diff --git a/December - 01/Python3_lakshmeeee.py b/December - 01/Python3_lakshmeeee.py new file mode 100644 index 0000000..e15b879 --- /dev/null +++ b/December - 01/Python3_lakshmeeee.py @@ -0,0 +1,9 @@ +code = [ "56", "6F", "75", "67", "68", "74"] +# code = input().split(',[]') +# print(code) +sr = "" +for i in code: + ch = chr(int(i, 16)) + sr+=ch +print(sr) + From 9cf51e45df0c89e5d47ff21591d86bd6d38e2e4b Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Tue, 13 Dec 2022 10:04:02 +0530 Subject: [PATCH 062/408] December 2 - The Secret Language --- December - 02/Java_souvikpal2000.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 December - 02/Java_souvikpal2000.java diff --git a/December - 02/Java_souvikpal2000.java b/December - 02/Java_souvikpal2000.java new file mode 100644 index 0000000..6119e5a --- /dev/null +++ b/December - 02/Java_souvikpal2000.java @@ -0,0 +1,18 @@ +import java.io.*; +public class Java_souvikpal2000{ + public static void main(String args[]) throws IOException{ + InputStreamReader isr=new InputStreamReader(System.in); + BufferedReader br=new BufferedReader(isr); + + System.out.println("Input : "); + String str = br.readLine(); + + int length = str.length(); + int actualWordLength = length - 2; + String actualWord = str.substring(length-4, actualWordLength) + str.substring(0, length-4); + + System.out.println(""); + System.out.println("Output : "); + System.out.println(actualWord); + } +} \ No newline at end of file From 738fb27ee410ebcb885e6b0be64d91348b39716e Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Tue, 13 Dec 2022 10:17:01 +0530 Subject: [PATCH 063/408] December 3 - Minesweeper --- December - 03/Java_souvikpal2000.java | 91 +++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 December - 03/Java_souvikpal2000.java diff --git a/December - 03/Java_souvikpal2000.java b/December - 03/Java_souvikpal2000.java new file mode 100644 index 0000000..753af3f --- /dev/null +++ b/December - 03/Java_souvikpal2000.java @@ -0,0 +1,91 @@ +import java.io.*; +import java.util.*; +public class Java_souvikpal2000{ + public String[][] convertDashToZero(String[][] arr, int n){ + for(int i=0;i= 0 && arr[verUp][j].equals("#") == false){ + arr[verUp][j] = Integer.toString(Integer.parseInt(arr[verUp][j]) + 1); + } + if(verDown <= (n-1) && arr[verDown][j].equals("#") == false){ + arr[verDown][j] = Integer.toString(Integer.parseInt(arr[verDown][j]) + 1); + } + if(horLeft >= 0 && arr[i][horLeft].equals("#") == false){ + arr[i][horLeft] = Integer.toString(Integer.parseInt(arr[i][horLeft]) + 1); + } + if(horRight <= (n-1) && arr[i][horRight].equals("#") == false){ + arr[i][horRight] = Integer.toString(Integer.parseInt(arr[i][horRight]) + 1); + } + + if(horLeft >= 0 && verUp >= 0 && arr[verUp][horLeft].equals("#") == false){ + arr[verUp][horLeft] = Integer.toString(Integer.parseInt(arr[verUp][horLeft]) + 1); + } + if(horLeft >= 0 && verDown <= (n-1) && arr[verDown][horLeft].equals("#") == false){ + arr[verDown][horLeft] = Integer.toString(Integer.parseInt(arr[verDown][horLeft]) + 1); + } + if(horRight <= (n-1) && verUp >= 0 && arr[verUp][horRight].equals("#") == false){ + arr[verUp][horRight] = Integer.toString(Integer.parseInt(arr[verUp][horRight]) + 1); + } + if(horRight <= (n-1) && verDown <= (n-1) && arr[verDown][horRight].equals("#") == false){ + arr[verDown][horRight] = Integer.toString(Integer.parseInt(arr[verDown][horRight]) + 1); + } + } + } + } + + return arr; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input : "); + int n = sc.nextInt(); + String[][] arr = new String[n][n]; + for(int i=0;i Date: Tue, 13 Dec 2022 12:17:52 +0530 Subject: [PATCH 064/408] day 11 added --- December - 11/GREEDnim_day11_java.java | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 December - 11/GREEDnim_day11_java.java diff --git a/December - 11/GREEDnim_day11_java.java b/December - 11/GREEDnim_day11_java.java new file mode 100644 index 0000000..879d466 --- /dev/null +++ b/December - 11/GREEDnim_day11_java.java @@ -0,0 +1,27 @@ +package acm; + +import java.util.Scanner; + +public class GREEDnim_day11_java { + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + String s=in.next(); + String steps=in.next(); + int curPos=0; + int i=0; + boolean flag=false; + while(curPos Date: Tue, 13 Dec 2022 22:49:06 +0530 Subject: [PATCH 065/408] Update README.md --- README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/README.md b/README.md index 1f417ea..82120a7 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Check out our FAQ for more information. - [**December 11 - Monkey jump**](#december-11---monkey-jump) - [**December 12 - Shez in a Maze!**](#december-12---shez-in-a-maze) - [**December 13 - The Labyrinth**](#december-13---the-labyrinth) + - [**December 14 - Math Mystery**](#december-14---math-mystery) - [**FAQ**](#faq) @@ -800,6 +801,68 @@ After computing a path to the destination, the output matrix represents the path ``` +---- +### December 14 - Math Mystery +#### Problem Statement +Dr. Satheesh Kumar is an outstanding professor in Discrete Mathematics. However, he has been assigned to teach an unruly batch of students. The lesson he planned to cover in the upcoming class was of utmost importance for the students. + +The lesson was none other than “Graph Theory”, which required a concise understanding of fundamental theoretical concepts and numerous theorems. + +The professor decided to execute those theorems programmatically as the students belong to the Computer Science department. He prepared all the theorems as programs except one theorem, which discussed the topic of “Graph Bipartite”. + +Bipartite Graph: It is a graph whose vertices can be divided into 2 independent sets U and V such that every edge (u,v), either connects a vertex from U to V or a vertex from V to U. (We can also say that there is no edge that connects vertices of the same set). + +Help Dr. Satheesh Kumar come up with a program which obtains a graph as input and produces an output verifying its bipartite property. + + +

+ + + + + +#### Sample Input/Output +``` +INPUT: +6 + +0 1 0 0 0 1 +1 0 1 0 0 0 +0 1 0 1 0 0 +0 0 1 0 1 0 +0 0 0 1 0 1 +1 0 0 0 1 0 + +OUTPUT: +The graph is Bipartite!!! + +``` +``` +INPUT: +4 + +0 1 0 1 +1 0 1 0 +0 1 0 1 +1 0 1 0 + +OUTPUT: +The graph is Bipartite!!! + +``` +#### Explanation: +``` +The first line of the input is the number of vertices in the graph.The next part of the input is the adjacency matrix of the graph, +where every row/column is a vertex and the 1 represents an edge connecting two vertices. +You are required to divide the given vertices into two sets such that: + 1. Every vertex in one set is connected to at least one vertex in the other set. + 2. There is no edge between the vertices of the same set. + +``` +- **References** +- [Bipartite graphs](https://www.tutorialspoint.com/bipartite-graphs) +- [Adjacency matrices](https://www.javatpoint.com/what-is-an-adjacency-matrix) + ---- From b7b82647b067357ff09491929537fbe64140046b Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Tue, 13 Dec 2022 23:05:40 +0530 Subject: [PATCH 066/408] First push with the folders and assets. --- December - 14/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 14/.gitignore diff --git a/December - 14/.gitignore b/December - 14/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 14/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 b31a3aa53a719fb37262038729f03a2a95bdc2cc Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Tue, 13 Dec 2022 23:07:50 +0530 Subject: [PATCH 067/408] Update README.md --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 82120a7..43e8120 100644 --- a/README.md +++ b/README.md @@ -834,7 +834,7 @@ INPUT: 1 0 0 0 1 0 OUTPUT: -The graph is Bipartite!!! +The graph is Bipartite! ``` ``` @@ -847,7 +847,7 @@ INPUT: 1 0 1 0 OUTPUT: -The graph is Bipartite!!! +The graph is Bipartite! ``` #### Explanation: @@ -862,6 +862,9 @@ You are required to divide the given vertices into two sets such that: - **References** - [Bipartite graphs](https://www.tutorialspoint.com/bipartite-graphs) - [Adjacency matrices](https://www.javatpoint.com/what-is-an-adjacency-matrix) +- [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) +- [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) +- [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) ---- From c787285fa4836f1167defe08a94a76aa3094a542 Mon Sep 17 00:00:00 2001 From: ABIPRAVI Date: Wed, 14 Dec 2022 05:53:28 +0530 Subject: [PATCH 068/408] Dec5 --- .../Praveen Kumar/praveen_python3.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 December - 05/Praveen Kumar/praveen_python3.py diff --git a/December - 05/Praveen Kumar/praveen_python3.py b/December - 05/Praveen Kumar/praveen_python3.py new file mode 100644 index 0000000..a08f2f8 --- /dev/null +++ b/December - 05/Praveen Kumar/praveen_python3.py @@ -0,0 +1,19 @@ +n = int(input()) +x1 = 0 +for x in range(1, 32): + if x % 3 == 0: + n = n+3 + x1 = x1 + (n*2) + if x % 5 == 0: + n = n-2 + x1 = x1 + (n*2) + else: + x1 = x1+(n*2) + print(x1, x, 'prince',n) + +if x1 > 5000: + print('Expenditure=',x1) + print('EXPENDITURE EXCEEDING LIMIT') +else: + print('Expenditure=',x1) + print('EXPENDITURE WITHIN LIMIT') \ No newline at end of file From c087a20dcbea11f62095c3410e7b5a0af63bb3bb Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Wed, 14 Dec 2022 11:22:03 +0530 Subject: [PATCH 069/408] December 4 - Industry --- December - 04/Java_souvikpal2000.java | 55 +++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 December - 04/Java_souvikpal2000.java diff --git a/December - 04/Java_souvikpal2000.java b/December - 04/Java_souvikpal2000.java new file mode 100644 index 0000000..1a8ac7b --- /dev/null +++ b/December - 04/Java_souvikpal2000.java @@ -0,0 +1,55 @@ +import java.io.*; +import java.util.*; +public class Java_souvikpal2000{ + public static int findMax(int i, int j){ + return i>j? i : j; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input : "); + System.out.println(""); + + System.out.print("No. of Days : "); + int noOfDays = sc.nextInt(); + + int[] arr = new int[noOfDays]; + System.out.print("Given stock market change values : "); + for(int i=0;i preRes){ + end = i+1; + } + } + + System.out.println(""); + System.out.println("Output : "); + System.out.println(""); + + System.out.println("Profit Value : " + res); + System.out.println("Proposed days to sell: Day: "+start+" to Day: "+end); + System.out.print("Stock market Change Values: {"); + for(int i=start-1;i<=end-1;i++){ + System.out.print(arr[i]); + if(i != (end-1)){ + System.out.print(","); + } + } + System.out.print("}"); + } +} \ No newline at end of file From 99fe3ee8bd03a71c6c3cad7d7f68314a21f9306c Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Wed, 14 Dec 2022 22:22:20 +0530 Subject: [PATCH 070/408] check as the input is feeded --- December - 10/cpp_nijuyonkadesu.cpp | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 December - 10/cpp_nijuyonkadesu.cpp diff --git a/December - 10/cpp_nijuyonkadesu.cpp b/December - 10/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..ad01ccd --- /dev/null +++ b/December - 10/cpp_nijuyonkadesu.cpp @@ -0,0 +1,34 @@ +#include + +using namespace std; +void result(); + +int main() { + int count; + cout<<"Enter no of words: "; + cin>>count; + cin.ignore(); + + for(int i=0; i Date: Wed, 14 Dec 2022 22:30:04 +0530 Subject: [PATCH 071/408] Update README.md --- README.md | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 43e8120..f465029 100644 --- a/README.md +++ b/README.md @@ -868,7 +868,43 @@ You are required to divide the given vertices into two sets such that: ---- - + +### December 15 - THE MURDERERS MEET +#### Problem Statement + +The death of Sam Keating, Annalise Keating's husband, caused the entire city to be in suspense as to who killed him because of the city of Philadelphia's soaring murder rate. The best defense attorney in Philadelphia, Annalise Keating also teaches law undergrads in addition to turning heads in the courtroom. She chooses pupils from her class for Keating 5. Due to security concerns, the Keating 5 have been conducting confidential missions via virtual meetings since her husband's death. The tech lead is Oliver, a hacker who organizes their meetings in a covert manner. Oliver is quite skilled at doing this. The last meeting, however, was chaotic due to the traffic that broke out as a result of several inmates speaking at once while muted. + +Help Oliver by creating an algorithm that uses mouse-based and timestamps to implement Queue in unmuting in order to get around this technical traffic. + + + +

+ + + +#### Sample Input/Output +``` +Input: {Wes, 12:00:30},{Michella, 12:03:40},{Asher, 12:00:01} + +Output: Asher, Wes, Michella. + +Input: {Annalise, 01:09:00},{ Frank, 01:02:30},{Laurel, 01:04:19} + +Output: Frank, Laurel, Annalise. + +``` +#### Explanation: +``` +When a meeting participant presses the unmute button, their name and the moment it was pressed are recorded. There are therefore three inputs, each with a timestamp and a name. + +They will now be organized into a queue based on when they pressed the microphone button, and once they are in a queue, the output is produced based on the time difference and the queue's arrangement. As a result, they will have quick access to unmute their mics. + +``` +- **References** +- [Queue data structure](https://www.javatpoint.com/data-structure-queue) +- [Queue in Java](https://www.geeksforgeeks.org/queue-interface-java/) +- [Queue in Python](https://www.geeksforgeeks.org/queue-interface-java/) + FAQ ====== From c1fe8cd6c55641a8143aa8906f8c682eff4c38b1 Mon Sep 17 00:00:00 2001 From: Tejasvi Bolla <119505502+tejasvibolla@users.noreply.github.com> Date: Wed, 14 Dec 2022 22:33:29 +0530 Subject: [PATCH 072/408] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f465029..692fada 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Check out our FAQ for more information. - [**December 12 - Shez in a Maze!**](#december-12---shez-in-a-maze) - [**December 13 - The Labyrinth**](#december-13---the-labyrinth) - [**December 14 - Math Mystery**](#december-14---math-mystery) + - [**December 15 - The Murderers Meet**](#december-15---the-murderers-meet) - [**FAQ**](#faq) @@ -870,6 +871,7 @@ You are required to divide the given vertices into two sets such that: ### December 15 - THE MURDERERS MEET + #### Problem Statement The death of Sam Keating, Annalise Keating's husband, caused the entire city to be in suspense as to who killed him because of the city of Philadelphia's soaring murder rate. The best defense attorney in Philadelphia, Annalise Keating also teaches law undergrads in addition to turning heads in the courtroom. She chooses pupils from her class for Keating 5. Due to security concerns, the Keating 5 have been conducting confidential missions via virtual meetings since her husband's death. The tech lead is Oliver, a hacker who organizes their meetings in a covert manner. Oliver is quite skilled at doing this. The last meeting, however, was chaotic due to the traffic that broke out as a result of several inmates speaking at once while muted. From d96b1a62e5d712138cc4827e390345c6d6a55da8 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Wed, 14 Dec 2022 22:40:46 +0530 Subject: [PATCH 073/408] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 692fada..d25bfb0 100644 --- a/README.md +++ b/README.md @@ -897,7 +897,11 @@ Output: Frank, Laurel, Annalise. ``` #### Explanation: ``` -When a meeting participant presses the unmute button, their name and the moment it was pressed are recorded. There are therefore three inputs, each with a timestamp and a name. +When a meeting participant presses the unmute button, their name and the moment it was pressed are recorded. + +There are therefore three inputs, each with a timestamp and a name. {name, timestamp}. + +The timestamp is in the format of hh:mm:ss. They will now be organized into a queue based on when they pressed the microphone button, and once they are in a queue, the output is produced based on the time difference and the queue's arrangement. As a result, they will have quick access to unmute their mics. From bbf8590d45d91dd71790637378041d7c1cd86016 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Wed, 14 Dec 2022 22:43:32 +0530 Subject: [PATCH 074/408] First push with the folders and assets. --- December - 15/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 15/.gitignore diff --git a/December - 15/.gitignore b/December - 15/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 15/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 d982b434eacd0157b0af3a295a1366455caf439b Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Wed, 14 Dec 2022 23:08:58 +0530 Subject: [PATCH 075/408] monkey jumping into the water score game --- December - 11/cpp_nijuyonkadesu.cpp | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 December - 11/cpp_nijuyonkadesu.cpp diff --git a/December - 11/cpp_nijuyonkadesu.cpp b/December - 11/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..89c41d6 --- /dev/null +++ b/December - 11/cpp_nijuyonkadesu.cpp @@ -0,0 +1,33 @@ +#include +#include + +using namespace std; +void getInput(vector&); + +int main(){ + // land: _ + // water: ~ + vector world; + vector moves; + + getInput(world); + getInput(moves); + + int totalSteps = 0; + for(auto i: moves){ + totalSteps += i - '0'; // convert char to int + if(world[totalSteps] == '~'){ + totalSteps -= i - '0'; + break; + } + } + cout<<"Monkey Score: "<& fillThis) { + char ch; + do{ + ch=getchar(); + fillThis.push_back(ch); + }while(ch!='\n'); +} From b1a483994e2f4f8dae702571e7c65a7777c78544 Mon Sep 17 00:00:00 2001 From: GREEDnim Date: Wed, 14 Dec 2022 23:25:03 +0530 Subject: [PATCH 076/408] day 12 , dfs, bruteforce --- December - 12/GREEDnim_day12_java.java | 62 ++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 December - 12/GREEDnim_day12_java.java diff --git a/December - 12/GREEDnim_day12_java.java b/December - 12/GREEDnim_day12_java.java new file mode 100644 index 0000000..18b406f --- /dev/null +++ b/December - 12/GREEDnim_day12_java.java @@ -0,0 +1,62 @@ +package acm; + +import java.util.ArrayList; +import java.util.List; + +public class GREEDnim_day12_java { + + static boolean[][]checked; + static List> ans; + public static void main(String[] args) { + + //hardcoded input XD + int[][]input={ {8,3,9}, {2,6,4}, {8,3,1}}; + + ans=new ArrayList<>(); + checked=new boolean[input.length][input[0].length]; + allCombinations(input,0,0,new ArrayList<>()); + int min=0; + + for(int i=1;ilist) + { + if(i==inp.length-1 && j==inp[0].length-1 ) + { + list.add(inp[i][j]); + ans.add(new ArrayList<>(list)); + list.remove(list.size()-1); + return; + } + if(i<0 || i>=inp.length || j<0 || j>=inp[0].length || checked[i][j]) return; + checked[i][j]=true; + list.add(inp[i][j]); + + allCombinations(inp,i+1,j,list); + allCombinations(inp,i-1,j,list); + allCombinations(inp,i,j-1,list); + allCombinations(inp,i,j+1,list); + list.remove(list.size()-1); + checked[i][j]=false; + + } + public static int sum(Listlist) + { + int ans=0; + for(int i=0;i Date: Thu, 15 Dec 2022 00:01:33 +0530 Subject: [PATCH 077/408] Add files via upload --- December - 01/Java_tarpandas.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 December - 01/Java_tarpandas.java diff --git a/December - 01/Java_tarpandas.java b/December - 01/Java_tarpandas.java new file mode 100644 index 0000000..da058ef --- /dev/null +++ b/December - 01/Java_tarpandas.java @@ -0,0 +1,28 @@ +import java.util.Scanner; +class Java_tarpandas{ + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + int n = sc.nextInt(); + sc.nextLine(); + String arr [] = new String[n]; + for(int i=0;i Date: Wed, 14 Dec 2022 19:24:00 +0000 Subject: [PATCH 078/408] added Monkey jump --- December - 11/C++_Dhruv.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 December - 11/C++_Dhruv.cpp diff --git a/December - 11/C++_Dhruv.cpp b/December - 11/C++_Dhruv.cpp new file mode 100644 index 0000000..63fcf84 --- /dev/null +++ b/December - 11/C++_Dhruv.cpp @@ -0,0 +1,33 @@ +#include +using namespace std; + +int main() { + // int n;cin>>n; + // vector input(n) ; + // for(auto &x:input)cin>>x; + + // int m;cin>>m; + // vector steps(m) ; + // for(auto &i:steps)cin>>i; + char input[] = [‘_’,’~’,’_’,’_’,’_’,’_’,’~’,’_’,’_’,’~’,’_’,’~’]; + int steps[]=[2,1,1,1,2,1,1,1,1]; + int n = input.length(); + int m = steps.length(); + int score =0; + // if(input[0]=='~')cout< Date: Wed, 14 Dec 2022 19:48:12 +0000 Subject: [PATCH 079/408] added dec 15 --- December - 15/C++_Dhruv.cpp | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 December - 15/C++_Dhruv.cpp diff --git a/December - 15/C++_Dhruv.cpp b/December - 15/C++_Dhruv.cpp new file mode 100644 index 0000000..0b12dbd --- /dev/null +++ b/December - 15/C++_Dhruv.cpp @@ -0,0 +1,51 @@ +#include +using namespace std; +class Compare +{ +public: + bool operator()(pair a, pair b) + { + string aa=""; + string bb =""; + for(int i=0;i<8;i++){ + if(i!=2 and i!=5){ + aa += a.second; + bb += b.second; + } + } + int A = stoi(aa); + int B =stoi(bb); + return A>B; + } +}; +int main() { + // INPUT IN BELOW FORMAT + // Wes 12:00:30 + // Michella 12:03:40 + // Asher 12:00:01 + + // Priority queue is defined using the custom comparator + priority_queue,vector>,Compare> minHeapBySecondEl; + int n; + + + for(int i=0;i<3;i++) + { + + string a,b; + cin>>a>>b; + minHeapBySecondEl.push({a,b}); + } + + cout<<"Output:"< top=minHeapBySecondEl.top(); + minHeapBySecondEl.pop(); + cout<<"("< Date: Thu, 15 Dec 2022 09:09:08 +0530 Subject: [PATCH 080/408] =?UTF-8?q?December=205=20-=20Don=E2=80=99t=20let?= =?UTF-8?q?=20Mason=20misspend!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- December - 05/Java_souvikpal2000.java | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 December - 05/Java_souvikpal2000.java diff --git a/December - 05/Java_souvikpal2000.java b/December - 05/Java_souvikpal2000.java new file mode 100644 index 0000000..79bf153 --- /dev/null +++ b/December - 05/Java_souvikpal2000.java @@ -0,0 +1,45 @@ +import java.io.*; +public class Java_souvikpal2000{ + public static void main(String args[]) throws IOException{ + InputStreamReader isr=new InputStreamReader(System.in); + BufferedReader br=new BufferedReader(isr); + + System.out.println("Input : "); + System.out.print("fuel_price="); + int fuel_price = Integer.parseInt(br.readLine()); + + int expenditure = 0; + int fixedFuelPrice = fuel_price; + for(int day=1; day<=31; day++){ + if(day%3 == 0 && day%5 == 0){ + fuel_price = fuel_price + 3 - 2; + } + else if(day%3 == 0){ + fuel_price = fuel_price + 3; + } + else if(day%5 == 0){ + fuel_price = fuel_price - 2; + } + else{ + fuel_price = fixedFuelPrice; + } + expenditure = expenditure + (fuel_price * 2); + } + expenditure = expenditure - 4; + + int percent = (50000 * 10)/100; + String msg = ""; + if(expenditure > percent){ + msg = "EXPENDITURE EXCEEDING LIMIT"; + }else{ + msg = "EXPENDITURE WITHIN LIMIT"; + } + + System.out.println(""); + System.out.println("Output : "); + System.out.println("Expenditure="+expenditure); + System.out.println(""); + System.out.println(msg); + + } +} \ No newline at end of file From d67b974f382dda01d94d886348a26caadaf9f469 Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Thu, 15 Dec 2022 14:26:45 +0530 Subject: [PATCH 081/408] shortest path in the maze using backtracking, added some comments --- December - 10/cpp_nijuyonkadesu.cpp | 6 ++- December - 12/cpp_nijuyonkadesu.cpp | 76 +++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 December - 12/cpp_nijuyonkadesu.cpp diff --git a/December - 10/cpp_nijuyonkadesu.cpp b/December - 10/cpp_nijuyonkadesu.cpp index ad01ccd..09f38f4 100644 --- a/December - 10/cpp_nijuyonkadesu.cpp +++ b/December - 10/cpp_nijuyonkadesu.cpp @@ -7,7 +7,7 @@ int main() { int count; cout<<"Enter no of words: "; cin>>count; - cin.ignore(); + cin.ignore(); // to prevent a edge case, try commenting this line and run ^_^ for(int i=0; i +#include +#include +#include + +using namespace std; + +vector> input(int); +void pathFinder(vector>& visited, vector> &maze, vector& path, vector> &possibility, int x, int y, int n); +bool isSafe(vector>& visited, int x, int y, int n); + +int main() { + int n; + cin>>n; + + vector> visited(n, vector (n, 0)); + vector> maze = input(n); + vector path; + vector> possibility; + + int min = INT_MAX; + int pathPointer = 0, index =0; + + pathFinder(visited, maze, path, possibility, 0, 0, n); + for(auto ans: possibility){ + index++; + int sum = accumulate(ans.begin(), ans.end(), 0); + if(sum < min){ + pathPointer = index; + min = sum; + } + } + + for(auto i: possibility[pathPointer]) + cout<> input(int n) { + vector> maze(n, vector (n, 0)); + + for(int i=0; i>maze[i][j]; + return maze; +} + +void pathFinder(vector> &visited, vector> &maze, vector &path, vector> &possibility, int x, int y, int n) { + if(x==n-1 && y==n-1){ + path.push_back(maze[x][y]); + possibility.push_back(path); + path.pop_back(); + return ; + } + + visited[x][y] = 1; // Mark visited + path.push_back(maze[x][y]); + + if(isSafe(visited, x+1, y, n)) // Right + pathFinder(visited, maze, path, possibility, x+1, y, n); + if(isSafe(visited, x, y+1, n)) // Bottom + pathFinder(visited, maze, path, possibility, x, y+1, n); + if(isSafe(visited, x-1, y, n)) // Left + pathFinder(visited, maze, path, possibility, x-1, y, n); + if(isSafe(visited, x, y+1, n)) // Up + pathFinder(visited, maze, path, possibility, x, y+1, n); + + visited[x][y] = 0; // Backtracking + path.pop_back(); + return ; +} + + +bool isSafe(vector>& visited, int x, int y, int n){ + return (x>=0 && x=0 && y Date: Thu, 15 Dec 2022 21:16:35 +0530 Subject: [PATCH 082/408] Create day2.cpp --- December - 02/day2.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 December - 02/day2.cpp diff --git a/December - 02/day2.cpp b/December - 02/day2.cpp new file mode 100644 index 0000000..8ed01a1 --- /dev/null +++ b/December - 02/day2.cpp @@ -0,0 +1,18 @@ +#include +#include + +using namespace std; +int main() { + + string str1; + cin >> str1; + + int l = str1.length(); + string str3 = str1.substr(l-4,2); + string str2 = str1.substr(0, l-4); + + cout< Date: Thu, 15 Dec 2022 21:58:01 +0530 Subject: [PATCH 083/408] Create day4.cpp --- December - 04/day4.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 December - 04/day4.cpp diff --git a/December - 04/day4.cpp b/December - 04/day4.cpp new file mode 100644 index 0000000..f7be128 --- /dev/null +++ b/December - 04/day4.cpp @@ -0,0 +1,51 @@ +// C++ program to print largest contiguous array sum + +#include +#include +using namespace std; + +void maxSubArraySum(int a[], int size) +{ + int max_so_far = INT_MIN, max_ending_here = 0, + start = 0, end = 0, s = 0; + + for (int i = 0; i < size; i++) { + max_ending_here += a[i]; + + if (max_so_far < max_ending_here) { + max_so_far = max_ending_here; + start = s; + end = i; + } + + if (max_ending_here < 0) { + max_ending_here = 0; + s = i + 1; + } + } + cout << "Profit Value: " << max_so_far << endl; + cout << "Proposed days to sell: Day: " << start+1 << " to Day: " << end+1 << endl; + cout<< "Stock market Change Values: "; + for(int i=start;i<=end;i++){ + cout << a[i] <<" "; + } + +} +//5 -4 12 -2 -5 6 -2 -3 1 5 -6 -11 7 -31 9 2 -3 8 -5 + +int main() +{ + int n; + cout<<"No. of Days: "; + cin>>n; + + cout<<"Enter stock market change values:"<> a[i]; + } + maxSubArraySum(a, n); + return 0; +} +//Create by +//Samriddh Prasad From ee7be4a4ce92d1d6af9c4488328709cf2d08d8f7 Mon Sep 17 00:00:00 2001 From: deepu2004 <120033475+deepu2004@users.noreply.github.com> Date: Thu, 15 Dec 2022 22:32:25 +0530 Subject: [PATCH 084/408] Update README.md --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/README.md b/README.md index d25bfb0..e6f416b 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ Check out our FAQ for more information. - [**December 13 - The Labyrinth**](#december-13---the-labyrinth) - [**December 14 - Math Mystery**](#december-14---math-mystery) - [**December 15 - The Murderers Meet**](#december-15---the-murderers-meet) + - [**December 16 - H2O Receptacle**](#december-16---h2o-receptacle) - [**FAQ**](#faq) @@ -911,6 +912,50 @@ They will now be organized into a queue based on when they pressed the microphon - [Queue in Java](https://www.geeksforgeeks.org/queue-interface-java/) - [Queue in Python](https://www.geeksforgeeks.org/queue-interface-java/) +---- + + +### December 16 - H2O Receptacle + +#### Problem Statement + +John has an integer array height of n non-negative integers height [n], where each value represents a point at coordinate (i, height[i]). Now n vertical lines are drawn such that the two endpoints of line i are at (i, 0) and (i, height[i]). Here each pair of a line with the x-axis forms a container. + +Determine two lines that together with the x-axis form a container, such that the container contains the most water. + +Return the maximum amount of water a container can store. + + + +

+ + + +#### Sample Input/Output +``` +Input: height = [6,2,5,4,8] +Output: 24 + + +Input: height = [1,8,6,2,5,4,8,3,7] +Output: 49 + +``` +#### Explanation: +``` +The above vertical lines are represented by an array [1,8,6,2,5,4,8,3,7]. In this case,the area between lines 7 and 8 will be maximum. +7 and 8 are 7 units in distance apart, so the size of the base is 7 . + +Height of the container is min(7,8)= 7. So the max area of water (blue section) the container can contain is 49. + +``` +- **References** +- [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) +- [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) +- [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + + +---- FAQ ====== From ea074c1bf04b730c8cfae7f19a8ec3ec959cdb19 Mon Sep 17 00:00:00 2001 From: Dhruv Rawat <89683914+yesdhruv@users.noreply.github.com> Date: Thu, 15 Dec 2022 17:06:29 +0000 Subject: [PATCH 085/408] added minesweeper --- December - 03/C++_Dhruv.cpp | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 December - 03/C++_Dhruv.cpp diff --git a/December - 03/C++_Dhruv.cpp b/December - 03/C++_Dhruv.cpp new file mode 100644 index 0000000..7fa8c14 --- /dev/null +++ b/December - 03/C++_Dhruv.cpp @@ -0,0 +1,53 @@ +#include +using namespace std; + +int main() { + + vector>v{{'-', '#', '-', '-', '#'},{'-', '-', '-', '-', '-'}, {'-', '-', '#', '-', '-'},{'-', '#', '-', '-', '#'},{'-', '#', '-', '-', '#'}}; + int n = size(v); + int m = size(v[0]); + vector>arr(n,vector (m, 0)); + for(int i=0;i=0 and arr[i-1][j]!=-1) + arr[i-1][j]++; + if(i+1=0 and arr[i][j-1]!=-1) + arr[i][j-1]++; + if(j+1=0 and j-1>=0 and arr[i-1][j-1]!=-1) + arr[i-1][j-1]++; + if(i-1>=0 and j+1=0 and arr[i+1][j-1]!=-1) + arr[i+1][j-1]++; + + + } + + } + } +// showing output matrix + + for(int i=0;i Date: Thu, 15 Dec 2022 23:12:11 +0530 Subject: [PATCH 086/408] First push with the folders and assets. --- December -16/.gitignore | 231 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December -16/.gitignore diff --git a/December -16/.gitignore b/December -16/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December -16/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 99a041631a9db715de109c5a37beef2e084f9915 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Thu, 15 Dec 2022 23:15:33 +0530 Subject: [PATCH 087/408] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e6f416b..6774e20 100644 --- a/README.md +++ b/README.md @@ -943,7 +943,10 @@ Output: 49 ``` #### Explanation: ``` -The above vertical lines are represented by an array [1,8,6,2,5,4,8,3,7]. In this case,the area between lines 7 and 8 will be maximum. +The above vertical lines are represented by an array [1,8,6,2,5,4,8,3,7]. + +In this case,the area between lines 7 and 8 will be maximum. + 7 and 8 are 7 units in distance apart, so the size of the base is 7 . Height of the container is min(7,8)= 7. So the max area of water (blue section) the container can contain is 49. From 77e54bb216dd9008b59c7153b4e2e0fb50439227 Mon Sep 17 00:00:00 2001 From: Dhruv Rawat <89683914+yesdhruv@users.noreply.github.com> Date: Thu, 15 Dec 2022 17:57:34 +0000 Subject: [PATCH 088/408] added word map --- December - 07/C++_Dhruv.cpp | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 December - 07/C++_Dhruv.cpp diff --git a/December - 07/C++_Dhruv.cpp b/December - 07/C++_Dhruv.cpp new file mode 100644 index 0000000..2bb3afc --- /dev/null +++ b/December - 07/C++_Dhruv.cpp @@ -0,0 +1,59 @@ +#include +using namespace std; +bool ismatch(string row , string word){ + if(size(row)grid{ + {"GEEE"}, + {"GELL"}, + {"IDGG"}}; + // all chars are concataned + // from col to row using nested for loops and store them as string + // in grid_on_col + vectorgrid_on_col{ + {"GGI"}, + {"EED"}, + {"ELG"}, + {"ELG"} + }; + string word= "ELL"; + + bool ans = false; + for(auto row:grid) + { + ans = ismatch(row,word); + if(ans == true)break; + } + if(ans!=true) + { + for(auto row:grid_on_col) + { + ans = ismatch(row,word); + if(ans == true)break; + } + + } + + + ans==true?cout<<"FOUND":cout<<"NOT FOUND"; +} From ae70aefa30c4348badab5046852aeaf63811a2d9 Mon Sep 17 00:00:00 2001 From: Dhruv Rawat <89683914+yesdhruv@users.noreply.github.com> Date: Thu, 15 Dec 2022 18:12:32 +0000 Subject: [PATCH 089/408] added DEC 10 --- December - 10/C++_Dhruv.cpp | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 December - 10/C++_Dhruv.cpp diff --git a/December - 10/C++_Dhruv.cpp b/December - 10/C++_Dhruv.cpp new file mode 100644 index 0000000..61efc57 --- /dev/null +++ b/December - 10/C++_Dhruv.cpp @@ -0,0 +1,40 @@ +#include +using namespace std; +bool check_vowel(char ch) +{ + if(ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u') + return true; + else + return false; +} +int main() { + + int t ;cin>>t; + + while(t--){ + bool flag = false; + int n;cin>>n;// size of word + string word;cin>>word; + if(n<4)flag = false; + else + { + for(int i=0;i=4){ + flag = true; + break; + } + i++; + streak++; + } + if(flag)break; + } + + } + + flag==true?cout<<"NO":cout<<"YES"; + cout< Date: Fri, 16 Dec 2022 09:43:29 +0530 Subject: [PATCH 090/408] day-13 recursion --- December - 13/GREEDnim_day13_java.java | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 December - 13/GREEDnim_day13_java.java diff --git a/December - 13/GREEDnim_day13_java.java b/December - 13/GREEDnim_day13_java.java new file mode 100644 index 0000000..fe5f4c3 --- /dev/null +++ b/December - 13/GREEDnim_day13_java.java @@ -0,0 +1,34 @@ +package acm; + +import java.util.Arrays; + +public class GREEDnim_day13_java { + static int[][] ans; + public static void main(String[] args) { + + int[][] inp={ {1,1,1,0}, + {1,0,1,1}, + {0,1,0,1}, + {0,1,1,1}}; + + ans=new int[inp.length][inp[0].length]; + findOnePath(inp,0,0); + for(int[] row:ans) + { + System.out.println(Arrays.toString(row)); + } + + } + + public static boolean findOnePath(int[][] inp,int i,int j) + { + if(i==inp.length-1 && j== inp[0].length) return true; + + if(i<0 || j<0 || i>=inp.length || j>=inp[0].length || inp[i][j]!=1) return false; + ans[i][j]=1; + boolean ansFound=findOnePath(inp,i,j+1) || findOnePath(inp,i+1,j); + if(!ansFound) inp[i][j]=0; + + return ansFound; + } +} From 1c1fa6b3e62a8c29bf1f66cde506c79ed91d9f06 Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Fri, 16 Dec 2022 10:14:41 +0530 Subject: [PATCH 091/408] December 6 - Swapped --- December - 06/Java_souvikpal2000.java | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 December - 06/Java_souvikpal2000.java diff --git a/December - 06/Java_souvikpal2000.java b/December - 06/Java_souvikpal2000.java new file mode 100644 index 0000000..b1492ff --- /dev/null +++ b/December - 06/Java_souvikpal2000.java @@ -0,0 +1,45 @@ +import java.util.*; +class Java_souvikpal2000{ + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input: "); + System.out.print("n="); + int n = sc.nextInt(); + int[] arr = new int[n]; + System.out.print("Set of numbers: "); + for(int i=0;i Date: Fri, 16 Dec 2022 12:13:53 +0000 Subject: [PATCH 092/408] added Shez in maze --- December - 12/C++_Dhruv.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 December - 12/C++_Dhruv.cpp diff --git a/December - 12/C++_Dhruv.cpp b/December - 12/C++_Dhruv.cpp new file mode 100644 index 0000000..c32644e --- /dev/null +++ b/December - 12/C++_Dhruv.cpp @@ -0,0 +1,30 @@ +#include +using namespace std; + +#define R 4 +#define C 4 + +int minCost(int cost[R][C], int m, int n) +{ + if (n < 0 || m < 0) + return INT_MAX; + else if (m == 0 && n == 0) + return cost[m][n]; + else + return cost[m][n] + + min(minCost(cost, m - 1, n), + minCost(cost, m, n - 1)); +} + +int main() +{ + + int cost[R][C] + = { {9,4,9,9}, {6,7,6,4}, {8,3,3,7}, {7,4,9,10} }; + + cout << minCost(cost, R-1, C-1) << endl; + + return 0; +} + + From 16e40a4976358404978a0f95cc4d99f43b6feade Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Fri, 16 Dec 2022 18:57:23 +0530 Subject: [PATCH 093/408] Largest H20 container using 2 pointers in single loop --- December -16/cpp_nijuyonkadesu.cpp | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 December -16/cpp_nijuyonkadesu.cpp diff --git a/December -16/cpp_nijuyonkadesu.cpp b/December -16/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..adcaafe --- /dev/null +++ b/December -16/cpp_nijuyonkadesu.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include + +using namespace std; + +vector input(int); +int maxPossibleVolume(vector&, int); + +int main(){ + int n; + cin>>n; + + vector water = input(n); + cout<<"Max Volume this container can hold: "<& water, int n){ + int s=0, e=n-1; // pointer to start and end of the given data + int volume = 0; + + for(int f=0, r=e; f input(int n){ + vector water(n); + for(int j=0; j>water[j]; + return water; +} From a0ed3ea296f8427efb8c02128e0b329aa08c5b69 Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Fri, 16 Dec 2022 19:11:26 +0530 Subject: [PATCH 094/408] calculate max volume, logic fix --- December -16/cpp_nijuyonkadesu.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/December -16/cpp_nijuyonkadesu.cpp b/December -16/cpp_nijuyonkadesu.cpp index adcaafe..074137b 100644 --- a/December -16/cpp_nijuyonkadesu.cpp +++ b/December -16/cpp_nijuyonkadesu.cpp @@ -1,7 +1,8 @@ #include #include -#include #include +#include +#include using namespace std; @@ -28,7 +29,7 @@ int maxPossibleVolume(vector& water, int n){ e=r; } } - return accumulate(water.begin()+s, water.begin()+e+1, 0); // without e+1, last element is not considered, idk why + return min(water[s],water[e]) * abs(s-e); // calculate volume and return it } vector input(int n){ From 7e8308c59298fd54aef8013d189a32cbf9ed3b9b Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <85601344+nijuyonkadesu@users.noreply.github.com> Date: Fri, 16 Dec 2022 19:33:08 +0530 Subject: [PATCH 095/408] fix another flaw in logic --- December -16/cpp_nijuyonkadesu.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/December -16/cpp_nijuyonkadesu.cpp b/December -16/cpp_nijuyonkadesu.cpp index 074137b..645dc16 100644 --- a/December -16/cpp_nijuyonkadesu.cpp +++ b/December -16/cpp_nijuyonkadesu.cpp @@ -20,16 +20,21 @@ int main(){ int maxPossibleVolume(vector& water, int n){ int s=0, e=n-1; // pointer to start and end of the given data int volume = 0; + int currentVolume = 0; - for(int f=0, r=e; f=0; f++, r--){ if(water[s] input(int n){ From 1c8240d1508d437663ccfe768c1ebd613e53e8c5 Mon Sep 17 00:00:00 2001 From: vedanth-pareek <120103552+vedanth-pareek@users.noreply.github.com> Date: Fri, 16 Dec 2022 21:33:27 +0530 Subject: [PATCH 096/408] Update README.md --- README.md | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/README.md b/README.md index 6774e20..5923ea7 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Check out our FAQ for more information. - [**December 14 - Math Mystery**](#december-14---math-mystery) - [**December 15 - The Murderers Meet**](#december-15---the-murderers-meet) - [**December 16 - H2O Receptacle**](#december-16---h2o-receptacle) + - [**December 17 - Zig Zag Conversion**](#december-17---zig-zag-conversion) - [**FAQ**](#faq) @@ -957,8 +958,72 @@ Height of the container is min(7,8)= 7. So the max area of water (blue section) - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) +---- + + +### December 17 - Zig Zag Conversion + +#### Problem Statement + +You are given a string ‘Str’ and an integer ‘Row’. You have to convert and print the row into a zig- +zag pattern with rows equal to ‘Row’ and display the output row-wise. You may refer to the given sample input/output. + + + +#### Sample Input/Output +``` +Input: + +Str = “spaghettigood” +Row = 4 + +Output: + +Zig-zag pattern: +s t d +p e t o +a h i o +g g + +Row-wise output: “stdpetoahiogg” + +Input: + +Str = “spritebetter” +Row = 3 + +Output: + +Zig-zag pattern: +s t t +p i e e t r +r b e + +Row-wise output: “sttpieetrrbe” + +``` +#### Explanation: +``` +Input Format : + +The first line of each test case contains a string ‘Str’, denoting the input string. +The second line of each test case contains a single integer ‘Row’, denoting the number of rows in the +zig-zag pattern to be created. + +Output Format : + +For each test case, print the new string after zig-zag conversion. +Output for each test case should be printed in a separate line. + +``` +- **References** +- [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) +- [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) +- [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) ---- + + FAQ ====== From af205c51420d071563b2a63148c79b8d5d558e6e Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Fri, 16 Dec 2022 23:08:07 +0530 Subject: [PATCH 097/408] First push with the folders and assets. --- December - 17/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 17/.gitignore diff --git a/December - 17/.gitignore b/December - 17/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 17/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 b7e51f8effc517c213554ed61c48fbfae3f77975 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Fri, 16 Dec 2022 23:10:55 +0530 Subject: [PATCH 098/408] First push with the folders and assets. --- {December -16 => December - 16}/.gitignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {December -16 => December - 16}/.gitignore (100%) diff --git a/December -16/.gitignore b/December - 16/.gitignore similarity index 100% rename from December -16/.gitignore rename to December - 16/.gitignore From 786e723e10f0b3786a8732f6b66b59752351fe3c Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Fri, 16 Dec 2022 23:13:35 +0530 Subject: [PATCH 099/408] Update README.md --- README.md | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 5923ea7..f73bfba 100644 --- a/README.md +++ b/README.md @@ -978,14 +978,7 @@ Str = “spaghettigood” Row = 4 Output: - -Zig-zag pattern: -s t d -p e t o -a h i o -g g - -Row-wise output: “stdpetoahiogg” +stdpetoahiogg Input: @@ -993,13 +986,7 @@ Str = “spritebetter” Row = 3 Output: - -Zig-zag pattern: -s t t -p i e e t r -r b e - -Row-wise output: “sttpieetrrbe” +sttpieetrrbe ``` #### Explanation: @@ -1007,6 +994,13 @@ Row-wise output: “sttpieetrrbe” Input Format : The first line of each test case contains a string ‘Str’, denoting the input string. + +Zig-zag pattern: +s t d +p e t o +a h i o +g g + The second line of each test case contains a single integer ‘Row’, denoting the number of rows in the zig-zag pattern to be created. From 529d0b0cc6c00b5c3cf7ca28a9e990e5f77e67c3 Mon Sep 17 00:00:00 2001 From: Tarpan Das <61510889+tarpandas@users.noreply.github.com> Date: Fri, 16 Dec 2022 23:46:02 +0530 Subject: [PATCH 100/408] Add files via upload December - 02 solved --- December - 02/Java_tarpandas.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 December - 02/Java_tarpandas.java diff --git a/December - 02/Java_tarpandas.java b/December - 02/Java_tarpandas.java new file mode 100644 index 0000000..d8a6764 --- /dev/null +++ b/December - 02/Java_tarpandas.java @@ -0,0 +1,20 @@ +import java.util.Scanner; +public class Java_tarpandas { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + String secretCode = sc.nextLine(); + + int n = secretCode.length(); + + String firstTwoLetters = secretCode.substring(n-4, n-2); + secretCode = secretCode.substring(0,n-4); + + StringBuilder sb = new StringBuilder(firstTwoLetters); + sb.append(secretCode); + + secretCode = sb.toString(); + + System.out.println(secretCode); + sc.close(); + } +} From 5743e836359dd69a7216bbb9c8ca7a79b264fa78 Mon Sep 17 00:00:00 2001 From: Tarpan Das <61510889+tarpandas@users.noreply.github.com> Date: Fri, 16 Dec 2022 23:46:51 +0530 Subject: [PATCH 101/408] Add files via upload December - 03 solved --- December - 03/Java_tarpandas.java | 83 +++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 December - 03/Java_tarpandas.java diff --git a/December - 03/Java_tarpandas.java b/December - 03/Java_tarpandas.java new file mode 100644 index 0000000..0025116 --- /dev/null +++ b/December - 03/Java_tarpandas.java @@ -0,0 +1,83 @@ +import java.util.Scanner; + +public class Java_tarpandas{ + + static void numberingTheNeighbours(char[][] arr, int i, int j, int n) { + + // Checking horizontal and vertical elements not out of bounds + + if(i-1 >= 0 && arr[i-1][j] != '#') { + arr[i-1][j] = (char)((int) arr[i-1][j] + 1); + } + + if(i+1 < n && arr[i+1][j] != '#') { + arr[i+1][j] = (char)((int) arr[i+1][j] + 1); + } + + if(j-1 > -1 && arr[i][j-1] != '#') { + arr[i][j-1] = (char)((int) arr[i][j-1] + 1); + } + + if(j+1 < n && arr[i][j+1] != '#') { + arr[i][j+1] = (char)((int) arr[i][j+1] + 1); + } + + // top left + + if(i-1 >= 0 && j-1 >=0 && arr[i-1][j-1] != '#') { + arr[i-1][j-1] = (char)((int) arr[i-1][j-1] + 1); + } + + // top right + + if(i-1 >= 0 && j+1 < n && arr[i-1][j+1] != '#') { + arr[i-1][j+1] = (char)((int) arr[i-1][j+1] + 1); + } + + // bottom left + + if(i+1 < n && j-1 >= 0 && arr[i+1][j-1] != '#') { + arr[i+1][j-1] = (char)((int) arr[i+1][j-1] + 1); + } + + // bottom right + + if(i+1 Date: Sat, 17 Dec 2022 00:28:30 +0530 Subject: [PATCH 102/408] Add files via upload December - 04 solved --- December - 04/Java_tarpandas.java | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 December - 04/Java_tarpandas.java diff --git a/December - 04/Java_tarpandas.java b/December - 04/Java_tarpandas.java new file mode 100644 index 0000000..b3e197c --- /dev/null +++ b/December - 04/Java_tarpandas.java @@ -0,0 +1,41 @@ +import java.util.Scanner; +public class Java_tarpandas { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.print("No. of Days:"); + int noOfDays = sc.nextInt(); + + int sMarktChangeValues[] = new int[noOfDays]; + + System.out.print("Given stock market change values: "); + for(int i=0; i max) { + startDayToSell = i+1; + endDayToSell = j+1; + max = count; + } + } + } + + // Display outputs + System.out.println("Profit Vlue: "+max); + System.out.println("Proposed days to sell: Day: "+startDayToSell+" to "+" Day: "+endDayToSell); + System.out.print("Stock market Change Values: {"); + for(int i=startDayToSell -1; i Date: Sat, 17 Dec 2022 10:31:07 +0530 Subject: [PATCH 103/408] December 8 - Aptitude Check! --- December - 08/Java_souvikpal2000.java | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 December - 08/Java_souvikpal2000.java diff --git a/December - 08/Java_souvikpal2000.java b/December - 08/Java_souvikpal2000.java new file mode 100644 index 0000000..c235b77 --- /dev/null +++ b/December - 08/Java_souvikpal2000.java @@ -0,0 +1,33 @@ +import java.util.*; +public class Java_souvikpal2000{ + public StringBuilder aptitudeCheck(String str){ + StringBuilder result=new StringBuilder(); + StringBuilder sb=new StringBuilder(); + int length = str.length(); + for(int i=0;i Date: Sat, 17 Dec 2022 12:35:16 +0530 Subject: [PATCH 104/408] Add files via upload December - 05 solved --- December - 05/Java_tarpandas.java | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 December - 05/Java_tarpandas.java diff --git a/December - 05/Java_tarpandas.java b/December - 05/Java_tarpandas.java new file mode 100644 index 0000000..b9b317a --- /dev/null +++ b/December - 05/Java_tarpandas.java @@ -0,0 +1,35 @@ +import java.util.Scanner; +public class Java_tarpandas { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.print("fuel_price="); + int fuelPrice = sc.nextInt(); + int tempFuelPrice = fuelPrice; + + // price increased by 3 every 3 days, so 10 times in 31 days + // price decreased by 2 every 5 days, so 6 times in 31 days + + int extraCostPerMonth = 0; + + for(int i=1; i<=31; i++) { + if(i%3 == 0) { + tempFuelPrice += 3; + } + if(i%5 == 0) { + tempFuelPrice -= 2; + } + extraCostPerMonth += tempFuelPrice; + tempFuelPrice = fuelPrice; + } + int totalCost = extraCostPerMonth * 2; + + System.out.println("Expenditure="+totalCost); + + if(totalCost <= 5000) { + System.out.println("\"EXPENDITURE WITHIN LIMIT\""); + } else { + System.out.println("\"EXPENDITURE EXCEEDING LIMIT\""); + } + sc.close(); + } +} From 8a2cbda51b18e3a911cd76b3d616204864f1957c Mon Sep 17 00:00:00 2001 From: Tarpan Das <61510889+tarpandas@users.noreply.github.com> Date: Sat, 17 Dec 2022 12:35:35 +0530 Subject: [PATCH 105/408] Add files via upload December - 06 solved --- December - 06/Java_tarpandas.java | 54 +++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 December - 06/Java_tarpandas.java diff --git a/December - 06/Java_tarpandas.java b/December - 06/Java_tarpandas.java new file mode 100644 index 0000000..e605156 --- /dev/null +++ b/December - 06/Java_tarpandas.java @@ -0,0 +1,54 @@ +import java.util.Scanner; +public class Java_tarpandas { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = 3; //sc.nextInt(); + int arr[] = new int[3]; + + System.out.print("Position="); + int p = sc.nextInt(); + if(p<=n && p>0){ + + String friends[] = {"Tanika", "Bob"}; + p -=1; + + System.out.print("Set of numbers: "); + for(int i=0; i Date: Sat, 17 Dec 2022 14:22:03 +0530 Subject: [PATCH 106/408] updated - dec 17 -Sahitya A --- December - 17/.gitignore | 140 +++++++++------------------------------ 1 file changed, 31 insertions(+), 109 deletions(-) diff --git a/December - 17/.gitignore b/December - 17/.gitignore index ac6d3a2..498fc1f 100644 --- a/December - 17/.gitignore +++ b/December - 17/.gitignore @@ -1,19 +1,35 @@ -# gitignore file for "A December of Algorithms 2022" -# 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 +#code +def printZigZagConcat(str, n): + if n == 1: + print(str) + return + l = len(str) + arr=["" for x in range(l)] + row = 0 + for i in range(l): + arr[row] += str[i] + if row == n - 1: + down = False + elif row == 0: + down = True + if down: + row += 1 + else: + row -= 1 + for i in range(n): + print(arr[i], end = "") +str = input("enter the string") +n = int(input("enter the number of rows")) +printZigZagConcat(str, n) +#code # C extensions *.so -# node.js -/node_modules -package-lock.json - # Distribution / packaging .Python build/ @@ -93,7 +109,13 @@ ipython_config.py .python-version # pipenv -Pipfile.lock +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff @@ -129,103 +151,3 @@ 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 9b2cbebd8e41923e27d94c50caac09bff17eec9e Mon Sep 17 00:00:00 2001 From: Samriddh Prasad <72660273+Samriddh2703@users.noreply.github.com> Date: Sat, 17 Dec 2022 17:32:47 +0530 Subject: [PATCH 107/408] Create day8.cpp --- December - 08/day8.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 December - 08/day8.cpp diff --git a/December - 08/day8.cpp b/December - 08/day8.cpp new file mode 100644 index 0000000..27ce728 --- /dev/null +++ b/December - 08/day8.cpp @@ -0,0 +1,19 @@ + +#include +using namespace std; + +int main() +{ + string str,ans,f; + getline(cin, str); + + for(int i = 0; i < str.length(); i+=2){ + ans = str.substr(i,2); + reverse(ans.begin(), ans.end()); + f+=ans; + } + cout< Date: Sat, 17 Dec 2022 18:48:35 +0530 Subject: [PATCH 108/408] Create python3_Esha.py --- December - 17/python3_Esha.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 December - 17/python3_Esha.py diff --git a/December - 17/python3_Esha.py b/December - 17/python3_Esha.py new file mode 100644 index 0000000..aa94eae --- /dev/null +++ b/December - 17/python3_Esha.py @@ -0,0 +1,17 @@ +s = input("Enter the string") +numRows = int(input("Enter the number of rows")) + +if numRows == 1: + print(s) + +rows = ["" for i in range(numRows)] +direction = -1 +row = 0 +for i in range(len(s)): + rows[row]+=s[i] + if (row == 0 or row==numRows-1): + direction *= -1 + row+=direction + +print("".join(rows)) + From d28741d8a36e298aaa6c3b55479a952e531fc440 Mon Sep 17 00:00:00 2001 From: Harsh Rajput <104441259+hrajput0322@users.noreply.github.com> Date: Sat, 17 Dec 2022 18:51:41 +0530 Subject: [PATCH 109/408] Add files via upload --- december2.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 december2.cpp diff --git a/december2.cpp b/december2.cpp new file mode 100644 index 0000000..e8c0810 --- /dev/null +++ b/december2.cpp @@ -0,0 +1,13 @@ +#include +using namespace std; + +int main(){ + string str; + cin>>str; + string ans; + ans=ans+str[str.length()-4]+str[str.length()-3]; + for (int i=0;i Date: Sat, 17 Dec 2022 18:55:45 +0530 Subject: [PATCH 110/408] Create python3_Esha.py --- December - 16/python3_Esha.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 December - 16/python3_Esha.py diff --git a/December - 16/python3_Esha.py b/December - 16/python3_Esha.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/December - 16/python3_Esha.py @@ -0,0 +1 @@ + From 6eb90b41a0c36a679962f9257c3a8a06d63cdda6 Mon Sep 17 00:00:00 2001 From: Esha H <54173101+eshah122@users.noreply.github.com> Date: Sat, 17 Dec 2022 19:01:42 +0530 Subject: [PATCH 111/408] Delete python3_Esha.py --- December - 16/python3_Esha.py | 1 - 1 file changed, 1 deletion(-) delete mode 100644 December - 16/python3_Esha.py diff --git a/December - 16/python3_Esha.py b/December - 16/python3_Esha.py deleted file mode 100644 index 8b13789..0000000 --- a/December - 16/python3_Esha.py +++ /dev/null @@ -1 +0,0 @@ - From 5d492c7ad314dd20191e518e56850c22b4daa7a8 Mon Sep 17 00:00:00 2001 From: Samriddh Prasad <72660273+Samriddh2703@users.noreply.github.com> Date: Sat, 17 Dec 2022 19:38:20 +0530 Subject: [PATCH 112/408] Create day7.cpp --- December - 07/day7.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 December - 07/day7.cpp diff --git a/December - 07/day7.cpp b/December - 07/day7.cpp new file mode 100644 index 0000000..08d2156 --- /dev/null +++ b/December - 07/day7.cpp @@ -0,0 +1,77 @@ +#include +using namespace std; + +#define R 15 +#define C 16 + +int x[] = {-1, 0, 0, 1}; +int y[] = {0, -1, 1, 0}; + +bool search2D(char grid[R][C], int row, int col, string word) +{ + if (grid[row][col] != word[0]) + return false; + + int len = word.length(); + for (int dir = 0; dir < 4; dir++) + { + int k, rd = row + x[dir], cd = col + y[dir]; + for (k = 1; k < len; k++) + { + if (rd >= R || rd < 0 || cd >= C || cd < 0) + break; + + if (grid[rd][cd] != word[k]) + break; + rd += x[dir], cd += y[dir]; + } + if (k == len) + return true; + } + return false; +} + +int patternSearch(char grid[R][C], string word) +{ + int flag = 0; + for (int row = 0; row < R; row++) + for (int col = 0; col < C; col++) + if (search2D(grid, row, col, word)) + flag = 1; + return flag; +} + +int main() +{ + char grid[R][C] = {"ASSERTIVENESSLJ", + "CFOGOODPOSITIVE", + "OPENBMUREWOPRPS", + "MEDIATIONELDIOG", + "MAASREGJEWINWIN", + "UCIAEMOEECSKENI", + "NEMRSHACDVTWTTL", + "ITEHOTLTSTERAOE", + "CASPLGLSIUNERFE", + "AISAUSYTPOISEVF", + "TTARTTDOCENPPIH", + "IOGAIGUPYMGOOEE", + "OGEPOAFPQIENOWA", + "NECONFLICTSDCER", + "FNHTCATNOCEYEBT"}; + + string ss; + cin >> ss; + int s = patternSearch(grid, ss); + + if (s == 1) + { + cout << "Found"; + } + else + { + cout << "Not Found"; + } + return 0; +} + +// Code written by Samriddh Prasad From 9ccf1bdac903f0f88fc5633ddcfd472ae1eec9ba Mon Sep 17 00:00:00 2001 From: tarpandas Date: Sat, 17 Dec 2022 20:12:16 +0530 Subject: [PATCH 113/408] December - 07 unsolved --- December - 07/Java_tarpandas.java | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 December - 07/Java_tarpandas.java diff --git a/December - 07/Java_tarpandas.java b/December - 07/Java_tarpandas.java new file mode 100644 index 0000000..3cf7c51 --- /dev/null +++ b/December - 07/Java_tarpandas.java @@ -0,0 +1,39 @@ +import java.util.Scanner; +public class Java_tarpandas { + + static void checkPossibilities(int arr[][], int i, int j, int n) { + if(n>i) + } + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + String input = sc.next().toUpperCase(); + int noOfLetters = input.length(); + char wordMap[][] = + { + {'A','S','S','E','R','T','I','V','E','N','E','S','S','L','J'}, + {'C','F','O','G','O','O','D','P','O','S','I','T','I','V','E'}, + {'O','P','E','N','B','M','U','R','E','W','O','P','R','P','S'}, + {'M','E','D','I','A','T','I','O','N','E','L','D','I','O','G'}, + {'M','A','A','S','R','E','G','J','E','W','I','N','W','I','N'}, + {'U','C','I','A','E','M','O','E','E','C','S','K','E','N','I'}, + {'N','E','M','R','S','H','A','C','D','V','T','W','T','T','L'}, + {'I','T','E','H','O','T','L','T','S','T','E','R','A','O','E'}, + {'C','A','S','P','L','G','L','S','I','U','N','E','R','F','E'}, + {'A','I','S','A','U','S','Y','T','P','O','I','S','E','V','F'}, + {'T','T','A','R','T','T','D','O','C','E','N','P','P','I','H'}, + {'I','O','G','A','I','G','U','P','Y','M','G','O','O','E','E'}, + {'O','G','E','P','O','A','F','P','Q','I','E','N','O','W','A'}, + {'N','E','C','O','N','F','L','I','C','T','S','D','C','E','R'}, + {'F','N','H','T','C','A','T','N','O','C','E','T','E','B','T'} + }; + + for(int i=0; i Date: Sat, 17 Dec 2022 21:26:48 +0530 Subject: [PATCH 114/408] Create day10.cpp --- December - 10/day10.cpp | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 December - 10/day10.cpp diff --git a/December - 10/day10.cpp b/December - 10/day10.cpp new file mode 100644 index 0000000..8779d7f --- /dev/null +++ b/December - 10/day10.cpp @@ -0,0 +1,46 @@ +#include +using namespace std; + +bool isVowel(char ch) +{ + return ( ch == 'a' || ch == 'e' ||ch == 'i' || ch == 'o' ||ch == 'u'); +} + +int calcDiff(string str) +{ + int c=0; + if(str.length() >= 4){} + for (int i = 0; i < str.length()-3; i++) + { + if ((!isVowel(str[i])) && (!isVowel(str[i+1])) && (!isVowel(str[i+2])) && (!isVowel(str[i+3]))) + { + c=1; + } +} + return c; +} + +int main() +{ + int n; + cin >> n; + + int s[n]; + string str[n]; + for(int i=0; i> s[i]; + cin >> str[i]; + } + + for(int i=0; i Date: Sat, 17 Dec 2022 22:06:31 +0530 Subject: [PATCH 115/408] updated dec-03 Sahitya A --- December - 03/.gitignore | 162 +++++++++++++-------------------------- 1 file changed, 54 insertions(+), 108 deletions(-) diff --git a/December - 03/.gitignore b/December - 03/.gitignore index ac6d3a2..47d4da9 100644 --- a/December - 03/.gitignore +++ b/December - 03/.gitignore @@ -1,6 +1,50 @@ -# gitignore file for "A December of Algorithms 2022" -# visit https://github.com/SVCE-ACM/A-December-of-Algorithms -# Written individually to adjust for the needs of the problem +#code +def minesweeper(n): + arr = [[0 for row in range(n)] for column in range(n)] + x = int(input("enter the x coordinate")) + y = int(input("enter the y coordinate")) + arr[y][x] = 'X' + if (x >= 1 and x <= 3): + arr[y][x+1] += 1 + arr[y][x-1] += 1 + if (x == 0): + arr[y][x+1] += 1 + if (x == 4): + arr[y][x-1] += 1 + if (x >= 1 and x <= 4) and (y >= 1 and y <= 4): + arr[y-1][x-1] += 1 + if (x >= 0 and x <= 3) and (y >= 1 and y <= 4): + arr[y-1][x+1] += 1 + if (x >= 0 and x <= 4) and (y >= 1 and y <= 4): + arr[y-1][x] += 1 + if (x >=0 and x <= 3) and (y >= 0 and y <= 3): + arr[y+1][x+1] += 1 + if (x >= 1 and x <= 4) and (y >= 0 and y <= 3): + arr[y+1][x-1] += 1 + if (x >= 0 and x <= 4) and (y >= 0 and y <= 3): + arr[y+1][x] += 1 + for row in arr: + print(" ".join(str(cell) for cell in row)) + print("") +if __name__ == "__main__": + s=int(input("enter the number")) + minesweeper(s) + + #code + + + + + + + + + + + + + + # Byte-compiled / optimized / DLL files __pycache__/ @@ -10,10 +54,6 @@ __pycache__/ # C extensions *.so -# node.js -/node_modules -package-lock.json - # Distribution / packaging .Python build/ @@ -93,7 +133,13 @@ ipython_config.py .python-version # pipenv -Pipfile.lock +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff @@ -129,103 +175,3 @@ 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 b2ad457c9e4190f0bc59ff32df4b51defe1b1b81 Mon Sep 17 00:00:00 2001 From: sruthi-v04 <119495356+sruthi-v04@users.noreply.github.com> Date: Sat, 17 Dec 2022 22:29:19 +0530 Subject: [PATCH 116/408] Update README.md --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/README.md b/README.md index f73bfba..54e66a7 100644 --- a/README.md +++ b/README.md @@ -1017,6 +1017,50 @@ Output for each test case should be printed in a separate line. ---- +### December 17 - Find the way + +#### Problem Statement + +Pooja and Ravi are two close friends that live in the city chosen by the user. The graph below shows the cities P, Q, R, S, T, U, V and W represented by the vertices and the rail connections between them represented by edges. The numbers on the edges are the times, in hours, it takes to travel by train between each of the cities. find the shortest time to travel by train between chosen city and W. Also find the time taken. + + +![find the way](https://user-images.githubusercontent.com/119495356/208252824-4486cb25-7557-411f-afa9-dc17f767e00a.png) + + + +#### Sample Input/Output +``` +Input: + +City chosen: P + +Output: + +Shortest path: P – R – V – W +Shortest time: 7 hours + + + +``` +#### Explanation: +``` +Input Format : + +The argument given is the city that they choose + +Output Format : + +Return the shortest path between the chosen city and w. If chosen city is W then the shortest path is 0. Also return the time taken. + +CONSTRAINT: +Time complexity is 0(V^2) + + +``` +- **References** +- [Bipartite graphs](https://www.tutorialspoint.com/bipartite-graphs) + +---- FAQ ====== From a2e90c601b14558d25632eb686d18ec00f0ab0b7 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sat, 17 Dec 2022 23:00:02 +0530 Subject: [PATCH 117/408] First push with the folders and assets. --- December - 18/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 18/.gitignore diff --git a/December - 18/.gitignore b/December - 18/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 18/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 1063fd16b864ac703899f39324bd2144176ef71e Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sat, 17 Dec 2022 23:05:16 +0530 Subject: [PATCH 118/408] Update README.md --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 54e66a7..91a05c6 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Check out our FAQ for more information. - [**December 15 - The Murderers Meet**](#december-15---the-murderers-meet) - [**December 16 - H2O Receptacle**](#december-16---h2o-receptacle) - [**December 17 - Zig Zag Conversion**](#december-17---zig-zag-conversion) + - [**December 18 - Find the way**](#december-18---find-the-way) - [**FAQ**](#faq) @@ -1017,7 +1018,7 @@ Output for each test case should be printed in a separate line. ---- -### December 17 - Find the way +### December 18 - Find the way #### Problem Statement @@ -1058,7 +1059,11 @@ Time complexity is 0(V^2) ``` - **References** -- [Bipartite graphs](https://www.tutorialspoint.com/bipartite-graphs) +- [Graphs](https://www.geeksforgeeks.org/graph-data-structure-and-algorithms/) +- [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) +- [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) +- [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) +- [Adjacency matrices](https://www.javatpoint.com/what-is-an-adjacency-matrix) ---- From 71004cb00f238e84f4e5d2ee8456c14463e0c5c4 Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <85601344+nijuyonkadesu@users.noreply.github.com> Date: Sat, 17 Dec 2022 23:16:31 +0530 Subject: [PATCH 119/408] Helping Labyrinth to cross the maze Solution using simple backtracking --- December - 13/cpp_nijuyonkadesu.cpp | 64 +++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 December - 13/cpp_nijuyonkadesu.cpp diff --git a/December - 13/cpp_nijuyonkadesu.cpp b/December - 13/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..8f923fb --- /dev/null +++ b/December - 13/cpp_nijuyonkadesu.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include + +using namespace std; + +vector> input(int); +void pathFinder(vector>&, vector>&, vector>&, int, int, int); +bool isSafe(vector>&, int, int, int); + +int main() { + int n; + cin>>n; + + vector> visited(n, vector (n, 0)); // To keep track of visited boxes + vector> maze = input(n); // The maze itself + vector> path; // Stores the final path + + int min = INT_MAX; + int pathPointer = 0, index =0; + + pathFinder(visited, maze, path, 0, 0, n); + cout<<"\n"; + + for(auto i: path){ + for(auto j = i.begin(); j!=i.end(); j++){ + cout<<*j<<" "; + } + cout<<"\n"; + } +} + +vector> input(int n) { + vector> maze(n, vector (n, 0)); + + for(int i=0; i>maze[i][j]; + return maze; +} + +void pathFinder(vector> &visited, vector> &maze, vector> &path, int x, int y, int n) { + if(x==n-1 && y==n-1){ + visited[x][y] = 1; + path = visited; // cannot use visited, on backtrack eventually, everything goes to 0. + visited[x][y] = 0; // Therefore take a snapshot and load it to a new variable for later access in main function + return ; + } + + visited[x][y] = 1; // Mark visited + + if(isSafe(maze, x+1, y, n)) // Right + pathFinder(visited, maze, path, x+1, y, n); + if(isSafe(maze, x, y+1, n)) // Bottom + pathFinder(visited, maze, path, x, y+1, n); + + visited[x][y] = 0; // Backtracking + return ; +} + +bool isSafe(vector>& maze, int x, int y, int n){ + return (x Date: Sat, 17 Dec 2022 23:51:49 +0530 Subject: [PATCH 120/408] updated -dec -04 -Sahitya A --- December - 04/.gitignore | 178 +++++++++++++++------------------------ 1 file changed, 69 insertions(+), 109 deletions(-) diff --git a/December - 04/.gitignore b/December - 04/.gitignore index ac6d3a2..0986ddf 100644 --- a/December - 04/.gitignore +++ b/December - 04/.gitignore @@ -1,8 +1,66 @@ -# gitignore file for "A December of Algorithms 2022" -# visit https://github.com/SVCE-ACM/A-December-of-Algorithms -# Written individually to adjust for the needs of the problem +#code +def maxCrossingSum(arr, l, m, h): + sm = 0 + left_sum = -10000 -# Byte-compiled / optimized / DLL files + for i in range(m, l-1, -1): + sm = sm + arr[i] + + if (sm > left_sum): + left_sum = sm + sm = 0 + right_sum = -1000 + for i in range(m, h + 1): + sm = sm + arr[i] + + if (sm > right_sum): + right_sum = sm + return max(left_sum + right_sum - arr[m], left_sum, right_sum) +def maxSubArraySum(arr, l, h): + if (l > h): + return -10000 + if (l == h): + return arr[l] + m = (l + h) // 2 + return max(maxSubArraySum(arr, l, m-1), + maxSubArraySum(arr, m+1, h), + maxCrossingSum(arr, l, m, h)) +arr = [] +n = int(input("enter the numbers")) +for i in range(0,n): + ele=int(input()) + arr.append(ele) +print(arr) +k=len(arr) +max_sum = maxSubArraySum(arr, 0, k-1) +print("Maximum sum is ", max_sum) +#code + + + + + + + + + + + + + + + + + + + + + + + + + +## Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class @@ -10,10 +68,6 @@ __pycache__/ # C extensions *.so -# node.js -/node_modules -package-lock.json - # Distribution / packaging .Python build/ @@ -93,7 +147,13 @@ ipython_config.py .python-version # pipenv -Pipfile.lock +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff @@ -129,103 +189,3 @@ 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 5b33f5dc5a26341bb3c3daed1247b3d3a0c58d0a Mon Sep 17 00:00:00 2001 From: Sahitya A <113616944+abc123-ux@users.noreply.github.com> Date: Sun, 18 Dec 2022 13:14:46 +0530 Subject: [PATCH 121/408] updated -dec 18 -Sahitya A --- December - 18/.gitignore | 183 ++++++++++++++++----------------------- 1 file changed, 75 insertions(+), 108 deletions(-) diff --git a/December - 18/.gitignore b/December - 18/.gitignore index ac6d3a2..f77faf7 100644 --- a/December - 18/.gitignore +++ b/December - 18/.gitignore @@ -1,6 +1,71 @@ -# gitignore file for "A December of Algorithms 2022" -# visit https://github.com/SVCE-ACM/A-December-of-Algorithms -# Written individually to adjust for the needs of the problem +class Graph(): + def __init__(self, vertices): + self.V = vertices + self.graph = [[0 for column in range(vertices)] + for row in range(vertices)] + def printSolution(self, dist): + print("Vertex \t Distance from Source") + for node in range(self.V): + print(node, "\t\t", dist[node]) + def minDistance(self, dist, sptSet): + min = 1e7 + for v in range(self.V): + if dist[v] < min and sptSet[v] == False: + min = dist[v] + min_index = v + return min_index + def dijkstra(self, src): + dist = [1e7] * self.V + dist[src] = 0 + sptSet = [False] * self.V + for cout in range(self.V): + u = self.minDistance(dist, sptSet) + sptSet[u] = True + for v in range(self.V): + if (self.graph[u][v] > 0 and + sptSet[v] == False and + dist[v] > dist[u] + self.graph[u][v]): + dist[v] = dist[u] + self.graph[u][v] + self.printSolution(dist) +g = Graph(8) +g.graph = [ + [0, 3, 4, 5, 0, 0, 0, 0], + [3, 0, 2, 0, 0, 5, 0, 0], + [4, 2, 0, 7, 3, 6, 2, 0], + [5, 0, 7, 0, 2, 0, 0, 0], + [0, 0, 3, 2, 0, 0, 4, 0], + [0, 5, 6, 0, 0, 0, 5, 2], + [0, 0, 2, 0, 4, 5, 0, 0], + [0, 0, 0, 0, 0, 2, 1, 0] + ] +g.dijkstra(0) + + + + + + + + + + + + + + + + + + + + + + + + + + + # Byte-compiled / optimized / DLL files __pycache__/ @@ -10,10 +75,6 @@ __pycache__/ # C extensions *.so -# node.js -/node_modules -package-lock.json - # Distribution / packaging .Python build/ @@ -93,7 +154,13 @@ ipython_config.py .python-version # pipenv -Pipfile.lock +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff @@ -129,103 +196,3 @@ 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 c3da9974158986df440778feb01e9d16c2fa0c10 Mon Sep 17 00:00:00 2001 From: Sahitya A <113616944+abc123-ux@users.noreply.github.com> Date: Sun, 18 Dec 2022 13:47:23 +0530 Subject: [PATCH 122/408] updated -dec 18-Sahtya A --- December - 15/.gitignore | 159 +++++++++++++-------------------------- 1 file changed, 51 insertions(+), 108 deletions(-) diff --git a/December - 15/.gitignore b/December - 15/.gitignore index ac6d3a2..a5829af 100644 --- a/December - 15/.gitignore +++ b/December - 15/.gitignore @@ -1,6 +1,47 @@ -# gitignore file for "A December of Algorithms 2022" -# visit https://github.com/SVCE-ACM/A-December-of-Algorithms -# Written individually to adjust for the needs of the problem + +#code +from collections import OrderedDict +import numpy as np +n=int(input("enter the number of inputs")) +d=dict(input("enter the key and value:").split() for i in range (n)) +print(d) +keys = list(d.keys()) +values = list(d.values()) +sorted_value_index = np.argsort(values) +sorted_dict = {keys[i]: values[i] for i in sorted_value_index} +print("the result is") +print(sorted_dict) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + # Byte-compiled / optimized / DLL files __pycache__/ @@ -10,10 +51,6 @@ __pycache__/ # C extensions *.so -# node.js -/node_modules -package-lock.json - # Distribution / packaging .Python build/ @@ -93,7 +130,13 @@ ipython_config.py .python-version # pipenv -Pipfile.lock +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff @@ -129,103 +172,3 @@ 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 f819ec5da91dd942fb048d32d35ec0e771524a17 Mon Sep 17 00:00:00 2001 From: Sahitya A <113616944+abc123-ux@users.noreply.github.com> Date: Sun, 18 Dec 2022 16:25:58 +0530 Subject: [PATCH 123/408] updated -dec15-Sahitya A --- December - 16/.gitignore | 163 +++++++++++++-------------------------- 1 file changed, 55 insertions(+), 108 deletions(-) diff --git a/December - 16/.gitignore b/December - 16/.gitignore index ac6d3a2..1382e10 100644 --- a/December - 16/.gitignore +++ b/December - 16/.gitignore @@ -1,6 +1,51 @@ -# gitignore file for "A December of Algorithms 2022" -# visit https://github.com/SVCE-ACM/A-December-of-Algorithms -# Written individually to adjust for the needs of the problem +#code + +def findLargest(arr): + secondLargest = 0 + largest = min(arr) + for i in range(len(arr)): + if arr[i] > largest: + secondLargest = largest + largest = arr[i] + else: + secondLargest = max(secondLargest, arr[i]) + return secondLargest +n = int(input("Enter number of elements : ")) +a = list(map(int,input("\nEnter the numbers : ").strip().split()))[:n] +print("\nList is - ", a) +j=int(findLargest(a)) +m=a.index(max(a)) +l=a.index(j) +print(m,l) +diff=abs(m-l) +result=int(diff*j) +print(result) +#code + + + + + + + + + + + + + + + + + + + + + + + + + # Byte-compiled / optimized / DLL files __pycache__/ @@ -10,10 +55,6 @@ __pycache__/ # C extensions *.so -# node.js -/node_modules -package-lock.json - # Distribution / packaging .Python build/ @@ -93,7 +134,13 @@ ipython_config.py .python-version # pipenv -Pipfile.lock +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff @@ -129,103 +176,3 @@ 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 b7b8c5ebeae96bd6ef795070dadf99cf3cea4c5f Mon Sep 17 00:00:00 2001 From: Sahitya A <113616944+abc123-ux@users.noreply.github.com> Date: Sun, 18 Dec 2022 16:28:16 +0530 Subject: [PATCH 124/408] updated -dec 15-Sahitya A --- December - 15/.gitignore | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/December - 15/.gitignore b/December - 15/.gitignore index a5829af..d00ae12 100644 --- a/December - 15/.gitignore +++ b/December - 15/.gitignore @@ -1,17 +1,23 @@ - -#code -from collections import OrderedDict -import numpy as np -n=int(input("enter the number of inputs")) -d=dict(input("enter the key and value:").split() for i in range (n)) -print(d) -keys = list(d.keys()) -values = list(d.values()) -sorted_value_index = np.argsort(values) -sorted_dict = {keys[i]: values[i] for i in sorted_value_index} -print("the result is") -print(sorted_dict) - +def findLargest(arr): + secondLargest = 0 + largest = min(arr) + for i in range(len(arr)): + if arr[i] > largest: + secondLargest = largest + largest = arr[i] + else: + secondLargest = max(secondLargest, arr[i]) + return secondLargest +n = int(input("Enter number of elements : ")) +a = list(map(int,input("\nEnter the numbers : ").strip().split()))[:n] +print("\nList is - ", a) +j=int(findLargest(a)) +m=a.index(max(a)) +l=a.index(j) +print(m,l) +diff=abs(m-l) +result=int(diff*j) +print(result) From d2acdcbc63cdbef0cd003fc1b95cb1262dc826cb Mon Sep 17 00:00:00 2001 From: Sahitya A <113616944+abc123-ux@users.noreply.github.com> Date: Sun, 18 Dec 2022 16:35:36 +0530 Subject: [PATCH 125/408] Updated dec15 Sahitya A --- December - 15/.gitignore | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/December - 15/.gitignore b/December - 15/.gitignore index d00ae12..5cd95a2 100644 --- a/December - 15/.gitignore +++ b/December - 15/.gitignore @@ -1,23 +1,17 @@ -def findLargest(arr): - secondLargest = 0 - largest = min(arr) - for i in range(len(arr)): - if arr[i] > largest: - secondLargest = largest - largest = arr[i] - else: - secondLargest = max(secondLargest, arr[i]) - return secondLargest -n = int(input("Enter number of elements : ")) -a = list(map(int,input("\nEnter the numbers : ").strip().split()))[:n] -print("\nList is - ", a) -j=int(findLargest(a)) -m=a.index(max(a)) -l=a.index(j) -print(m,l) -diff=abs(m-l) -result=int(diff*j) -print(result) +DEC-15 CODE: +from collections import OrderedDict +import numpy as np +n=int(input("enter the number of inputs")) +d=dict(input("enter the key and value:").split() for i in range (n)) +print(d) +keys = list(d.keys()) +values = list(d.values()) +sorted_value_index = np.argsort(values) +sorted_dict = {keys[i]: values[i] for i in sorted_value_index} +print("the result is") +print(sorted_dict) + + From 4bab881942ad3f9b3c9df7576e1e0441a7f807fc Mon Sep 17 00:00:00 2001 From: Sahitya A <113616944+abc123-ux@users.noreply.github.com> Date: Sun, 18 Dec 2022 16:37:16 +0530 Subject: [PATCH 126/408] Updated dec 16 Sahitya A --- December - 16/.gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/December - 16/.gitignore b/December - 16/.gitignore index 1382e10..5d21d69 100644 --- a/December - 16/.gitignore +++ b/December - 16/.gitignore @@ -1,5 +1,4 @@ #code - def findLargest(arr): secondLargest = 0 largest = min(arr) From c2224b316d2f64f04f9e21ff2450d4e3782b3e3f Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Sun, 18 Dec 2022 17:59:04 +0530 Subject: [PATCH 127/408] December 9 - Kochouseph Konundrum! --- December - 09/Java_souvikpal2000.java | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 December - 09/Java_souvikpal2000.java diff --git a/December - 09/Java_souvikpal2000.java b/December - 09/Java_souvikpal2000.java new file mode 100644 index 0000000..36c58d3 --- /dev/null +++ b/December - 09/Java_souvikpal2000.java @@ -0,0 +1,37 @@ +import java.util.*; +public class Java_souvikpal2000{ + public String guessTheWord(String[] arr, int n){ + int maxLength = 0; + String str = ""; + for(int i=0;imaxLength){ + maxLength = length; + str = arr[i]; + } + } + return str; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input:"); + int n = sc.nextInt(); + String[] arr = new String[n]; + for(int i=0;i Date: Sun, 18 Dec 2022 18:28:41 +0530 Subject: [PATCH 128/408] Updated dec -14-Sahtiya A --- December - 14/.gitignore | 181 ++++++++++++++++----------------------- 1 file changed, 73 insertions(+), 108 deletions(-) diff --git a/December - 14/.gitignore b/December - 14/.gitignore index ac6d3a2..7ea9849 100644 --- a/December - 14/.gitignore +++ b/December - 14/.gitignore @@ -1,6 +1,69 @@ -# gitignore file for "A December of Algorithms 2022" -# visit https://github.com/SVCE-ACM/A-December-of-Algorithms -# Written individually to adjust for the needs of the problem + + +#code +class Graph(): + def __init__(self, V): + self.V = V + self.graph = [[0 for column in range(V)] \ + for row in range(V)] + def isBipartite(self, src): + colorArr = [-1] * self.V + colorArr[src] = 1 + queue = [] + queue.append(src) + while queue: + u = queue.pop() + if self.graph[u][u] == 1: + return False; + for v in range(self.V): + if self.graph[u][v] == 1 and colorArr[v] == -1: + colorArr[v] = 1 - colorArr[u] + queue.append(v) + elif self.graph[u][v] == 1 and colorArr[v] == colorArr[u]: + return False + return True +g = Graph(n) +g.graph = [[0, 1, 0, 1], + [1, 0, 1, 0], + [0, 1, 0, 1], + [1, 0, 1, 0] + ] +print ("This is bipartite graph" if g.isBipartite(0) else "No") + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + # Byte-compiled / optimized / DLL files __pycache__/ @@ -10,10 +73,6 @@ __pycache__/ # C extensions *.so -# node.js -/node_modules -package-lock.json - # Distribution / packaging .Python build/ @@ -93,7 +152,13 @@ ipython_config.py .python-version # pipenv -Pipfile.lock +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff @@ -129,103 +194,3 @@ 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 2ac89df620c2fa8e55eeb54d125e11ee858b819c Mon Sep 17 00:00:00 2001 From: Sahitya A <113616944+abc123-ux@users.noreply.github.com> Date: Sun, 18 Dec 2022 18:40:45 +0530 Subject: [PATCH 129/408] Updated dec -13 Sahitya A --- December - 13/.gitignore | 193 +++++++++++++++++---------------------- 1 file changed, 85 insertions(+), 108 deletions(-) diff --git a/December - 13/.gitignore b/December - 13/.gitignore index ac6d3a2..8844c9f 100644 --- a/December - 13/.gitignore +++ b/December - 13/.gitignore @@ -1,6 +1,81 @@ -# gitignore file for "A December of Algorithms 2022" -# visit https://github.com/SVCE-ACM/A-December-of-Algorithms -# Written individually to adjust for the needs of the problem +n = int(input("enter the size of maze")) +def isValid(n, maze, x, y, res): + if x >= 0 and y >= 0 and x < n and y < n and maze[x][y] == 1 and res[x][y] == 0: + return True + return False +def RatMaze(n, maze, move_x, move_y, x, y, res): + if x == n-1 and y == n-1: + return True + for i in range(4): + x_new = x + move_x[i] + y_new = y + move_y[i] + if isValid(n, maze, x_new, y_new, res): + res[x_new][y_new] = 1 + if RatMaze(n, maze, move_x, move_y, x_new, y_new, res): + return True + res[x_new][y_new] = 0 + return False +def solveMaze(maze): + res = [[0 for i in range(n)] for i in range(n)] + res[0][0] = 1 + move_x = [-1, 1, 0, 0] + move_y = [0, 0, -1, 1] + if RatMaze(n, maze, move_x, move_y, 0, 0, res): + for i in range(n): + for j in range(n): + print(res[i][j], end=' ') + print() + else: + print('Solution does not exist') +if __name__ == "__main__": + matrix=[] +for i in range(n): + a =[] + for j in range(n): + a.append(int(input())) + matrix.append(a) +for i in range(n): + for j in range(n): + print(matrix[i][j], end = " ") + print() +solveMaze(matrix) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + # Byte-compiled / optimized / DLL files __pycache__/ @@ -10,10 +85,6 @@ __pycache__/ # C extensions *.so -# node.js -/node_modules -package-lock.json - # Distribution / packaging .Python build/ @@ -93,7 +164,13 @@ ipython_config.py .python-version # pipenv -Pipfile.lock +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff @@ -129,103 +206,3 @@ 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 f1a59e28c5539834817d19419e6a023e85dde3f7 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sun, 18 Dec 2022 21:54:05 +0530 Subject: [PATCH 130/408] Update README.md --- README.md | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/README.md b/README.md index 91a05c6..cba4361 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ Check out our FAQ for more information. - [**December 16 - H2O Receptacle**](#december-16---h2o-receptacle) - [**December 17 - Zig Zag Conversion**](#december-17---zig-zag-conversion) - [**December 18 - Find the way**](#december-18---find-the-way) + - [**December 19 - Hidden Anagram**](#december-18---hidden-anagram) - [**FAQ**](#faq) @@ -1065,6 +1066,77 @@ Time complexity is 0(V^2) - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) - [Adjacency matrices](https://www.javatpoint.com/what-is-an-adjacency-matrix) +---- + +### December 19 - Hidden Anagram + +#### Problem Statement + +You are given two strings (String 1 and String 2). The first string contains a sentence containing the letters of the second string in a consecutive sequence but in a different order. + +Your task is to find the hidden anagram of the second string in the first string. + +The hidden anagram must contain all the letters, including duplicates, from the second string in any order and must not contain any other alphabetic characters. + +Write a program to find the anagram of the second string embedded somewhere in the first string. + +You should ignore character case, any spaces, and punctuation marks and return the anagram as a lower case string with no spaces or punctuation marks. + + +

+ + + +#### Sample Input/Output +``` +Input: + +String 1: +"My world evolves in a beautiful space called Tesh." + +String 2: +"sworn love lived" + + +Output: + +"worldevolvesin" + +``` + +``` +Input: + +String 1: +"Mr. Mojo Rising could be a song title" + +String 2: +"Jim Morrison" + + +Output: + +"mrmojorisin" + + +``` + +#### Explanation: +``` + +The sequence "world evolves in" is a perfect anagram of "sworn love lived". + +The sequence "Mr. Mojo Risin" ignoring the full stop, is a perfect +Anagram of "Jim Morrison". + + +``` +- **References** + - [Strings in C++](https://www.geeksforgeeks.org/stdstring-class-in-c/) + - [Strings in Python](https://www.geeksforgeeks.org/python-string/) + - [String in Java](https://www.geeksforgeeks.org/strings-in-java/) + + ---- FAQ From 778158d91f5eef7ca570ff50d5a1068aa159925d Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sun, 18 Dec 2022 23:18:16 +0530 Subject: [PATCH 131/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cba4361..e5565b5 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Check out our FAQ for more information. - [**December 16 - H2O Receptacle**](#december-16---h2o-receptacle) - [**December 17 - Zig Zag Conversion**](#december-17---zig-zag-conversion) - [**December 18 - Find the way**](#december-18---find-the-way) - - [**December 19 - Hidden Anagram**](#december-18---hidden-anagram) + - [**December 19 - Hidden Anagram**](#december-19---hidden-anagram) - [**FAQ**](#faq) From 5b96b4fd985036b68281a88a87adbfe5ea0fb2eb Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sun, 18 Dec 2022 23:19:21 +0530 Subject: [PATCH 132/408] First push with the folders and assets. --- December - 19/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 19/.gitignore diff --git a/December - 19/.gitignore b/December - 19/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 19/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 8d1fd5d1b417bb3cee37728509df8b256d22df41 Mon Sep 17 00:00:00 2001 From: tarpandas Date: Sun, 18 Dec 2022 23:59:52 +0530 Subject: [PATCH 133/408] December - 08 solved --- December - 07/Java_tarpandas.java | 7 +------ December - 08/Java_tarpandas.java | 25 +++++++++++++++++++++++++ December - 08/tempCodeRunnerFile.java | 1 + 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 December - 08/Java_tarpandas.java create mode 100644 December - 08/tempCodeRunnerFile.java diff --git a/December - 07/Java_tarpandas.java b/December - 07/Java_tarpandas.java index 3cf7c51..4654afa 100644 --- a/December - 07/Java_tarpandas.java +++ b/December - 07/Java_tarpandas.java @@ -1,9 +1,5 @@ import java.util.Scanner; public class Java_tarpandas { - - static void checkPossibilities(int arr[][], int i, int j, int n) { - if(n>i) - } public static void main(String[] args) { Scanner sc = new Scanner(System.in); String input = sc.next().toUpperCase(); @@ -30,8 +26,7 @@ public static void main(String[] args) { for(int i=0; i Date: Mon, 19 Dec 2022 10:12:11 +0530 Subject: [PATCH 134/408] December 10 - Play with words --- December - 10/Java_souvikpal2000.java | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 December - 10/Java_souvikpal2000.java diff --git a/December - 10/Java_souvikpal2000.java b/December - 10/Java_souvikpal2000.java new file mode 100644 index 0000000..f77fbc8 --- /dev/null +++ b/December - 10/Java_souvikpal2000.java @@ -0,0 +1,54 @@ +import java.util.*; +public class Java_souvikpal2000{ + public String[] playWithWords(String[] arr, int n){ + String[] results = new String[n]; + for(int i=0;i= 4){ + break; + } + } + } + + if(consonants >= 4){ + results[i] = "NO"; + }else{ + results[i] = "YES"; + } + } + return results; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input:"); + int n = sc.nextInt(); + String[] strArr = new String[n]; + for(int i=0;i Date: Mon, 19 Dec 2022 20:06:08 +0530 Subject: [PATCH 135/408] Update README.md --- README.md | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/README.md b/README.md index e5565b5..cbc3675 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Check out our FAQ for more information. - [**December 17 - Zig Zag Conversion**](#december-17---zig-zag-conversion) - [**December 18 - Find the way**](#december-18---find-the-way) - [**December 19 - Hidden Anagram**](#december-19---hidden-anagram) + - [**December 20 - Code a Subsequence**](#december-20---code-a-subsequence) - [**FAQ**](#faq) @@ -1139,6 +1140,92 @@ Anagram of "Jim Morrison". ---- +### December 20 - Code a Subsequence + +#### Problem Statement + +A subsequence of a sequence is a sequence which is obtained by deleting zero or more elements from the sequence. + +You are given a sequence A in which every element is a pair of integers i.e A = [(a1, w1), (a2, w2),..., (aN, wN)]. + +For a subsequence B = [(b1, v1), (b2, v2), ...., (bM, vM)] of the given sequence : + +We call it increasing if for every i (1 <= i < M ) , bi < bi+1. + +Weight(B) = v1 + v2 + ... + vM. + +Task: +Given a sequence, output the maximum weight formed by an increasing subsequence. + +Input: + +The first line of input contains a single integer T. T test-cases follow. The first line of each test-case contains an integer N. The next line contains a1, a2 ,... , aN separated by a single space. The next line contains w1, w2, ..., wN separated by a single space. + +Output: + +For each test-case output a single integer: The maximum weight of increasing subsequences of the given sequence. +Constraints: +1 <= T <= 5 +1 <= N <= 150000 +1 <= ai <= 109, where i ∈ [1..N] +1 <= wi <= 109, where i ∈ [1..N] + +#### Sample Input/Output +``` +Input: + +2 +4 +1 2 3 4 +10 20 30 40 +8 +1 2 3 4 1 2 3 4 +10 20 30 40 15 15 15 50 + + +Output: + +100 +110 + + +``` + +#### Explanation: + +``` + +In the first sequence, the maximum size increasing subsequence is 4, and there's only one of them. We choose B = [(1, 10), (2, 20), (3, 30), (4, 40)], and we have Weight(B) = 100. +In the second sequence, the maximum size increasing subsequence is still 4, but there are now 5 possible subsequences: +1 2 3 4 +10 20 30 40 + +1 2 3 4 +10 20 30 50 + +1 2 3 4 +10 20 15 50 + +1 2 3 4 +10 15 15 50 + +1 2 3 4 +15 15 15 50 + +Of those, the one with the greatest weight is B = [(1, 10), (2, 20), (3, 30), (4, 50)], with Weight(B) = 110. +Please note that this is not the maximum weight generated from picking the highest value element of each index. That value, 115, comes from [(1, 15), (2, 20), (3, 30), (4, 50)], which is not a valid subsequence because it cannot be created by only deleting elements in the original sequence. + + +

+ +``` +- **References** + - [Strings in C++](https://www.geeksforgeeks.org/stdstring-class-in-c/) + - [Strings in Python](https://www.geeksforgeeks.org/python-string/) + - [String in Java](https://www.geeksforgeeks.org/strings-in-java/) + + +---- FAQ ====== From b8a3152a79cf990bffb17feacf8a707d663c67c4 Mon Sep 17 00:00:00 2001 From: eshanthekam <110716198+eshanthekam@users.noreply.github.com> Date: Mon, 19 Dec 2022 20:45:56 +0530 Subject: [PATCH 136/408] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cbc3675..6f7eab7 100644 --- a/README.md +++ b/README.md @@ -1223,6 +1223,7 @@ Please note that this is not the maximum weight generated from picking the highe - [Strings in C++](https://www.geeksforgeeks.org/stdstring-class-in-c/) - [Strings in Python](https://www.geeksforgeeks.org/python-string/) - [String in Java](https://www.geeksforgeeks.org/strings-in-java/) + - [Dynamic Programming](https://www.geeksforgeeks.org/dynamic-programming/) ---- From 9aef7540072a471a84b418f06ac0d0ecbfd47f58 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Mon, 19 Dec 2022 23:08:41 +0530 Subject: [PATCH 137/408] First push with the folders and assets. --- December - 20/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 20/.gitignore diff --git a/December - 20/.gitignore b/December - 20/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 20/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 68deb8660f66150fe26f235e9ef25d417fa1c396 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Mon, 19 Dec 2022 23:11:50 +0530 Subject: [PATCH 138/408] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6f7eab7..5b1b2be 100644 --- a/README.md +++ b/README.md @@ -1170,6 +1170,8 @@ Constraints: 1 <= ai <= 109, where i ∈ [1..N] 1 <= wi <= 109, where i ∈ [1..N] +

+ #### Sample Input/Output ``` Input: @@ -1216,8 +1218,6 @@ Of those, the one with the greatest weight is B = [(1, 10), (2, 20), (3, 30), (4 Please note that this is not the maximum weight generated from picking the highest value element of each index. That value, 115, comes from [(1, 15), (2, 20), (3, 30), (4, 50)], which is not a valid subsequence because it cannot be created by only deleting elements in the original sequence. -

- ``` - **References** - [Strings in C++](https://www.geeksforgeeks.org/stdstring-class-in-c/) From 458a4716bedd1db3773e1bdd2ab96e9cba09c84f Mon Sep 17 00:00:00 2001 From: Asad Date: Tue, 20 Dec 2022 10:07:51 +0530 Subject: [PATCH 139/408] Day 1 William Butcher's Mission --- .vscode/settings.json | 6 ++++++ December - 01/WilliamButcher.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 December - 01/WilliamButcher.cpp diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b5dd4f3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "vector": "cpp", + "iostream": "cpp" + } +} diff --git a/December - 01/WilliamButcher.cpp b/December - 01/WilliamButcher.cpp new file mode 100644 index 0000000..9e67e65 --- /dev/null +++ b/December - 01/WilliamButcher.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; + +int main() +{ + vector> vec; + int n, x, k = 0; + string a; + cin >> n; + for (int i = 0; i < n; i++) + { + cin >> a; + vector v1; + for (int i = 0; i < a.length(); i += 2) + { + string s = a.substr(i, 2); + int ascii = stoi(s, 0, 16); + v1.push_back(ascii); + } + vec.push_back(v1); + } + + for (int i = 0; i < vec.size(); i++) + { + for (int j = 0; j < vec[i].size(); j++) + { + cout << char(vec[i][j]); + } + cout << endl; + } + return 0; +} \ No newline at end of file From 7e4d6759140228bc7868e9425ea545a0c2316ff7 Mon Sep 17 00:00:00 2001 From: Asad Date: Tue, 20 Dec 2022 10:44:15 +0530 Subject: [PATCH 140/408] Day 2 The Secret Language --- .vscode/settings.json | 3 ++- December - 02/TheSecretLanguage.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 December - 02/TheSecretLanguage.cpp diff --git a/.vscode/settings.json b/.vscode/settings.json index b5dd4f3..8b52f7b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "files.associations": { "vector": "cpp", - "iostream": "cpp" + "iostream": "cpp", + "xstring": "cpp" } } diff --git a/December - 02/TheSecretLanguage.cpp b/December - 02/TheSecretLanguage.cpp new file mode 100644 index 0000000..7cd2839 --- /dev/null +++ b/December - 02/TheSecretLanguage.cpp @@ -0,0 +1,13 @@ +#include +using namespace std; + +int main() +{ + string str, str0; + cin >> str; + str.erase(str.size() - 2); + str0 = str.substr(str.length() - 2, 2); + str.erase(str.size() - 2); + str = str0 + str; + cout << str; +} \ No newline at end of file From 16c505125233af4a772af0bc23a080ddaed5d8ec Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Tue, 20 Dec 2022 12:20:56 +0530 Subject: [PATCH 141/408] December 11 - Monkey jump --- December - 11/Java_souvikpal2000.java | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 December - 11/Java_souvikpal2000.java diff --git a/December - 11/Java_souvikpal2000.java b/December - 11/Java_souvikpal2000.java new file mode 100644 index 0000000..1b9509a --- /dev/null +++ b/December - 11/Java_souvikpal2000.java @@ -0,0 +1,35 @@ +import java.util.*; +public class Java_souvikpal2000{ + public int monkeyJump(String land_water, String steps){ + int steps_length = steps.length(); + int i = 0; + int j = 0; + int score = 0; + while(iq=new LinkedList<>(); + map.put(cur,0); + check[0]=true; + for(int i=0;imax) max=curVol; + + if(input[s]>input[e]) e--; + else s++; + } + System.out.println(max); + + } + public static int waterStored(int left,int right) + { + int length=right-left; + int height=Math.min(input[left],input[right]); + return length*height; + } +} From 176b00da027d30168f5ab40646da8568e9e6f7b1 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Tue, 20 Dec 2022 22:44:38 +0530 Subject: [PATCH 143/408] Update README.md --- README.md | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/README.md b/README.md index 5b1b2be..79ff3ae 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ Check out our FAQ for more information. - [**December 18 - Find the way**](#december-18---find-the-way) - [**December 19 - Hidden Anagram**](#december-19---hidden-anagram) - [**December 20 - Code a Subsequence**](#december-20---code-a-subsequence) + - [**December 21 - The Devil Towers**](#december-21---the-devil-towers) - [**FAQ**](#faq) @@ -1227,6 +1228,87 @@ Please note that this is not the maximum weight generated from picking the highe ---- + +### December 21 - The Devil Towers + +#### Problem Statement + +Morpheus, the ruler of the Kingdom of Dreaming was summoned and robbed of his possessions and kept in confinement for 106 years. Upon his escape from the shackles of time, Morpheus now wishes to find his lost possessions, a scarlet ruby, a pouch of sand, and his helm, a ceremonial crown he must dorn to become King of Dreaming again. + +To his utter shock, his helm resides in the hands of a Lesser Daemon in the depths of Hell. Morpheus descends into hell and is immediately in an audience with Pandaemonium’s ruler, Lucifer Morningstar. The Lesser Daemon challenges Morpheus to a tourney of brilliance, to a game known as the Devil Towers. + +The Daemon gives Morpheus 3 towers. At the end of the game, all discs must be stacked on only a single tower, leaving the others empty. + +The Daemon claims Lucifer as his champion, while Morpheus calls you in as his, and so you are tasked with moving all discs from the first to the third tower, heeding the Daemon’s rules:- + + - You can only move one disc at a time. + + - Only the disc at the top of the tower can be moved. + + - Discs can only be moved by first moving discs above them. + + - No disc may be placed on top of a smaller disc. + + - You have only certain fixed moves: + + left->right, left->middle + + middle->left, middle->right + + right->left, right->middle + + + +

+ + +#### Sample Input/Output +``` +Input: + +Number of discs: 3 + +Output: + +The sequence of moves : +Move disk 1 from tower I to tower III +Move disk 2 from tower I to tower II +Move disk 1 from tower III to tower II +Move disk 3 from tower I to tower III +Move disk 1 from tower II to tower I +Move disk 2 from tower II to tower III +Move disk 1 from tower I to tower III + +``` + +``` +Input: + +Number of discs: 2 + +Output: + +The sequence of moves : + Move disk 1 from tower I to tower II + Move disk 2 from tower I to tower III + Move disk 1 from tower II to tower III + +``` + +#### Explanation: + +``` + +Your input will be a number indicating the total number of disks on the first (left) tower. +Your output must be the sequence of moves for the given number of discs. + +``` +- **References** + - [Recursive Algorithms](https://www.geeksforgeeks.org/introduction-to-recursion-data-structure-and-algorithm-tutorials/) + + +---- + FAQ ====== From cbdc20f3079e063b5283e0555ad029885d1186d8 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Tue, 20 Dec 2022 22:46:02 +0530 Subject: [PATCH 144/408] First push with the folders and assets. --- December - 21/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 21/.gitignore diff --git a/December - 21/.gitignore b/December - 21/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 21/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 d3bb5370f9934a31b46dfc31e9374ea68fb8787f Mon Sep 17 00:00:00 2001 From: tarpandas Date: Tue, 20 Dec 2022 23:44:02 +0530 Subject: [PATCH 145/408] December - 07 solved --- December - 07/Java_tarpandas.java | 60 +++++++++++++++++++++++---- December - 08/tempCodeRunnerFile.java | 1 - 2 files changed, 52 insertions(+), 9 deletions(-) delete mode 100644 December - 08/tempCodeRunnerFile.java diff --git a/December - 07/Java_tarpandas.java b/December - 07/Java_tarpandas.java index 4654afa..8f26228 100644 --- a/December - 07/Java_tarpandas.java +++ b/December - 07/Java_tarpandas.java @@ -1,10 +1,56 @@ import java.util.Scanner; public class Java_tarpandas { + + static boolean wordSearch(char arr[][], int i, int j, String input) { + + int xDirection[] = {-1, -1, -1, 0, 0, 1, 1, 1}; + int yDirection[] = {-1, 0, 1, -1, 1, -1, 0, 1}; + + + if(arr[i][j] != input.charAt(0)) { + return false; + } + + for(int k = 0; k < 8; k++) { + int l; + int rowDir = i + xDirection[k]; + int colDir = j + yDirection[k]; + for(l = 1; l < input.length(); l++) { + if(rowDir >= arr.length || rowDir < 0 + || colDir >= arr[i].length || colDir < 0) + break; + + if (arr[rowDir][colDir] != input.charAt(l)) + break; + + rowDir += xDirection[k]; + colDir += yDirection[k]; + } + if(l == input.length()) + return true; + } + return false; + } + + static boolean searchPattern(char arr[][], String input) { + int rowSize = arr.length; + int columnSize = arr[0].length; + System.out.println(rowSize+" "+columnSize); + + for(int i=0; i Date: Wed, 21 Dec 2022 09:52:08 +0530 Subject: [PATCH 146/408] Day 4 Industry --- .vscode/settings.json | 3 +- December - 03/Minesweeper.cpp | 51 +++++++++++++++++++++++++++++++++ December - 04/Industry.cpp | 54 +++++++++++++++++++++++++++++++++++ December - 04/output.txt | 11 +++++++ 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 December - 03/Minesweeper.cpp create mode 100644 December - 04/Industry.cpp create mode 100644 December - 04/output.txt diff --git a/.vscode/settings.json b/.vscode/settings.json index 8b52f7b..27cdefb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,7 @@ "files.associations": { "vector": "cpp", "iostream": "cpp", - "xstring": "cpp" + "xstring": "cpp", + "ostream": "cpp" } } diff --git a/December - 03/Minesweeper.cpp b/December - 03/Minesweeper.cpp new file mode 100644 index 0000000..c6d6403 --- /dev/null +++ b/December - 03/Minesweeper.cpp @@ -0,0 +1,51 @@ +#include +using namespace std; + +int main() +{ + int n; + cin >> n; + vector> vec; + string a; + for (int i = 0; i < n; i++) + { + vector v1; + for (int j = 0; j < n; j++) + { + cin >> a; + v1.push_back(a); + } + vec.push_back(v1); + } + cout << endl; + + for (int i = 0; i < vec.size(); i++) + { + for (int j = 0; j < vec[i].size(); j++) + { + int count = 0; + if (vec[i][j] == "-" && vec[i][j + 1] == "#") + { + count++; + } + if (vec[i][j] == "-" && vec[i + 1][j] == "#") + { + count++; + } + if (vec[i][j] == "-" && vec[i + 1][j + 1] == "#") + { + count++; + } + } + } + + for (int i = 0; i < vec.size(); i++) + { + for (auto x : vec[i]) + { + cout << x << " "; + } + cout << endl; + } + return 0; +} \ No newline at end of file diff --git a/December - 04/Industry.cpp b/December - 04/Industry.cpp new file mode 100644 index 0000000..5f726de --- /dev/null +++ b/December - 04/Industry.cpp @@ -0,0 +1,54 @@ +#include +using namespace std; + +void SubarrayMax(vector nums, int n) +{ + int maxsum = 0, currsum = 0; + int maxstart = 0, maxend = 0; + int currstart = 0, currend = 0; + + for (int i = 0; i < n; i++) + { + currsum = currsum + nums[i]; + currend = i; + + if (currsum < 0) + { + currsum = 0; + currstart = currend + 1; + } + + if (maxsum < currsum) + { + maxsum = currsum; + maxstart = currstart; + maxend = currend; + } + } + cout << "Profit Value: " << maxsum << "\n"; + cout << "Proposed days to sell: Day: " << maxstart + 1 << " Day: " << maxend + 1 << "\n"; + + cout << "Stock market Change Values: "; + for (int i = maxstart; i <= maxend; i++) + { + cout << nums[i] << " "; + } +} + +int main() +{ + int n, value; + cout << "No. of days: "; + cin >> n; + + vector trade; + cout << "Given stock market change values: "; + for (int i = 0; i < n; i++) + { + cin >> value; + trade.push_back(value); + } + + SubarrayMax(trade, n); + return 0; +} \ No newline at end of file diff --git a/December - 04/output.txt b/December - 04/output.txt new file mode 100644 index 0000000..e432962 --- /dev/null +++ b/December - 04/output.txt @@ -0,0 +1,11 @@ +No. of days: 19 +Given stock market change values: 5 -4 12 -2 -5 6 -2 -3 1 5 -6 -11 7 -31 9 2 -3 8 -5 +Profit Value: 16 +Proposed days to sell: Day: 15 Day: 18 +Stock market Change Values: 9 2 -3 8 + +No. of days: 5 +Given stock market change values: 5 4 -1 7 8 +Profit Value: 23 +Proposed days to sell: Day: 1 Day: 5 +Stock market Change Values: 5 4 -1 7 8 \ No newline at end of file From 68cfeb19553e76c6b44cc8f8ca3be9a80efec129 Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Wed, 21 Dec 2022 10:23:02 +0530 Subject: [PATCH 147/408] December 15 - THE MURDERERS MEET --- December - 15/Java_souvikpal2000.java | 58 +++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 December - 15/Java_souvikpal2000.java diff --git a/December - 15/Java_souvikpal2000.java b/December - 15/Java_souvikpal2000.java new file mode 100644 index 0000000..3aa4fa6 --- /dev/null +++ b/December - 15/Java_souvikpal2000.java @@ -0,0 +1,58 @@ +import java.util.*; +class Detail{ + String name; + String timestamp; + Detail(String name, String timestamp){ + this.name = name; + this.timestamp = timestamp; + } +} + +class Sortbytimestamp implements Comparator +{ + public int compare(Detail a, Detail b){ + int hhmmssA = Integer.parseInt(a.timestamp.replace(":","")); + int hhmmssB = Integer.parseInt(b.timestamp.replace(":","")); + return hhmmssA - hhmmssB; + } +} + +class Java_souvikpal2000{ + public Queue theMurderersMeet(List list){ + Collections.sort(list, new Sortbytimestamp()); + + Queue queue=new LinkedList<>(); + for(Detail d : list){ + queue.add(d.name); + } + + return queue; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input: "); + List list=new ArrayList<>(); + String name, timestamp; + for(int i=0;i<3;i++){ + name = sc.next(); + while(true){ + timestamp = sc.next(); + String[] hhmmss = timestamp.split(":"); + if(Integer.parseInt(hhmmss[0])>24 || Integer.parseInt(hhmmss[1])>59 || Integer.parseInt(hhmmss[2])>59){ + System.out.println("Invalid Timestamp!! Enter again ..."); + }else{ + break; + } + } + list.add(new Detail(name,timestamp)); + } + + Java_souvikpal2000 ob=new Java_souvikpal2000(); + Queue queue = ob.theMurderersMeet(list); + + System.out.println(""); + System.out.print("Output: "+queue); + } +} \ No newline at end of file From 2bc605668105be61048a9000b297580bb8698466 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Wed, 21 Dec 2022 22:55:10 +0530 Subject: [PATCH 148/408] First push with the folders and assets. --- December - 22/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 22/.gitignore diff --git a/December - 22/.gitignore b/December - 22/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 22/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 6eb5bcf28a9b55379906ff1004f68c47e42c24f8 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Wed, 21 Dec 2022 23:11:32 +0530 Subject: [PATCH 149/408] Update README.md --- README.md | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/README.md b/README.md index 79ff3ae..3adef26 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Check out our FAQ for more information. - [**December 19 - Hidden Anagram**](#december-19---hidden-anagram) - [**December 20 - Code a Subsequence**](#december-20---code-a-subsequence) - [**December 21 - The Devil Towers**](#december-21---the-devil-towers) + - [**December 22 - The Markowitz Paradox**](#december-22---the-markowitz-paradox) - [**FAQ**](#faq) @@ -1307,6 +1308,98 @@ Your output must be the sequence of moves for the given number of discs. - [Recursive Algorithms](https://www.geeksforgeeks.org/introduction-to-recursion-data-structure-and-algorithm-tutorials/) +---- + +### December 22 - The Markowitz Paradox + +#### Problem Statement + +In the year 1977, Meyer Offerman, a rich Jewish businessman in New York and his covert associates called began hunting down all Nazi officials given asylum in the United States of America as a part of Operation Paperclip. + +On one of their missions they intercepted some messages hinting at a possible Third Reich in the works, but most of the message was encrypted into some code language meant only for the Reich. After spending weeks on trying to decode the messages and worried that the Third Reich of Nazi Germany may be inevitable, Murray Markowitz was finally able to interpret them and uncover one of the most sinister plots in American history. + +The Hunters devised a plan to send bogus messages to the other Nazis on behalf of their Colonel, altering their plan of action and in the process destabilising the Reich. However, before Murray was able to encrypt the bogus messages he was killed in a subway explosion leaving Jonah Heidlbaum, the responsibility of completing his task. + +The only reference Jonah has in order to correctly translate the given text into the secret message is Murray’s old Caesar Cipher notes as the encryption algorithm he discovered was destroyed during the explosion. + +Upon studying them he discovered that the method of encryption, used a series of interwoven Caesar ciphers, that takes a codeword and given a plaintext repeats the codeword until it matches the length of the plaintext. + +Help Jonah by writing a program to encrypt the bogus messages correctly. + + + +

+ + +#### Sample Input/Output +``` +Input: + +LEMON +ATTACKATDAWN + +Output: + +LXFOPVEFRNHR + +``` + +``` +Input: + +HOTDOG +CONEYISLANDONFRI + + +Output: + +JCGHMOZZTQRUUTKL + +``` + +``` +Input: + +MUSTANG +THECOLNELWILLBEATCENTRALPARKWITHTHEDETONATORDONOTAPPROACHWITHOUTBACKUP + +Output: + +FBWVOYTQFOBLYHQULVEAZDUDIAEQICLATUKPYLHNNZALVHNBZMJHKONITQAMHBAFVSVKHV + +``` + +#### Explanation: + +``` + +The first line of input is the codeword in this case “LEMON” and the next line of input is the message to be encrypted. +The message as well as the codeword do not have any spaces between the words. + +L E M O N L E M O N L E +A T T A C K A T D A W N + +The algorithm should encrypt every letter using a Caesar cipher shifted to the corresponding letter of the codeword. + +So, for example: + + - The first "A" is encrypted using a Caesar cipher of A → L (+11), so it becomes L. + + - The first "T" is encrypted using a Caesar cipher of A → E (+4), so it becomes X. + + - The second "T" is encrypted using a Caesar cipher of A → M (+12), so it becomes F. + + Subsequently, we get: + LXFOPVEFRNHR + +``` +- **References** + - [Strings in C++](https://www.geeksforgeeks.org/stdstring-class-in-c/) + - [Strings in Python](https://www.geeksforgeeks.org/python-string/) + - [String in Java](https://www.geeksforgeeks.org/strings-in-java/) + - [Caesar Cipher](https://www.geeksforgeeks.org/caesar-cipher-in-cryptography/) + + ---- FAQ From 57f78c92e1153736016ec07cafdf7349990f88cc Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Wed, 21 Dec 2022 23:13:14 +0530 Subject: [PATCH 150/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a98c5dc..3bb0f6c 100644 --- a/README.md +++ b/README.md @@ -1316,7 +1316,7 @@ Your output must be the sequence of moves for the given number of discs. #### Problem Statement -In the year 1977, Meyer Offerman, a rich Jewish businessman in New York and his covert associates called began hunting down all Nazi officials given asylum in the United States of America as a part of Operation Paperclip. +In the year 1977, Meyer Offerman, a rich Jewish businessman in New York and his covert associates began hunting down all Nazi officials given asylum in the United States of America as a part of Operation Paperclip. On one of their missions they intercepted some messages hinting at a possible Third Reich in the works, but most of the message was encrypted into some code language meant only for the Reich. After spending weeks on trying to decode the messages and worried that the Third Reich of Nazi Germany may be inevitable, Murray Markowitz was finally able to interpret them and uncover one of the most sinister plots in American history. From 2aa24d52b0b17fae4a7510608301f2a5b46ae006 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Wed, 21 Dec 2022 23:16:14 +0530 Subject: [PATCH 151/408] Update README.md --- README.md | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 3bb0f6c..cd09774 100644 --- a/README.md +++ b/README.md @@ -1326,6 +1326,22 @@ The only reference Jonah has in order to correctly translate the given text into Upon studying them he discovered that the method of encryption, used a series of interwoven Caesar ciphers, that takes a codeword and given a plaintext repeats the codeword until it matches the length of the plaintext. +L E M O N L E M O N L E +A T T A C K A T D A W N + +The algorithm should encrypt every letter using a Caesar cipher shifted to the corresponding letter of the codeword. + +So, for example: + + - The first "A" is encrypted using a Caesar cipher of A → L (+11), so it becomes L. + + - The first "T" is encrypted using a Caesar cipher of A → E (+4), so it becomes X. + + - The second "T" is encrypted using a Caesar cipher of A → M (+12), so it becomes F. + + Subsequently, we get: + LXFOPVEFRNHR + Help Jonah by writing a program to encrypt the bogus messages correctly. @@ -1377,24 +1393,9 @@ FBWVOYTQFOBLYHQULVEAZDUDIAEQICLATUKPYLHNNZALVHNBZMJHKONITQAMHBAFVSVKHV The first line of input is the codeword in this case “LEMON” and the next line of input is the message to be encrypted. The message as well as the codeword do not have any spaces between the words. - -L E M O N L E M O N L E -A T T A C K A T D A W N - -The algorithm should encrypt every letter using a Caesar cipher shifted to the corresponding letter of the codeword. - -So, for example: - - - The first "A" is encrypted using a Caesar cipher of A → L (+11), so it becomes L. - - - The first "T" is encrypted using a Caesar cipher of A → E (+4), so it becomes X. - - - The second "T" is encrypted using a Caesar cipher of A → M (+12), so it becomes F. - - Subsequently, we get: - LXFOPVEFRNHR ``` + - **References** - [Strings in C++](https://www.geeksforgeeks.org/stdstring-class-in-c/) - [Strings in Python](https://www.geeksforgeeks.org/python-string/) From 057421e8d52d9444533428744c7f88708eeafd0c Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Wed, 21 Dec 2022 23:17:40 +0530 Subject: [PATCH 152/408] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cd09774..6b3988a 100644 --- a/README.md +++ b/README.md @@ -1327,6 +1327,7 @@ The only reference Jonah has in order to correctly translate the given text into Upon studying them he discovered that the method of encryption, used a series of interwoven Caesar ciphers, that takes a codeword and given a plaintext repeats the codeword until it matches the length of the plaintext. L E M O N L E M O N L E + A T T A C K A T D A W N The algorithm should encrypt every letter using a Caesar cipher shifted to the corresponding letter of the codeword. @@ -1339,8 +1340,8 @@ So, for example: - The second "T" is encrypted using a Caesar cipher of A → M (+12), so it becomes F. - Subsequently, we get: - LXFOPVEFRNHR +Subsequently, we get: +LXFOPVEFRNHR Help Jonah by writing a program to encrypt the bogus messages correctly. From d9cce422c83ff5e71931e05d7a588849b42abae4 Mon Sep 17 00:00:00 2001 From: Dhruv Rawat <89683914+yesdhruv@users.noreply.github.com> Date: Wed, 21 Dec 2022 18:16:09 +0000 Subject: [PATCH 153/408] added H2O --- December -16/C++_Dhruv.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 December -16/C++_Dhruv.cpp diff --git a/December -16/C++_Dhruv.cpp b/December -16/C++_Dhruv.cpp new file mode 100644 index 0000000..5682eef --- /dev/null +++ b/December -16/C++_Dhruv.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; + + +int main() +{ + int n; + cin>>n; + vectorarr(n); + for(auto &x:arr)cin>>x; + int low =0; + int high = arr.size()-1; + int maxi =INT_MIN; + while(low Date: Wed, 21 Dec 2022 18:17:32 +0000 Subject: [PATCH 154/408] Delete C++_Dhruv.cpp --- December -16/C++_Dhruv.cpp | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 December -16/C++_Dhruv.cpp diff --git a/December -16/C++_Dhruv.cpp b/December -16/C++_Dhruv.cpp deleted file mode 100644 index 5682eef..0000000 --- a/December -16/C++_Dhruv.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -using namespace std; - - -int main() -{ - int n; - cin>>n; - vectorarr(n); - for(auto &x:arr)cin>>x; - int low =0; - int high = arr.size()-1; - int maxi =INT_MIN; - while(low Date: Wed, 21 Dec 2022 18:18:09 +0000 Subject: [PATCH 155/408] added H2O --- December - 16/C++_Dhruv.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 December - 16/C++_Dhruv.cpp diff --git a/December - 16/C++_Dhruv.cpp b/December - 16/C++_Dhruv.cpp new file mode 100644 index 0000000..7712faf --- /dev/null +++ b/December - 16/C++_Dhruv.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; + + +int main() +{ + int n; + cin>>n; + vectorarr(n); + for(auto &x:arr)cin>>x; + int low =0; + int high = arr.size()-1; + int maxi =INT_MIN; + while(low Date: Thu, 22 Dec 2022 00:00:54 +0530 Subject: [PATCH 156/408] December - 10 solved --- December - 07/Java_tarpandas.java | 4 +-- December - 09/Java_tarpandas.java | 30 +++++++++++++++++++++ December - 10/Java_tarpandas.java | 45 +++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 December - 09/Java_tarpandas.java create mode 100644 December - 10/Java_tarpandas.java diff --git a/December - 07/Java_tarpandas.java b/December - 07/Java_tarpandas.java index 8f26228..0a5f699 100644 --- a/December - 07/Java_tarpandas.java +++ b/December - 07/Java_tarpandas.java @@ -3,8 +3,8 @@ public class Java_tarpandas { static boolean wordSearch(char arr[][], int i, int j, String input) { - int xDirection[] = {-1, -1, -1, 0, 0, 1, 1, 1}; - int yDirection[] = {-1, 0, 1, -1, 1, -1, 0, 1}; + int xDirection[] = {-1, 0, 0, 1}; + int yDirection[] = {-1, -1, 1, 1}; if(arr[i][j] != input.charAt(0)) { diff --git a/December - 09/Java_tarpandas.java b/December - 09/Java_tarpandas.java new file mode 100644 index 0000000..4ed84bb --- /dev/null +++ b/December - 09/Java_tarpandas.java @@ -0,0 +1,30 @@ +import java.util.Scanner; +public class Java_tarpandas { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int noOfWords = sc.nextInt(); + sc.nextLine(); + String [] arr = new String[noOfWords] ; + + for(int i=0; i< noOfWords; i++) { + arr[i] = sc.next(); + } + + String choiceString = ""; + int maxStringLength = 0; + for(int i=0; i< arr.length; i++) { + if(arr[i].length() % 2 != 0 && arr[i].length() > maxStringLength) { + maxStringLength = arr[i].length(); + choiceString = arr[i]; + } + } + + if(choiceString.length() == 0) { + System.out.println("Better luck next time"); + } else { + System.out.println(choiceString); + } + + sc.close(); + } +} diff --git a/December - 10/Java_tarpandas.java b/December - 10/Java_tarpandas.java new file mode 100644 index 0000000..eb05d8a --- /dev/null +++ b/December - 10/Java_tarpandas.java @@ -0,0 +1,45 @@ +import java.util.Scanner; +public class Java_tarpandas { + static String count(String word) { + int count = 0; + for(int i=0; i=4) { + return "NO"; + } + } + } + return "YES"; + } + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int wordCount = sc.nextInt(); + String responses[] = new String[wordCount]; + + for(int i = 0; i< wordCount; i++) { + int charCount = sc.nextInt(); + sc.nextLine(); + String word = sc.next().substring(0,charCount); + responses[i] = count(word);; + } + + for(String answer : responses) { + System.out.println(answer); + } + sc.close(); + } +} From 4b4251b891b6801769188062668700a268cb73b1 Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Thu, 22 Dec 2022 10:14:22 +0530 Subject: [PATCH 157/408] December 16 - H2O Receptacle --- December - 16/Java_souvikpal2000.java | 51 +++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 December - 16/Java_souvikpal2000.java diff --git a/December - 16/Java_souvikpal2000.java b/December - 16/Java_souvikpal2000.java new file mode 100644 index 0000000..9387632 --- /dev/null +++ b/December - 16/Java_souvikpal2000.java @@ -0,0 +1,51 @@ +import java.util.*; +public class Java_souvikpal2000{ + public int findMax(int no1, int no2){ + int max = 0; + if(no1>no2){ + max = no1; + }else{ + max = no2; + } + return max; + } + + public int findMin(int no1, int no2){ + int min = 0; + if(no1 Date: Thu, 22 Dec 2022 19:43:58 +0530 Subject: [PATCH 158/408] Update README.md --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3adef26..46298c1 100644 --- a/README.md +++ b/README.md @@ -1192,6 +1192,19 @@ Output: 100 110 +Input: + +2 +5 6 +2 4 3 5 1 +7 15 +6 3 12 4 5 1 2 + + +Output: + +1 1 2 2 3 1 +1 1 1 2 3 2 2 3 1 1 2 2 0 0 0 ``` @@ -1199,7 +1212,7 @@ Output: ``` -In the first sequence, the maximum size increasing subsequence is 4, and there's only one of them. We choose B = [(1, 10), (2, 20), (3, 30), (4, 40)], and we have Weight(B) = 100. +In the first Example,at the first sequence, the maximum size increasing subsequence is 4, and there's only one of them. We choose B = [(1, 10), (2, 20), (3, 30), (4, 40)], and we have Weight(B) = 100. In the second sequence, the maximum size increasing subsequence is still 4, but there are now 5 possible subsequences: 1 2 3 4 10 20 30 40 @@ -1230,6 +1243,8 @@ Please note that this is not the maximum weight generated from picking the highe ---- + + ### December 21 - The Devil Towers #### Problem Statement From f0f6e382b79b45a28d0ce68e0470086858f11726 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Thu, 22 Dec 2022 22:36:19 +0530 Subject: [PATCH 159/408] Update README.md --- README.md | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/README.md b/README.md index 46298c1..0b91c2e 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ Check out our FAQ for more information. - [**December 20 - Code a Subsequence**](#december-20---code-a-subsequence) - [**December 21 - The Devil Towers**](#december-21---the-devil-towers) - [**December 22 - The Markowitz Paradox**](#december-22---the-markowitz-paradox) + - [**December 23 - Meeting Rooms**](#december-22---meeting-rooms) - [**FAQ**](#faq) @@ -1415,6 +1416,92 @@ So, for example: - [Caesar Cipher](https://www.geeksforgeeks.org/caesar-cipher-in-cryptography/) +---- + +### December 23 - Meeting Rooms + +#### Problem Statement + +You are given an integer n. There are n rooms numbered from 0 to n - 1. + +You are given a 2D integer array meetings where meetings[i] = [starti, endi] means that a meeting will be held during the half-closed time interval [starti, endi). All the values of starti are unique. + +Meetings are allocated to rooms in the following manner: + +Each meeting will take place in the unused room with the lowest number. + +If there are no available rooms, the meeting will be delayed until a room becomes free. The delayed meeting should have the same duration as the original meeting. + +When a room becomes unused, meetings that have an earlier original start time should be given the room. + +Return the number of the room that held the most meetings. If there are multiple rooms, return the room with the lowest number. + +A half-closed interval [a, b) is the interval between a and b including a and not including b. + + + +

+ + +#### Sample Input/Output +``` +Input: + +n = 2 + +meetings = [[0,10],[1,5],[2,7],[3,4]] + + +Output: + +0 + +``` + +``` +Input: + +n = 3 + +meetings = [[1,20],[2,10],[3,5],[4,9],[6,8]] + + +Output: + +1 + +``` + + +#### Explanation: + +``` + +For the first sample input the first line is the number of rooms and the second line of input is the meetings with the start and end time. + +- At time 0, both rooms are not being used. The first meeting starts in room 0. + +- At time 1, only room 1 is not being used. The second meeting starts in room 1. + +- At time 2, both rooms are being used. The third meeting is delayed. + +- At time 3, both rooms are being used. The fourth meeting is delayed. + +- At time 5, the meeting in room 1 finishes. The third meeting starts in room 1 for the time period [5,10). + +- At time 10, the meetings in both rooms finish. The fourth meeting starts in room 0 for the time period [10,11). + + Both rooms 0 and 1 held 2 meetings, so we return 0. + + + +``` +- **References** + - [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) + - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) + - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + + ---- FAQ From 9482a3aeafa822a3a268233a3895aaf67d004d9a Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Thu, 22 Dec 2022 22:37:43 +0530 Subject: [PATCH 160/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0b91c2e..3327a18 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Check out our FAQ for more information. - [**December 20 - Code a Subsequence**](#december-20---code-a-subsequence) - [**December 21 - The Devil Towers**](#december-21---the-devil-towers) - [**December 22 - The Markowitz Paradox**](#december-22---the-markowitz-paradox) - - [**December 23 - Meeting Rooms**](#december-22---meeting-rooms) + - [**December 23 - Meeting Rooms**](#december-23---meeting-rooms) - [**FAQ**](#faq) From ec499fd8e952d29f610814ccea9ea6a4d7fa0851 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Thu, 22 Dec 2022 22:39:03 +0530 Subject: [PATCH 161/408] First push with the folders and assets. --- December - 23/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 23/.gitignore diff --git a/December - 23/.gitignore b/December - 23/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 23/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 e290d59fe1b7f44cfc46ed17b50907f0389710be Mon Sep 17 00:00:00 2001 From: tarpandas Date: Thu, 22 Dec 2022 23:33:17 +0530 Subject: [PATCH 162/408] Upto December - 11 solved --- December - 07/Java_tarpandas.java | 5 ++--- December - 11/Java_tarpandas.java | 35 +++++++++++++++++++++++++++++++ December - 12/Java_tarpandas.java | 17 +++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 December - 11/Java_tarpandas.java create mode 100644 December - 12/Java_tarpandas.java diff --git a/December - 07/Java_tarpandas.java b/December - 07/Java_tarpandas.java index 0a5f699..80d44dc 100644 --- a/December - 07/Java_tarpandas.java +++ b/December - 07/Java_tarpandas.java @@ -4,14 +4,14 @@ public class Java_tarpandas { static boolean wordSearch(char arr[][], int i, int j, String input) { int xDirection[] = {-1, 0, 0, 1}; - int yDirection[] = {-1, -1, 1, 1}; + int yDirection[] = {0,-1,1,0}; if(arr[i][j] != input.charAt(0)) { return false; } - for(int k = 0; k < 8; k++) { + for(int k = 0; k < 4; k++) { int l; int rowDir = i + xDirection[k]; int colDir = j + yDirection[k]; @@ -35,7 +35,6 @@ static boolean wordSearch(char arr[][], int i, int j, String input) { static boolean searchPattern(char arr[][], String input) { int rowSize = arr.length; int columnSize = arr[0].length; - System.out.println(rowSize+" "+columnSize); for(int i=0; i Date: Fri, 23 Dec 2022 15:51:42 +0530 Subject: [PATCH 164/408] day 15 added ,sorting --- December - 15/GREEDnim_day15_java.java | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 December - 15/GREEDnim_day15_java.java diff --git a/December - 15/GREEDnim_day15_java.java b/December - 15/GREEDnim_day15_java.java new file mode 100644 index 0000000..aeb8e27 --- /dev/null +++ b/December - 15/GREEDnim_day15_java.java @@ -0,0 +1,31 @@ +package acm; + +import java.util.*; +import java.util.stream.Collectors; + +public class GREEDnim_day15_java { + + public static void main(String[] args) { + + String[][] inp = {{"Annalise", "01:09:00"},{ "Frank", "01:02:30"},{"Laurel", "01:04:19"}}; + Arrays.sort(inp, new Comparator() { + + @Override + public int compare(String[] a, String[]b ) { + + String[] time1 = a[1].split(":", 0); + String[] time2 = b[1].split(":", 0); + int t = time1[0].compareTo(time2[0]); + if (t != 0) return t; + t = time1[1].compareTo(time2[1]); + if (t != 0) return t; + t = time1[2].compareTo(time2[2]); + return t; + + } + }); + + for(String[]ans:inp) System.out.print(ans[0]+" ,"); + + } +} From d8c3f113ed4ac9efed6e93f2dc23f072b5e78dd9 Mon Sep 17 00:00:00 2001 From: Asad Date: Fri, 23 Dec 2022 21:26:02 +0530 Subject: [PATCH 165/408] =?UTF-8?q?Day=205=20Don=E2=80=99t=20let=20Mason?= =?UTF-8?q?=20misspend!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- December - 05/Misspend.cpp | 27 +++++++++++++++++++++++++++ December - 05/output.txt | 7 +++++++ 2 files changed, 34 insertions(+) create mode 100644 December - 05/Misspend.cpp create mode 100644 December - 05/output.txt diff --git a/December - 05/Misspend.cpp b/December - 05/Misspend.cpp new file mode 100644 index 0000000..6bf6268 --- /dev/null +++ b/December - 05/Misspend.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +int main() +{ + uint16_t income10per = 50000 * 0.1; + uint16_t fuel_price; + cin >> fuel_price; + uint8_t adjust_value = 36; + // adjust value + // so calculating for 3rd day , it comes 10 times , so 6*10 = 60 + // calculating for 5th day , it comes 6 times, so 4*6 = 24 (negative) + // so adjusting values = 60 - 24 = +36 + // normal mathematics + int total = (fuel_price * 2 * 31) + adjust_value; + cout << total << endl; + if (total <= income10per) + { + cout << "EXPENDITURE WITHIN LIMIT" << endl; + } + else + { + cout << "EXPENDITURE EXCEEDING LIMIT" << endl; + } + + return 0; +} \ No newline at end of file diff --git a/December - 05/output.txt b/December - 05/output.txt new file mode 100644 index 0000000..50eff60 --- /dev/null +++ b/December - 05/output.txt @@ -0,0 +1,7 @@ +75 +4686 +EXPENDITURE WITHIN LIMIT + +97 +6050 +EXPENDITURE EXCEEDING LIMIT \ No newline at end of file From 3e3eb866a76cec08566b3d72d30295aee8959f4e Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Fri, 23 Dec 2022 21:50:23 +0530 Subject: [PATCH 166/408] bipartite working proved by assumption --- December - 14/cpp_nijuyonkadesu.cpp | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 December - 14/cpp_nijuyonkadesu.cpp diff --git a/December - 14/cpp_nijuyonkadesu.cpp b/December - 14/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..9ef01c8 --- /dev/null +++ b/December - 14/cpp_nijuyonkadesu.cpp @@ -0,0 +1,32 @@ +#include +#include + +using namespace std; + +void input(int); + +int main() +{ + int n; + cin>>n; + input(n); +} + +void input(int n) { + bool isBipartiteFlag=true; + int edgeCounter=0; + + vector> adjMat(n, vector {0}); + for (int i = 0; i>adjMat[i][j]; + // I found out, 1 cannot exist if both i & j are odd or even at the same time + // and should contain a loop with all vertices + if(adjMat[i][j] == 1 && ((i%2==0 && j%2==0) || (i%2!=0 && j%2!=0))){ + isBipartiteFlag = false; + } + } + } + cout< Date: Fri, 23 Dec 2022 22:11:30 +0530 Subject: [PATCH 167/408] day 14 error modified , and added comments --- December - 14/GREEDnim_day14_java.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/December - 14/GREEDnim_day14_java.java b/December - 14/GREEDnim_day14_java.java index 8f5982e..cc916a2 100644 --- a/December - 14/GREEDnim_day14_java.java +++ b/December - 14/GREEDnim_day14_java.java @@ -8,7 +8,10 @@ public class GREEDnim_day14_java { +// map for every vetex and its group static HashMapmap=new HashMap<>(); + +// checker to check if ive already visited the node and placed it in correct group static boolean[] check; public static void main(String[] args) { Scanner in=new Scanner(System.in); @@ -41,9 +44,10 @@ public static void main(String[] args) { public static boolean isBipartate(int[][] inp,int cur) { + // making the current element as group 0, adding group to its neighbours as 1 and putting neighbours into queue for bfs Queueq=new LinkedList<>(); map.put(cur,0); - check[0]=true; + check[cur]=true; for(int i=0;i Date: Fri, 23 Dec 2022 22:33:53 +0530 Subject: [PATCH 168/408] day 17 added --- December - 14/GREEDnim_day14_java.java | 1 + December - 17/GREEDnim_day17_java.java | 43 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 December - 17/GREEDnim_day17_java.java diff --git a/December - 14/GREEDnim_day14_java.java b/December - 14/GREEDnim_day14_java.java index cc916a2..5c2c204 100644 --- a/December - 14/GREEDnim_day14_java.java +++ b/December - 14/GREEDnim_day14_java.java @@ -57,6 +57,7 @@ public static boolean isBipartate(int[][] inp,int cur) q.offer(i); } } + //bfs while(!q.isEmpty()){ int row=q.poll(); int curG=map.get(row); diff --git a/December - 17/GREEDnim_day17_java.java b/December - 17/GREEDnim_day17_java.java new file mode 100644 index 0000000..6edb7e7 --- /dev/null +++ b/December - 17/GREEDnim_day17_java.java @@ -0,0 +1,43 @@ +package acm; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class GREEDnim_day17_java { + + public static void main(String[] args) { + + Scanner in=new Scanner(System.in); + String inp=in.next(); + int row=in.nextInt(); + + List[] index= new ArrayList[row]; + for(int i=0;i(); + } + + int i=0; + + while(i0 && iele:index) + { + for(int k:ele) + { + System.out.print(inp.charAt(k)); + } + } + } +} From 58a4d465a3ffa24b9d0e969b536006d6c437eb34 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Fri, 23 Dec 2022 22:47:30 +0530 Subject: [PATCH 169/408] First push with the folders and assets. --- December - 24/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 24/.gitignore diff --git a/December - 24/.gitignore b/December - 24/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 24/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 440d6bde9f9ca8d72aeaa3f25020ce9a6d2f659d Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Fri, 23 Dec 2022 22:56:08 +0530 Subject: [PATCH 170/408] Update README.md --- README.md | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/README.md b/README.md index 3327a18..a1ca3a9 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ Check out our FAQ for more information. - [**December 21 - The Devil Towers**](#december-21---the-devil-towers) - [**December 22 - The Markowitz Paradox**](#december-22---the-markowitz-paradox) - [**December 23 - Meeting Rooms**](#december-23---meeting-rooms) + - [**December 24 - Cracking The Safe**](#december-24---cracking-the-safe) - [**FAQ**](#faq) @@ -1504,6 +1505,101 @@ For the first sample input the first line is the number of rooms and the second ---- +### December 24 - Cracking The Safe + +#### Problem Statement + +There is a safe protected by a password. The password is a sequence of n digits where each digit can be in the range [0, k - 1]. + +The safe has a peculiar way of checking the password. When you enter in a sequence, it checks the most recent n digits that were entered each time you type a digit. + +For example, the correct password is "345" and you enter in "012345": + + - After typing 0, the most recent 3 digits is "0", which is incorrect. + + - After typing 1, the most recent 3 digits is "01", which is incorrect. + + - After typing 2, the most recent 3 digits is "012", which is incorrect. + + - After typing 3, the most recent 3 digits is "123", which is incorrect. + + - After typing 4, the most recent 3 digits is "234", which is incorrect. + + - After typing 5, the most recent 3 digits is "345", which is correct and the safe unlocks. + +Return any string of minimum length that will unlock the safe at some point of entering it + + + + +

+ + + +#### Sample Input/Output +``` +Input: + + n = 1 + k = 2 + + +Output: + +"10" + +``` + +``` +Input: + +n = 2 +k = 2 + + +Output: + +"01100" + +``` + + +#### Explanation: + +``` +Sample - 1 + + The password is a single digit, so enter each digit. "01" would also unlock the safe. + + +Sample - 2 + +For each possible password: + +- "00" is typed in starting from the 4th digit. + +- "01" is typed in starting from the 1st digit. + +- "10" is typed in starting from the 3rd digit. + +- "11" is typed in starting from the 2nd digit. + +Thus "01100" will unlock the safe. "01100", "10011", and "11001" would also unlock the safe. + + +``` +- **References** + - [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) + - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) + - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + - [Strings in C++](https://www.geeksforgeeks.org/stdstring-class-in-c/) + - [Strings in Python](https://www.geeksforgeeks.org/python-string/) + - [String in Java](https://www.geeksforgeeks.org/strings-in-java/) + + +---- + + FAQ ====== From b2f2007567c574ad72908cd24a830c412c118e02 Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Sat, 24 Dec 2022 17:58:12 +0530 Subject: [PATCH 171/408] December 19 - Hidden Anagram --- December - 19/Java_souvikpal2000.java | 135 ++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 December - 19/Java_souvikpal2000.java diff --git a/December - 19/Java_souvikpal2000.java b/December - 19/Java_souvikpal2000.java new file mode 100644 index 0000000..9802858 --- /dev/null +++ b/December - 19/Java_souvikpal2000.java @@ -0,0 +1,135 @@ +import java.util.*; +class AlphabetDetail{ + char alphabet; + int count; + AlphabetDetail(char alphabet, int count){ + this.alphabet = alphabet; + this.count = count; + } +} +class Java_souvikpal2000{ + public String removeSpecialCharacters(String str){ + String newStr = ""; + for(int i=0;i alphabetCount(String str){ + str = str.toLowerCase(); + int length = str.length(); + List list = new ArrayList<>(); + for(int i=97;i<=122;i++){ + int count=0; + for(int j=0;j0){ + list.add(new AlphabetDetail((char)i,count)); + } + } + return list; + } + + public List makingDummyObjectList(List list){ + List dummy = new ArrayList<>(); + for(AlphabetDetail l : list){ + dummy.add(new AlphabetDetail(l.alphabet, l.count)); + } + return dummy; + } + + public String findAnagram(String str, List list, List dummy){ + String anagram = ""; + String flag = ""; + str = str.toLowerCase() + ' '; + int length = str.length(); + int i = 0; + boolean alphabetCountChanged = false; + while(i list = ob.alphabetCount(str2); + List dummy = ob.makingDummyObjectList(list); + String anagram = ob.findAnagram(str1,list,dummy); + + System.out.println(""); + System.out.println("Output:"); + System.out.println(""); + System.out.println(anagram.length() == 0? "No Anagram" : anagram); + } +} \ No newline at end of file From 65b90aa470fa58ada4e2f0f5d39d0686de76befe Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sat, 24 Dec 2022 22:32:51 +0530 Subject: [PATCH 172/408] Update README.md --- README.md | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/README.md b/README.md index a1ca3a9..17a4b8e 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ Check out our FAQ for more information. - [**December 22 - The Markowitz Paradox**](#december-22---the-markowitz-paradox) - [**December 23 - Meeting Rooms**](#december-23---meeting-rooms) - [**December 24 - Cracking The Safe**](#december-24---cracking-the-safe) + - [**December 25 - The Motorbike Race**](#december-25---the-motorbike-race) - [**FAQ**](#faq) @@ -1599,6 +1600,90 @@ Thus "01100" will unlock the safe. "01100", "10011", and "11001" would also unlo ---- +### December 25 - The Motorbike Race + +#### Problem Statement + +It's time for the annual exciting Motorbike Race in Bangalore. + +There are N motorcyclists taking part in the competition. George is watching the race. + +At the present moment (time 0), he has taken note of the current velocity and position of each motorcyclist. + +He wants to know at a given point of time, which motorcyclist is in a specific place in the rank list. + +Please help him! + +If at any given time two motorcyclists are in same position, the motorcyclist with the smaller index will be placed before the one with the larger index. + +To make the problem simple, he assumes that each motorcyclist is moving at a constant velocity. + + + +

+ + + +#### Sample Input/Output +``` +Input: + +1 +4 +2 100 +3 50 +4 60 +5 1 +4 +1 1 +50 2 +60 4 +100 1 + + + +Output: + +1 +4 +1 +4 + + +``` + + +#### Explanation: + +``` +Input + +The first line contains a number t (about 10) which is the number of test cases. + +Then t test cases follow. Each test case has the following form. + +The first line of the test case contains a number N (1 <= N <= 2000), the number of motorcyclists. + +The i-th line in the next N lines contains two numbers, v and x, which are the velocity and the current position of the i-th motorcyclist (1 <= v, x <= 100,000). + +The next line contains a number Q (1 <= Q <= 2000), the number of time queries. + +Each line in the next Q lines contains two numbers, t (1 <= t <= 1,000,000,000) and k (1 <= k <= n), representing the query: "at time t, which motorcyclist is positioned k-th in the rank list?" + +Output: + +For each test case, print Q lines, with each line containing the index of the motorcyclist for the corresponding query. + +Remember to print a new line after each test case. + +``` +- **References** + - [Looping in C](https://www.tutorialspoint.com/cprogramming/c_loops.htm) + - [Looping in C++](https://www.programiz.com/cpp-programming/for-loop) + - [Looping in Java](https://www.geeksforgeeks.org/loops-in-java/) + - [Looping in Python](https://www.w3schools.com/python/python_for_loops.asp) + +---- FAQ ====== From c85f8fd716864e9fe6647923621c244c0eab11e1 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sat, 24 Dec 2022 22:33:48 +0530 Subject: [PATCH 173/408] First push with the folders and assets. --- December - 25/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 25/.gitignore diff --git a/December - 25/.gitignore b/December - 25/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 25/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 f3ea096e2c3d683d802e35660f1db45fdb06d8bf Mon Sep 17 00:00:00 2001 From: tarpandas Date: Sat, 24 Dec 2022 23:24:32 +0530 Subject: [PATCH 174/408] Completed only December - 16 --- December - 16/Java_tarpandas.java | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 December - 16/Java_tarpandas.java diff --git a/December - 16/Java_tarpandas.java b/December - 16/Java_tarpandas.java new file mode 100644 index 0000000..f4e0d16 --- /dev/null +++ b/December - 16/Java_tarpandas.java @@ -0,0 +1,37 @@ +import java.util.Scanner; +class Java_tarpandas { + static int smallerNumber(int iNum1, int iNum2) { + if(iNum1 > iNum2) { + return iNum2; + } + return iNum1; + } + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + System.out.print("height = "); + + String input = sc.nextLine(); + + String [] tempArr = input.split(","); + int [] arr = new int [tempArr.length]; + + for(int i=0;i maxArea) { + maxArea = tempNumber; + } + } + } + System.out.println(maxArea); + sc.close(); + } +} \ No newline at end of file From 5cb87e4681d4304035efad96f95909600b2377b9 Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Sun, 25 Dec 2022 09:58:10 +0530 Subject: [PATCH 175/408] December 22 - The Markowitz Paradox --- December - 22/Java_souvikpal2000.java | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 December - 22/Java_souvikpal2000.java diff --git a/December - 22/Java_souvikpal2000.java b/December - 22/Java_souvikpal2000.java new file mode 100644 index 0000000..fccca8f --- /dev/null +++ b/December - 22/Java_souvikpal2000.java @@ -0,0 +1,42 @@ +import java.util.*; +public class Java_souvikpal2000{ + public String theMarkowitzParadox(String codeword, String message){ + String encrypt = ""; + int length = message.length(); + int l = codeword.length(); + int j = 0; + for(int i=0;i 90){ + int diff = sum - 90; + encrypt = encrypt + (char)(64 + diff); + + }else{ + encrypt = encrypt + (char)sum; + } + j++; + } + return encrypt; + } + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input:"); + String codeword = sc.next(); + String message = sc.next(); + + Java_souvikpal2000 ob=new Java_souvikpal2000(); + String encrypt = ob.theMarkowitzParadox(codeword.toUpperCase(),message.toUpperCase()); + + System.out.println(""); + System.out.println("Output:"); + System.out.println(""); + System.out.println(encrypt); + } +} \ No newline at end of file From 1779af0c7340fd53cbe92899f45742204f8ba06b Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sun, 25 Dec 2022 22:13:41 +0530 Subject: [PATCH 176/408] First push with the folders and assets. --- December - 26/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 26/.gitignore diff --git a/December - 26/.gitignore b/December - 26/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 26/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 56b51646ed8ef35d3496baf75e7213d61b297ad9 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sun, 25 Dec 2022 22:20:47 +0530 Subject: [PATCH 177/408] Update README.md --- README.md | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/README.md b/README.md index 17a4b8e..d7a75d4 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ Check out our FAQ for more information. - [**December 23 - Meeting Rooms**](#december-23---meeting-rooms) - [**December 24 - Cracking The Safe**](#december-24---cracking-the-safe) - [**December 25 - The Motorbike Race**](#december-25---the-motorbike-race) + - [**December 26 - Circulate**](#december-26---circulate) - [**FAQ**](#faq) @@ -1685,6 +1686,81 @@ Remember to print a new line after each test case. ---- +### December 26 - Circulate + +#### Problem Statement + +A group of n people are trying to spread a word among themselves. + +The word is initially only known by the first person in the group. + +The first person may share the word with a few people that he knows, and those people may share the word with the people they know, and so on. + +The task is to determine whether the word has been successfully spread to all n people in the group. + +If the word has been successfully spread to all n people, the program should print "Spread". + +If the word has not yet been successfully spread to all n people, the program should print "Nope". + + + +

+ + + +#### Sample Input/Output +``` +Input: + +[[2], [3, 4], [2], [2]] + + +Output: + +Spread + + +``` + +``` +Input: + +[[2], [5, 4, 6], [3], [4], [5], [6]] + + +Output: + +Nope + + +``` + + +#### Explanation: + +``` + +The first person said the word to the second person. + +The second person said the word to the third and fourth person. + +Third person shares the word with the second person. + +The list has four persons and everyone knows what the word is so the output is “Spread”. + + +``` + +

+ + +- **References** + - [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) + - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) + - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + +---- + FAQ ====== From 10371f5cf8090cd8affaebde5725ddade35911eb Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Mon, 26 Dec 2022 09:53:03 +0530 Subject: [PATCH 178/408] December 23 - Meeting Rooms --- December - 23/Java_souvikpal2000.java | 114 ++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 December - 23/Java_souvikpal2000.java diff --git a/December - 23/Java_souvikpal2000.java b/December - 23/Java_souvikpal2000.java new file mode 100644 index 0000000..97a0381 --- /dev/null +++ b/December - 23/Java_souvikpal2000.java @@ -0,0 +1,114 @@ +import java.util.*; +class Room{ + int allocatedTime; + int count; + Room(int allocatedTime, int count){ + this.allocatedTime = allocatedTime; + this.count = count; + } +} +public class Java_souvikpal2000{ + public List allocateRooms(int n){ + List list = new ArrayList<>(); + for(int i=0;i meetings[j][0]){ + start = meetings[i][0]; + meetings[i][0] = meetings[j][0]; + meetings[j][0] = start; + + end = meetings[i][1]; + meetings[i][1] = meetings[j][1]; + meetings[j][1] = end; + } + } + } + return meetings; + } + + public List meetingRooms(int[][] meetings, int n, List rooms){ + int time = 0; + int i = -1; + while(i meetings.length-1){ + break; + } + room.allocatedTime = Math.abs(meetings[i][0] - meetings[i][1]); + room.count = room.count + 1; + } + /*for(Room r : rooms){ + System.out.println(r.allocatedTime+" "+r.count); + } + System.out.println("");*/ + time++; + } + + return rooms; + } + + public int findRoomWithMaxMeetings(List rooms){ + int roomNo = 0; + int noOfMeetings = 0; + int roomWithMaxMeetings = 0; + for(Room r : rooms){ + if(r.count > noOfMeetings){ + noOfMeetings = r.count; + roomWithMaxMeetings = roomNo; + } + roomNo++; + } + return roomWithMaxMeetings; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + // Input 1: + int n = 2; //Number of Rooms + int[][] meetings = { + {0,10},{1,5},{2,7},{3,4} + }; + + //Input 2: + /*int n = 3; //Number of Rooms + int[][] meetings = { + {1,20},{2,10},{3,5},{4,9},{6,8} + };*/ + + Java_souvikpal2000 ob=new Java_souvikpal2000(); + List rooms = ob.allocateRooms(n); + int[][] sortedMeetings = ob.sortMeetings(meetings); + List meetingsEnd = ob.meetingRooms(sortedMeetings,n,rooms); + int roomNo = ob.findRoomWithMaxMeetings(meetingsEnd); + + System.out.println(""); + System.out.println("Output:"); + System.out.println(""); + System.out.println(roomNo); + } +} \ No newline at end of file From 6dcb7cfbcbde64ca8d3e9e999253216f2da6973c Mon Sep 17 00:00:00 2001 From: Deepika-Govindaswamy <118124756+Deepika-Govindaswamy@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:16:24 +0530 Subject: [PATCH 179/408] Update README.md --- README.md | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d7a75d4..47357ff 100644 --- a/README.md +++ b/README.md @@ -1754,11 +1754,62 @@ The list has four persons and everyone knows what the word is so the output is

-- **References** - - [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) - - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) - - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) - +### December 27 - Mission to Earth: Re-Calibrated + +#### Problem Statement + +AUTO, the autopilot helm of the starliner The Axiom lead a coup of robots and breached security, infiltrating the Boiler Room and Fuel Tank mechanics to steer the Axiom away from the Earth. +WALL-E manages to follow the robots who joined AUTO’s cause in disguise to annihilate him and recalibrate the Fuel Tank mechanics so that humans can finally set foot on their home planet in 2805. +Fuel gauges indicate, often with fractions, just how much fuel is in a tank. For instance, 1/4 indicates that a tank is 25% full, 1/2 indicates that a tank is 50% full, and 3/4 indicates that a tank is 75% full. +You are the Fuel Engine Calibrator, FEC and WALL-E needs your help. +The Fuel Tank’s capacity is 30,000 L. Implement a program that prompts the user for a fraction, formatted as X/Y, wherein each of X and Y is an integer, and then outputs, as a percentage rounded to the nearest integer, how much fuel is in the tank. +If 1% or less remains, output E instead indicates that the tank is essentially empty. And if 99% or more remains, output F instead to indicate that the tank is essentially full. Calculate the total fuel in the Fuel Tank. +If X or Y is not an integer, X is greater than Y, or Y is 0, prompt the user again. (It is optional for Y to be 4.) Be sure to catch any exceptions like ValueError or ZeroDivisionError. + + + +

+ + + +#### Sample Input/Output +``` +Input: + +Enter the Hydrogen fuel fraction: +5/7 + +Output: +Fuel calibration: +71.428% +Amount of fuel in tank: +21,428.4 L out of 30,000 L + + +Input: +Enter the Hydrogen fuel fraction: +722/729 + +Output: +Fuel calibration: +99.039% +Amount of fuel in tank: +29,711.7 L out of 30,000 L +The tank is FULL!!! + +Input: +Enter the Hydrogen fuel fraction: +25/156 + +Output: + +Fuel calibration: +0.160% +Amount of fuel in tank: +48 L out of 30,000 L +The tank is EMPTY!!! +Refill tank. + ---- FAQ From d43f653a4ab29734e03ea932363993ea1d8173ae Mon Sep 17 00:00:00 2001 From: Deepika-Govindaswamy <118124756+Deepika-Govindaswamy@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:19:36 +0530 Subject: [PATCH 180/408] Update README.md --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 47357ff..882138d 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ Check out our FAQ for more information. - [**December 24 - Cracking The Safe**](#december-24---cracking-the-safe) - [**December 25 - The Motorbike Race**](#december-25---the-motorbike-race) - [**December 26 - Circulate**](#december-26---circulate) + - [**December 26 - Circulate**](#december-27---Mission to Earth: Re-Calibrated) - [**FAQ**](#faq) @@ -1759,17 +1760,22 @@ The list has four persons and everyone knows what the word is so the output is #### Problem Statement AUTO, the autopilot helm of the starliner The Axiom lead a coup of robots and breached security, infiltrating the Boiler Room and Fuel Tank mechanics to steer the Axiom away from the Earth. + WALL-E manages to follow the robots who joined AUTO’s cause in disguise to annihilate him and recalibrate the Fuel Tank mechanics so that humans can finally set foot on their home planet in 2805. + Fuel gauges indicate, often with fractions, just how much fuel is in a tank. For instance, 1/4 indicates that a tank is 25% full, 1/2 indicates that a tank is 50% full, and 3/4 indicates that a tank is 75% full. + You are the Fuel Engine Calibrator, FEC and WALL-E needs your help. + The Fuel Tank’s capacity is 30,000 L. Implement a program that prompts the user for a fraction, formatted as X/Y, wherein each of X and Y is an integer, and then outputs, as a percentage rounded to the nearest integer, how much fuel is in the tank. + If 1% or less remains, output E instead indicates that the tank is essentially empty. And if 99% or more remains, output F instead to indicate that the tank is essentially full. Calculate the total fuel in the Fuel Tank. -If X or Y is not an integer, X is greater than Y, or Y is 0, prompt the user again. (It is optional for Y to be 4.) Be sure to catch any exceptions like ValueError or ZeroDivisionError. +If X or Y is not an integer, X is greater than Y, or Y is 0, prompt the user again. (It is optional for Y to be 4.) Be sure to catch any exceptions like ValueError or ZeroDivisionError. -

+

#### Sample Input/Output From 02828e9468035d84252c64c429865ac1e67bc7b5 Mon Sep 17 00:00:00 2001 From: Deepika-Govindaswamy <118124756+Deepika-Govindaswamy@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:20:13 +0530 Subject: [PATCH 181/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 882138d..33c8433 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Check out our FAQ for more information. - [**December 24 - Cracking The Safe**](#december-24---cracking-the-safe) - [**December 25 - The Motorbike Race**](#december-25---the-motorbike-race) - [**December 26 - Circulate**](#december-26---circulate) - - [**December 26 - Circulate**](#december-27---Mission to Earth: Re-Calibrated) + - [**December 27 - Mission to Earth: Re-Calibrated**](#december-27---Mission to Earth: Re-Calibrated) - [**FAQ**](#faq) From 954fc6cef682a0fed6da24609fc2a6aad523f926 Mon Sep 17 00:00:00 2001 From: Deepika-Govindaswamy <118124756+Deepika-Govindaswamy@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:21:39 +0530 Subject: [PATCH 182/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 33c8433..f458d5e 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Check out our FAQ for more information. - [**December 24 - Cracking The Safe**](#december-24---cracking-the-safe) - [**December 25 - The Motorbike Race**](#december-25---the-motorbike-race) - [**December 26 - Circulate**](#december-26---circulate) - - [**December 27 - Mission to Earth: Re-Calibrated**](#december-27---Mission to Earth: Re-Calibrated) + - [**December 27 - Mission to Earth: Re-Calibrated**](#december-27---Mission-to-Earth:-Re-Calibrated) - [**FAQ**](#faq) From f1e287d0023b28564a560ac72b1ad3118aab0a58 Mon Sep 17 00:00:00 2001 From: Deepika-Govindaswamy <118124756+Deepika-Govindaswamy@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:22:34 +0530 Subject: [PATCH 183/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f458d5e..9bda77d 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Check out our FAQ for more information. - [**December 24 - Cracking The Safe**](#december-24---cracking-the-safe) - [**December 25 - The Motorbike Race**](#december-25---the-motorbike-race) - [**December 26 - Circulate**](#december-26---circulate) - - [**December 27 - Mission to Earth: Re-Calibrated**](#december-27---Mission-to-Earth:-Re-Calibrated) + - [**December 27 - Mission to Earth Re-Calibrated**](#december-27---Mission-to-Earth:-Re-Calibrated) - [**FAQ**](#faq) From cdb43417761b5f592f2115312eb3eec4c7005e33 Mon Sep 17 00:00:00 2001 From: Deepika-Govindaswamy <118124756+Deepika-Govindaswamy@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:24:38 +0530 Subject: [PATCH 184/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9bda77d..5317a39 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Check out our FAQ for more information. - [**December 24 - Cracking The Safe**](#december-24---cracking-the-safe) - [**December 25 - The Motorbike Race**](#december-25---the-motorbike-race) - [**December 26 - Circulate**](#december-26---circulate) - - [**December 27 - Mission to Earth Re-Calibrated**](#december-27---Mission-to-Earth:-Re-Calibrated) + - [**December 27 - Mission to Earth: Re-Calibrated**](#december-27--- Mission-to-Earth:-Re-Calibrated) - [**FAQ**](#faq) From 885f9d1a25d217c5c3e0f5d204dc1b21f63d5a0c Mon Sep 17 00:00:00 2001 From: Deepika-Govindaswamy <118124756+Deepika-Govindaswamy@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:25:07 +0530 Subject: [PATCH 185/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5317a39..a3354ac 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Check out our FAQ for more information. - [**December 24 - Cracking The Safe**](#december-24---cracking-the-safe) - [**December 25 - The Motorbike Race**](#december-25---the-motorbike-race) - [**December 26 - Circulate**](#december-26---circulate) - - [**December 27 - Mission to Earth: Re-Calibrated**](#december-27--- Mission-to-Earth:-Re-Calibrated) + - [**December 27 - Mission to Earth: Re-Calibrated**](#december-27--- Mission-to-Earth:-Re-Calibrated) - [**FAQ**](#faq) From 2c951714861e0aa11ff4974b820abf6f54b78e80 Mon Sep 17 00:00:00 2001 From: Deepika-Govindaswamy <118124756+Deepika-Govindaswamy@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:25:36 +0530 Subject: [PATCH 186/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a3354ac..f458d5e 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Check out our FAQ for more information. - [**December 24 - Cracking The Safe**](#december-24---cracking-the-safe) - [**December 25 - The Motorbike Race**](#december-25---the-motorbike-race) - [**December 26 - Circulate**](#december-26---circulate) - - [**December 27 - Mission to Earth: Re-Calibrated**](#december-27--- Mission-to-Earth:-Re-Calibrated) + - [**December 27 - Mission to Earth: Re-Calibrated**](#december-27---Mission-to-Earth:-Re-Calibrated) - [**FAQ**](#faq) From 4ccbc3a7220478688c249fe69ca2f134b1578c08 Mon Sep 17 00:00:00 2001 From: Deepika-Govindaswamy <118124756+Deepika-Govindaswamy@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:29:07 +0530 Subject: [PATCH 187/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f458d5e..bf6b886 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Check out our FAQ for more information. - [**December 24 - Cracking The Safe**](#december-24---cracking-the-safe) - [**December 25 - The Motorbike Race**](#december-25---the-motorbike-race) - [**December 26 - Circulate**](#december-26---circulate) - - [**December 27 - Mission to Earth: Re-Calibrated**](#december-27---Mission-to-Earth:-Re-Calibrated) + - [**December 27 - Mission to Earth: Re-Calibrated**](#december-27---mission-to-earth:-re-calibrated) - [**FAQ**](#faq) From cfa4dd0b9ce7a892cdf134de98e67dd87335c651 Mon Sep 17 00:00:00 2001 From: Deepika-Govindaswamy <118124756+Deepika-Govindaswamy@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:36:37 +0530 Subject: [PATCH 188/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf6b886..611553d 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Check out our FAQ for more information. - [**December 24 - Cracking The Safe**](#december-24---cracking-the-safe) - [**December 25 - The Motorbike Race**](#december-25---the-motorbike-race) - [**December 26 - Circulate**](#december-26---circulate) - - [**December 27 - Mission to Earth: Re-Calibrated**](#december-27---mission-to-earth:-re-calibrated) + - [**December 27 - Mission to Earth: Re Calibrated**](#december-27---mission-to-earth:-re-calibrated) - [**FAQ**](#faq) From fa13da286ddfd689463736c2d097993335f77bd0 Mon Sep 17 00:00:00 2001 From: Deepika-Govindaswamy <118124756+Deepika-Govindaswamy@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:38:08 +0530 Subject: [PATCH 189/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 611553d..5eb58c2 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Check out our FAQ for more information. - [**December 24 - Cracking The Safe**](#december-24---cracking-the-safe) - [**December 25 - The Motorbike Race**](#december-25---the-motorbike-race) - [**December 26 - Circulate**](#december-26---circulate) - - [**December 27 - Mission to Earth: Re Calibrated**](#december-27---mission-to-earth:-re-calibrated) + - [**December 27 - Mission to Earth: Re-Calibrated**](#december-27---mission-to-earth-re-calibrated) - [**FAQ**](#faq) From 8fb9b79f15bd4b938f6401c2d829c8979bd9596f Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:49:17 +0530 Subject: [PATCH 190/408] Update README.md --- README.md | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5eb58c2..14d49a3 100644 --- a/README.md +++ b/README.md @@ -1754,6 +1754,7 @@ The list has four persons and everyone knows what the word is so the output is

+---- ### December 27 - Mission to Earth: Re-Calibrated @@ -1767,7 +1768,9 @@ Fuel gauges indicate, often with fractions, just how much fuel is in a tank. For You are the Fuel Engine Calibrator, FEC and WALL-E needs your help. -The Fuel Tank’s capacity is 30,000 L. Implement a program that prompts the user for a fraction, formatted as X/Y, wherein each of X and Y is an integer, and then outputs, as a percentage rounded to the nearest integer, how much fuel is in the tank. +The Fuel Tank’s capacity is 30,000 L. + +Implement a program that prompts the user for a fraction, formatted as X/Y, wherein each of X and Y is an integer, and then outputs, as a percentage rounded to the nearest integer, how much fuel is in the tank. If 1% or less remains, output E instead indicates that the tank is essentially empty. And if 99% or more remains, output F instead to indicate that the tank is essentially full. Calculate the total fuel in the Fuel Tank. @@ -1786,22 +1789,28 @@ Enter the Hydrogen fuel fraction: 5/7 Output: -Fuel calibration: -71.428% -Amount of fuel in tank: -21,428.4 L out of 30,000 L +Fuel calibration: 71.428% +Amount of fuel in tank: 21,428.4 L out of 30,000 L + +``` + +``` Input: + Enter the Hydrogen fuel fraction: 722/729 Output: -Fuel calibration: -99.039% -Amount of fuel in tank: -29,711.7 L out of 30,000 L -The tank is FULL!!! + +Fuel calibration: 99.039% +Amount of fuel in tank: 29,711.7 L out of 30,000 L +The tank is FULL! + +``` + +``` Input: Enter the Hydrogen fuel fraction: @@ -1809,13 +1818,19 @@ Enter the Hydrogen fuel fraction: Output: -Fuel calibration: -0.160% -Amount of fuel in tank: -48 L out of 30,000 L +Fuel calibration: 0.160% +Amount of fuel in tank: 48 L out of 30,000 L The tank is EMPTY!!! Refill tank. +``` + +- **References** + - [Looping in C](https://www.tutorialspoint.com/cprogramming/c_loops.htm) + - [Looping in C++](https://www.programiz.com/cpp-programming/for-loop) + - [Looping in Java](https://www.geeksforgeeks.org/loops-in-java/) + - [Looping in Python](https://www.w3schools.com/python/python_for_loops.asp) + ---- FAQ From c94149047e8ffb021fa9d620cdfb3146b92bab68 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:50:13 +0530 Subject: [PATCH 191/408] First push with the folders and assets. --- December - 27/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 27/.gitignore diff --git a/December - 27/.gitignore b/December - 27/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 27/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 553319adadc0cca1a2dc0024702727c52c7d0725 Mon Sep 17 00:00:00 2001 From: Tejasvi Bolla <119505502+tejasvibolla@users.noreply.github.com> Date: Tue, 27 Dec 2022 22:20:57 +0530 Subject: [PATCH 192/408] Update README.md --- README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/README.md b/README.md index 14d49a3..33821cc 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ Check out our FAQ for more information. - [**December 25 - The Motorbike Race**](#december-25---the-motorbike-race) - [**December 26 - Circulate**](#december-26---circulate) - [**December 27 - Mission to Earth: Re-Calibrated**](#december-27---mission-to-earth-re-calibrated) + - [**December 28 - The Journey to the Eternal Engine**](#december-28---the-journey-to-the-eternal-engine) - [**FAQ**](#faq) @@ -1833,6 +1834,68 @@ Refill tank. ---- +### December 28 - The Journey to the Eternal Engine + +#### Problem Statement + +In a dystopian world where a failed attempt at reversing the effects of global warming has left the Earth frozen over and has eradicated most of life, the only surviving souls live on a perpetually moving train called Snowpiercer. The passengers of the train are divided based on class (First, Second and Third). Passengers who did not purchase a ticket and are not of the working class of the train have been locked up in the back of the train called the Tail. Andre Layton the head Tailie inspires a rebellion along with the other Tailies to take over the Eternal Engine from the Head Engineer. +In order for them to do this, they must leave the tail without getting caught by the Jackboots or the Brakemen. +Layton comes up with a plan to help him and a few of the other Tailies reach the Engine. They must scale the outside of the train to go from the Tail to the nearest third class compartment, in order to not get caught. One of their allies in the third class has agreed to keep the compartment door open and keep a watch for the Jackboots or the Brakemen patrolling the train. + +Conditions: +There are only 2 breach suits and without them, if one is exposed to the freezing air, they will instantly succumb to frostbite. +There needs to be at least 3 Tailies (including Layton) to even attempt to take over the engine. +One Tailie must move back and forth along the same path in order to bring back a breach suit for the remaining Tailies left to make it to the third class compartment. +While moving along the path, both the Tailies must walk at the slower person’s pace. + +Given the time taken for each individual Tailie to walk in seconds, calculate the minimum amount of time, in minutes, it will take for all the Tailies to make it from the Tail to the Third Class compartment successfully. + +

+ + +#### Sample Input/Output +``` +Input: + +n=3 + +Walking time: { 15, 40, 60 } + +Output: + +1.916 + +Input: + +n=9 + +Walking time: { 3, 10, 12, 13, 15, 17, 21, 35, 23 } + +Output: + +2.683 + +``` +EXPLANATION +``` +Input format: +In the first line of the input you are given the number of Tailies (including Layton). +In the second line of the input you are given the walking time of each of the Tailies in seconds as an array in sorted order. + +In the first example, the first person, say Layton (15) and the second (40) travel together, this takes 40 seconds. +Layton walks back to the Tail with the breach suit and this takes another 15 seconds. + +With the last Tailie he walks to the third class compartment and this takes 60 seconds. +Adding all this we get, 40+15+60= 115 seconds which is 1.916 minutes. + +``` + +- **References** + - [Looping in C](https://www.tutorialspoint.com/cprogramming/c_loops.htm) + - [Looping in C++](https://www.programiz.com/cpp-programming/for-loop) + - [Looping in Java](https://www.geeksforgeeks.org/loops-in-java/) + - [Looping in Python](https://www.w3schools.com/python/python_for_loops.asp) + FAQ ====== From 9ae458b3822236b351e58b75959f6ae7a556d4d7 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Tue, 27 Dec 2022 23:00:43 +0530 Subject: [PATCH 193/408] First push with the folders and assets. --- December - 28/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 28/.gitignore diff --git a/December - 28/.gitignore b/December - 28/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 28/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 95956987965602dac7490beddef15d105a7e289e Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Tue, 27 Dec 2022 23:05:12 +0530 Subject: [PATCH 194/408] Update README.md --- README.md | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 33821cc..9812e20 100644 --- a/README.md +++ b/README.md @@ -1839,16 +1839,22 @@ Refill tank. #### Problem Statement In a dystopian world where a failed attempt at reversing the effects of global warming has left the Earth frozen over and has eradicated most of life, the only surviving souls live on a perpetually moving train called Snowpiercer. The passengers of the train are divided based on class (First, Second and Third). Passengers who did not purchase a ticket and are not of the working class of the train have been locked up in the back of the train called the Tail. Andre Layton the head Tailie inspires a rebellion along with the other Tailies to take over the Eternal Engine from the Head Engineer. + In order for them to do this, they must leave the tail without getting caught by the Jackboots or the Brakemen. Layton comes up with a plan to help him and a few of the other Tailies reach the Engine. They must scale the outside of the train to go from the Tail to the nearest third class compartment, in order to not get caught. One of their allies in the third class has agreed to keep the compartment door open and keep a watch for the Jackboots or the Brakemen patrolling the train. Conditions: -There are only 2 breach suits and without them, if one is exposed to the freezing air, they will instantly succumb to frostbite. -There needs to be at least 3 Tailies (including Layton) to even attempt to take over the engine. -One Tailie must move back and forth along the same path in order to bring back a breach suit for the remaining Tailies left to make it to the third class compartment. -While moving along the path, both the Tailies must walk at the slower person’s pace. -Given the time taken for each individual Tailie to walk in seconds, calculate the minimum amount of time, in minutes, it will take for all the Tailies to make it from the Tail to the Third Class compartment successfully. + There are only 2 breach suits and without them, if one is exposed to the freezing air, they will instantly succumb to frostbite. + + There needs to be at least 3 Tailies (including Layton) to even attempt to take over the engine. + + One Tailie must move back and forth along the same path in order to bring back a breach suit for the remaining Tailies left to make it to the third class compartment. + + While moving along the path, both the Tailies must walk at the slower person’s pace. + + +Given the time taken for each individual Tailie to walk in seconds, calculate the minimum amount of time, in minutes, it will take for all the Tailies to make it from the Tail to the Third Class compartment successfully.

@@ -1865,6 +1871,9 @@ Output: 1.916 +``` + +``` Input: n=9 @@ -1876,16 +1885,23 @@ Output: 2.683 ``` -EXPLANATION + +#### Explanation + ``` Input format: + In the first line of the input you are given the number of Tailies (including Layton). + In the second line of the input you are given the walking time of each of the Tailies in seconds as an array in sorted order. + In the first example, the first person, say Layton (15) and the second (40) travel together, this takes 40 seconds. + Layton walks back to the Tail with the breach suit and this takes another 15 seconds. With the last Tailie he walks to the third class compartment and this takes 60 seconds. + Adding all this we get, 40+15+60= 115 seconds which is 1.916 minutes. ``` @@ -1896,6 +1912,8 @@ Adding all this we get, 40+15+60= 115 seconds which is 1.916 minutes. - [Looping in Java](https://www.geeksforgeeks.org/loops-in-java/) - [Looping in Python](https://www.w3schools.com/python/python_for_loops.asp) +---- + FAQ ====== From 9c8d41bcd30f0953e288efc90d7cf18acf176c5e Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Tue, 27 Dec 2022 23:10:53 +0530 Subject: [PATCH 195/408] December 26 - Circulate --- December - 26/Java_souvikpal2000.java | 82 +++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 December - 26/Java_souvikpal2000.java diff --git a/December - 26/Java_souvikpal2000.java b/December - 26/Java_souvikpal2000.java new file mode 100644 index 0000000..c2121b1 --- /dev/null +++ b/December - 26/Java_souvikpal2000.java @@ -0,0 +1,82 @@ +import java.util.*; +public class Java_souvikpal2000{ + public String circulate(int[][] arr){ + int know[] = new int[arr.length]; + know[0] = 1; //First Person know the word + for(int i=1;i Date: Wed, 28 Dec 2022 22:32:12 +0530 Subject: [PATCH 196/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f7bb300..c2fbe71 100644 --- a/README.md +++ b/README.md @@ -1882,7 +1882,7 @@ Input: n=9 -Walking time: { 3, 10, 12, 13, 15, 17, 21, 35, 23 } +Walking time: { 3, 10, 12, 13, 15, 17, 21, 23, 35 } Output: From 52009378ae60bdebcc8bba01a2c3de04ac2a7bb5 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Wed, 28 Dec 2022 22:37:31 +0530 Subject: [PATCH 197/408] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c2fbe71..4418521 100644 --- a/README.md +++ b/README.md @@ -1882,7 +1882,7 @@ Input: n=9 -Walking time: { 3, 10, 12, 13, 15, 17, 21, 23, 35 } +Walking time: { 3, 10, 12, 13, 15, 17, 21, 35, 23 } Output: @@ -1897,7 +1897,7 @@ Input format: In the first line of the input you are given the number of Tailies (including Layton). -In the second line of the input you are given the walking time of each of the Tailies in seconds as an array in sorted order. +In the second line of the input you are given the walking time of each of the Tailies in seconds as an array. In the first example, the first person, say Layton (15) and the second (40) travel together, this takes 40 seconds. From 549bb798cbc4c74fa10f77fef520758d72190691 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Wed, 28 Dec 2022 22:53:41 +0530 Subject: [PATCH 198/408] Update README.md --- README.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/README.md b/README.md index 9812e20..fd69aee 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Check out our FAQ for more information. - [**December 26 - Circulate**](#december-26---circulate) - [**December 27 - Mission to Earth: Re-Calibrated**](#december-27---mission-to-earth-re-calibrated) - [**December 28 - The Journey to the Eternal Engine**](#december-28---the-journey-to-the-eternal-engine) + - [**December 29 - Candies**](#december-29---candies) - [**FAQ**](#faq) @@ -1914,6 +1915,74 @@ Adding all this we get, 40+15+60= 115 seconds which is 1.916 minutes. ---- +### December 29 - Candies + +#### Problem Statement + +There are n children standing in a line. Each child is assigned a rating value given in the integer array ratings. + +You are giving candies to these children subjected to the following requirements: + + Each child must have at least one candy. + + Children with a higher rating get more candies than their neighbors. + +Return the minimum number of candies you need to have to distribute the candies to the children + + +

+ + +#### Sample Input/Output +``` +Input: + +n=3 +ratings = {1,2,2} + +Output: + +4 + +``` + +``` +Input: + +n=11 +ratings = {1, 4, 3, 6, 2, 1, 8, 1, 3, 7, 7} + +Output: + +73 + +``` + +#### Explanation + +``` +Input format: + +In the first line of the input you are given the number of children. + +In the second line of the input you are given the rating of each child. + +Sample -1 : + +You can allocate to the first, second and third child with 1, 2, 1 candies respectively. +The third child gets 1 candy because it satisfies the above two conditions. + +``` + +- **References** + - [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) + - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) + - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + - [Graphs](https://www.geeksforgeeks.org/graph-data-structure-and-algorithms/) + +---- + + FAQ ====== From c08bd7ad0ca50f959e12a9b1dfbddab913681541 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Wed, 28 Dec 2022 22:54:52 +0530 Subject: [PATCH 199/408] First push with the folders and assets. --- December - 29/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 29/.gitignore diff --git a/December - 29/.gitignore b/December - 29/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 29/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 6b79baa2f3e07ed458a56928cb2128f26b7d0860 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Wed, 28 Dec 2022 23:11:14 +0530 Subject: [PATCH 200/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f83149..e16d983 100644 --- a/README.md +++ b/README.md @@ -1854,7 +1854,7 @@ Conditions: There needs to be at least 3 Tailies (including Layton) to even attempt to take over the engine. - One Tailie must move back and forth along the same path in order to bring back a breach suit for the remaining Tailies left to make it to the third class compartment. + One Tailie must move back and forth along the same path in order to bring back a breach suit for the remaining Tailies left to make it to the third class compartment. It is not necessary that the same Tailie moves back and forth the whole time. While moving along the path, both the Tailies must walk at the slower person’s pace. From b12bf145bb95e3f974ba945105bba79632ac202b Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Thu, 29 Dec 2022 07:16:08 +0530 Subject: [PATCH 201/408] Update README.md --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index e16d983..71d69e6 100644 --- a/README.md +++ b/README.md @@ -1881,6 +1881,19 @@ Output: ``` Input: +n=4 + +Walking time: { 1, 2, 8, 5 } + +Output: + +0.25 + +``` + +``` +Input: + n=9 Walking time: { 3, 10, 12, 13, 15, 17, 21, 35, 23 } @@ -1891,6 +1904,7 @@ Output: ``` + #### Explanation ``` From ab098f15271afc93f4e08cb276114ff056302ff1 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Thu, 29 Dec 2022 07:37:49 +0530 Subject: [PATCH 202/408] Update README.md --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 71d69e6..4cf2eea 100644 --- a/README.md +++ b/README.md @@ -1883,11 +1883,11 @@ Input: n=4 -Walking time: { 1, 2, 8, 5 } +Walking time: { 1, 4, 7, 8, 3, 2 } Output: -0.25 +0.4 ``` @@ -1923,6 +1923,10 @@ With the last Tailie he walks to the third class compartment and this takes 60 s Adding all this we get, 40+15+60= 115 seconds which is 1.916 minutes. +Sample -2 + +2+1+8+2+4+1+3+1+2=24 seconds = 0.4 minutes + ``` - **References** From 66fd309ebbba3475b67cf5b0c226c0822f089b52 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Thu, 29 Dec 2022 10:29:29 +0530 Subject: [PATCH 203/408] Update README.md --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4cf2eea..8b97154 100644 --- a/README.md +++ b/README.md @@ -1854,7 +1854,7 @@ Conditions: There needs to be at least 3 Tailies (including Layton) to even attempt to take over the engine. - One Tailie must move back and forth along the same path in order to bring back a breach suit for the remaining Tailies left to make it to the third class compartment. It is not necessary that the same Tailie moves back and forth the whole time. + In order to bring back the breach suit for the other Tailies, one of the Tailies already in the compartment must come back. It is not necessary that the same Tailie comes back everytime. While moving along the path, both the Tailies must walk at the slower person’s pace. @@ -1925,6 +1925,19 @@ Adding all this we get, 40+15+60= 115 seconds which is 1.916 minutes. Sample -2 +The tailes are identified using indices 1 to 6. The Tail is T and the third class compartment is C: + +1. 1 and 6 move to C = 2s +2. 1 moves to T = 1 +3. 3 and 4 move to C= 8 +4. 6 moves to T = 2 +5. 1 and 2 move to C= 4 +6. 1 moves to T= 1 +7. 1 and 5 move to C= 3 +8. 1 moves to T = 1 +9. 1 and 6 move to C= 2 + +Adding the time: 2+1+8+2+4+1+3+1+2=24 seconds = 0.4 minutes ``` From 287e5655b35293f483f715f6a2245f931669807b Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Thu, 29 Dec 2022 11:31:12 +0530 Subject: [PATCH 204/408] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8b97154..580fb8c 100644 --- a/README.md +++ b/README.md @@ -1925,6 +1925,8 @@ Adding all this we get, 40+15+60= 115 seconds which is 1.916 minutes. Sample -2 +{ 1, 4, 7, 8, 3, 2 } + The tailes are identified using indices 1 to 6. The Tail is T and the third class compartment is C: 1. 1 and 6 move to C = 2s From 5ba902833e7a37e1e3b138b15292c717092ececd Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Thu, 29 Dec 2022 12:45:20 +0530 Subject: [PATCH 205/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 580fb8c..e7c22ff 100644 --- a/README.md +++ b/README.md @@ -1820,7 +1820,7 @@ The tank is FULL! Input: Enter the Hydrogen fuel fraction: -25/156 +25/15600 Output: From e398296bc7d83ed91cb92da1c8a4cbb682c6b404 Mon Sep 17 00:00:00 2001 From: Dhruv Rawat <89683914+yesdhruv@users.noreply.github.com> Date: Thu, 29 Dec 2022 12:45:48 +0000 Subject: [PATCH 206/408] added Dec 13 --- December - 13/C++_Dhruv.cpp | 114 ++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 December - 13/C++_Dhruv.cpp diff --git a/December - 13/C++_Dhruv.cpp b/December - 13/C++_Dhruv.cpp new file mode 100644 index 0000000..43b9392 --- /dev/null +++ b/December - 13/C++_Dhruv.cpp @@ -0,0 +1,114 @@ +#include +#include +#include +using namespace std; + +const int N = 4; // size of the maze + +int maze[N][N] = { // the maze, with 1s representing clear paths and 0s representing dead ends + {1,0,0,0}, +{1,1,0,1}, +{0,1,0,0}, +{1,1,1,1} + +}; + +// structure to store the coordinates of a block in the maze +struct Point { + int x, y; +}; + +// function to check if a given point is within the bounds of the maze +bool is_valid(int x, int y) { + return x >= 0 && x < N && y >= 0 && y < N; +} + +// function to find a solution to the maze using BFS +std::vector solve_maze_bfs(Point start, Point end) { + std::vector path; // vector to store the solution path + + std::queue q; // queue to store the blocks that need to be explored + q.push(start); + + // two-dimensional array to store the "came from" information for each block + // came_from[i][j] stores the coordinates of the block that was explored just before the block at (i, j) + Point came_from[N][N]; + came_from[start.x][start.y] = start; // the starting block was explored just before itself + + // array to store the visited status of each block + bool visited[N][N] = {false}; // all blocks are initially unvisited + + // explore the maze one block at a time + while (!q.empty()) { + Point p = q.front(); + q.pop(); + + // check if the block is the endpoint + if (p.x == end.x && p.y == end.y) { + // construct the solution path by following the "came from" information back from the endpoint + while (p.x != start.x || p.y != start.y) { + path.push_back(p); + p = came_from[p.x][p.y]; + } + path.push_back(start); // add the starting block to the path + std::reverse(path.begin(), path.end()); // reverse the path + return path; // return the solution path + } + + // if the block is not the endpoint, add its neighbors to the queue + if (is_valid(p.x + 1, p.y) && !visited[p.x + 1][p.y] && maze[p.x + 1][p.y] == 1) { + q.push({p.x + 1, p.y}); + came_from[p.x + 1][p.y] = p; + visited[p.x + 1][p.y] = true; + } + if (is_valid(p.x - 1, p.y) && !visited[p.x - 1][p.y] && maze[p.x - 1][p.y] == 1) { + q.push({p.x - 1, p.y}); + came_from[p.x - 1][p.y] = p; + visited[p.x - 1][p.y] = true; + } + if (is_valid(p.x, p.y + 1) && !visited[p.x][p.y + 1] && maze[p.x][p.y + 1] == 1) { + q.push({p.x, p.y + 1}); + came_from[p.x][p.y + 1] = p; + visited[p.x][p.y + 1] = true; + } + if (is_valid(p.x, p.y - 1) && !visited[p.x][p.y - 1] && maze[p.x][p.y - 1] == 1) { + q.push({p.x, p.y - 1}); + came_from[p.x][p.y - 1] = p; + visited[p.x][p.y - 1] = true; + } + } + + return {}; // no solution was found +} + +int main() { + int n=4; + vector > res(n, vector(n,0)); + // define the starting and ending points of the maze + Point start = {0, 0}; + Point end = {N - 1, N - 1}; + + // find a solution to the maze using BFS + std::vector path = solve_maze_bfs(start, end); + + if (path.empty()) { + std::cout << "No solution found." << std::endl; + } else { + // std::cout << "Solution found: " << std::endl; + for (Point p : path) { + res[p.x][p.y]=1; + // std::cout << "(" << p.x << ", " << p.y << ")" << std::endl; + } + for(int i=0;i<4;i++) + { + for(int j=0;j<4;j++) + { + + std::cout< Date: Thu, 29 Dec 2022 13:25:00 +0000 Subject: [PATCH 207/408] submitted --- December - 14/C++_Dhruv.cpp | 91 +++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 December - 14/C++_Dhruv.cpp diff --git a/December - 14/C++_Dhruv.cpp b/December - 14/C++_Dhruv.cpp new file mode 100644 index 0000000..a96ce44 --- /dev/null +++ b/December - 14/C++_Dhruv.cpp @@ -0,0 +1,91 @@ +#include +#include +#include +using namespace std; + + +const int N = 4; // number of vertices in the graph + +// 2D vector representation of the graph +int graph[N][N] = { + {0, 1, 0, 1}, + {1, 0, 1, 0}, + {0, 1, 0, 1}, + {1, 0, 1, 0} +}; + // initialize the adjacency list + std::vector> adj(N); +// function to check if the graph is bipartite +bool is_bipartite() { + // sets to store the vertices of the graph + std::vector U, V; + + // initialize the sets with an arbitrary vertex + U.push_back(0); + + // mark all vertices as unvisited + bool visited[N] = {false}; + + // iterate over the vertices in set U + for (int u : U) { + visited[u] = true; // mark the vertex as visited + // iterate over the neighbors of u + for (int v : adj[u]) { + // if the neighbor has not been visited, add it to set V + if (!visited[v]) { + V.push_back(v); + } + // if the neighbor has already been visited, check which set it belongs to + else { + // if the neighbor belongs to set U, the graph is not bipartite + if (std::find(U.begin(), U.end(), v) != U.end()) { + return false; + } + } + } + } + + // repeat the process for the vertices in set V + for (int v : V) { + visited[v] = true; // mark the vertex as visited + // iterate over the neighbors of v + for (int u : adj[v]) { + // if the neighbor has not been visited, add it to set U + if (!visited[u]) { + U.push_back(u); + } + // if the neighbor has already been visited, check which set it belongs to + else { + // if the neighbor belongs to set V, the graph is not bipartite + if (std::find(V.begin(), V.end(), u) != V.end()) { + return false; + } + } + } + } + + // if no neighbors belonging to the same set as the current vertex were found, the graph is bipartite + return true; +} +int main() { + + + // iterate over the rows and columns of the 2D vector + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + // if the element is equal to 1, add the column index as a neighbor of the row index + if (graph[i][j] == 1) { + adj[i].push_back(j); + } + } + } + + if (is_bipartite()) { + std::cout << "The graph is bipartite." << std::endl; + } + else { + std::cout << "The graph is not bipartite." << std::endl; + } + + return 0; +} From c5daf2e4548432ed0b67d21f309eac658c2effe1 Mon Sep 17 00:00:00 2001 From: Dhruv Rawat <89683914+yesdhruv@users.noreply.github.com> Date: Thu, 29 Dec 2022 13:30:55 +0000 Subject: [PATCH 208/408] zig-zag added --- December - 17/C++_Dhruv.cpp | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 December - 17/C++_Dhruv.cpp diff --git a/December - 17/C++_Dhruv.cpp b/December - 17/C++_Dhruv.cpp new file mode 100644 index 0000000..0c39100 --- /dev/null +++ b/December - 17/C++_Dhruv.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +using namespace std; +int main() { + // input string and number of rows + // std::string Str = "spaghettigood"; + string Str; + cin>>Str; + int Row = 4; + + // initialize the zigzag pattern + std::vector> zigzag(Row); + + // initialize the variables to traverse the rows + int row = 0; + int direction = 1; + + // iterate over the characters in the string + for (char c : Str) { + // add the character to the current row + zigzag[row].push_back(c); + + // update the row and direction + if (row == Row - 1) { + direction = -1; + } + else if (row == 0) { + direction = 1; + } + row += direction; + } + + // print the zigzag pattern row-wise + for (auto& row : zigzag) { + for (char c : row) { + std::cout << c; + } + } + std::cout << std::endl; + + return 0; +} From 0627513ad0eef6e52c1c5e6a5ac935fb6af05cb4 Mon Sep 17 00:00:00 2001 From: Dhruv Rawat <89683914+yesdhruv@users.noreply.github.com> Date: Thu, 29 Dec 2022 13:52:41 +0000 Subject: [PATCH 209/408] added shortest path also --- December - 18/C++_Dhruv.cpp | 70 +++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 December - 18/C++_Dhruv.cpp diff --git a/December - 18/C++_Dhruv.cpp b/December - 18/C++_Dhruv.cpp new file mode 100644 index 0000000..0d46e06 --- /dev/null +++ b/December - 18/C++_Dhruv.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +using namespace std; +const int N = 8; // number of cities + +// adjacency list representation of the graph +std::vector> graph[N] = { + {{1, 5}, {3, 2}}, // city P has neighbors Q (5 hours) and S (2 hours) + {{0, 5}, {2, 3}, {3, 1}}, // city Q has neighbors P (5 hours), R (3 hours), and S (1 hour) + {{1, 3}, {4, 1}, {5, 5}}, // city R has neighbors Q (3 hours), T (1 hour), and V (5 hours) + {{0, 2}, {1, 1}, {4, 1}}, // city S has neighbors P (2 hours), Q (1 hour), and T (1 hour) + {{3, 1}, {2, 1}, {5, 1}, {6, 2}, {7, 1}}, // city T has neighbors S (1 hour), R (1 hour), V (1 hour), U (2 hours), and W (1 hour) + {{2, 5}, {4, 1}, {7, 2}}, // city V has neighbors R (5 hours), T (1 hour), and W (2 hours) + {{4, 2}, {7, 3}}, // city U has neighbors T (2 hours) and W (3 hours) + {{4, 1}, {5, 2}, {6, 3}} // city W has neighbors T (1 hour), V (2 hours), and U (3 hours) +}; + +// function to find the shortest time to travel by train from a given city to city W +int find_shortest_time(int city) { + // initialize the distances to infinity + std::vector distances(N, std::numeric_limits::max()); + + // initialize the queue and visited array + std::queue q; + std::vector visited(N); + + // set the distance of the starting city to 0 and mark it as visited + distances[city] = 0; + visited[city] = true; + q.push(city); + + // perform BFS + while (!q.empty()) { + int u = q.front(); + q.pop(); + + // visit the neighbors of u + for (auto [v, w] : graph[u]) { + // if v has not been visited and the distance to v is shorter through u, update the distance + if (!visited[v] && distances[u] + w < distances[v]) { + distances[v] = distances[u] + w; + visited[v] = true; + q.push(v); + } + } + } + + // return the distance to city W + return distances[7]; +} + +int main() { + // choose a city + int city; + cin >> city; + // find the shortest time to travel from the chosen city to city W +int shortest_time = find_shortest_time(city); + +// print the result +if (shortest_time == std::numeric_limits::max()) { + std::cout << "There is no route from city " << city << " to city W." << std::endl; +} else { + std::cout << "The shortest time to travel from city " << city << " to city W is " << shortest_time << " hours." << std::endl; +} + +return 0; +} + From c7d7ee6d1782151fb4063eae5978752145b470ec Mon Sep 17 00:00:00 2001 From: Dhruv Rawat <89683914+yesdhruv@users.noreply.github.com> Date: Thu, 29 Dec 2022 14:21:31 +0000 Subject: [PATCH 210/408] added --- December - 19/C++_Dhruv.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 December - 19/C++_Dhruv.cpp diff --git a/December - 19/C++_Dhruv.cpp b/December - 19/C++_Dhruv.cpp new file mode 100644 index 0000000..d1c990a --- /dev/null +++ b/December - 19/C++_Dhruv.cpp @@ -0,0 +1,22 @@ +#include +#include + +using namespace std; + +string get_unique_chars(string string1, string string2) { + string unique_chars = ""; + for (char c : string1) { + if (string2.find(c) != string::npos && isalpha(c)) { + unique_chars += c; + } + } + return unique_chars; +} + +int main() { + // Test the function + string string1 = "My world evolves in a beautiful space called Tesh."; + string string2 = "sworn love lived"; + cout << get_unique_chars(string1, string2) << endl; + return 0; +} From 6c17194f7c58a2c9dfbda90a6d4b913445f0e523 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Thu, 29 Dec 2022 23:50:55 +0530 Subject: [PATCH 211/408] First push with the folders and assets. --- December - 30/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 30/.gitignore diff --git a/December - 30/.gitignore b/December - 30/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 30/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 295c3523daee108d08bd131989c9c362547bd4b7 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Fri, 30 Dec 2022 00:14:16 +0530 Subject: [PATCH 212/408] Update README.md --- README.md | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) diff --git a/README.md b/README.md index fd69aee..d237893 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Check out our FAQ for more information. - [**December 27 - Mission to Earth: Re-Calibrated**](#december-27---mission-to-earth-re-calibrated) - [**December 28 - The Journey to the Eternal Engine**](#december-28---the-journey-to-the-eternal-engine) - [**December 29 - Candies**](#december-29---candies) + - [**December 30 - Precise Portion**](#december-30---precise-portion) - [**FAQ**](#faq) @@ -1982,6 +1983,168 @@ The third child gets 1 candy because it satisfies the above two conditions. ---- +### December 30 - Precise Portion + +#### Problem Statement + +The Elite students society in Nevermore changed their riddle in order not to allow further more people to enter into their library. + +The puzzle is now with 2 jugs, with different volumes and a fountain instead of the statue. + +And a riddle engraved on a plate with the target volume made from the two jugs. + + “Wednesday’s child is full of woe, + + Amount of wisdom, + + And amount of foe. + + The wisdom of Wednesday I seek, + + Is her position from the first workday of the week.” + + +Being in the shoes of Wednesday Addams, in order to enter the library , formulate a code to fill a particular jug with the amount of water specified in the riddle with only the two jugs given. + +Note: + + 1. You can fill the jugs from the fountain + 2.Transfer water from one jug to another + 3.Empty the water from the jug into the fountain + 4.None of the jugs have markings on them, nor do you have any additional measuring device. + +Note: The examples given for the input and output format must NOT be used as sample input and must only be used to understand the FORMAT of the input. + +Input format: + + The first line of input is a 1 Dimensional array with 2 elements representing the 2 jugs with their respective volumes in ounces. + + eg. (8,1) + + Jug 1 has volume = 8 ounces + + Jug 2 has volume = 1 ounces + + The second line of input is a 1 Dimensional array with 2 elements representing the 2 jugs. + + eg. (5, 0) + + The target we must reach is : Jug 1 is filled with 5 ounces of water and Jug 2 is empty. + + +Output format: + + The output must contain the sequence of steps, where each line is a different step. + + Every line of the output is a 1 dimensional array with 2 elements representing the current volume of water in each jug at the end of that step. + + You must start with both jugs being empty, that is, (0,0) + + + +

+ + + +#### Sample Input/Output +``` +Input: + +(4, 9) +(3, 0) + +Output: + +(0, 0) +(4, 0) +(0, 4) +(4, 4) +(0, 8) +(4, 8) +(3, 9) +(3, 0) + + +``` + +``` +Input: + + ( 5, 4) + ( 3, 0) + +Output: + + (0, 0) + (5, 0) + (1, 4) + (1, 0) + (0, 1) + (5, 1) + (2, 4) + (2, 0) + (0, 2) + (5, 2) + (3, 4) + (3, 0) + +``` + +``` +Input: + +(11,9) +(0,3) + +Output: +(0, 0) +(11, 0) +(2, 9) +(0, 9) +(9, 0) +(9, 9) +(11, 7) +(0, 7) +(7, 0) +(7, 9) +(11, 5) +(0, 5) +(5, 0) +(5, 9) +(11, 3) +(0, 3) + +``` + +#### Explanation + +``` +Sample 1: +(4,9) Jug 1 is the 4 ounce jug and Jug 2 is the 9 ounce jug. +We have to get (3,0) + +1. We first start with both the jugs being empty +2. We fill the 4 ounce jug to the brim from the fountain. +3. Then we transfer the water from the 4 ounce jug to the 9 ounce jug. The 4 ounce jug is now empty and the 9 ounce jug has 4 ounces of water. +4. Fill the 4 ounce jug from the fountain. +5. Transfer the water in the 4 ounce jug to the 9 ounce jug. The 4 ounce jug is empty and the 9 ounce jug has 8 ounces of water. +6. Fill the 4 ounce jug to the brim. +7. Fill the 9 ounce jug to the brim by transferring water from the 4 ounce jug to the 9 ounce jug. The 4 ounce jug has 3 ounces of water and the 9 ounce jug is filled completely. +8. Empty the contents of the 9 ounce jug into the fountain. + + We now have the target which is (3,0) that is, jug 1 is filled with 3 ounces of water and jug 2 is empty. + + +``` + +- **References** + - [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) + - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) + - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + - [Graphs](https://www.geeksforgeeks.org/graph-data-structure-and-algorithms/) + - [BFS](https://www.geeksforgeeks.org/breadth-first-search-or-bfs-for-a-graph/) + +---- FAQ ====== From 53f48bb57e37d40211c3b46df83d6581d89536b8 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Fri, 30 Dec 2022 00:16:59 +0530 Subject: [PATCH 213/408] Update README.md --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index eff9dc4..10c571b 100644 --- a/README.md +++ b/README.md @@ -2024,11 +2024,10 @@ The third child gets 1 candy because it satisfies the above two conditions. #### Problem Statement -The Elite students society in Nevermore changed their riddle in order not to allow further more people to enter into their library. +The Elite students society in Nevermore changed their riddle in order to not allow non- members of the society to enter their library. -The puzzle is now with 2 jugs, with different volumes and a fountain instead of the statue. - -And a riddle engraved on a plate with the target volume made from the two jugs. +The puzzle is currently with 2 jugs, with different volumes and a fountain instead of the statue. +And a riddle engraved on a plate with the target volume of water made from the two jugs. “Wednesday’s child is full of woe, From 23d938979bfbfac28e887ee0ecac85508d44d164 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Fri, 30 Dec 2022 12:02:07 +0530 Subject: [PATCH 214/408] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 10c571b..76aaf37 100644 --- a/README.md +++ b/README.md @@ -1992,7 +1992,7 @@ ratings = {1, 4, 3, 6, 2, 1, 8, 1, 3, 7, 7} Output: -73 +19 ``` From 27bee553858de927e5ecb7a84f3361c129408103 Mon Sep 17 00:00:00 2001 From: GREEDnim Date: Fri, 30 Dec 2022 15:47:45 +0530 Subject: [PATCH 215/408] bruteforcing dfs, day 18 --- December - 18/GREEDnim_day18_java.java | 92 ++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 December - 18/GREEDnim_day18_java.java diff --git a/December - 18/GREEDnim_day18_java.java b/December - 18/GREEDnim_day18_java.java new file mode 100644 index 0000000..859233e --- /dev/null +++ b/December - 18/GREEDnim_day18_java.java @@ -0,0 +1,92 @@ +package acm; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Scanner; + +public class GREEDnim_day18_java { + static int[][]adjacency; + static HashMap>neighbours; + + static boolean[] alreadySaw; + + static int min=Integer.MAX_VALUE; + static ArrayListans; + public static void main(String[] args) { + + adjacency= new int[][]{ + {0, 3, 4, 5, -1, -1, -1, -1}, + {3, 0, 2, -1, -1, 5, -1, -1}, + {4, 2, 0, 7, 3, 6, 2, -1}, + {5, -1, 7, 0, 2, -1, -1, -1}, + {-1, -1, 3, 2, 0, -1, 4, -1}, + {-1, 5, 6, -1, -1, 0, 5, 2}, + {-1, -1, 2, -1, 4, 5, 0, 1}, + {-1, -1, -1, -1, -1, 2, 1, 0}}; + alreadySaw=new boolean[adjacency.length]; + neighbours=new HashMap<>(); + int i=0; + for(int[] arr:adjacency) + { + int col=0; + ArrayListl=new ArrayList<>(); + for(int ele: arr) + { + if(ele>0) l.add(col); + col++; + } + neighbours.put(i++,l); + } + + + Scanner in=new Scanner(System.in); + int source=in.next().charAt(0)-'P'; + +// adding the source to the cur path + ArrayListdummy=new ArrayList<>(); + dummy.add(source); + alreadySaw[source]=true; + dfs(source,0,dummy); + + System.out.print("path is :"); + for(int ele:ans) + { + System.out.print((char)(ele+'P')+" "); + } + System.out.println(); + System.out.println("shortest time :"+min+" hours"); + + } + static void dfs(int source,int sum,ArrayListpath) + { + if(source== adjacency.length-1) + { + if(sum(path); + } + return; + } + + + Listneigh=neighbours.get(source); + + for(int next:neigh){ + + if(!alreadySaw[next]) + { + alreadySaw[next]=true; + path.add(next); + dfs(next,sum+adjacency[source][next],path); + path.remove(path.size()-1); + alreadySaw[next]=false; + } + + } + } + + + +} From bb5b93c013700a5aa89989b95364c477ff5c26fa Mon Sep 17 00:00:00 2001 From: Dhruv Rawat <89683914+yesdhruv@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:33:17 +0000 Subject: [PATCH 216/408] added Tower of Hanoi --- December - 21/C++_Dhruv.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 December - 21/C++_Dhruv.cpp diff --git a/December - 21/C++_Dhruv.cpp b/December - 21/C++_Dhruv.cpp new file mode 100644 index 0000000..9c8bade --- /dev/null +++ b/December - 21/C++_Dhruv.cpp @@ -0,0 +1,20 @@ +#include + +using namespace std; + +void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod) { + if (n == 1) { + cout << "Move disk 1 from rod " << from_rod << " to rod " << to_rod << endl; + return; + } + towerOfHanoi(n-1, from_rod, aux_rod, to_rod); + cout << "Move disk " << n << " from rod " << from_rod << " to rod " << to_rod << endl; + towerOfHanoi(n-1, aux_rod, to_rod, from_rod); +} + +int main() { + int n; + cin >> n; + towerOfHanoi(n, 'A', 'C', 'B'); + return 0; +} From 9bd3b87c07ef54b3facf4d6811a53e5f047ac900 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Fri, 30 Dec 2022 23:05:09 +0530 Subject: [PATCH 217/408] First push with the folders and assets. --- December - 31/.gitignore | 231 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 December - 31/.gitignore diff --git a/December - 31/.gitignore b/December - 31/.gitignore new file mode 100644 index 0000000..ac6d3a2 --- /dev/null +++ b/December - 31/.gitignore @@ -0,0 +1,231 @@ +# gitignore file for "A December of Algorithms 2022" +# 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 d0f2ab002641ecfbeccb866b3ee78e2e63727112 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Fri, 30 Dec 2022 23:19:41 +0530 Subject: [PATCH 218/408] Update README.md --- README.md | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) diff --git a/README.md b/README.md index d237893..318f521 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ Check out our FAQ for more information. - [**December 28 - The Journey to the Eternal Engine**](#december-28---the-journey-to-the-eternal-engine) - [**December 29 - Candies**](#december-29---candies) - [**December 30 - Precise Portion**](#december-30---precise-portion) + - [**December 31 - The Quad of Queens**](#december-31---the-quad-of-queens) - [**FAQ**](#faq) @@ -2146,6 +2147,194 @@ We have to get (3,0) ---- +### December 31 - The Quad of Queens + +#### Problem Statement + +The queens of the Hogwarts realm were invited to a chess themed royal ball held at the kingdom’s capital city. + +The chess themed royal ball assigned each “square” of the chessboard themed floor for each royalty, with Kings, Queens and Bishops having similar stride as that of chess to keep it fun. + +But here’s the catch. The Queens hate each other. + +Now, being the prime minister of this realm, how many distinct ways would you assign seats to the Queens without them being able to attack each other, and make this more generalised for ‘N’ number of such Queens. + +Assume the floor to be an N x N grid , with N being the number of queens. + +The Queens must be placed on the grid, such that they are unable to attack another Queen, or be attacked by another Queen. + +The input must have: + + A single line input with the number of Queens. This will be the N value mentioned above. + +Each solution must contain : + + 1. The number of distinct solutions in the first line + 2. All the distinct board configurations of the N-queens' placement, where 'Q' and '.' , indicate a Queen and an empty space, respectively. + They must be printed one after the other. + They can be printed in any order. + +Note: all the Queens must be represented only as 'Q' and the empty spaces, only as '.'. + +CONSTRAINT: 1 <= N <= 9 + + + + +

+ + + +#### Sample Input/Output +``` +Input: + +4 + +Output: + +2 + +. Q . . +. . . Q +Q . . . +. . Q . + +. . Q . +Q . . . +. . . Q +. Q . . + + +``` + +``` +Input: + +1 + +Output: + +1 +Q + +``` + +``` +Input: + +5 + +Output: + +10 + +Q . . . . +. . Q . . +. . . . Q +. Q . . . +. . . Q . + +Q . . . . +. . . Q . +. Q . . . +. . . . Q +. . Q . . + +. Q . . . +. . . Q . +Q . . . . +. . Q . . +. . . . Q + +. Q . . . +. . . . Q +. . Q . . +Q . . . . +. . . Q . + +. . Q . . +Q . . . . +. . . Q . +. Q . . . +. . . . Q + +. . Q . . +. . . . Q +. Q . . . +. . . Q . +Q . . . . + +. . . Q . +Q . . . . +. . Q . . +. . . . Q +. Q . . . + +. . . Q . +. Q . . . +. . . . Q +. . Q . . +Q . . . . + +. . . . Q +. Q . . . +. . . Q . +Q . . . . +. . Q . . + +. . . . Q +. . Q . . +Q . . . . +. . . Q . +. Q . . . + +``` + +#### Explanation + +``` +For N=4 +There are 4 queens: Q1, Q2, Q3, Q4 +Let’s suppose we’re putting our first queen Q1 at position (1, 1) now for Q2 we can’t put it in row 1( because they will conflict ). + Q . . . + . . . . + . . . . + . . . . + +So for Q2 we will have to consider row 2. In row 2 we can place it in column 3 I.e at (2, 3) but then there will be no option for placing Q3 in row 3. + Q . . . + . . Q . + . . . . + . . . . + +So we backtrack one step and place Q2 at (2, 4) then we find the position for placing Q3 is (3, 2) but by this, no option will be left for placing Q4. + + + Q . . . + . . . Q + . Q . . + . . . . + +Then we have to backtrack till ‘Q1’ and put it at (1, 2) instead of (1, 1) and then all other queens can be placed safely by moving Q2 to the position (2, 4), Q3 to (3, 1), and Q4 to (4, 3). + . Q . . + . . . Q + Q . . . + . . Q . + +Similarly the other output for N=4 is also evaluated. +Proceed using this example as reference to evaluate the other inputs. + + +``` + +- **References** + - [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) + - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) + - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + +---- + FAQ ====== From 62ccc66b8812f7acf45c504a79d7f2692c1386d6 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Sat, 31 Dec 2022 05:44:48 +0530 Subject: [PATCH 219/408] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7e624bc..e762aa0 100644 --- a/README.md +++ b/README.md @@ -2171,6 +2171,8 @@ We have to get (3,0) We now have the target which is (3,0) that is, jug 1 is filled with 3 ounces of water and jug 2 is empty. +Note: There maybe more than one solution for the given input +If you do get another solution, you can still submit it. ``` From d97d8e1d8645b0ac45439ceb38b2bfbd54879f61 Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Fri, 30 Dec 2022 23:10:18 +0530 Subject: [PATCH 220/408] move dec 16 file --- {December -16 => December - 16}/cpp_nijuyonkadesu.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {December -16 => December - 16}/cpp_nijuyonkadesu.cpp (100%) diff --git a/December -16/cpp_nijuyonkadesu.cpp b/December - 16/cpp_nijuyonkadesu.cpp similarity index 100% rename from December -16/cpp_nijuyonkadesu.cpp rename to December - 16/cpp_nijuyonkadesu.cpp From d10bf309953a38c8e3d05fe8c4120fa70a3017d0 Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Sat, 31 Dec 2022 20:24:00 +0530 Subject: [PATCH 221/408] zigzag beauty --- December - 17/cpp_nijuyonkadesu.cpp | 58 +++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 December - 17/cpp_nijuyonkadesu.cpp diff --git a/December - 17/cpp_nijuyonkadesu.cpp b/December - 17/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..6755860 --- /dev/null +++ b/December - 17/cpp_nijuyonkadesu.cpp @@ -0,0 +1,58 @@ +#include +#include + +using namespace std; + +int main (int argc, char *argv[]) +{ + char ch; + string message; + cin >> message; + + int rows, i=0, j=0, pos=0; + bool startFlag= true; + cin >> rows; + + vector> wall(rows, vector (message.size(), ' ')); + + // i -> upto row | i-> 0 && j+= upto row + // i ossilates from 0 to row-1 + // j starts from 1 to row-1 when i reaches maximum + + + while(startFlag){ + + for(i=0; i0; i--){ + if(pos != message.size()){ + ch = message[pos++]; + j++; + wall[i][j] = ch; + } + else { + startFlag= false; + break; + } + } + j++; + } + + for(auto row: wall){ + for(auto it = row.begin(); it != row.end(); it++){ + cout<<*it<<" "; + } + cout<<"\n"; + } + + return 0; +} From 94f8047589c337b10c876c1f3c554ff70f1f1d74 Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Sat, 31 Dec 2022 23:35:25 +0530 Subject: [PATCH 222/408] yes the murderers met at index 3 --- December - 15/cpp_nijuyonkadesu.cpp | 86 +++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 December - 15/cpp_nijuyonkadesu.cpp diff --git a/December - 15/cpp_nijuyonkadesu.cpp b/December - 15/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..11e5459 --- /dev/null +++ b/December - 15/cpp_nijuyonkadesu.cpp @@ -0,0 +1,86 @@ +#include +#include +#include + +using namespace std; +vector splitter(vector& person); + +int main (int argc, char *argv[]) +{ + string name, time; + int count = 3; + vector> persons(3, vector(2)); + cout<<"Enter person name and Time in HH:MM:SS "; // mommy 10:00:00 omit `{` + + for(int i=0 ;count !=0; count--){ + cin>>name; + cin>>time; + + persons[i].push_back(name); + persons[i].push_back(time); + i++; + } + + sort(persons.begin(), persons.end(), [](vector& lhs, vector& rhs) + { + vector timeOne = splitter(lhs); // HH MM SS in 0 1 2 indices + vector timeTwo = splitter(rhs); + + if(timeOne[0] < timeTwo[0]) return true; + else if (timeOne[0] > timeTwo[0]) return false; + else{ + + if(timeOne[1] < timeTwo[1]) return true; + else if (timeOne[1] > timeTwo[1]) return false; + else { + + if(timeOne[2] < timeTwo[2]) return true; + else if (timeOne[2] > timeTwo[2]) return false; + } + + } + return false; + }); + + for(auto person: persons){ + for(auto row: person){ + cout< splitter(vector& person) { + vector time; + int digit; + + auto it = person[3].begin(); // Please never ask me why 3 + + digit = *it - '0'; + *it++; + digit = digit * 10; + digit = digit + (*it - '0'); + time.push_back(digit); // HH + + *it++; // skip delimiter + *it++; // skip delimiter + + digit = *it - '0'; + *it++; + digit = digit * 10; + digit = digit + (*it - '0'); + time.push_back(digit); // MM + + *it++; // skip delimiter + *it++; // skip delimiter + + digit = *it - '0'; + *it++; + digit = digit * 10; + digit = digit + (*it - '0'); + time.push_back(digit); // SS + + return time; +} From 430ce143b5a7aa2ee0b2577e23e4e265b751dbe1 Mon Sep 17 00:00:00 2001 From: tarpandas Date: Sat, 31 Dec 2022 23:53:44 +0530 Subject: [PATCH 223/408] December 29 solved --- December - 29/Java_tarpandas.java | 59 +++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 December - 29/Java_tarpandas.java diff --git a/December - 29/Java_tarpandas.java b/December - 29/Java_tarpandas.java new file mode 100644 index 0000000..bae9a76 --- /dev/null +++ b/December - 29/Java_tarpandas.java @@ -0,0 +1,59 @@ +import java.util.Scanner; +class Java_tarpandas{ + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.print("n="); + int n=sc.nextInt(); + sc.nextLine(); + System.out.print("ratings = "); + String str = sc.nextLine(); + String [] tempRatings = str.split(","); + int [] ratings = new int[n]; + for(int i=0;i ratings[i+1]) { + candies[i+1] -= 1; + } else { + candies[i] -= 1; + } + } + } + + int sum=0; + for(int i=0; i Date: Sun, 1 Jan 2023 11:32:16 +0000 Subject: [PATCH 224/408] dec 20 added --- December - 20/C++_Dhruv.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 December - 20/C++_Dhruv.cpp diff --git a/December - 20/C++_Dhruv.cpp b/December - 20/C++_Dhruv.cpp new file mode 100644 index 0000000..a48bddc --- /dev/null +++ b/December - 20/C++_Dhruv.cpp @@ -0,0 +1,36 @@ +#include +using namespace std; + +const int INF = 1e9; + +int t, n, a[150001], w[150001], dp[150001][109]; + +int main() { + cin >> t; + while (t--) { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) cin >> w[i]; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= 109; j++) { + if (j == a[i]) dp[i][j] = w[i]; + else dp[i][j] = -INF; + } + } + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= 109; j++) { + for (int k = 1; k < i; k++) { + if (j < a[i]) dp[i][j] = max(dp[i][j], dp[k][j]); + } + } + } + + int result = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= 109; j++) { + result = max(result, dp[i][j]); + } + } + cout << result << endl From 2441f7fdb6114ceaaedf436b86efa3eb4798b4de Mon Sep 17 00:00:00 2001 From: Dhruv Rawat <89683914+yesdhruv@users.noreply.github.com> Date: Sun, 1 Jan 2023 11:45:29 +0000 Subject: [PATCH 225/408] encoded_message decoded --- December - 22/C++_Dhruv.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 December - 22/C++_Dhruv.cpp diff --git a/December - 22/C++_Dhruv.cpp b/December - 22/C++_Dhruv.cpp new file mode 100644 index 0000000..4be9493 --- /dev/null +++ b/December - 22/C++_Dhruv.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; + +string encode(string codeword, string message) { + int n = codeword.length(); + int m = message.length(); + string encoded_message = ""; + for (int i = 0; i < m; i++) { + char c = message[i]; + int k = codeword[i % n] - 'A'; + char e = (c + k - 'A') % 26 + 'A'; + encoded_message += e; + } + return encoded_message; +} + +int main() { + string codeword = "LEMON"; + string message = "ATTACKATDAWN"; + string encoded_message = encode(codeword, message); + cout << encoded_message << endl; + return 0; +} From 9d789c6aacc00767bda0ec734393e67adbed8c0a Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Tue, 3 Jan 2023 10:57:42 +0530 Subject: [PATCH 226/408] December 27 - Mission to Earth: Re-Calibrated --- December - 27/Java_souvikpal2000.java | 87 +++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 December - 27/Java_souvikpal2000.java diff --git a/December - 27/Java_souvikpal2000.java b/December - 27/Java_souvikpal2000.java new file mode 100644 index 0000000..0e15286 --- /dev/null +++ b/December - 27/Java_souvikpal2000.java @@ -0,0 +1,87 @@ +import java.util.*; +class InvalidNumerator extends Exception{ + public InvalidNumerator(String str){ + super(str); + } +} +class InvalidDenominator extends Exception{ + public InvalidDenominator(String str){ + super(str); + } +} +class Java_souvikpal2000{ + public float calculateFuelCalibration(int x, int y){ + float percentage = ((float)x*100)/(float)y; + return percentage; + } + + public String calculateLeftFuel(int x, int y, float totalFuel){ + float leftFuel = ((float)x * totalFuel)/(float)y; + return String.format("%.1f",leftFuel); + } + + public String checkTank(float result){ + String msg = ""; + if(result <= 1){ + msg = "warning"; + } + if(result >= 99){ + msg = "ok"; + } + return msg; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input:"); + System.out.println(""); + int x,y; + while(true){ + System.out.println("Enter the Hydrogen fuel fraction:"); + String fraction = sc.next(); + + String[] xy = fraction.split("/"); + try{ + x = Integer.parseInt(xy[0]); + y = Integer.parseInt(xy[1]); + if(y == 0){ + throw new InvalidDenominator("Y must not be Zero"); + } + if(x > y){ + throw new InvalidNumerator("X must be less than Y"); + } + break; + } + catch(NumberFormatException e){ + System.out.println("X & Y must be Integer"); + } + catch(InvalidDenominator e){ + System.out.println(e); + } + catch(InvalidNumerator e){ + System.out.println(e); + } + System.out.println(""); + } + + float totalFuel = 30000f; + Java_souvikpal2000 ob=new Java_souvikpal2000(); + float result = ob.calculateFuelCalibration(x,y); + String leftFuel = ob.calculateLeftFuel(x,y,totalFuel); + String flag = ob.checkTank(result); + + System.out.println(""); + System.out.println("Output:"); + System.out.println(""); + System.out.println("Fuel calibration: "+String.format("%.3f",result)+"%"); + System.out.println("Amount of fuel in tank: "+leftFuel+" L out of "+totalFuel+" L"); + + if(flag.equals("ok")){ + System.out.println("The tank is FULL!"); + }else if(flag.equals("warning")){ + System.out.println("The tank is EMPTY!!!"); + System.out.println("Refill tank"); + } + } +} \ No newline at end of file From 4dac61c39a93555ddb2d68ba9ceed9554254b71f Mon Sep 17 00:00:00 2001 From: Venkatakrishnan Date: Tue, 3 Jan 2023 16:22:08 +0530 Subject: [PATCH 227/408] Day 2 --- December - 01/solution.py | 0 December - 02/solution.py | 12 ++++++++++++ 2 files changed, 12 insertions(+) create mode 100644 December - 01/solution.py create mode 100644 December - 02/solution.py diff --git a/December - 01/solution.py b/December - 01/solution.py new file mode 100644 index 0000000..e69de29 diff --git a/December - 02/solution.py b/December - 02/solution.py new file mode 100644 index 0000000..e197567 --- /dev/null +++ b/December - 02/solution.py @@ -0,0 +1,12 @@ +def main(): + to_piglatin = "nguetoae" + print(translate_to_english(to_piglatin)) + return True +def translate_to_english(word): + list_word = list(word) + last_two_letters = list_word[-2:] + if last_two_letters == ['a', 'e']: + word = word[:-2] + word= word[-2]+word[-1]+word[:-2] + return word +main() \ No newline at end of file From 11fbcfe281342b0281578a7f581d2732640bfe05 Mon Sep 17 00:00:00 2001 From: GREEDnim Date: Tue, 3 Jan 2023 18:59:00 +0530 Subject: [PATCH 228/408] day 19 , sliding window --- December - 19/GREEDnim_day19_java.java | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 December - 19/GREEDnim_day19_java.java diff --git a/December - 19/GREEDnim_day19_java.java b/December - 19/GREEDnim_day19_java.java new file mode 100644 index 0000000..2d95cdc --- /dev/null +++ b/December - 19/GREEDnim_day19_java.java @@ -0,0 +1,38 @@ +package acm; + +import java.util.Locale; +import java.util.Scanner; + +public class GREEDnim_day19_java { + + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + String big=in.nextLine().toLowerCase(); + String smol=in.nextLine().toLowerCase(); + big=big.replaceAll("[^a-z]+", ""); + smol=smol.replaceAll("[^a-z]+", ""); + int[]map=new int[26]; + for(char s:smol.toCharArray()) + { + map[s-'a']++; + } + + int s=0; + int e=0; + while(e Date: Tue, 3 Jan 2023 18:59:29 +0530 Subject: [PATCH 229/408] day 21, tower of hanoi --- December - 21/GREEDnim_day21_java.java | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 December - 21/GREEDnim_day21_java.java diff --git a/December - 21/GREEDnim_day21_java.java b/December - 21/GREEDnim_day21_java.java new file mode 100644 index 0000000..b848cc1 --- /dev/null +++ b/December - 21/GREEDnim_day21_java.java @@ -0,0 +1,34 @@ +package acm; + +import java.util.Scanner; + +public class GREEDnim_day21_java { + + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + int disks=in.nextInt(); + towerOfHanoi("tower 1","tower 2","tower 3",disks); + } + public static void towerOfHanoi(String left,String middle,String right , int diskNo ) + { + if(diskNo==1) + { + System.out.println("move disk "+diskNo+" from "+left+" to "+ right); + return; + } + + towerOfHanoi(left,right,middle,diskNo-1); + System.out.println("move disk "+diskNo+" from "+left+" to "+ right); + towerOfHanoi(middle,left,right,diskNo-1); + + + + + + + } + + +} + + From b3a440828dadf18104d96ee3d28649d8ad3e4e22 Mon Sep 17 00:00:00 2001 From: GREEDnim Date: Tue, 3 Jan 2023 19:32:13 +0530 Subject: [PATCH 230/408] day 22 added --- December - 22/GREEDnim_day22_java.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 December - 22/GREEDnim_day22_java.java diff --git a/December - 22/GREEDnim_day22_java.java b/December - 22/GREEDnim_day22_java.java new file mode 100644 index 0000000..9179d09 --- /dev/null +++ b/December - 22/GREEDnim_day22_java.java @@ -0,0 +1,25 @@ +package acm; + +import java.util.Scanner; + +public class GREEDnim_day22_java { + + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + String ciper=in.next(); + String toEncrypt=in.next(); + StringBuilder ans=new StringBuilder(); + + int j=0; + for(int i=0;i Date: Wed, 4 Jan 2023 01:15:16 +0530 Subject: [PATCH 231/408] Dijkstra core logic --- December - 18/cpp_nijuyonkadesu.cpp | 76 +++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 December - 18/cpp_nijuyonkadesu.cpp diff --git a/December - 18/cpp_nijuyonkadesu.cpp b/December - 18/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..ef1d7d0 --- /dev/null +++ b/December - 18/cpp_nijuyonkadesu.cpp @@ -0,0 +1,76 @@ +#include +#include +#include +#include + +using namespace std; + +int NO_PARENTS = -1; // Flag to indicate a node does not have a parent node + +void dijkstras(vector>& adjMat, int start); + +int main() { + vector> adjMat{ + /* P Q R S T U V W */ + { 0, 3, 4, 5, 0, 0, 0, 0}, + { 3, 0, 2, 0, 0, 5, 0, 0}, + { 4, 2, 0, 7, 3, 6, 2, 0}, + { 5, 0, 7, 0, 2, 0, 0, 0}, + { 0, 0, 3, 2, 0, 0, 4, 0}, + { 0, 5, 6, 0, 0, 0, 5, 2}, + { 0, 0, 2, 0, 4, 5, 0, 1}, + { 0, 0, 0, 0, 0, 2, 1, 0} + }; + + // Choice input an alphabet p = 112 in ascii + char charChoice; + cin >> charChoice; + charChoice = tolower(charChoice); + int ch = charChoice - 112; + cout<>& adjMat, int start){ + + int n = adjMat[0].size(); // No of nodes in the given graph + + vector isNodeAdded(n, false); // Tells if a node is added to the shortest path tree + + vector allPathShortestDistance(n, INT_MAX); // This is where the shortest possible length is stored + allPathShortestDistance[start] = 0; // start node is 0 acc. to algorithm + + vector parentOfNode(n); // keep track of a node's parent node + parentOfNode[start] = NO_PARENTS; + + // Begin to find shortest distance of every node from start + for (int i=1; i 0) && ((currentNodeWeight + nextNodeWeight) < allPathShortestDistance[nextNode])){ + parentOfNode[nextNode] = currentNode; + allPathShortestDistance[nextNode] = currentNodeWeight + nextNodeWeight; + } + } + } +} From 07fb504af41df79f8b0cbd3fcb2cad75d041f9ad Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Wed, 4 Jan 2023 19:34:41 +0530 Subject: [PATCH 232/408] December 28 - The Journey to the Eternal Engine --- December - 28/Java_souvikpal2000.java | 142 ++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 December - 28/Java_souvikpal2000.java diff --git a/December - 28/Java_souvikpal2000.java b/December - 28/Java_souvikpal2000.java new file mode 100644 index 0000000..7217216 --- /dev/null +++ b/December - 28/Java_souvikpal2000.java @@ -0,0 +1,142 @@ +import java.util.*; +public class Java_souvikpal2000{ + public int findFirstSmallest(List tail){ + int firstSmallest = Integer.MAX_VALUE; + for(Integer tailie : tail){ + if(firstSmallest > tailie){ + firstSmallest = tailie; + } + } + return firstSmallest; + } + + public int findSecondSmallest(List tail, int firstSmallest){ + int secondSmallest = Integer.MAX_VALUE; + for(Integer tailie : tail){ + if(secondSmallest > tailie){ + int flag = tailie; + if(flag > firstSmallest){ + secondSmallest = flag; + } + } + } + return secondSmallest; + } + + public int findFirstLargest(List tail){ + int firstLargest = Integer.MIN_VALUE; + for(Integer tailie : tail){ + if(firstLargest < tailie){ + firstLargest = tailie; + } + } + return firstLargest; + } + + public int findSecondLargest(List tail, int firstLargest){ + int secondLargest = Integer.MIN_VALUE; + for(Integer tailie : tail){ + if(secondLargest < tailie){ + int flag = tailie; + if(flag < firstLargest){ + secondLargest = flag; + } + } + } + return secondLargest; + } + + public int minimumBetweenTwo(int a, int b){ + int min = a tail, int n){ + int firstSmallest = findFirstSmallest(tail); + int secondSmallest = findSecondSmallest(tail,firstSmallest); + + int travelTime = 0; + + while(true){ + if(tail.size() == 3){ + int firstLargest = findFirstLargest(tail); + travelTime = travelTime + (secondSmallest + firstSmallest + firstLargest); + break; + } + if(tail.size() == 2){ + travelTime = travelTime + secondSmallest; + break; + } + else{ + int firstLargest = findFirstLargest(tail); + int secondLargest = findSecondLargest(tail,firstLargest); + + int result01 = firstApproach(firstLargest,secondLargest,firstSmallest); + int result02 = secondApproach(firstLargest,firstSmallest,secondSmallest); + + tail.remove(tail.indexOf(firstLargest)); + tail.remove(tail.indexOf(secondLargest)); + + int minTime = minimumBetweenTwo(result01,result02); + + travelTime = travelTime + minTime; + } + } + + return travelTime; + } + + public float secondsToMinutes(int time){ + float timeInMinutes = (float)time/60; + return timeInMinutes; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input:"); + System.out.println(""); + int n; + while(true){ + System.out.print("n="); + n = sc.nextInt(); + System.out.println(""); + + if(n >= 3){ + break; + }else{ + System.out.println("There needs to be at least 3 Tailies"); + System.out.println(""); + } + } + + System.out.print("Walking time: "); + int[] walkingTime = new int[n]; + for(int i=0;i tail = new ArrayList<>(); + for(int time : walkingTime){ + tail.add(time); + } + + Java_souvikpal2000 ob=new Java_souvikpal2000(); + int timeInSeconds = ob.theJourneyToTheEternalEngine(tail,n); + float timeInMinutes = ob.secondsToMinutes(timeInSeconds); + + System.out.println(""); + System.out.println("Output:"); + System.out.println(""); + System.out.println(String.format("%.3f",timeInMinutes)); + } +} \ No newline at end of file From 6d73fee3a6bac8758663aaf8e4381a2b149474a1 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Wed, 4 Jan 2023 19:46:49 +0530 Subject: [PATCH 233/408] Update README.md --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e762aa0..8918345 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,9 @@ Check out our FAQ for more information. #### Explanation ``` - The first line of input will specify the number of words (n). The subsequent 'n' lines will specify the word to be translated. + The first line of input will specify the number of words (n). + + The subsequent 'n' lines will specify the word to be translated, where each letter is separated by a comma. ``` @@ -337,7 +339,7 @@ Expenditure=6050 #### Explanation ``` - The input is the rate of the fuel in the beginning of the month. + The input is the rate of the fuel in the beginning of the month. The output is the amount he must spend on fueling his bike. If the expenditure exceeds 10% of the income (i.e greater than 5000), then an alert message must be displayed. @@ -472,6 +474,8 @@ Output: - [Strings in C++](https://www.tutorialspoint.com/cplusplus/cpp_strings.htm) - [Strings in Java](https://www.tutorialspoint.com/java/java_strings.htm) - [String in Python](https://www.tutorialspoint.com/python/python_strings.htm) + - [2D Arrays](https://www.simplilearn.com/tutorials/data-structure-tutorial/two-dimensional-arrays#:~:text=ExpertView%20Course-,What%20Are%20Two%2DDimensional%20Arrays%3F,similar%20to%20the%20data%20structure.) + - [Pattern Searching in Strings](https://www.geeksforgeeks.org/algorithms-gq/pattern-searching/) ---- @@ -505,6 +509,7 @@ Help Arshith develop a way to translate any given word to that particular langua - [Strings in C++](https://www.geeksforgeeks.org/stdstring-class-in-c/) - [Strings in Python](https://www.geeksforgeeks.org/python-string/) - [String in Java](https://www.geeksforgeeks.org/strings-in-java/) + - [Pattern Searching in Strings](https://www.geeksforgeeks.org/algorithms-gq/pattern-searching/) ---- @@ -562,6 +567,7 @@ Better luck next time - [Strings in C++](https://www.geeksforgeeks.org/stdstring-class-in-c/) - [Strings in Python](https://www.geeksforgeeks.org/python-string/) - [String in Java](https://www.geeksforgeeks.org/strings-in-java/) + - [Pattern Searching in Strings](https://www.geeksforgeeks.org/algorithms-gq/pattern-searching/) ---- @@ -641,6 +647,8 @@ S contains only lowercase Latin characters, i.e, the characters {a,b,c…….z} - [Strings in C++](https://www.geeksforgeeks.org/stdstring-class-in-c/) - [Strings in Python](https://www.geeksforgeeks.org/python-string/) - [String in Java](https://www.geeksforgeeks.org/strings-in-java/) + - [Pattern Searching in Strings](https://www.geeksforgeeks.org/algorithms-gq/pattern-searching/) + ---- From a9d2b8cb00e8429e731b450a1c41f90db1e3f16f Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Wed, 4 Jan 2023 21:13:16 +0530 Subject: [PATCH 234/408] Update README.md --- README.md | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 8918345..cb949a4 100644 --- a/README.md +++ b/README.md @@ -699,13 +699,13 @@ Since in the 8th jump the monkey touches water, the total jump count before he t ``` - **References** -- [Looping in C](https://www.tutorialspoint.com/cprogramming/c_loops.htm) -- [Looping in C++](https://www.programiz.com/cpp-programming/for-loop) -- [Looping in Java](https://www.geeksforgeeks.org/loops-in-java/) -- [Looping in Python](https://www.w3schools.com/python/python_for_loops.asp) -- [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) -- [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) -- [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + - [Looping in C](https://www.tutorialspoint.com/cprogramming/c_loops.htm) + - [Looping in C++](https://www.programiz.com/cpp-programming/for-loop) + - [Looping in Java](https://www.geeksforgeeks.org/loops-in-java/) + - [Looping in Python](https://www.w3schools.com/python/python_for_loops.asp) + - [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) + - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) + - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) ---- @@ -768,6 +768,14 @@ From 7 she has 4 options; paths of costs 6,6,3,4 (Taking path 4 is not advisable ``` +- **References** + - [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) + - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) + - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + - [Graphs](https://www.geeksforgeeks.org/graph-data-structure-and-algorithms/) + - [Shortest Path Algorithms](https://brilliant.org/wiki/shortest-path-algorithms/#:~:text=There%20are%20two%20main%20types,because%20of%20the%20added%20complexity.) + + ---- ### December 13 - The Labyrinth #### Problem Statement @@ -827,6 +835,12 @@ In the given samples, the input matrix specifies the structure of the maze in wh After computing a path to the destination, the output matrix represents the path to the destination block using 1’s. ``` +- **References** + - [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) + - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) + - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + - [Graphs](https://www.geeksforgeeks.org/graph-data-structure-and-algorithms/) + - [Backtracking Algorithms](https://www.geeksforgeeks.org/backtracking-algorithms/) ---- ### December 14 - Math Mystery @@ -887,11 +901,12 @@ You are required to divide the given vertices into two sets such that: ``` - **References** -- [Bipartite graphs](https://www.tutorialspoint.com/bipartite-graphs) -- [Adjacency matrices](https://www.javatpoint.com/what-is-an-adjacency-matrix) -- [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) -- [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) -- [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + - [Bipartite graphs](https://www.geeksforgeeks.org/bipartite-graph/) + - [Adjacency matrices](https://www.javatpoint.com/what-is-an-adjacency-matrix) + - [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) + - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) + - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + - [Graphs](https://www.geeksforgeeks.org/graph-data-structure-and-algorithms/) ---- From 174829966547140f2f7bacdc02ad76f6bb137512 Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Wed, 4 Jan 2023 22:07:28 +0530 Subject: [PATCH 235/408] Update README.md --- README.md | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index cb949a4..2140b4c 100644 --- a/README.md +++ b/README.md @@ -948,9 +948,9 @@ They will now be organized into a queue based on when they pressed the microphon ``` - **References** -- [Queue data structure](https://www.javatpoint.com/data-structure-queue) -- [Queue in Java](https://www.geeksforgeeks.org/queue-interface-java/) -- [Queue in Python](https://www.geeksforgeeks.org/queue-interface-java/) + - [Queue data structure](https://www.javatpoint.com/data-structure-queue) + - [Queue in Java](https://www.geeksforgeeks.org/queue-interface-java/) + - [Queue in Python](https://www.geeksforgeeks.org/queue-interface-java/) ---- @@ -991,11 +991,17 @@ In this case,the area between lines 7 and 8 will be maximum. Height of the container is min(7,8)= 7. So the max area of water (blue section) the container can contain is 49. +The selected two heights need not necessarily be maximum but including the max distance between them at the same time. +Considering both the length and breadth to be maximum the area is found. So it is a combination of height and distance between the two heights. +So that the resultant area will be the maximum amount of water in the the given container. + ``` - **References** -- [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) -- [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) -- [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + - [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) + - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) + - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + - [Sorting Algorithms](https://www.geeksforgeeks.org/sorting-algorithms/) + - [Two Pointer Approach](https://www.geeksforgeeks.org/two-pointers-technique//) ---- @@ -1050,9 +1056,9 @@ Output for each test case should be printed in a separate line. ``` - **References** -- [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) -- [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) -- [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + - [Strings in C++](https://www.geeksforgeeks.org/stdstring-class-in-c/) + - [Strings in Python](https://www.geeksforgeeks.org/python-string/) + - [String in Java](https://www.geeksforgeeks.org/strings-in-java/) ---- @@ -1097,11 +1103,11 @@ Time complexity is 0(V^2) ``` - **References** -- [Graphs](https://www.geeksforgeeks.org/graph-data-structure-and-algorithms/) -- [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) -- [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) -- [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) -- [Adjacency matrices](https://www.javatpoint.com/what-is-an-adjacency-matrix) + - [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) + - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) + - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + - [Graphs](https://www.geeksforgeeks.org/graph-data-structure-and-algorithms/) + - [Shortest Path Algorithms](https://brilliant.org/wiki/shortest-path-algorithms/#:~:text=There%20are%20two%20main%20types,because%20of%20the%20added%20complexity.) ---- @@ -1273,6 +1279,7 @@ Please note that this is not the maximum weight generated from picking the highe - [Strings in Python](https://www.geeksforgeeks.org/python-string/) - [String in Java](https://www.geeksforgeeks.org/strings-in-java/) - [Dynamic Programming](https://www.geeksforgeeks.org/dynamic-programming/) + - [Subsequences in Arrays and Strings](https://www.geeksforgeeks.org/subarraysubstring-vs-subsequence-and-programs-to-generate-them/) ---- @@ -1449,6 +1456,7 @@ The message as well as the codeword do not have any spaces between the words. - [Strings in Python](https://www.geeksforgeeks.org/python-string/) - [String in Java](https://www.geeksforgeeks.org/strings-in-java/) - [Caesar Cipher](https://www.geeksforgeeks.org/caesar-cipher-in-cryptography/) + - [Caesar Cipher Techniques](https://www.javatpoint.com/caesar-cipher-technique) ---- From 60652ea06f8b8a7a2f4b83fa03d69c7c807aa3fc Mon Sep 17 00:00:00 2001 From: neha2127 <105559815+neha2127@users.noreply.github.com> Date: Wed, 4 Jan 2023 22:18:56 +0530 Subject: [PATCH 236/408] Update README.md --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2140b4c..07359df 100644 --- a/README.md +++ b/README.md @@ -1543,6 +1543,8 @@ For the first sample input the first line is the number of rooms and the second - [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + - [Sorting](https://www.geeksforgeeks.org/sorting-algorithms/) + - [Heap (Priority Queue)](https://www.geeksforgeeks.org/priority-queue-using-binary-heap/) ---- @@ -1634,9 +1636,10 @@ Thus "01100" will unlock the safe. "01100", "10011", and "11001" would also unlo - [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) - - [Strings in C++](https://www.geeksforgeeks.org/stdstring-class-in-c/) - - [Strings in Python](https://www.geeksforgeeks.org/python-string/) - - [String in Java](https://www.geeksforgeeks.org/strings-in-java/) + - [Graphs](https://www.geeksforgeeks.org/graph-data-structure-and-algorithms/) + - [Hierholzer’s Algorithm](https://www.geeksforgeeks.org/hierholzers-algorithm-directed-graph/) + - [Eulerian Path and Circuit](https://www.geeksforgeeks.org/eulerian-path-and-circuit/) + - [Depth First Search](https://www.geeksforgeeks.org/depth-first-search-or-dfs-for-a-graph/) ---- From daf6be7511e38d1a8ad46d99d51d9038a6d84de1 Mon Sep 17 00:00:00 2001 From: GREEDnim Date: Thu, 5 Jan 2023 05:54:37 +0530 Subject: [PATCH 237/408] day 23 completed --- December - 23/GREEDnim_day23_java.java | 78 ++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 December - 23/GREEDnim_day23_java.java diff --git a/December - 23/GREEDnim_day23_java.java b/December - 23/GREEDnim_day23_java.java new file mode 100644 index 0000000..f28695f --- /dev/null +++ b/December - 23/GREEDnim_day23_java.java @@ -0,0 +1,78 @@ +package acm; + +import java.util.*; + +public class GREEDnim_day23_java { + public static void main(String[] args) { + +// int roomCount=2; +// int[][] ques={{0,10},{1,5},{2,7},{3,4}}; + + int roomCount=3; + int[][]ques={{1,20},{2,10},{3,5},{4,9},{6,8}}; + int noOfProcess=ques.length; + List>inp=new ArrayList<>(); + + for(int[] arr:ques) + { + Listlist=new ArrayList<>(); + list.add(arr[0]); + list.add(arr[1]); + inp.add(list); + } + + Collections.sort(inp, new Comparator<>() { + + public int compare(List a, List b) { + if (a.get(0) < b.get(0) || (int)a.get(0) == (int)b.get(0) && a.get(1) < b.get(1)) return -1; + return 1; + } + }); + + int[] rooms=new int[roomCount]; + int[] timeRemaining=new int[roomCount]; + + int processCompleted=0; + while(processCompleted=0) + { + rooms[room]++; + timeRemaining[room]=inp.get(processCompleted).get(1)-inp.get(processCompleted).get(0) ; + processCompleted++; + } + reduceTime(timeRemaining); + } + int max=Integer.MIN_VALUE; + int roomNo=0; + for(int i=0;imax) + { + roomNo=i; + max=rooms[i]; + } + } + + System.out.println(roomNo); + + } + public static int freeRoom(int[] t) + { + + for(int i=0;i0) t[i]--; + + } + } +} From 8bdfdc39d82cd0a2c3abf26a8d5ff65a44e773f4 Mon Sep 17 00:00:00 2001 From: GREEDnim Date: Thu, 5 Jan 2023 17:49:59 +0530 Subject: [PATCH 238/408] day 26 added --- December - 26/GREEDnim_day26_java.java | 47 ++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 December - 26/GREEDnim_day26_java.java diff --git a/December - 26/GREEDnim_day26_java.java b/December - 26/GREEDnim_day26_java.java new file mode 100644 index 0000000..9a8a2f6 --- /dev/null +++ b/December - 26/GREEDnim_day26_java.java @@ -0,0 +1,47 @@ +package acm; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.Queue; + +public class GREEDnim_day26_java { + + public static void main(String[] args) { +// int[][] arr={{2}, {3, 4}, {2}, {2}}; + int[][] arr={{2}, {5, 4, 6}, {3}, {4}, {5}, {6}}; + boolean[] heard=new boolean[arr.length+1]; + heard[1]=true; + Queueq=new LinkedList<>(); + for(int ele: arr[0]) + { + q.offer(ele); + } + + while(!q.isEmpty()) + { + int size=q.size(); + for(int i=0;i Date: Thu, 5 Jan 2023 18:11:20 +0530 Subject: [PATCH 239/408] Update README.md --- README.md | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 07359df..d3f6db1 100644 --- a/README.md +++ b/README.md @@ -1662,6 +1662,26 @@ If at any given time two motorcyclists are in same position, the motorcyclist wi To make the problem simple, he assumes that each motorcyclist is moving at a constant velocity. +Input Format: + + The first line contains a number t (about 10) which is the number of test cases. + + Then t test cases follow. Each test case has the following form. + + The first line of the test case contains a number N (1 <= N <= 2000), the number of motorcyclists. + + The i-th line in the next N lines contains two numbers, v and x, which are the velocity and the current position of the i-th motorcyclist (1 <= v, x <= 100,000). + + The next line contains a number Q (1 <= Q <= 2000), the number of time queries. + + Each line in the next Q lines contains two numbers, t (1 <= t <= 1,000,000,000) and k (1 <= k <= n), representing the query: "at time t, which motorcyclist is positioned k-th in the rank list?" + +Output Format: + + For each test case, print Q lines, with each line containing the index of the motorcyclist for the corresponding query. + + Remember to print a new line after each test case. +

@@ -1696,31 +1716,6 @@ Output: ``` - -#### Explanation: - -``` -Input - -The first line contains a number t (about 10) which is the number of test cases. - -Then t test cases follow. Each test case has the following form. - -The first line of the test case contains a number N (1 <= N <= 2000), the number of motorcyclists. - -The i-th line in the next N lines contains two numbers, v and x, which are the velocity and the current position of the i-th motorcyclist (1 <= v, x <= 100,000). - -The next line contains a number Q (1 <= Q <= 2000), the number of time queries. - -Each line in the next Q lines contains two numbers, t (1 <= t <= 1,000,000,000) and k (1 <= k <= n), representing the query: "at time t, which motorcyclist is positioned k-th in the rank list?" - -Output: - -For each test case, print Q lines, with each line containing the index of the motorcyclist for the corresponding query. - -Remember to print a new line after each test case. - -``` - **References** - [Looping in C](https://www.tutorialspoint.com/cprogramming/c_loops.htm) - [Looping in C++](https://www.programiz.com/cpp-programming/for-loop) From f74d70079beb8e2bf80cb073558b1e5e393d070a Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Thu, 5 Jan 2023 19:25:29 +0530 Subject: [PATCH 240/408] December 29 - Candies --- December - 29/Java_souvikpal2000.java | 58 +++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 December - 29/Java_souvikpal2000.java diff --git a/December - 29/Java_souvikpal2000.java b/December - 29/Java_souvikpal2000.java new file mode 100644 index 0000000..8343481 --- /dev/null +++ b/December - 29/Java_souvikpal2000.java @@ -0,0 +1,58 @@ +import java.util.*; +public class Java_souvikpal2000{ + public int[] distributeCandies(int[] ratings, int n){ + int[] candies = new int[n]; + + // Every child must have atleast 1 candy, so distribute it + for(int i=0;i ratings[i]){ + candies[i+1] = candies[i] + 1; + } + } + + // Right to Left Traversal + for(int i=n-1;i>0;i--){ + if(ratings[i-1] > ratings[i] && candies[i-1] < candies[i]+1){ + candies[i-1] = candies[i] + 1; + } + } + + return candies; + } + + public int calculateMinimumCandies(int[] candies, int n){ + int sum = 0; + for(int i=0;i Date: Fri, 6 Jan 2023 05:28:07 +0530 Subject: [PATCH 241/408] Print path in characters --- December - 18/cpp_nijuyonkadesu.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/December - 18/cpp_nijuyonkadesu.cpp b/December - 18/cpp_nijuyonkadesu.cpp index ef1d7d0..942462c 100644 --- a/December - 18/cpp_nijuyonkadesu.cpp +++ b/December - 18/cpp_nijuyonkadesu.cpp @@ -8,6 +8,8 @@ using namespace std; int NO_PARENTS = -1; // Flag to indicate a node does not have a parent node void dijkstras(vector>& adjMat, int start); +void printSolution(int start, vector& allPathShortestDistance, vector& parentOfNode); +void printPath(int end, vector& parentOfNode); int main() { vector> adjMat{ @@ -27,7 +29,6 @@ int main() { cin >> charChoice; charChoice = tolower(charChoice); int ch = charChoice - 112; - cout<>& adjMat, int start){ } } } + printSolution(start, allPathShortestDistance, parentOfNode); } + +void printSolution(int start, vector& allPathShortestDistance, vector& parentOfNode){ + int n = allPathShortestDistance.size(); + int end = 7; // node W + cout<<"Vertex\t Distance \t Path"; + cout<<"\n"<<((char)(start + 112))<<" -> "; + cout<<((char)(end + 112))<<"\t "; + cout<& parentOfNode){ + if(node == NO_PARENTS) return; + printPath(parentOfNode[node], parentOfNode); + cout<<(char)(node + 112)<<" "; +} + From a2db681ae1b2d48f8da97eb11ca2ee835254a918 Mon Sep 17 00:00:00 2001 From: Venkatakrishnan Ramesh Date: Fri, 6 Jan 2023 09:22:26 +0530 Subject: [PATCH 242/408] day 14 --- December - 07/Solution.py | 70 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 December - 07/Solution.py diff --git a/December - 07/Solution.py b/December - 07/Solution.py new file mode 100644 index 0000000..8bcf112 --- /dev/null +++ b/December - 07/Solution.py @@ -0,0 +1,70 @@ +def main(): + grid = ["ASSERTIVENESSLJ","CFOGOODPOSITIVE","OPENBMUREWOPRPS","MEDIATIONELDIOG","MAASREGJEWINWIN","UCIAEMOEECSKENI","NEMRSHACDVTWTTL","ITEHOTLTERAOE","CASPLGLSIUNERFE","AISAUSYTPOISEVF","TTARTTDOCENPPIH","IOGAIGUPYMGOOEE","OGEPOAFPQIENOWA","NECONFLICTSDCER","FNHTCATNOCEYEBT"] + word = "MEDIATION" + print(find_word(grid, word)) + return True + +def __init__(self): +        self.R = None +        self.C = None +        self.dir = [[-1, 0], [1, 0], [1, 1], +                    [1, -1], [-1, -1], [-1, 1], +                    [0, 1], [0, -1]] +                      +    # This function searches in all 8-direction +    # from point(row, col) in grid[][] +    def search2D(self, grid, row, col, word): +          +        # If first character of word doesn't match +        # with the given starting point in grid. +        if grid[row][col] != word[0]: +            return False +              +        # Search word in all 8 directions +        # starting from (row, col) +        for x, y in self.dir: +              +            # Initialize starting point +            # for current direction +            rd, cd = row + x, col + y +            flag = True +              +            # First character is already checked, +            # match remaining characters +            for k in range(1, len(word)): +                  +                # If out of bound or not matched, break +                if (0 <= rd Date: Fri, 6 Jan 2023 18:51:41 +0530 Subject: [PATCH 243/408] Update README.md --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index d3f6db1..43b8223 100644 --- a/README.md +++ b/README.md @@ -1721,6 +1721,8 @@ Output: - [Looping in C++](https://www.programiz.com/cpp-programming/for-loop) - [Looping in Java](https://www.geeksforgeeks.org/loops-in-java/) - [Looping in Python](https://www.w3schools.com/python/python_for_loops.asp) + - [Sorting Algorithms](https://www.geeksforgeeks.org/sorting-algorithms/) + - [Searching Algorithms](https://www.geeksforgeeks.org/searching-algorithms/) ---- @@ -1791,6 +1793,11 @@ The list has four persons and everyone knows what the word is so the output is

+- **References** + - [Arrays in C++](http://www.cplusplus.com/doc/tutorial/arrays/) + - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) + - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) + ---- ### December 27 - Mission to Earth: Re-Calibrated @@ -1862,6 +1869,18 @@ Refill tank. ``` +``` +Input: + +Enter the Hydrogen fuel fraction: +583/0 + +Output: + +Error! + +``` + - **References** - [Looping in C](https://www.tutorialspoint.com/cprogramming/c_loops.htm) - [Looping in C++](https://www.programiz.com/cpp-programming/for-loop) @@ -1980,6 +1999,7 @@ Adding the time: - [Looping in C++](https://www.programiz.com/cpp-programming/for-loop) - [Looping in Java](https://www.geeksforgeeks.org/loops-in-java/) - [Looping in Python](https://www.w3schools.com/python/python_for_loops.asp) + - [Dynamic Programming](https://www.geeksforgeeks.org/introduction-to-dynamic-programming-data-structures-and-algorithm-tutorials/) ---- @@ -2047,6 +2067,8 @@ The third child gets 1 candy because it satisfies the above two conditions. - [Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) - [Arrays in Python](https://www.w3schools.com/python/python_lists.asp) - [Graphs](https://www.geeksforgeeks.org/graph-data-structure-and-algorithms/) + - [Dynamic Programming](https://www.geeksforgeeks.org/introduction-to-dynamic-programming-data-structures-and-algorithm-tutorials/) + - [Greedy Algorithms](https://www.geeksforgeeks.org/greedy-algorithms/) ---- From aea66b2151d5ba5bddf426fd751456eb279167bc Mon Sep 17 00:00:00 2001 From: GREEDnim Date: Fri, 6 Jan 2023 22:03:21 +0530 Subject: [PATCH 244/408] day 19 , updated --- December - 19/GREEDnim_day19_java.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/December - 19/GREEDnim_day19_java.java b/December - 19/GREEDnim_day19_java.java index 2d95cdc..35a53d4 100644 --- a/December - 19/GREEDnim_day19_java.java +++ b/December - 19/GREEDnim_day19_java.java @@ -21,18 +21,15 @@ public static void main(String[] args) { int e=0; while(e Date: Sun, 8 Jan 2023 00:53:24 +0530 Subject: [PATCH 245/408] day 29 added --- December - 29/GREEDnim_day29_java.java | 58 ++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 December - 29/GREEDnim_day29_java.java diff --git a/December - 29/GREEDnim_day29_java.java b/December - 29/GREEDnim_day29_java.java new file mode 100644 index 0000000..68a680c --- /dev/null +++ b/December - 29/GREEDnim_day29_java.java @@ -0,0 +1,58 @@ +package acm; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Scanner; + +public class GREEDnim_day29_java { + static List[] shouldIncrease; + static int[] ans; + public static void main(String[] args) { + + Scanner in=new Scanner(System.in); + int n=in.nextInt(); + int[] rating=new int[n]; + for(int i=0;i list=new ArrayList<>(); + if(left>=0 && rating[left]>rating[i]) list.add(left); + if(rightrating[i]) list.add(right); + shouldIncrease[i]=list; +// System.out.println(list); + } + + Arrays.fill(ans,1); + for(int i=0;ilist=shouldIncrease[k]; + for(int i=0;i Date: Sun, 8 Jan 2023 01:11:54 +0530 Subject: [PATCH 246/408] Day 6 Swapped --- December - 05/Misspend.cpp | 12 +++--------- December - 06/output.txt | 5 +++++ December - 06/swapped.cpp | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 December - 06/output.txt create mode 100644 December - 06/swapped.cpp diff --git a/December - 05/Misspend.cpp b/December - 05/Misspend.cpp index 6bf6268..9574853 100644 --- a/December - 05/Misspend.cpp +++ b/December - 05/Misspend.cpp @@ -8,20 +8,14 @@ int main() cin >> fuel_price; uint8_t adjust_value = 36; // adjust value - // so calculating for 3rd day , it comes 10 times , so 6*10 = 60 + // so calculating for 3rd day , it comes 10 time~s , so 6*10 = 60 // calculating for 5th day , it comes 6 times, so 4*6 = 24 (negative) // so adjusting values = 60 - 24 = +36 // normal mathematics int total = (fuel_price * 2 * 31) + adjust_value; cout << total << endl; - if (total <= income10per) - { - cout << "EXPENDITURE WITHIN LIMIT" << endl; - } - else - { - cout << "EXPENDITURE EXCEEDING LIMIT" << endl; - } + string result = (total <= income10per) ? "EEXPENDITURE WITHIN LIMIT" : "EXPENDITURE EXCEEDING LIMIT"; + cout << result; return 0; } \ No newline at end of file diff --git a/December - 06/output.txt b/December - 06/output.txt new file mode 100644 index 0000000..66aad94 --- /dev/null +++ b/December - 06/output.txt @@ -0,0 +1,5 @@ +Position = 3 +Set of numbers: 544 +Player going first: Tanika +Tanika wins the game! +Bob loses the game \ No newline at end of file diff --git a/December - 06/swapped.cpp b/December - 06/swapped.cpp new file mode 100644 index 0000000..579cf77 --- /dev/null +++ b/December - 06/swapped.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; + +int main() +{ + int position, count = 1; + string player, nums; + int numbers; + + cout << "Position = "; + cin >> position; + position -= 1; + + // Assuming to get single digit numbers i.e. 0-9 + cout << "Set of numbers: "; + cin >> nums; + + cout << "Player going first: "; + cin >> player; + + while (nums[0] != 0) + { + nums[0] -= 1; + swap(nums[0], nums[position]); + count++; + } + + string sen1 = "Tanika wins the game!\nBob loses the game"; + string sen2 = "Bob wins the game!\nTanika loses the game"; + + string result = (player == "tanika" || player == "Tanika") ? ((count % 2 == 0) ? sen1 : sen2) : ((count % 2 == 0) ? sen2 : sen1); + cout << result; + + return 0; +} \ No newline at end of file From cda78d6ffaa6bca9f9a10f926594c0c0601d7e2f Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Sun, 8 Jan 2023 02:42:39 +0530 Subject: [PATCH 247/408] detection using map --- December - 19/cpp_nijuyonkadesu.cpp | 57 +++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 December - 19/cpp_nijuyonkadesu.cpp diff --git a/December - 19/cpp_nijuyonkadesu.cpp b/December - 19/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..ebee5c7 --- /dev/null +++ b/December - 19/cpp_nijuyonkadesu.cpp @@ -0,0 +1,57 @@ +#include +#include + +using namespace std; + +int isAnagramPossible(string& text, string& anagram); // if -1 not found +void printFoundMatch(string& text, string& anagram, int endPos); // prints the matched substring from the text + +int main (int argc, char *argv[]) +{ + string text, anagram; + + getline(cin>>ws, text); // consumes white space as well + getline(cin>>ws, anagram); + printFoundMatch(text, anagram, isAnagramPossible(text, anagram)); + return 0; +} + +int isAnagramPossible(string& text, string& anagram){ + map myChartedAccountantGirl; + int concecutiveCounter = 0, restorePointer = 0; + char c; + + for(int i=0; i Date: Sun, 8 Jan 2023 10:37:35 +0530 Subject: [PATCH 248/408] day 31, N QUEENS --- December - 31/GREEDnim_day31_java.java | 67 ++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 December - 31/GREEDnim_day31_java.java diff --git a/December - 31/GREEDnim_day31_java.java b/December - 31/GREEDnim_day31_java.java new file mode 100644 index 0000000..3c7642f --- /dev/null +++ b/December - 31/GREEDnim_day31_java.java @@ -0,0 +1,67 @@ +package acm; + +import java.util.Scanner; + +public class GREEDnim_day31_java { + static boolean[][] placedQueens; + static int count=0; + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + int n=in.nextInt(); + placedQueens=new boolean[n][n]; + placeQueens(0); + System.out.println("no of combinations "+count); + } + public static void placeQueens(int row) + { + if(row==placedQueens.length) + { + count++; + printQueens(); + return; + } + for(int i=0;i< placedQueens.length;i++) + { + if(placable(row,i)) + { + placedQueens[row][i]=true; + placeQueens(row+1); + placedQueens[row][i]=false; + } + } + } + public static boolean placable(int row,int col) + { + + //vertical top + for(int i=row-1;i>=0;i--) + { + if(placedQueens[i][col]) return false; + } + //left top diagonal + for(int i=row-1, j=col-1; i>=0 && j>=0 ; i--,j--) + { + if(placedQueens[i][j]) return false; + } + //right top diagonal + for(int i=row-1,j=col+1; i>=0 && j Date: Sun, 8 Jan 2023 13:45:32 +0530 Subject: [PATCH 249/408] tower of hanoi naive reverse soln --- December - 21/cpp_nijuyonkadesu.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 December - 21/cpp_nijuyonkadesu.cpp diff --git a/December - 21/cpp_nijuyonkadesu.cpp b/December - 21/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..fcb937d --- /dev/null +++ b/December - 21/cpp_nijuyonkadesu.cpp @@ -0,0 +1,24 @@ +#include + +using namespace std; + +void hanoi(int disks, char source, char auxillary, char destination); + +int main (int argc, char *argv[]) +{ + int disks; + cout<<"Number of disks: "; + cin>>disks; + hanoi(disks, 'A', 'B', 'C'); + return 0; +} + +void hanoi(int disk, char source, char auxillary, char destination){ + if(disk==1) { + cout<<"Move disk "< Date: Sun, 8 Jan 2023 18:02:33 +0530 Subject: [PATCH 250/408] nQueens using virgin backtrack --- December - 31/cpp_nijuyonkadesu.cpp | 78 +++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 December - 31/cpp_nijuyonkadesu.cpp diff --git a/December - 31/cpp_nijuyonkadesu.cpp b/December - 31/cpp_nijuyonkadesu.cpp new file mode 100644 index 0000000..9260405 --- /dev/null +++ b/December - 31/cpp_nijuyonkadesu.cpp @@ -0,0 +1,78 @@ +#include +#include + +using namespace std; + +void nQueens(vector>& kitchenFloor,int row = 0, int column = 0); +bool isPossibleToMove(vector>&, int , int); +void printBoard(vector>&); +static int count = 0; + + +int main (int argc, char *argv[]) +{ + int tilesCount; + cin>>tilesCount; + vector> kitchenFloor(tilesCount, vector (tilesCount, 0)); + nQueens(kitchenFloor); + cout<>& kitchenFloor, int row, int column){ + +// base condition + if(row == kitchenFloor[0].size()){ + count++; + printBoard(kitchenFloor); + return; + } + +// if it's possible to place the queen, place it and go to next row + if(isPossibleToMove(kitchenFloor, row, column)){ + kitchenFloor[row][column] = 1; + nQueens(kitchenFloor, row + 1); + kitchenFloor[row][column] = 0; + } +// if queen cannot be placed on current positon, move towards right and check + if (column + 1 < kitchenFloor[0].size()) + nQueens(kitchenFloor, row, column + 1); +} + +bool isPossibleToMove(vector>& kitchenFloor, int row, int column){ + bool safe = true; + + int i = row, j = column; + // left diagonal, check for queen + while(i>=0 && j>=0 && safe){ + safe = !(kitchenFloor[i][j] == 1); + j--; + i--; + } + + // right diagonal + i = row, j = column; + while(i=0 && safe){ + safe = !(kitchenFloor[i][j] == 1); + j++; + i--; + } + + // top + j = row; + while(j>=0 && safe){ + safe = !(kitchenFloor[j--][column] == 1); + } + return safe; +} + +void printBoard(vector>& kitchenFloor){ + for(auto part: kitchenFloor){ + for(auto it = part.begin(); it < part.end(); it++){ + cout<< *it; + } + cout<< endl; + } + cout<< endl; +} + From 63c4d2f853cf761d42213fc5e775503162e13046 Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:35:12 +0530 Subject: [PATCH 251/408] day_1 --- December - 01/py_gowsrini2004_day_01.py | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 December - 01/py_gowsrini2004_day_01.py diff --git a/December - 01/py_gowsrini2004_day_01.py b/December - 01/py_gowsrini2004_day_01.py new file mode 100644 index 0000000..7bf7937 --- /dev/null +++ b/December - 01/py_gowsrini2004_day_01.py @@ -0,0 +1,38 @@ +#day_01 + +y = 1 +while y > 0: + print("#problem_statment_01!!") + array_pre = input("") + junk_hexa = array_pre.split("},") + l = len(junk_hexa) + d = {} + x=1 + for i in junk_hexa: + d["lis{0}".format(x)] = i + x+=1 + #d=dict + t=0 + finlist=[] + for i in d: + a=d[i] + if(t==len(d)-1): + a1=a[1:len(a)-1] + tlist=a1.split(',') + finlist.append(tlist) + else: + a1=a[1:len(a)] + tlist=a1.split(',') + finlist.append(tlist) + t+=1 + + ascl=[] + + for i in finlist: + for j in i: + ascl.append(bytes.fromhex(j).decode('utf-8')) + ascl.append(' ') + + for i in ascl: + print(i,end='') + print("\n") \ No newline at end of file From 230e088898b13af2038ab1ee985bf16ee1f3d8f2 Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:35:27 +0530 Subject: [PATCH 252/408] day_2 --- December - 02/py_gowsrini2004_day_02.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 December - 02/py_gowsrini2004_day_02.py diff --git a/December - 02/py_gowsrini2004_day_02.py b/December - 02/py_gowsrini2004_day_02.py new file mode 100644 index 0000000..431d5e6 --- /dev/null +++ b/December - 02/py_gowsrini2004_day_02.py @@ -0,0 +1,11 @@ +#day_02 +y = 1 +while y > 0: + print("#problem_statment_02!!") + a=input() + msg_split=a.split() + for i in msg_split: + word_t=i[:len(i)-2:] + word_f1,word_f2=word_t[len(word_t)-2:len(word_t)+1],word_t[:len(word_t)-2] + finalword=word_f1+word_f2 + print(finalword) \ No newline at end of file From 3fe569dd1b0c76bedf744aa62c190a83dcaa9e25 Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:35:47 +0530 Subject: [PATCH 253/408] day_3 --- December - 03/py_gowsrini2004_day_03.py | 152 ++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 December - 03/py_gowsrini2004_day_03.py diff --git a/December - 03/py_gowsrini2004_day_03.py b/December - 03/py_gowsrini2004_day_03.py new file mode 100644 index 0000000..cebb448 --- /dev/null +++ b/December - 03/py_gowsrini2004_day_03.py @@ -0,0 +1,152 @@ +#day_03 +import numpy as np +import json +y = 1 +while y > 0: + print("#problem_statment_03!!") + n = int(input("n =")) + v1_mat = [] + hash_ind_lis = [] + add_one_ind_lis = [] + + x = 1 + index = n-1 + for i in range(0, n): + mat = input("") + junk_mat = mat.split("\"") + for j in junk_mat: + if j == "[" or j == "]" or j == "]," or j == ", ": + pass + else: + v1_mat.append(j) + + + for i in range(0, len(v1_mat)): + if v1_mat[i] == "#": + hash_ind_lis.append(i) + else: + v1_mat[i] = 0 + + col_h_1, col_h_2,list_1 = [], [],[] + + index_of_column_last = [] + element =0 + for i in range (0,((n*n))): + if element==4: + index_of_column_last.append(i) + element=-1 + element+=1 + + for j in hash_ind_lis: + # print(j) + if j % n == 0: + col_h_1.append(j) + elif j in index_of_column_last: + col_h_2.append(j) + + + + for i in hash_ind_lis: + if i == 0: + x1 = i+1 + x2 = i+n + x3 = i+(n+1) + temp = [x1, x2, x3] + + elif i < (n-1) and i > 0: + x1 = i+1 + x2 = i-1 + x3 = i+n + x4 = i+(n-1) + x5 = i+(n+1) + temp = [x1, x2, x3, x4, x5] + elif i == n-1: + x1 = i-1 + x2 = i+(n-1) + x3 = i+n + temp = [x1, x2, x3] + + elif i in col_h_1 and i != 0 and i != ((n*n)-n): + x1 = i-n + x2 = i-(n-1) + x3 = i+1 + x4 = i+n + x5 = i+(n+1) + temp = [x1, x2, x3, x4, x5] + + elif i == (n*n)-n: + x1 = i-n + x2 = i-(n+1) + x3 = i+1 + temp = [x1, x2, x3] + + elif i > (n*n)-n and i < ((n*n)-1): + x1 = i-(n-1) + x2 = i-(n+1) + x3 = i-n + x4 = i-1 + x5 = i+1 + temp = [x1, x2, x3, x4, x5] + + elif i == (n*n)-1: + x1 = i-(n+1) + x2 = i-n + x3 = i-1 + temp = [x1, x2, x3] + + elif i in col_h_2 and i != (n*n)-1 and i != (n-1): + x1 = i-1 + x2 = i-(n+1) + x3 = i-n + x4 = i+n + x5 = i+(n-1) + temp = [x1, x2, x3, x4, x5] + else: + x1 = i-(n-1) + x2 = i-(n+1) + x3 = i-n + x4 = i-1 + x5 = i+1 + x6 = i+n + x7 = i+(n-1) + x8 = i+(n+1) + temp = [x1, x2, x3, x4, x5, x6, x7, x8] + for j in temp: + list_1.append(j) + + for i in list_1: + if i in hash_ind_lis: + list_1.remove(i) + + # print(hash_ind_lis) + # print(list_1) + # print(v1_mat) + + for i in list_1: + try: + v1_mat[i] += 1 + except: + pass + + A = [str(x) for x in v1_mat] + + + def nest_list(list1,rows, columns): + result=[] + start = 0 + end = columns + for i in range(rows): + result.append(list1[start:end]) + start +=columns + end += columns + return result + x = nest_list(A,n,n) + print("\n\noutput:") + + index = 0 + for i in x: + if index<(n-1): + print(json.dumps(i),",",sep="") + index+=1 + else: + print(json.dumps(i)) \ No newline at end of file From 5dfb1d60d8ffbeeead9dfdbaf44143b8a7e85c42 Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:36:04 +0530 Subject: [PATCH 254/408] day_4 --- December - 04/py_gowsrini2004_day_04.py | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 December - 04/py_gowsrini2004_day_04.py diff --git a/December - 04/py_gowsrini2004_day_04.py b/December - 04/py_gowsrini2004_day_04.py new file mode 100644 index 0000000..40b17b1 --- /dev/null +++ b/December - 04/py_gowsrini2004_day_04.py @@ -0,0 +1,28 @@ +#day04 +from sys import maxsize +y = 1 +while y > 0: + print("#problem_statment_04!!") + max_so_far = -maxsize - 1 + max_ending_here, start, end, s = 0, 0, 0, 0 + s_change,a = [],[] + size = int(input("No. of Days: ")) + a_1 = input("Given stock market change values: ").replace(" ","").replace("{","").replace("}","").split(",") + a = [int(i) for i in a_1] + for i in range(0, size): + max_ending_here += a[i] + + if max_so_far < max_ending_here: + max_so_far = max_ending_here + start = s + end = i + + if max_ending_here < 0: + max_ending_here = 0 + s = i+1 + + print("Profit Value: ", max_so_far) + print("Proposed days to sell: Day:", (start+1), ", to Day:", (end+1)) + for i in range(start, (end+1)): + s_change.append(a[i]) + print("Stock market Change Values: " + '{' + ', '.join([str(x) for x in s_change]) + '}') \ No newline at end of file From 4967a24ab7abec04a408fb70ec6a89ba0b9a22ad Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:45:36 +0530 Subject: [PATCH 255/408] day_5 --- December - 05/py_gowsrini2004_day_05.py | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 December - 05/py_gowsrini2004_day_05.py diff --git a/December - 05/py_gowsrini2004_day_05.py b/December - 05/py_gowsrini2004_day_05.py new file mode 100644 index 0000000..d8b2748 --- /dev/null +++ b/December - 05/py_gowsrini2004_day_05.py @@ -0,0 +1,27 @@ +#day_05 +y = 1 +while y > 0: + print("#problem_statment_05!!") + input_f_p = int(input("fuel_price=")) + f_p = input_f_p + day = 1 + exp = 0 + + + while day <= 31: + if day % 3 == 0: + f_p += 3 + if day % 5 == 0: + f_p -= 2 + day +=1 + exp += f_p + # print(day,f_p) + f_p = input_f_p + + exp = exp*2 + print("Expenditure=",exp) + + if exp > 5000: + print("EXPENDITURE EXCEEDING LIMIT") + else: + print("EXPENDITURE WITHIN LIMIT") \ No newline at end of file From d444a55a379a9e44891e1bbd9913a908304aa53c Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:46:10 +0530 Subject: [PATCH 256/408] day_6 --- December - 06/py_gowsrini2004_day_06.py | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 December - 06/py_gowsrini2004_day_06.py diff --git a/December - 06/py_gowsrini2004_day_06.py b/December - 06/py_gowsrini2004_day_06.py new file mode 100644 index 0000000..a4c90d2 --- /dev/null +++ b/December - 06/py_gowsrini2004_day_06.py @@ -0,0 +1,44 @@ +#day_06 +y = 1 +while y > 0: + print("#problem_statment_06!!") + t,temp,count = 1,0,1 + pos = int(input("Enter The Position: ")) + p = pos -1 + set = input("Set of Numbers: ") + player_1 = input("Player going first:") + if player_1 == "Tanika" or player_1 == "tanika": + player_1 = "Tanika" + player_2 = "Bob" + else: + player_2 = "Tanika" + player_1 = "Bob" + set_l = set.split() + set_l_n = [] + for j in set_l: + set_l_n.append(int(j)) + set_l = set_l_n + # print(set_l) + play = 1 + while t == 1: + set_l[0] -= 1 + temp = set_l[p] + set_l[p] = set_l[0] + set_l[0] = temp + if set_l[0] == 0: + t = 0 + if count%2 == 0: + play = 1 + else: + play = 2 + # print(set_l) + count = 0 + # print(player_1,player_2) + if play == 1: + winnner = player_1 + loser = player_2 + print(winnner,"wins the game!\n",loser,"loses the game!") + else: + winnner = player_2 + loser = player_1 + print(winnner,"wins the game!\n",loser,"loses the game!") \ No newline at end of file From ee967ff08d51fa68c34054493931fc2e2726a5ad Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:46:28 +0530 Subject: [PATCH 257/408] day_7 --- December - 07/py_gowsrini2004_day_07.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 December - 07/py_gowsrini2004_day_07.py diff --git a/December - 07/py_gowsrini2004_day_07.py b/December - 07/py_gowsrini2004_day_07.py new file mode 100644 index 0000000..0b86a31 --- /dev/null +++ b/December - 07/py_gowsrini2004_day_07.py @@ -0,0 +1,18 @@ +#day_07 +y = 1 +while y > 0: + print("#problem_statment_07!!") + input_str_user = input("Enter The String: ") + input_str = input_str_user.upper() + # print(input_str) + str_row = "ASSERTIVENESSLJCFOGOODPOSITIVEOPENBMUREWOPRPSMEDIATIONELDIOGMAASREGJEWINWINUCIAEMOEECSKENINEMRSHACDVTWTTLITEHOTLTSTERAOECASPLGLSIUNERFEAISAUSYTPOISEVFTTARTTDOCENPPIHIOGAIGUPYMGOOEEOGEPOAFPQIENOWANECONFLICTSDCERFNHTCATNOCEYEBT" + str_column = "ACOMMUNICATIONFSFPEACETAITOGENSOEDAIMESSAGECHEGNISARHPARAPOTROBARESOLUTIONCTOMTEMHTGSTGAFAALLYDUFLTCTSTOPPINDSIPCYQCONSWEWCVTUOEMITCEIOLISTENINGESSESTPDNKWRESPONDYSIRIWETAREPOOCESIRIWETAREPOOCELVPOINTOFVIEWEVJESGNILEEFHEART" + + if input_str in str_row: + print("Found") + + elif input_str in str_column: + print("Found") + + else: + print("Not Found") \ No newline at end of file From f1d77b100fa9157b83b2ba451c75c0c6f304372a Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:46:44 +0530 Subject: [PATCH 258/408] day_8 --- December - 08/py_gowsrini2004_day_08.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 December - 08/py_gowsrini2004_day_08.py diff --git a/December - 08/py_gowsrini2004_day_08.py b/December - 08/py_gowsrini2004_day_08.py new file mode 100644 index 0000000..1a7a75e --- /dev/null +++ b/December - 08/py_gowsrini2004_day_08.py @@ -0,0 +1,18 @@ +#day_08 +y = 1 +while y > 0: + print("#problem_statment_08!!") + s = input("Input: ") + index,u,new_str,updated_list,list_str = 0, 0,"",[],list(s) + for i in list_str: + if index % 2 == 0: + updated_list.append(i) + index += 1 + else: + u = index-1 + updated_list.insert(u, i) + # print(index,i) + index += 1 + for i in updated_list: + new_str += i + print("Output:",new_str) \ No newline at end of file From 70aa1132f005dda755adab0e815e5d3a10c78707 Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:47:00 +0530 Subject: [PATCH 259/408] day_9 --- December - 09/py_gowsrini2004_day_09.py | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 December - 09/py_gowsrini2004_day_09.py diff --git a/December - 09/py_gowsrini2004_day_09.py b/December - 09/py_gowsrini2004_day_09.py new file mode 100644 index 0000000..6d9fa67 --- /dev/null +++ b/December - 09/py_gowsrini2004_day_09.py @@ -0,0 +1,30 @@ +#day_09 +y = 1 +while y > 0: + print("#problem_statment_09!!") + index = 0 + n = int(input("")) + s = input("") + str = s.split(" ") + max = "" + for i in str: + l = len(i) + index +=1 + if l > len(max): + if index len(max): + if l % 2 == 0: + max = '' + else: + max = i + + + if len(max)%2 == 0: + print("Better luck next time") + else: + print(max) \ No newline at end of file From dde81a15cc56de589234be349cc50a6d1877b1d3 Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:47:28 +0530 Subject: [PATCH 260/408] day_10 --- December - 10/py_gowsrini2004_day_10.py | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 December - 10/py_gowsrini2004_day_10.py diff --git a/December - 10/py_gowsrini2004_day_10.py b/December - 10/py_gowsrini2004_day_10.py new file mode 100644 index 0000000..cd1e0ce --- /dev/null +++ b/December - 10/py_gowsrini2004_day_10.py @@ -0,0 +1,31 @@ +#day_10 +y = 1 +while y > 0: + print("#problem_statment_10!!") + T = int(input("")) + vowels = ["a","e","i","o","u"] + output = [] + for i in range(0,T): + index = 0 + N = int(input("")) + S = input("") + s_1 = S.lower() + s_l = list(s_1) + for j in s_l: + if index<4: + if j in vowels: + index=0 + pass + else: + index+=1 + else: + pass + if index<4: + output.append("Y") + else: + output.append("N") + for j in output: + if j == "Y": + print("YES") + else: + print("NO") \ No newline at end of file From 6ef9a5be011d5ebfdb787d0b12509a44bbf1bd1c Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:48:41 +0530 Subject: [PATCH 261/408] day_11 --- December - 11/py_gowsrini2004_day_11.py | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 December - 11/py_gowsrini2004_day_11.py diff --git a/December - 11/py_gowsrini2004_day_11.py b/December - 11/py_gowsrini2004_day_11.py new file mode 100644 index 0000000..e36e6a5 --- /dev/null +++ b/December - 11/py_gowsrini2004_day_11.py @@ -0,0 +1,32 @@ +#day_11 +y = 1 +while y > 0: + print("#problem_statment_11!!") + l_w_lis = input("").replace(" ","").replace("’","").replace("‘","").replace("[","").replace("]","").split(",") + step_lis = input("").replace("[","").replace("]","").split(",") + step_lis = [int(x) for x in step_lis] + w_lis = [] + jump, index = 0, 0 + for i in l_w_lis: + if i == "~": + w_lis.append(index) + index += 1 + # print(w_lis) + index = 0 + for i in step_lis: + if i == 2: + index+=2 + if index in w_lis: + break + else: + jump+=1 + else: + index+=1 + if index in w_lis: + break + else: + jump+=1 + # print(i,index,jump) + + + print("Score:",jump) \ No newline at end of file From 4d64586231802f654d8596108cd1bb40581aeb31 Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:48:57 +0530 Subject: [PATCH 262/408] day_12 --- December - 12/py_gowsrini2004_day_12.py | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 December - 12/py_gowsrini2004_day_12.py diff --git a/December - 12/py_gowsrini2004_day_12.py b/December - 12/py_gowsrini2004_day_12.py new file mode 100644 index 0000000..9209d5a --- /dev/null +++ b/December - 12/py_gowsrini2004_day_12.py @@ -0,0 +1,40 @@ +#day_12 +y = 1 +while y > 0: + print("#problem_statment_12!!") + n = int(input("")) + path = input("path: ").replace(" ","").replace("{","").replace("}","").split(",") + path = [int(x) for x in path] + # print(path) + index = 0 + final_lis = [] + final_lis.append(path[0]) + while index<((n*n)-1): + if index == ((n*(n-1))-1): + y = path[index+n] + final_lis.append(y) + break + if index>= ((n*n)-(n-1)): + x = path[index+1] + final_lis.append(x) + index+=1 + else: + x = path[index+1] + y = path[index+n] + # print(x,y,index) + if y>x: + final_lis.append(x) + index+=1 + elif x>y or x==y: + final_lis.append(y) + index+=n + + # print(final_lis) + sum = 0 + for i in final_lis: + sum+=i + + + print("\n\n") + print("path_taken="+'{' + ','.join([str(x) for x in final_lis]) + '}') + print("The minimum coins dropped is",sum) \ No newline at end of file From a237a1e873abdeb6d9dc3843dc4834be33563305 Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:49:11 +0530 Subject: [PATCH 263/408] day_13 --- December - 13/py_gowsrini2004_day_13.py | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 December - 13/py_gowsrini2004_day_13.py diff --git a/December - 13/py_gowsrini2004_day_13.py b/December - 13/py_gowsrini2004_day_13.py new file mode 100644 index 0000000..ae3d9ff --- /dev/null +++ b/December - 13/py_gowsrini2004_day_13.py @@ -0,0 +1,59 @@ +#day_13 +y = 1 +while y > 0: + print("#problem_statment_13!!") + def check_condition(n, path, x, y, lis): + if x >= 0 and y >= 0 and x < n and y < n and path[x][y] == 1 and lis[x][y] == 0: + return True + return False + + def move_path(n, path, x1, y1, x, y, lis): + if x == n-1 and y == n-1: + return True + for i in range(4): + x2 = x + x1[i] + y2 = y + y1[i] + if check_condition(n, path, x2, y2, lis): + lis[x2][y2] = 1 + if move_path(n, path, x1, y1, x2, y2, lis): + return True + lis[x2][y2] = 0 + return False + + def find_path(path): + lis = [[0 for i in range(n)] for i in range(n)] + lis[0][0] = 1 + x1 = [-1, 1, 0, 0] + y1 = [0, 0, -1, 1] + if move_path(n, path, x1, y1, 0, 0, lis): + for i in range(n): + for j in range(n): + pre_final_lis.append(lis[i][j]) + print() + else: + print('Path Cannot Be Found') + + def sub_array(inp,out): + start = 0 + end = len(inp) + step = n + for i in range(start, end, step): + x = i + out.append(inp[x:x+step]) + + + n = int(input("n= ")) + v1_mat,path,final_lis,pre_final_lis= [],[],[],[] + for i in range(0, n): + mat = input("").replace(" ","").replace("{","").replace("}","").split(",") + mat = [int(x) for x in mat] + for j in mat: + v1_mat.append(j) + + sub_array(v1_mat,path) + find_path(path) + sub_array(pre_final_lis,final_lis) + # print(pre_final_lis,final_lis) + print("OUTPUT:") + for i in final_lis: + print('{' + ','.join([str(x) for x in i]) + '}') \ No newline at end of file From 1df5801025f276027d56004bf84dee6a7fefdc8b Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:49:27 +0530 Subject: [PATCH 264/408] day_14 --- December - 14/py_gowsrini2004_day_14.py | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 December - 14/py_gowsrini2004_day_14.py diff --git a/December - 14/py_gowsrini2004_day_14.py b/December - 14/py_gowsrini2004_day_14.py new file mode 100644 index 0000000..e6e984c --- /dev/null +++ b/December - 14/py_gowsrini2004_day_14.py @@ -0,0 +1,43 @@ +#day_14 +y = 1 +while y > 0: + print("#problem_statment_14!!") + def co_g(input_G, color, p, c): + if color[p] != -1 and color[p] != c: + return False + color[p] = c + ans = True + for i in range(0, n): + if input_G[p][i]: + if color[i] == -1: + ans &= co_g(input_G, color, i, 1-c) + if color[i] !=-1 and color[i] != 1-c: + return False + if not ans: + return False + return True + def check_bipartite(input_G): + color = [-1]*n + p = 0 + return co_g(input_G, color, p, 1) + + #main + n = int(input("")) + print("") + v1_mat,input_G = [],[] + for i in range(0, n): + mat = input("").split(" ") + mat = [int(x) for x in mat] + for j in mat: + v1_mat.append(j) + start = 0 + end = len(v1_mat) + step = n + for i in range(start, end, step): + x = i + input_G.append(v1_mat[x:x+step]) + print("\n\nOUTPUT:") + if check_bipartite(input_G): + print("The graph is Bipartite!") + else: + print("The graph is Not Bipartite!") \ No newline at end of file From cb76be271533c5926fd8c73ce544ec3b158ed72e Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:49:42 +0530 Subject: [PATCH 265/408] day_15 --- December - 15/py_gowsrini2004_day_15.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 December - 15/py_gowsrini2004_day_15.py diff --git a/December - 15/py_gowsrini2004_day_15.py b/December - 15/py_gowsrini2004_day_15.py new file mode 100644 index 0000000..473f864 --- /dev/null +++ b/December - 15/py_gowsrini2004_day_15.py @@ -0,0 +1,25 @@ +#day_15 +y = 1 +while y > 0: + print("#problem_statment_15!!") + input_i = input("").replace("},",",").replace(", ",",").replace("}","").replace("{","").split(",") + names,time_stamp= [],[] + for i in range (0,len(input_i)): + if i % 2 == 0: + names.append(input_i[i]) + else: + time_stamp.append(input_i[i]) + res = {names[i]: time_stamp[i] for i in range(len(names))} + sorted_res = sorted(res.items(),key=lambda item: item[1]) + res = dict(sorted_res) + print("\n\nOutput:") + + i = 1 + for key in res: + if i < len(res): + print(key,end=", ") + i+=1 + else: + print(key,end=".") + i+=1 + print("\n") \ No newline at end of file From b56b57d664d1d96135266b881f783ba69b64686d Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:49:54 +0530 Subject: [PATCH 266/408] day_16 --- December - 16/py_gowsrini2004_day_16.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 December - 16/py_gowsrini2004_day_16.py diff --git a/December - 16/py_gowsrini2004_day_16.py b/December - 16/py_gowsrini2004_day_16.py new file mode 100644 index 0000000..35eaace --- /dev/null +++ b/December - 16/py_gowsrini2004_day_16.py @@ -0,0 +1,19 @@ +#day_15 +y = 1 +while y > 0: + print("#problem_statment_16!!") + def m_a(lis): + l = 0 + r = len(lis) -1 + area = 0 + while l < r: + area = max(area, min(lis[l],lis[r])*(r - l)) + if lis[l] < lis[r]: + l+=1 + else: + r-=1 + return area + + step_lis = input("height = ").replace("[","").replace("]","").split(",") + step_lis = [int(x) for x in step_lis] + print("\nOutput:",m_a(step_lis)) \ No newline at end of file From bbe88717f31c09a546eecf685015231257b572c2 Mon Sep 17 00:00:00 2001 From: Gowtham S <79265235+gowsrini2004@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:50:07 +0530 Subject: [PATCH 267/408] day_17 --- December - 17/py_gowsrini2004_day_17.py | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 December - 17/py_gowsrini2004_day_17.py diff --git a/December - 17/py_gowsrini2004_day_17.py b/December - 17/py_gowsrini2004_day_17.py new file mode 100644 index 0000000..768fe07 --- /dev/null +++ b/December - 17/py_gowsrini2004_day_17.py @@ -0,0 +1,27 @@ +#day_15 +y = 1 +while y > 0: + print("#problem_statment_17!!") + str = input("Str = ").replace("“","").replace("”","") + row = int(input("Row = ")) + if row == 1: + print(str) + l = len(str) + arr=["" for x in range(l)] + # print(arr) + row_r = 0 + for i in range(l): + arr[row_r] += str[i] + # print(str[i]) + if row_r == row - 1: + down = False + elif row_r == 0: + down = True + if down: + row_r += 1 + else: + row_r -= 1 + print("\nOutput:") + for i in range(row): + print(arr[i], end = "") + print("\n") \ No newline at end of file From 5a248db7fda1cbe92d3b01549b58359dc28b98a3 Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Mon, 9 Jan 2023 22:33:31 +0530 Subject: [PATCH 268/408] December 7 - Word Map --- December - 07/Java_souvikpal2000.java | 96 +++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 December - 07/Java_souvikpal2000.java diff --git a/December - 07/Java_souvikpal2000.java b/December - 07/Java_souvikpal2000.java new file mode 100644 index 0000000..553e36e --- /dev/null +++ b/December - 07/Java_souvikpal2000.java @@ -0,0 +1,96 @@ +import java.util.*; +class Coordinates{ + int xPos; + int yPos; + Coordinates(int xPos, int yPos){ + this.xPos = xPos; + this.yPos = yPos; + } +} +public class Java_souvikpal2000{ + public Coordinates[] searchForString(int row, int column, char[][] map, String str){ + int[] rowDirection = {1,-1,0,0}; + int[] columnDirection = {0,0,1,-1}; + Coordinates starting = new Coordinates(row,column); + Coordinates[] coordinateDetails = new Coordinates[2]; + int count = 1; + for(int i=0;i(map.length-1) || colPos>(map[0].length-1) || map[rowPos][colPos] != c){ + break; + } + if(map[rowPos][colPos] == c){ + count++; + } + if(count == str.length()){ + Coordinates ending = new Coordinates(rowPos,colPos); + coordinateDetails[0] = starting; + coordinateDetails[1] = ending; + return coordinateDetails; + } + } + } + return null; + } + + public Coordinates[] wordMap(char[][] map, String str){ + int rowSize = map.length; + int columnSize = map[0].length; + for(int i=0;i Date: Tue, 10 Jan 2023 11:43:59 +0530 Subject: [PATCH 269/408] Day 7 Word Map --- December - 07/output.txt | 8 ++++ December - 07/wordmap.cpp | 86 +++++++++++++++++++++++++++++++++++++ December - 08/apptitude.cpp | 24 +++++++++++ 3 files changed, 118 insertions(+) create mode 100644 December - 07/output.txt create mode 100644 December - 07/wordmap.cpp create mode 100644 December - 08/apptitude.cpp diff --git a/December - 07/output.txt b/December - 07/output.txt new file mode 100644 index 0000000..2a49e57 --- /dev/null +++ b/December - 07/output.txt @@ -0,0 +1,8 @@ +Input: COMMUNICATION +FOUND + +Input: DOCUMENT +NOT FOUND + +Input: MEDIATION +FOUND \ No newline at end of file diff --git a/December - 07/wordmap.cpp b/December - 07/wordmap.cpp new file mode 100644 index 0000000..1492074 --- /dev/null +++ b/December - 07/wordmap.cpp @@ -0,0 +1,86 @@ +#include +using namespace std; + +// DFS +bool search(vector> board, string word, int i, int j, int pos) +{ + if (pos == word.size()) + return true; + if ((i < 0) || (i >= board.size()) || (j < 0) || (j >= board[i].size())) + return false; + + char c = board[i][j]; + if (c == word[pos]) + { + board[i][j] = '#'; + if (search(board, word, i - 1, j, pos + 1)) + return true; + if (search(board, word, i + 1, j, pos + 1)) + return true; + if (search(board, word, i, j - 1, pos + 1)) + return true; + if (search(board, word, i, j + 1, pos + 1)) + return true; + board[i][j] = c; + } + return false; +} + +bool found(vector> board, string word) +{ + for (int i = 0; i < board.size(); i++) + { + for (int j = 0; j < board[i].size(); j++) + { + if (search(board, word, i, j, 0)) + return true; + } + } + return false; +} + +int main() +{ + vector> wordmap = { + {'A', 'S', 'E', 'E', 'R', 'T', 'I', 'V', 'E', 'N', 'E', 'S', 'S', 'L', 'J'}, + + {'C', 'F', 'O', 'G', 'O', 'O', 'D', 'P', 'O', 'S', 'I', 'T', 'I', 'V', 'E'}, + + {'O', 'P', 'E', 'N', 'B', 'M', 'U', 'R', 'E', 'W', 'O', 'P', 'R', 'P', 'S'}, + + {'M', 'E', 'D', 'I', 'A', 'T', 'I', 'O', 'N', 'E', 'L', 'D', 'I', 'O', 'G'}, + + {'M', 'A', 'A', 'S', 'R', 'E', 'G', 'J', 'E', 'W', 'I', 'N', 'W', 'I', 'N'}, + + {'U', 'C', 'I', 'A', 'E', 'M', 'O', 'E', 'E', 'C', 'S', 'K', 'E', 'N', 'I'}, + + {'N', 'E', 'M', 'R', 'S', 'H', 'A', 'C', 'D', 'V', 'T', 'W', 'T', 'T', 'L'}, + + {'I', 'T', 'E', 'H', 'O', 'T', 'L', 'T', 'S', 'T', 'E', 'R', 'A', 'O', 'E'}, + + {'C', 'A', 'S', 'P', 'L', 'G', 'L', 'S', 'I', 'U', 'N', 'E', 'R', 'F', 'E'}, + + {'A', 'I', 'S', 'A', 'U', 'S', 'Y', 'T', 'P', 'O', 'I', 'S', 'E', 'V', 'F'}, + + {'T', 'T', 'A', 'R', 'T', 'T', 'D', 'O', 'C', 'E', 'N', 'P', 'P', 'I', 'H'}, + + {'I', 'O', 'G', 'A', 'I', 'G', 'U', 'P', 'Y', 'M', 'G', 'O', 'O', 'E', 'E'}, + + {'O', 'G', 'E', 'P', 'O', 'A', 'F', 'P', 'Q', 'I', 'E', 'N', 'O', 'W', 'A'}, + + {'N', 'E', 'C', 'O', 'N', 'F', 'L', 'I', 'C', 'T', 'S', 'D', 'C', 'E', 'R'}, + + {'F', 'N', 'H', 'T', 'C', 'A', 'T', 'N', 'O', 'C', 'E', 'Y', 'E', 'B', 'T'}}; + + string word; + cout << "Input: "; + cin >> word; + + transform(word.begin(), word.end(), word.begin(), ::toupper); + + bool tf = found(wordmap, word); + string result = tf == true ? "FOUND" : "NOT FOUND"; + cout << result; + + return 0; +} \ No newline at end of file diff --git a/December - 08/apptitude.cpp b/December - 08/apptitude.cpp new file mode 100644 index 0000000..d36f36f --- /dev/null +++ b/December - 08/apptitude.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +int main() +{ + string word; + cout << "INPUT: "; + cin >> word; + string sub = word; + vector v; + int n = word.length(); + + for (int i = 0; i < n; i += 2) + { + swap(sub[i], sub[i + 1]); + } + + if (n % 2 != 0) + { + sub = sub + word.back(); + } + + cout << "OUTPUT: " << sub; +} \ No newline at end of file From 3113a5446f00543ff91ded5628afc74439caf200 Mon Sep 17 00:00:00 2001 From: Asad Date: Tue, 10 Jan 2023 11:46:33 +0530 Subject: [PATCH 270/408] Day 8 Aptitude Check! --- December - 08/output.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 December - 08/output.txt diff --git a/December - 08/output.txt b/December - 08/output.txt new file mode 100644 index 0000000..d496511 --- /dev/null +++ b/December - 08/output.txt @@ -0,0 +1,5 @@ +INPUT: UNCOPYRIGHTABLE +OUTPUT: NUOCYPIRHGATLBE + +INPUT: SPEEDRUNNER +OUTPUT: PSEERDNUENR \ No newline at end of file From db7b71db336466454139a93bdd608551b2439aa0 Mon Sep 17 00:00:00 2001 From: souvikpal2000 Date: Tue, 10 Jan 2023 22:02:38 +0530 Subject: [PATCH 271/408] December 21 - The Devil Towers --- December - 21/Java_souvikpal2000.java | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 December - 21/Java_souvikpal2000.java diff --git a/December - 21/Java_souvikpal2000.java b/December - 21/Java_souvikpal2000.java new file mode 100644 index 0000000..2c4cd7b --- /dev/null +++ b/December - 21/Java_souvikpal2000.java @@ -0,0 +1,30 @@ +import java.util.*; +public class Java_souvikpal2000{ + public void move(int n, String left, String right, String middle){ + if(n == 1){ + System.out.println("Move disk "+n+" from tower "+left+" to tower "+right); + } + else{ + move(n-1,left,middle,right); + System.out.println("Move disk "+n+" from tower "+left+" to tower "+right); + move(n-1,middle,right,left); + } + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input:"); + System.out.println(""); + System.out.print("Number of discs: "); + int n = sc.nextInt(); + + Java_souvikpal2000 ob=new Java_souvikpal2000(); + + System.out.println(""); + System.out.println("Output:"); + System.out.println(""); + System.out.println("The sequence of moves :"); + ob.move(n,"I","III","II"); + } +} \ No newline at end of file From 48cd97d73eebae01c4c93666c0a39b29e786ac6a Mon Sep 17 00:00:00 2001 From: tarpandas Date: Thu, 12 Jan 2023 10:03:23 +0530 Subject: [PATCH 272/408] December 15,17,19,21,22 solved --- December - 22/Java_tarpandas.java | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 December - 22/Java_tarpandas.java diff --git a/December - 22/Java_tarpandas.java b/December - 22/Java_tarpandas.java new file mode 100644 index 0000000..6611fb9 --- /dev/null +++ b/December - 22/Java_tarpandas.java @@ -0,0 +1,41 @@ +import java.util.*; +public class Java_tarpandas{ + public String theMarkowitzParadox(String codeword, String message){ + String encrypt = ""; + int length = message.length(); + int l = codeword.length(); + int j = 0; + for(int i=0;i 90){ + int diff = sum - 90; + encrypt = encrypt + (char)(64 + diff); + + }else{ + encrypt = encrypt + (char)sum; + } + j++; + } + return encrypt; + } + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + String codeword = sc.next(); + String message = sc.next(); + + Java_tarpandas ob=new Java_tarpandas(); + String encrypt = ob.theMarkowitzParadox(codeword.toUpperCase(),message.toUpperCase()); + + System.out.println(""); + System.out.println(encrypt); + + sc.close(); + } +} \ No newline at end of file From e0e9ef8a42bc130b8521acb82bf0202276721fa4 Mon Sep 17 00:00:00 2001 From: tarpandas Date: Thu, 12 Jan 2023 10:04:39 +0530 Subject: [PATCH 273/408] December 15,17,19,21,22 solved --- December - 15/Java_tarpandas.java | 61 ++++++++++++++ December - 17/Java_tarpandas.java | 63 ++++++++++++++ December - 19/Java_tarpandas.java | 131 ++++++++++++++++++++++++++++++ December - 21/Java_tarpandas.java | 28 +++++++ 4 files changed, 283 insertions(+) create mode 100644 December - 15/Java_tarpandas.java create mode 100644 December - 17/Java_tarpandas.java create mode 100644 December - 19/Java_tarpandas.java create mode 100644 December - 21/Java_tarpandas.java diff --git a/December - 15/Java_tarpandas.java b/December - 15/Java_tarpandas.java new file mode 100644 index 0000000..814a8dc --- /dev/null +++ b/December - 15/Java_tarpandas.java @@ -0,0 +1,61 @@ +import java.util.*; +class Detail{ + String name; + String timestamp; + Detail(String name, String timestamp){ + this.name = name; + this.timestamp = timestamp; + } +} + +class Sortbytimestamp implements Comparator +{ + public int compare(Detail a, Detail b){ + int hhmmssA = Integer.parseInt(a.timestamp.replace(":","")); + int hhmmssB = Integer.parseInt(b.timestamp.replace(":","")); + return hhmmssA - hhmmssB; + } +} + +class Java_tarpandas{ + public Queue murderersMeet(List list){ + Collections.sort(list, new Sortbytimestamp()); + + Queue queue=new LinkedList<>(); + for(Detail d : list){ + queue.add(d.name); + } + + return queue; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + List list=new ArrayList<>(); + String name, timestamp; + // input type: + // Name hh:mm:ss + for(int i=0;i<3;i++){ + name = sc.next(); + while(true){ + timestamp = sc.next(); + String[] hhmmss = timestamp.split(":"); + if(Integer.parseInt(hhmmss[0])>24 || Integer.parseInt(hhmmss[1])>59 || Integer.parseInt(hhmmss[2])>59){ + System.out.println("Invalid Timestamp!! Enter again ..."); + }else{ + break; + } + } + list.add(new Detail(name,timestamp)); + } + + Java_tarpandas ob=new Java_tarpandas(); + Queue queue = ob.murderersMeet(list); + + System.out.println(""); + System.out.print(queue); + + sc.close(); + } +} \ No newline at end of file diff --git a/December - 17/Java_tarpandas.java b/December - 17/Java_tarpandas.java new file mode 100644 index 0000000..65a9561 --- /dev/null +++ b/December - 17/Java_tarpandas.java @@ -0,0 +1,63 @@ +import java.util.*; +public class Java_tarpandas{ + public List zigzagConversion(String str, int row){ + int length = str.length(); + char[] characters; + List list=new ArrayList<>(); + int j=0; + int c = row - 2; + while(j=1){ + characters = new char[row]; + if(j==length){ + break; + } + for(int i=0;i alphabetCount(String str){ + str = str.toLowerCase(); + int length = str.length(); + List list = new ArrayList<>(); + for(int i=97;i<=122;i++){ + int count=0; + for(int j=0;j0){ + list.add(new AlphabetDetail((char)i,count)); + } + } + return list; + } + + public List makingDummyObjectList(List list){ + List dummy = new ArrayList<>(); + for(AlphabetDetail l : list){ + dummy.add(new AlphabetDetail(l.alphabet, l.count)); + } + return dummy; + } + + public String findAnagram(String str, List list, List dummy){ + String anagram = ""; + String flag = ""; + str = str.toLowerCase() + ' '; + int length = str.length(); + int i = 0; + boolean alphabetCountChanged = false; + while(i list = ob.alphabetCount(str2); + List dummy = ob.makingDummyObjectList(list); + String anagram = ob.findAnagram(str1,list,dummy); + + System.out.println(""); + System.out.println(""); + System.out.println(anagram.length() == 0? "No Anagram" : anagram); + } +} \ No newline at end of file diff --git a/December - 21/Java_tarpandas.java b/December - 21/Java_tarpandas.java new file mode 100644 index 0000000..0c274db --- /dev/null +++ b/December - 21/Java_tarpandas.java @@ -0,0 +1,28 @@ +import java.util.*; +public class Java_tarpandas{ + public void move(int n, String left, String right, String middle){ + if(n == 1){ + System.out.println("Move disk "+n+" from tower "+left+" to tower "+right); + } + else{ + move(n-1,left,middle,right); + System.out.println("Move disk "+n+" from tower "+left+" to tower "+right); + move(n-1,middle,right,left); + } + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.print("Number of discs: "); + int n = sc.nextInt(); + + Java_tarpandas ob=new Java_tarpandas(); + + System.out.println(""); + System.out.println(""); + System.out.println("The sequence of moves :"); + ob.move(n,"I","III","II"); + sc.close(); + } +} \ No newline at end of file From af76435ca3f5563aa0082f0a616266aa40cb35ee Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:24:49 +0530 Subject: [PATCH 274/408] added December 1 - William Butcher's Mission --- December - 01/C++_MugundhanY.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 December - 01/C++_MugundhanY.cpp diff --git a/December - 01/C++_MugundhanY.cpp b/December - 01/C++_MugundhanY.cpp new file mode 100644 index 0000000..1299b90 --- /dev/null +++ b/December - 01/C++_MugundhanY.cpp @@ -0,0 +1,25 @@ +// Question 1: +#include +using namespace std; + +string hexToASCII(string hex){ + string ascii = ""; + for (size_t i = 0; i < hex.length(); i += 2){ + string part = hex.substr(i, 2); + char ch = stoul(part, nullptr, 16); + ascii += ch; + } + return ascii; +} + +int main(){ + int n; + cin >> n; + while(n>0){ + string a; + cin >> a; //Give input as a single word. + cout << hexToASCII(a) << endl; + n--; + } + return 0; +} From b1a6e52aa194247ab74ad9f2a482fd333ad2f442 Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:26:36 +0530 Subject: [PATCH 275/408] added December 2 - The Secret Language --- December - 02/C++_MugundhanY.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 December - 02/C++_MugundhanY.cpp diff --git a/December - 02/C++_MugundhanY.cpp b/December - 02/C++_MugundhanY.cpp new file mode 100644 index 0000000..c580a49 --- /dev/null +++ b/December - 02/C++_MugundhanY.cpp @@ -0,0 +1,19 @@ +// Question 2: +#include +using namespace std; + +string piglatin (string s){ + int len = s.length (); + s.resize (len - 2); + string part = s.substr(s.size()-2, s.size()-1); + + return part + s.substr (0, s.size()-2); +} + +int main (){ + string str; + cin >> str; + string word = piglatin (str); + cout << word; + return 0; +} From 6bd374cb9b898e29211d3d50e6a31b8c21c870ca Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:27:46 +0530 Subject: [PATCH 276/408] added December 3 - Minesweeper --- December - 03/C++_MugundhanY.cpp | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 December - 03/C++_MugundhanY.cpp diff --git a/December - 03/C++_MugundhanY.cpp b/December - 03/C++_MugundhanY.cpp new file mode 100644 index 0000000..996e2ee --- /dev/null +++ b/December - 03/C++_MugundhanY.cpp @@ -0,0 +1,47 @@ +//Question 3: +#include +using namespace std; + +int count(char a){ + if(a == '#'){ + return 1; + } + return 0; +} + +void FindTheBomb( vector>arr, int row, int col){ + for(size_t i=0; i> col; + cin >> row; + vector> arr(row+1, vector(col+1,0)); + + for(int i=0; i> arr[i][j]; + } + } + + FindTheBomb(arr,row,col); + + return 0; +} From 41b78375905a765fc9587762ddc10c0bbb08cedc Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:29:10 +0530 Subject: [PATCH 277/408] added December 4 - Industry --- December - 04/C++_MugundhanY.cpp | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 December - 04/C++_MugundhanY.cpp diff --git a/December - 04/C++_MugundhanY.cpp b/December - 04/C++_MugundhanY.cpp new file mode 100644 index 0000000..88090b0 --- /dev/null +++ b/December - 04/C++_MugundhanY.cpp @@ -0,0 +1,39 @@ +//Question 4: +#include +using namespace std; + +//Kadane's Algorithm +void maxProfit(int prices[], int n) { + int sum = 0, profit=INT_MIN, sellday, buyday=1; + for(int i=0; i> n; + cout << "Given stock market change values:"; + int prices[n]; + for(int i=0; i> prices[i]; + } + maxProfit(prices, n); + return 0; +} From 618a2d39eb1759ce4ffc240c6d6674779c3b4885 Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:30:03 +0530 Subject: [PATCH 278/408] =?UTF-8?q?added=20December=205=20-=20Don=E2=80=99?= =?UTF-8?q?t=20let=20Mason=20misspend!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- December - 05/C++_MugundhanY.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 December - 05/C++_MugundhanY.cpp diff --git a/December - 05/C++_MugundhanY.cpp b/December - 05/C++_MugundhanY.cpp new file mode 100644 index 0000000..8633626 --- /dev/null +++ b/December - 05/C++_MugundhanY.cpp @@ -0,0 +1,29 @@ +//Question 5: +#include +using namespace std; + +void expenditure(int &fuelprice) { + int Expenditure = 0; + for(int i=1; i<=31; i++){ + if(i%3 == 0 && i%5==0){ + Expenditure += (fuelprice+1)*2; + } else if((i%5)==0){ + Expenditure += (fuelprice-2)*2; + } else if ((i%3)==0){ + Expenditure += (fuelprice+3)*2; + } else { + Expenditure += fuelprice*2; + } + } + cout << "Expenditure=" << Expenditure << endl; + if(Expenditure > 5000) cout << "“EXPENDITURE EXCEEDING LIMIT”"; + else cout << "“EXPENDITURE WITHIN LIMIT”"; +} + +int main(){ + cout << "fuel_price="; + int fuelprice; + cin >> fuelprice; + expenditure(fuelprice); + return 0; +} From 5388ecfa38fd72f80c265cd55a81b228c87e4ced Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:31:07 +0530 Subject: [PATCH 279/408] added December 6 - Swapped --- December - 06/C++_MugundhanY.cpp | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 December - 06/C++_MugundhanY.cpp diff --git a/December - 06/C++_MugundhanY.cpp b/December - 06/C++_MugundhanY.cpp new file mode 100644 index 0000000..040307c --- /dev/null +++ b/December - 06/C++_MugundhanY.cpp @@ -0,0 +1,47 @@ +//Question 6: +#include +using namespace std; + +void swapped(int n, int arr[], string name1){ + + int turns = 0; + string name2; + + if(name1 == "Bob") name2 = "Tanika"; + else name2 = "Bob"; + + while(arr[0]>0){ + arr[0] -= 1; + swap(arr[0], arr[n-1]); + turns++; + } + + if(turns % 2 != 0) cout << name1; + else cout << name2; + cout << " wins the game!" << endl; + + if(turns % 2 != 0) cout << name2; + else cout << name1; + cout << " loses the game!"; + +} + +int main() { + cout << "Position="; + int position; + cin >> position; + + cout << "Set of numbers:"; + int arr[position]; + for(int i=0; i> arr[i]; + } + + cout << "Player going first:"; + string name; + cin >> name; + + swapped(position, arr, name); + + return 0; +} From e38e72eb1420e4b14cfe66e20a4cf872aab145a3 Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:32:06 +0530 Subject: [PATCH 280/408] added December 7 - Word Map --- December - 07/C++_MugundhanY.cpp | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 December - 07/C++_MugundhanY.cpp diff --git a/December - 07/C++_MugundhanY.cpp b/December - 07/C++_MugundhanY.cpp new file mode 100644 index 0000000..b35d91e --- /dev/null +++ b/December - 07/C++_MugundhanY.cpp @@ -0,0 +1,53 @@ +//Question 7: +#include +using namespace std; + +int x[] = { -1, 0, 0, 1}; +int y[] = { 0, -1, 1, 0}; + +bool search2D(char *grid, int row, int col, string word, int R, int C){ + if (*(grid+row*C+col) != word[0]) + return false; + + int len = word.length(); + + for (int dir = 0; dir < 4; dir++) { + int k, rd = row + x[dir], cd = col + y[dir]; + + for (k = 1; k < len; k++) { + if (rd >= R || rd < 0 || cd >= C || cd < 0) + break; + + if (*(grid+rd*C+cd) != word[k]) + break; + + rd += x[dir], cd += y[dir]; + } + + + if (k == len) + return true; + } + return false; +} + + +void patternSearch(char *grid, string word, int R, int C){ + for (int row = 0; row < R; row++) + for (int col = 0; col < C; col++) + if(search2D(grid, row, col, word, R, C)){ + cout << "Found"; + return; + } + cout << "Not Found"; +} + +int main(){ + int R = 15, C = 15; + char grid[R][C] = {"ASSERTIVENESSLJ","CFOGOODPOSITIVE","OPENBMUREWOPRPS","MEDIATIONELDIOG", "MAASREGJEWINWIN", "UCIAEMOEECSKENI", "NEMRSHACDVTWTTL", "ITEHOTLTSTERAOE", "CASPLGLSIUNERFE", "AISAUSYTPOISEVF", "TTARTTDOCENPPIH", "IOGAIGUPYMGOOEE", "OGEPOAFPQIENOWA", "NECONFLICTSDCER", "FNHTCATNOCEYEBT"}; + + string word; + cin >> word; + patternSearch((char *)grid, word, R, C); + return 0; +} From 8d13497001937b80aece33ec2286a5f13ee1c4fd Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:33:08 +0530 Subject: [PATCH 281/408] added December 8 - Aptitude Check! --- December - 08/C++_MugundhanY.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 December - 08/C++_MugundhanY.cpp diff --git a/December - 08/C++_MugundhanY.cpp b/December - 08/C++_MugundhanY.cpp new file mode 100644 index 0000000..97d8e10 --- /dev/null +++ b/December - 08/C++_MugundhanY.cpp @@ -0,0 +1,19 @@ +//Question 8: +#include +using namespace std; + +void reverseword(string word){ + + for (size_t i = 0; i < word.length(); i += 2){ + string part = word.substr(i, 2); + reverse(part.begin(), part.end()); + cout << part; + } +} + +int main(){ + string a; + cin >> a; + reverseword(a); + return 0; +} From 42ecf464261ed9e39ddb64e6bad27541373adb27 Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:34:10 +0530 Subject: [PATCH 282/408] added December 9 - Kochouseph Konundrum! --- December - 09/C++_MugundhanY.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 December - 09/C++_MugundhanY.cpp diff --git a/December - 09/C++_MugundhanY.cpp b/December - 09/C++_MugundhanY.cpp new file mode 100644 index 0000000..0a72892 --- /dev/null +++ b/December - 09/C++_MugundhanY.cpp @@ -0,0 +1,28 @@ +//Question 9: +#include +using namespace std; + +void randomword(string word[], int n){ + string temp; + for(size_t i = 0; i < n; i++){ + if(word[i].size()%2 != 0){ + if(temp.size() < word[i].size()){ + temp = word[i]; + } + } + } + if(temp.empty()) cout << "Better luck next time"; + else cout << temp; +} + +int main(){ + int n; + cin >> n; + + string word[n]; + for(int i=0; i> word[i]; + } + randomword(word, n); + return 0; +} From c59ca1ed66a24fab07256a669f5b173dc1e7fca4 Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:34:56 +0530 Subject: [PATCH 283/408] added December 10 - Play with words --- December - 10/C++_MugundhanY.cpp | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 December - 10/C++_MugundhanY.cpp diff --git a/December - 10/C++_MugundhanY.cpp b/December - 10/C++_MugundhanY.cpp new file mode 100644 index 0000000..66935fa --- /dev/null +++ b/December - 10/C++_MugundhanY.cpp @@ -0,0 +1,38 @@ +//Question 10: +#include +using namespace std; + +void pronounce(char word[], int n){ + int count = 0; + for(size_t i = 0; i < n; i++){ + if(word[i] != 'a' && word[i] != 'e' && word[i] != 'i' && word[i] != 'o' && word[i] != 'u'){ + count++; + if(count == 4){ + cout << "NO" <> T; + + while(T>0){ + int n; + cin >> n; + + char word[n]; + for(int i=0; i> word[i]; + } + + pronounce(word, n); + T--; + } + return 0; +} From 9aaf12a704949514400499d5a4cdaf53c206a311 Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:36:16 +0530 Subject: [PATCH 284/408] added December 11 - Monkey jump --- December - 11/C++_MugundhanY.cpp | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 December - 11/C++_MugundhanY.cpp diff --git a/December - 11/C++_MugundhanY.cpp b/December - 11/C++_MugundhanY.cpp new file mode 100644 index 0000000..c1b380d --- /dev/null +++ b/December - 11/C++_MugundhanY.cpp @@ -0,0 +1,43 @@ +//Question 11: +#include +using namespace std; + +int count1(char character[]){ + for(int i=0; i<100000; i++){ + if(character[i]=='1' || character[i]=='2') return i; + } + return 0; +} + +int count2(char character[]){ + for(int i=0; i<100000; i++){ + if(character[i]=='\0') return i; + } + return 0; +} + +int monkeycount(char character[], int n1, int n2, int jump[]){ + int pos = 0; + for(int i =0; i> character[i]; + } + + int n1 = count1(character); + int n2 = count2(character); + int jump[n2-n1]; + for(int i = n1; i Date: Thu, 12 Jan 2023 18:37:06 +0530 Subject: [PATCH 285/408] added December 12 - Shez in a Maze! --- December - 12/C++_MugundhanY.cpp | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 December - 12/C++_MugundhanY.cpp diff --git a/December - 12/C++_MugundhanY.cpp b/December - 12/C++_MugundhanY.cpp new file mode 100644 index 0000000..44c632e --- /dev/null +++ b/December - 12/C++_MugundhanY.cpp @@ -0,0 +1,66 @@ +//Question 12: +#include +using namespace std; + +class Solution +{ + public: + int minimumCostPath(vector>& grid){ + + int n=grid.size(); + int m=grid[0].size(); + int ans=0; + int dist[n][m]; + for(int i=0; i>, vector>>, greater>>>pq; + dist[0][0]=grid[0][0]; + pq.push({dist[0][0], {0, 0}}); + int dx[4]={0, 0, -1, 1}; + int dy[4]={-1, 1, 0, 0}; + while(pq.empty()==false){ + auto x=pq.top(); pq.pop(); + int cost=x.first; + auto y=x.second; + int i=y.first; + int j=y.second; + ans+=cost; + if(i==n-1 && j==m-1){ + break; + } + for(int k=0; k<4; k++){ + int u=i+dx[k]; + int v=j+dy[k]; + if(u>=0 && u=0 && v=dist[i][j]+ grid[u][v]){ + dist[u][v]=dist[i][j]+grid[u][v]; + pq.push({dist[u][v], {u, v}}); + } + } + } + } + return dist[n-1][m-1]; + } +}; + +int main(){ + int tc; + cin >> tc; + while(tc--){ + int n; + cin >> n; + vector>grid(n, vector(n, -1)); + for(int i = 0; i < n; i++){ + for(int j = 0; j < n; j++){ + cin >> grid[i][j]; + } + } + Solution obj; + int ans = obj.minimumCostPath(grid); + cout << ans << "\n"; + } + return 0; +} From 28446ffdb0a740775e4146ad2c822218f2033ff1 Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:38:25 +0530 Subject: [PATCH 286/408] added December 13 - The Labyrinth --- December - 13/C++_MugundhanY.cpp | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 December - 13/C++_MugundhanY.cpp diff --git a/December - 13/C++_MugundhanY.cpp b/December - 13/C++_MugundhanY.cpp new file mode 100644 index 0000000..7b7f0ef --- /dev/null +++ b/December - 13/C++_MugundhanY.cpp @@ -0,0 +1,57 @@ +//Question 13: +#include +using namespace std; + +bool issafe(int** arr, int x, int y, int n){ + if(x>n; + int** arr=new int*[n]; + for(int i=0; i>arr[i][j]; + } + } + int** solArr=new int*[n]; + for(int i=0; i Date: Thu, 12 Jan 2023 18:39:06 +0530 Subject: [PATCH 287/408] added December 14 - Math Mystery --- December - 14/C++_MugundhanY.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 December - 14/C++_MugundhanY.cpp diff --git a/December - 14/C++_MugundhanY.cpp b/December - 14/C++_MugundhanY.cpp new file mode 100644 index 0000000..1ce7250 --- /dev/null +++ b/December - 14/C++_MugundhanY.cpp @@ -0,0 +1,29 @@ +//Question 14: +#include +using namespace std; + +bool isBipartite(int n, vector> &arr){ + for(int i=0; i>n; + int temp; + vector> arr; + for(int i=0; i row; + for(int j=0; j>temp; + row.push_back(temp); + } + arr.push_back(row); + } + if(isBipartite(n, arr)) cout << "The graph is Bipartite!"; + else cout << "The graph is not a Bipartite!"; + return 0; +} From 9f074fab611139990c0aece9b6376704839c132f Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:40:14 +0530 Subject: [PATCH 288/408] added December 15 - THE MURDERERS MEET --- December - 15/C++_MugundhanY.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 December - 15/C++_MugundhanY.cpp diff --git a/December - 15/C++_MugundhanY.cpp b/December - 15/C++_MugundhanY.cpp new file mode 100644 index 0000000..0e4453f --- /dev/null +++ b/December - 15/C++_MugundhanY.cpp @@ -0,0 +1,31 @@ +//Question 15: +#include +using namespace std; + +void timediff (string arr[3][2]){ + for(int i = 0; i < 3; i++){ + for(int j = i + 1; j < 3; j++){ + if(arr[j][1] < arr[i][1]){ + swap (arr[j][1], arr[i][1]); + swap (arr[j][0], arr[i][0]); + } + } + } +} + +int main (){ + string arr[3][2]; + for(int i = 0; i < 3; i++){ + for (int j = 0; j < 2; j++){ + cin >> arr[i][j]; + } + } + + timediff (arr); + + cout << arr[0][0] << ","; + cout << " " << arr[1][0] << ","; + cout << " " << arr[2][0] << "."; + + return 0; +} From 653c5b2fce9311ee6a457d494c4c9e30c9f98ede Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:41:12 +0530 Subject: [PATCH 289/408] added December 16 - H2O Receptacle --- December - 16/C++_MugundhanY.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 December - 16/C++_MugundhanY.cpp diff --git a/December - 16/C++_MugundhanY.cpp b/December - 16/C++_MugundhanY.cpp new file mode 100644 index 0000000..3dfdfda --- /dev/null +++ b/December - 16/C++_MugundhanY.cpp @@ -0,0 +1,31 @@ +//Question 16: +#include +using namespace std; + +int getinputno(int hist[10000]){ + for(int i=0 ;i<10000; i++){ + if(hist[i] == 0 && hist[i+1] == 0 && hist[i+2] == 0) return i; + } +} + +int getMaxArea(int arr[], int n){ + int maxarea; + for(int i = n-1;i>=0; i--){ + for(int j = 0; j> hist[i]; + } + int n = getinputno(hist); + + cout << getMaxArea(hist, n); + return 0; +} From 7d21ad7bff7039c0b6b425c7ef1cf640dc5cce48 Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:41:49 +0530 Subject: [PATCH 290/408] added December 17 - Zig Zag Conversion --- December - 17/C++_MugundhanY.cpp | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 December - 17/C++_MugundhanY.cpp diff --git a/December - 17/C++_MugundhanY.cpp b/December - 17/C++_MugundhanY.cpp new file mode 100644 index 0000000..dc5753a --- /dev/null +++ b/December - 17/C++_MugundhanY.cpp @@ -0,0 +1,41 @@ +//Question 17: +#include +using namespace std; + +string convert(string s, int numRows){ + int n = numRows; + string str; + if(n == 0 || n == 1) return s; + + for(int i = 0; i < s.length(); i += (n-1)*2){ + str += s[i]; + } + + for(int j = 1; j < n-1; j++){ + bool goDown = true; + for(int i = j; i < s.length();){ + str += s[i]; + if(goDown){ + i+=(n-j-1)*2; + }else{ + i+=(n-1)*2-(n-j-1)*2; + } + goDown = !goDown; + } + + } + + for(int i = n-1; i < s.length(); i += (n-1)*2){ + str += s[i]; + } + return str; +} + +int main(){ + string s; + cin >> s; + int numRows; + cin >> numRows; + cout << convert(s, numRows); + return 0; +} From dd99cfe1f1221d9c95b1305d74e43c15962880e6 Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:43:18 +0530 Subject: [PATCH 291/408] added December 18 - Find the way --- December - 18/C++_MugundhanY.cpp | 197 +++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 December - 18/C++_MugundhanY.cpp diff --git a/December - 18/C++_MugundhanY.cpp b/December - 18/C++_MugundhanY.cpp new file mode 100644 index 0000000..4f55a19 --- /dev/null +++ b/December - 18/C++_MugundhanY.cpp @@ -0,0 +1,197 @@ +//Question 18: +#include + +#define INT_MAX 10000000 + +using namespace std; + +void DijkstrasTest(char a); + +int main() { + char a; + cin >> a; + DijkstrasTest(a); + return 0; +} + +class Node; +class Edge; + +void Dijkstras(); +vector* AdjacentRemainingNodes(Node* node); +Node* ExtractSmallest(vector& nodes); +int Distance(Node* node1, Node* node2); +bool Contains(vector& nodes, Node* node); +void PrintShortestRouteTo(Node* destination); + +vector nodes; +vector edges; + +class Node { + public: + Node(char id) + : id(id), previous(NULL), distanceFromStart(INT_MAX) { + nodes.push_back(this); + } + + public: + char id; + Node* previous; + int distanceFromStart; +}; + +class Edge { + public: + Edge(Node* node1, Node* node2, int distance) + : node1(node1), node2(node2), distance(distance) { + edges.push_back(this); + } + bool Connects(Node* node1, Node* node2) { + return ( + (node1 == this->node1 && + node2 == this->node2) || + (node1 == this->node2 && + node2 == this->node1)); + } + + public: + Node* node1; + Node* node2; + int distance; +}; + + +void DijkstrasTest(char a) { + Node* P = new Node('P'); + Node* Q = new Node('Q'); + Node* R = new Node('R'); + Node* S = new Node('S'); + Node* T = new Node('T'); + Node* U = new Node('U'); + Node* V = new Node('V'); + Node* W = new Node('W'); + + Edge* e1 = new Edge(P, Q, 3); + Edge* e2 = new Edge(Q, U, 5); + Edge* e3 = new Edge(U, W, 2); + Edge* e4 = new Edge(P, S, 5); + Edge* e5 = new Edge(S, T, 2); + Edge* e6 = new Edge(T, V, 4); + Edge* e7 = new Edge(V, W, 1); + Edge* e8 = new Edge(P, R, 4); + Edge* e9 = new Edge(R, U, 6); + Edge* e10 = new Edge(Q, R, 2); + Edge* e11 = new Edge(S, R, 7); + Edge* e12 = new Edge(R, T, 3); + Edge* e13 = new Edge(R, V, 2); + Edge* e14 = new Edge(U, V, 5); + + W->distanceFromStart = 0; + Dijkstras(); + if(a=='P')PrintShortestRouteTo(P); + if(a=='Q')PrintShortestRouteTo(Q); + if(a=='R')PrintShortestRouteTo(R); + if(a=='S')PrintShortestRouteTo(S); + if(a=='T')PrintShortestRouteTo(T); + if(a=='U')PrintShortestRouteTo(U); + if(a=='V')PrintShortestRouteTo(V); + if(a=='W')PrintShortestRouteTo(W); +} + +void Dijkstras() { + while (nodes.size() > 0) { + Node* smallest = ExtractSmallest(nodes); + vector* adjacentNodes = + AdjacentRemainingNodes(smallest); + + const int size = adjacentNodes->size(); + for (int i = 0; i < size; ++i) { + Node* adjacent = adjacentNodes->at(i); + int distance = Distance(smallest, adjacent) + + smallest->distanceFromStart; + + if (distance < adjacent->distanceFromStart) { + adjacent->distanceFromStart = distance; + adjacent->previous = smallest; + } + } + delete adjacentNodes; + } +} + +Node* ExtractSmallest(vector& nodes) { + int size = nodes.size(); + if (size == 0) return NULL; + int smallestPosition = 0; + Node* smallest = nodes.at(0); + for (int i = 1; i < size; ++i) { + Node* current = nodes.at(i); + if (current->distanceFromStart < + smallest->distanceFromStart) { + smallest = current; + smallestPosition = i; + } + } + nodes.erase(nodes.begin() + smallestPosition); + return smallest; +} + +vector* AdjacentRemainingNodes(Node* node) { + vector* adjacentNodes = new vector(); + const int size = edges.size(); + for (int i = 0; i < size; ++i) { + Edge* edge = edges.at(i); + Node* adjacent = NULL; + if (edge->node1 == node) { + adjacent = edge->node2; + } else if (edge->node2 == node) { + adjacent = edge->node1; + } + if (adjacent && Contains(nodes, adjacent)) { + adjacentNodes->push_back(adjacent); + } + } + return adjacentNodes; +} + +int Distance(Node* node1, Node* node2) { + const int size = edges.size(); + for (int i = 0; i < size; ++i) { + Edge* edge = edges.at(i); + if (edge->Connects(node1, node2)) { + return edge->distance; + } + } + return -1; +} + +bool Contains(vector& nodes, Node* node) { + const int size = nodes.size(); + for (int i = 0; i < size; ++i) { + if (node == nodes.at(i)) { + return true; + } + } + return false; +} + +void PrintShortestRouteTo(Node* destination) { + Node* previous = destination; + cout << "Shortest path: "; + while (previous) { + cout << previous-> id << " "; + previous = previous->previous; + } + cout << endl; + cout << "Shortest time: " << destination->distanceFromStart << " hours"<< endl; +} + +void RemoveEdge(vector& edges, Edge* edge) { + vector::iterator it; + for (it = edges.begin(); it < edges.end(); ++it) { + if (*it == edge) { + edges.erase(it); + return; + } + } +} From c31792cef1b4edbfc0c3be0269ecbb78d64e48a7 Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:44:27 +0530 Subject: [PATCH 292/408] added December 19 - Hidden Anagram --- December - 19/C++_MugundhanY.cpp | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 December - 19/C++_MugundhanY.cpp diff --git a/December - 19/C++_MugundhanY.cpp b/December - 19/C++_MugundhanY.cpp new file mode 100644 index 0000000..aa4941c --- /dev/null +++ b/December - 19/C++_MugundhanY.cpp @@ -0,0 +1,47 @@ +//Question 19: +#include +using namespace std; + +void ans(char substring1[], int n1, char substring2[], int n2){ + unordered_map map; + cout << "\""; + for(int i=0; i 0){ + cout << substring1[i]; + map[substring1[i] - 'a']--; + } + } + cout << "\""; +} + +int main(){ + int n1=0, n2=0, n = 3; + char main_string[1000000]; + char substring1[1000000]; + char substring2[1000000]; + for(int i=0; i<1000000; i++){ + cin >> main_string[i]; + } + for(int i=1; i<1000000; i++){ + if(n==0){ + break; + } else if(main_string[i] == '"'){ + n--; + }else if((main_string[i] >= 65 && main_string[i] <= 90) || (main_string[i] >= 97 && main_string[i] <= 122)){ + if(n == 3){ + substring1[n1] = main_string[i]; + n1++; + }else if(n == 1){ + substring2[n2] = main_string[i]; + n2++; + } + } + } + transform(substring1, substring1+n1+1, substring1, ::tolower); + transform(substring2, substring2+n2+1, substring2, ::tolower); + ans(substring1, n1, substring2, n2); + return 0; +} From a62eeb5638c255d371a6b5f3635c57ff35ce0e5d Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:45:36 +0530 Subject: [PATCH 293/408] added December 20 - Code a Subsequence --- December - 20/C++_MugundhanY.cpp | 244 +++++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 December - 20/C++_MugundhanY.cpp diff --git a/December - 20/C++_MugundhanY.cpp b/December - 20/C++_MugundhanY.cpp new file mode 100644 index 0000000..c8991bb --- /dev/null +++ b/December - 20/C++_MugundhanY.cpp @@ -0,0 +1,244 @@ +//Question 20: +#include +using namespace std; +typedef long long mint; + +class any_node{ + public: + mint depth_; + mint max_depth_; + + mint min_a_, max_a_; + mint min_w_, max_w_; + + any_node(mint depth, mint max_depth): depth_(depth), max_depth_(max_depth){ + } + + virtual ~any_node(){ + } + + virtual any_node *ins(any_node *l) = 0; + virtual mint max_w(mint a) = 0; + virtual any_node *drop(mint a, mint w) = 0; +}; + +class node : public any_node{ + public: + bool banzai_; + + any_node *left_; + any_node *right_; + + node(mint depth, mint max_depth, any_node *l, any_node *r): any_node(depth, max_depth), banzai_(true){ + min_a_ = min(l->min_a_, r->min_a_); + max_a_ = max(l->max_a_, r->max_a_); + min_w_ = min(l->min_w_, r->min_w_); + max_w_ = max(l->max_w_, r->max_w_); + + if (l->max_a_ < r->min_a_){ + left_ = l; + right_ = r; + } else { + left_ = r; + right_ = l; + } + } + + virtual ~node(){ + if (banzai_){ + delete left_; + delete right_; + } + } + + virtual any_node *ins(any_node *l){ + ++(l->depth_); + + if (left_->max_a_ > l->min_a_){ + left_ = left_->ins(l); + } else if (right_->min_a_ < l->max_a_){ + right_ = right_->ins(l); + } else if (left_->max_depth_ < right_->max_depth_){ + left_ = left_->ins(l); + } else { + right_ = right_->ins(l); + } + + max_depth_ = max(left_->max_depth_, right_->max_depth_); + + min_a_ = min(left_->min_a_, right_->min_a_); + max_a_ = max(left_->max_a_, right_->max_a_); + min_w_ = min(left_->min_w_, right_->min_w_); + max_w_ = max(left_->max_w_, right_->max_w_); + + return this; + } + + virtual mint max_w(mint a){ + mint left_max_w = (a < left_->min_a_ ? 0 : (a > left_->max_a_ ? left_->max_w_ : left_->max_w(a))); + mint right_max_w = (a < right_->min_a_ ? 0 : (a > right_->max_a_ ? right_->max_w_ : right_->max_w(a))); + + return max(left_max_w, right_max_w); + } + + // does not update depth_ or max_depth_ which might screw up later insertions + virtual any_node *drop(mint a, mint w){ + if ((max_a_ < a) || (min_w_ > w)){ + return this; + } + + left_ = left_->drop(a, w); + right_ = right_->drop(a, w); + + banzai_ = false; + + if ((left_ == NULL) && (right_ == NULL)){ + delete this; + + return NULL; + } else if ((left_ == NULL) && (right_ != NULL)){ + delete this; + + return right_; + } else if ((left_ != NULL) && (right_ == NULL)){ + delete this; + + return left_; + } else { + min_a_ = min(left_->min_a_, right_->min_a_); + max_a_ = max(left_->max_a_, right_->max_a_); + min_w_ = min(left_->min_w_, right_->min_w_); + max_w_ = max(left_->max_w_, right_->max_w_); + + banzai_ = true; + + return this; + } + } +}; + +class leaf : public any_node{ + public: + + leaf(mint depth, mint max_depth): any_node(depth, max_depth){ + } + + virtual ~leaf(){ + } + + virtual any_node *ins(any_node *l){ + if (l->min_a_ == min_a_){ + min_w_ = max_w_ = max(l->min_w_, max_w_); + + delete l; + + return this; + } + + ++(l->depth_); + ++(l->max_depth_); + + return new node(depth_++, max_depth_++, this, l); + } + + virtual mint max_w(mint a){ + return a > max_a_ ? max_w_ : 0; + } + + virtual any_node *drop(mint a, mint w){ + if ((max_a_ <= a) || (max_w_ > w)){ + return this; + } + + delete this; + + return NULL; + } +}; + +class tree{ + public: + + any_node *root_; + + tree(): root_(NULL){ + } + + ~tree(){ + if (root_ != NULL){ + delete root_; + } + } + + void prc(mint a, mint w){ + mint wmax = max_w(a) + w; + drop(a, wmax); + ins(a, wmax); + } + + void ins(mint a, mint w){ + leaf *nl = new leaf(0, 0); + + nl->min_a_ = nl->max_a_ = a; + nl->min_w_ = nl->max_w_ = w; + + if (root_ == NULL){ + root_ = nl; + + return; + } + + root_ = root_->ins(nl); + } + + mint max_w(mint a){ + if (root_ == NULL){ + return 0; + } + + return root_->max_w(a); + } + + void drop(mint a, mint w){ + if (root_ == NULL){ + return; + } + + root_ = root_->drop(a, w); + } +}; + +int main(){ + mint c; + + cin >> c; + + for (; c; --c){ + mint n; + + cin >> n; + + mint *a = new mint[n]; + mint *w = new mint[n]; + + for (mint i = 0; i != n; ++i){ + cin >> a[i]; + } + + for (mint i = 0; i != n; ++i){ + cin >> w[i]; + } + + tree tr; + + for (mint i = 0; i != n; ++i){ + tr.prc(a[i], w[i]); + } + + cout << tr.root_->max_w_ << endl; + + delete[] a; + delete[] w; + } + return 0; +} From 663237aa0f1647f7a2a79844c65b5072d10e454a Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:46:29 +0530 Subject: [PATCH 294/408] added December 21 - The Devil Towers --- December - 21/C++_MugundhanY.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 December - 21/C++_MugundhanY.cpp diff --git a/December - 21/C++_MugundhanY.cpp b/December - 21/C++_MugundhanY.cpp new file mode 100644 index 0000000..98401e3 --- /dev/null +++ b/December - 21/C++_MugundhanY.cpp @@ -0,0 +1,19 @@ +//Question 21: +#include +using namespace std; + +void towerOfHanoi(int totalDisc, string A, string B, string C){ + if(totalDisc > 0) + { + towerOfHanoi(totalDisc-1, A, C, B); + cout << "Move disk " << totalDisc << " from tower " << A << " to tower " << C << endl; + towerOfHanoi(totalDisc-1, B, A, C); + } +} + +int main(){ + int totalDisc; + cin >> totalDisc; + towerOfHanoi(totalDisc, "I", "II", "III"); + return 0; +} From 1de53d555e57c07bf83862bf3ae437b4da84a650 Mon Sep 17 00:00:00 2001 From: MugundhanY <122536258+MugundhanY@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:47:27 +0530 Subject: [PATCH 295/408] added December 22 - The Markowitz Paradox --- December - 22/C++_MugundhanY.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 December - 22/C++_MugundhanY.cpp diff --git a/December - 22/C++_MugundhanY.cpp b/December - 22/C++_MugundhanY.cpp new file mode 100644 index 0000000..7cbbd1b --- /dev/null +++ b/December - 22/C++_MugundhanY.cpp @@ -0,0 +1,24 @@ +//Question 22: +#include +using namespace std; + +void TheMarkowitzParadox(char a, char b){ + int c = a - 'A'; + int e = ((int(b) + c)-65)%26; + char d = 65 + e; + cout << d; + } +int main(){ + string a, b; + cin >> a; + cin >> b; + char* a1 = &a[0]; + char* b1 = &b[0]; + int n1 = a.size(), n2 = b.size(), x=0, i=0; + while(i Date: Sat, 14 Jan 2023 12:55:11 +0530 Subject: [PATCH 296/408] solved 10 question --- December - 01/cpp_abhi-atg.cpp | 48 +++++++++++++++++++++++ December - 02/cpp_abhi-atg.cpp | 25 ++++++++++++ December - 03/cpp_abhi-atg.cpp | 71 ++++++++++++++++++++++++++++++++++ December - 04/cpp_abhi-atg.cpp | 42 ++++++++++++++++++++ December - 05/cpp_abhi-atg.cpp | 22 +++++++++++ December - 06/cpp_abhi-atg.cpp | 30 ++++++++++++++ December - 07/cpp_abhi-atg.cpp | 64 ++++++++++++++++++++++++++++++ December - 08/cpp_abhi-atg.cpp | 22 +++++++++++ December - 09/cpp_abhi-atg.cpp | 29 ++++++++++++++ December - 10/cpp_abhi-atg.cpp | 36 +++++++++++++++++ 10 files changed, 389 insertions(+) create mode 100644 December - 01/cpp_abhi-atg.cpp create mode 100644 December - 02/cpp_abhi-atg.cpp create mode 100644 December - 03/cpp_abhi-atg.cpp create mode 100644 December - 04/cpp_abhi-atg.cpp create mode 100644 December - 05/cpp_abhi-atg.cpp create mode 100644 December - 06/cpp_abhi-atg.cpp create mode 100644 December - 07/cpp_abhi-atg.cpp create mode 100644 December - 08/cpp_abhi-atg.cpp create mode 100644 December - 09/cpp_abhi-atg.cpp create mode 100644 December - 10/cpp_abhi-atg.cpp diff --git a/December - 01/cpp_abhi-atg.cpp b/December - 01/cpp_abhi-atg.cpp new file mode 100644 index 0000000..d5667f1 --- /dev/null +++ b/December - 01/cpp_abhi-atg.cpp @@ -0,0 +1,48 @@ +#include +using namespace std; +/* Abhi-Atg */ + +int check(char &c){ + if(c=='F'){ + return 15; + }else if(c=='E'){ + return 14; + }else if(c=='D'){ + return 13; + }else if(c=='C'){ + return 12; + }else if(c=='B'){ + return 11; + }else if(c=='A'){ + return 10; + } + return (int)(c-'0'); +} + +char solve(string &s){ + return (char)(check(s[0])*16+check(s[1])); +} + +int main(){ + + int n;cin>>n; + while(n--){ + fflush(stdin); + string s; + getline(cin,s); + string ans; + int len=s.size(); + string c; + for(int i=0;i +using namespace std; +/* Abhi-Atg */ + + +int main(){ + + string s;cin>>s; + s.pop_back(); + s.pop_back(); + string ans; + ans.push_back(s.back()); + s.pop_back(); + ans.push_back(s.back()); + s.pop_back(); + reverse(ans.begin(),ans.end()); + reverse(s.begin(),s.end()); + while(s.size()){ + ans.push_back(s.back()); + s.pop_back(); + } + cout< +using namespace std; +/* Abhi-Atg */ + + +int main(){ + + int n;cin>>n; + vector v; + fflush(stdin); + for(int i=0;i ans=v; + for(int i=0;i=0 && ans[i-1][j]!='#'){ + ans[i-1][j]++; + } + if(i+1=0 && ans[i][j-5]!='#'){ + ans[i][j-5]++; + } + if(j+5=0 && j-5>=0 && ans[i-1][j-5]!='#'){ + ans[i-1][j-5]++; + } + if(i-1>=0 && j+5=0 && ans[i+1][j-5]!='#'){ + ans[i+1][j-5]++; + } + if(i+1 +using namespace std; +/* Abhi-Atg */ + + +int main(){ + + int n;cin>>n; + vector arr(n); + for(int i=0;i>arr[i]; + } + + int sum=0; + int l=1; + int ansl,ansr; + ansl=ansr=0; + int tmp=0; + for(int i=0;isum){ + sum=tmp; + ansl=l; + ansr=i+1; + } + } + + cout<<"Profit Value: "< +using namespace std; +/* Abhi-Atg */ + + +int main(){ + + int n;cin>>n; + int tmp=62*n+60-24; + cout<<"Expenditure: "< +using namespace std; +/* Abhi-Atg */ + + +int main(){ + + int pos;cin>>pos; + int n=pos; + vector arr(pos); + for(int i=0;i>arr[i]; + } + int flag=0; + for(int i=1;i +using namespace std; +/* Abhi-Atg */ + + +int main(){ + + int n=15; + vector v; + for(int i=0;i>s; + v.push_back(s); + } + + string s;cin>>s; + int len=s.size(); + int flag=0; + for(int i=0;i +using namespace std; +/* Abhi-Atg */ + + +int main(){ + + string s;cin>>s; + string ans; + int n=s.size(); + for(int i=0;i +using namespace std; +/* Abhi-Atg */ + + +int main(){ + + int n;cin>>n; + string ans; + + for(int i=0;i>s; + if(s.size()&1){ + if(ans.size() +using namespace std; +/* Abhi-Atg */ + + +int main(){ + + int t;cin>>t; + string c="aeiou"; + while(t--){ + int n;cin>>n; + string s;cin>>s; + int cnt=-1; + int flag=0; + for(int i=0;i=4){ + flag=1; + } + } + if(flag){ + cout<<"NO\n"; + }else{ + cout<<"YES\n"; + } + } + + + + return 0; +} \ No newline at end of file From b948d4d1b1e68cdf4c644c3f624b543a1a74685a Mon Sep 17 00:00:00 2001 From: Abhi-atg-1021 Date: Sat, 14 Jan 2023 13:16:16 +0530 Subject: [PATCH 297/408] 11 question done --- December - 11/cpp_abhi-atg.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 December - 11/cpp_abhi-atg.cpp diff --git a/December - 11/cpp_abhi-atg.cpp b/December - 11/cpp_abhi-atg.cpp new file mode 100644 index 0000000..c906feb --- /dev/null +++ b/December - 11/cpp_abhi-atg.cpp @@ -0,0 +1,30 @@ +#include +using namespace std; +/* Abhi-Atg */ + + +int main(){ + + string s;cin>>s; + int n=s.size(); + string jump;cin>>jump; + int m=jump.size(); + int ans=0; + int ind=0; + for(int i=0;i Date: Sat, 14 Jan 2023 17:52:05 +0530 Subject: [PATCH 298/408] solved 22 days worth of problems --- December - 01/Cpp_Ankur.cpp | 70 +++++++++ December - 02/Cpp_Ankur.cpp | 28 ++++ December - 03/Java_Ankur2606.java | 91 +++++++++++ December - 04/Java_Ankur2606.java | 55 +++++++ December - 05/Java_Ankur2606.java | 45 ++++++ December - 06/Java_Ankur2606.java | 45 ++++++ December - 07/Java_Ankur2606.java | 96 ++++++++++++ December - 08/Java_Ankur2606.java | 33 ++++ December - 09/Java_Ankur2606.java | 37 +++++ December - 10/Java_Ankur2606.java | 54 +++++++ December - 11/Java_Ankur2606.java | 35 +++++ December - 12/Cpp_Ankur2606.cpp | 65 ++++++++ December - 13/Cpp_Ankur2606.cpp | 56 +++++++ December - 14/Cpp_Ankur2606.cpp | 28 ++++ December - 15/Java_Ankur2606.java | 58 +++++++ December - 16/Java_Ankur2606.java | 51 +++++++ December - 17/Java_Ankur2606.java | 65 ++++++++ December - 18/Cpp_Ankur2606.cpp | 196 ++++++++++++++++++++++++ December - 19/Java_Ankur2606.java | 135 +++++++++++++++++ December - 20/Cpp_Ankur2606.cpp | 243 ++++++++++++++++++++++++++++++ December - 21/Java_Ankur2606.java | 30 ++++ December - 22/Java_Ankur2606.java | 42 ++++++ 22 files changed, 1558 insertions(+) create mode 100644 December - 01/Cpp_Ankur.cpp create mode 100644 December - 02/Cpp_Ankur.cpp create mode 100644 December - 03/Java_Ankur2606.java create mode 100644 December - 04/Java_Ankur2606.java create mode 100644 December - 05/Java_Ankur2606.java create mode 100644 December - 06/Java_Ankur2606.java create mode 100644 December - 07/Java_Ankur2606.java create mode 100644 December - 08/Java_Ankur2606.java create mode 100644 December - 09/Java_Ankur2606.java create mode 100644 December - 10/Java_Ankur2606.java create mode 100644 December - 11/Java_Ankur2606.java create mode 100644 December - 12/Cpp_Ankur2606.cpp create mode 100644 December - 13/Cpp_Ankur2606.cpp create mode 100644 December - 14/Cpp_Ankur2606.cpp create mode 100644 December - 15/Java_Ankur2606.java create mode 100644 December - 16/Java_Ankur2606.java create mode 100644 December - 17/Java_Ankur2606.java create mode 100644 December - 18/Cpp_Ankur2606.cpp create mode 100644 December - 19/Java_Ankur2606.java create mode 100644 December - 20/Cpp_Ankur2606.cpp create mode 100644 December - 21/Java_Ankur2606.java create mode 100644 December - 22/Java_Ankur2606.java diff --git a/December - 01/Cpp_Ankur.cpp b/December - 01/Cpp_Ankur.cpp new file mode 100644 index 0000000..1fd1425 --- /dev/null +++ b/December - 01/Cpp_Ankur.cpp @@ -0,0 +1,70 @@ + +#include +#include +using namespace std; +int main() +{ + // Declare a string to store the hexadecimal input + string hex; + int size, string_set; + cout << "Enter the number of hexadecimal strings sets\n"; + cin >> string_set; + cout << endl; + // Prompt the user to enter a hexadecimal string + + // Convert the hexadecimal string to an ASCII string + string ascii[string_set]; + for (int k = 0; k < string_set; k++) + { + cout<<"For the string set "<> size; + for (int j = 0; j < size; j++) + { + cout << "Enter the hexadecimal value at index " << j + 1 << endl; + cin >> hex; + // { 56, 6F, 75, 67, 68, 74} + for (int i = 0; i < hex.length(); i += 2) + { + char c = (char)strtol(hex.substr(i, 2).c_str(), NULL, 16); + ascii[k] += c; + } + } + } + + for (int i = 0; i < string_set; i++) + { + cout << ascii[i]<< endl; + } + + + // Print the ASCII string + + return 0; +} +// #include +// #include +// #include +// using namespace std; +// int main(){ +// string t; +// cout<<"Enter a vector of arrays\n"; +// vector a[5]; +// for (int i = 0; i <2 ; i++) +// { +// for (int j = 0; j < 5; j++) +// { +// cin>>t; +// a[i].push_back(t); +// } +// } +// for (int i = 0; i < 2; i++) { +// for (auto it = a[i].begin(); +// it != a[i].end(); it++) { +// cout << stoi(*it) << ' '; +// } +// cout << endl; +// } + +// return 0; +// } diff --git a/December - 02/Cpp_Ankur.cpp b/December - 02/Cpp_Ankur.cpp new file mode 100644 index 0000000..32370cd --- /dev/null +++ b/December - 02/Cpp_Ankur.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +using namespace std; +int main(){ + cout< s{'k','i','p','e','d','i','a','w','i','a','e'}; + for (auto it = s.begin(); it != s.end(); it++) + { + cout<<*it; + } + cout<= 0 && arr[verUp][j].equals("#") == false){ + arr[verUp][j] = Integer.toString(Integer.parseInt(arr[verUp][j]) + 1); + } + if(verDown <= (n-1) && arr[verDown][j].equals("#") == false){ + arr[verDown][j] = Integer.toString(Integer.parseInt(arr[verDown][j]) + 1); + } + if(horLeft >= 0 && arr[i][horLeft].equals("#") == false){ + arr[i][horLeft] = Integer.toString(Integer.parseInt(arr[i][horLeft]) + 1); + } + if(horRight <= (n-1) && arr[i][horRight].equals("#") == false){ + arr[i][horRight] = Integer.toString(Integer.parseInt(arr[i][horRight]) + 1); + } + + if(horLeft >= 0 && verUp >= 0 && arr[verUp][horLeft].equals("#") == false){ + arr[verUp][horLeft] = Integer.toString(Integer.parseInt(arr[verUp][horLeft]) + 1); + } + if(horLeft >= 0 && verDown <= (n-1) && arr[verDown][horLeft].equals("#") == false){ + arr[verDown][horLeft] = Integer.toString(Integer.parseInt(arr[verDown][horLeft]) + 1); + } + if(horRight <= (n-1) && verUp >= 0 && arr[verUp][horRight].equals("#") == false){ + arr[verUp][horRight] = Integer.toString(Integer.parseInt(arr[verUp][horRight]) + 1); + } + if(horRight <= (n-1) && verDown <= (n-1) && arr[verDown][horRight].equals("#") == false){ + arr[verDown][horRight] = Integer.toString(Integer.parseInt(arr[verDown][horRight]) + 1); + } + } + } + } + + return arr; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input : "); + int n = sc.nextInt(); + String[][] arr = new String[n][n]; + for(int i=0;ij? i : j; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input : "); + System.out.println(""); + + System.out.print("No. of Days : "); + int noOfDays = sc.nextInt(); + + int[] arr = new int[noOfDays]; + System.out.print("Given stock market change values : "); + for(int i=0;i preRes){ + end = i+1; + } + } + + System.out.println(""); + System.out.println("Output : "); + System.out.println(""); + + System.out.println("Profit Value : " + res); + System.out.println("Proposed days to sell: Day: "+start+" to Day: "+end); + System.out.print("Stock market Change Values: {"); + for(int i=start-1;i<=end-1;i++){ + System.out.print(arr[i]); + if(i != (end-1)){ + System.out.print(","); + } + } + System.out.print("}"); + } +} \ No newline at end of file diff --git a/December - 05/Java_Ankur2606.java b/December - 05/Java_Ankur2606.java new file mode 100644 index 0000000..9b37a84 --- /dev/null +++ b/December - 05/Java_Ankur2606.java @@ -0,0 +1,45 @@ +import java.io.*; +public class Java_Ankur2606{ + public static void main(String args[]) throws IOException{ + InputStreamReader isr=new InputStreamReader(System.in); + BufferedReader br=new BufferedReader(isr); + + System.out.println("Input : "); + System.out.print("fuel_price="); + int fuel_price = Integer.parseInt(br.readLine()); + + int expenditure = 0; + int fixedFuelPrice = fuel_price; + for(int day=1; day<=31; day++){ + if(day%3 == 0 && day%5 == 0){ + fuel_price = fuel_price + 3 - 2; + } + else if(day%3 == 0){ + fuel_price = fuel_price + 3; + } + else if(day%5 == 0){ + fuel_price = fuel_price - 2; + } + else{ + fuel_price = fixedFuelPrice; + } + expenditure = expenditure + (fuel_price * 2); + } + expenditure = expenditure - 4; + + int percent = (50000 * 10)/100; + String msg = ""; + if(expenditure > percent){ + msg = "EXPENDITURE EXCEEDING LIMIT"; + }else{ + msg = "EXPENDITURE WITHIN LIMIT"; + } + + System.out.println(""); + System.out.println("Output : "); + System.out.println("Expenditure="+expenditure); + System.out.println(""); + System.out.println(msg); + + } +} \ No newline at end of file diff --git a/December - 06/Java_Ankur2606.java b/December - 06/Java_Ankur2606.java new file mode 100644 index 0000000..cd2abc2 --- /dev/null +++ b/December - 06/Java_Ankur2606.java @@ -0,0 +1,45 @@ +import java.util.*; +class Java_Ankur2606{ + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input: "); + System.out.print("n="); + int n = sc.nextInt(); + int[] arr = new int[n]; + System.out.print("Set of numbers: "); + for(int i=0;i(map.length-1) || colPos>(map[0].length-1) || map[rowPos][colPos] != c){ + break; + } + if(map[rowPos][colPos] == c){ + count++; + } + if(count == str.length()){ + Coordinates ending = new Coordinates(rowPos,colPos); + coordinateDetails[0] = starting; + coordinateDetails[1] = ending; + return coordinateDetails; + } + } + } + return null; + } + + public Coordinates[] wordMap(char[][] map, String str){ + int rowSize = map.length; + int columnSize = map[0].length; + for(int i=0;imaxLength){ + maxLength = length; + str = arr[i]; + } + } + return str; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input:"); + int n = sc.nextInt(); + String[] arr = new String[n]; + for(int i=0;i= 4){ + break; + } + } + } + + if(consonants >= 4){ + results[i] = "NO"; + }else{ + results[i] = "YES"; + } + } + return results; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input:"); + int n = sc.nextInt(); + String[] strArr = new String[n]; + for(int i=0;i +using namespace std; + +bool issafe(int** arr, int x, int y, int n){ + if(x>n; + int** arr=new int*[n]; + for(int i=0; i>arr[i][j]; + } + } + int** solArr=new int*[n]; + for(int i=0; i +using namespace std; + +bool isBipartite(int n, vector> &arr){ + for(int i=0; i>n; + int temp; + vector> arr; + for(int i=0; i row; + for(int j=0; j>temp; + row.push_back(temp); + } + arr.push_back(row); + } + if(isBipartite(n, arr)) cout << "The graph is Bipartite!"; + else cout << "The graph is not a Bipartite!"; + return 0; +} \ No newline at end of file diff --git a/December - 15/Java_Ankur2606.java b/December - 15/Java_Ankur2606.java new file mode 100644 index 0000000..c37dd18 --- /dev/null +++ b/December - 15/Java_Ankur2606.java @@ -0,0 +1,58 @@ +import java.util.*; +class Detail{ + String name; + String timestamp; + Detail(String name, String timestamp){ + this.name = name; + this.timestamp = timestamp; + } +} + +class Sortbytimestamp implements Comparator +{ + public int compare(Detail a, Detail b){ + int hhmmssA = Integer.parseInt(a.timestamp.replace(":","")); + int hhmmssB = Integer.parseInt(b.timestamp.replace(":","")); + return hhmmssA - hhmmssB; + } +} + +class Java_Ankur2606{ + public Queue theMurderersMeet(List list){ + Collections.sort(list, new Sortbytimestamp()); + + Queue queue=new LinkedList<>(); + for(Detail d : list){ + queue.add(d.name); + } + + return queue; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input: "); + List list=new ArrayList<>(); + String name, timestamp; + for(int i=0;i<3;i++){ + name = sc.next(); + while(true){ + timestamp = sc.next(); + String[] hhmmss = timestamp.split(":"); + if(Integer.parseInt(hhmmss[0])>24 || Integer.parseInt(hhmmss[1])>59 || Integer.parseInt(hhmmss[2])>59){ + System.out.println("Invalid Timestamp!! Enter again ..."); + }else{ + break; + } + } + list.add(new Detail(name,timestamp)); + } + + Java_Ankur2606 ob=new Java_Ankur2606(); + Queue queue = ob.theMurderersMeet(list); + + System.out.println(""); + System.out.print("Output: "+queue); + } +} \ No newline at end of file diff --git a/December - 16/Java_Ankur2606.java b/December - 16/Java_Ankur2606.java new file mode 100644 index 0000000..43875bd --- /dev/null +++ b/December - 16/Java_Ankur2606.java @@ -0,0 +1,51 @@ +import java.util.*; +public class Java_Ankur2606{ + public int findMax(int no1, int no2){ + int max = 0; + if(no1>no2){ + max = no1; + }else{ + max = no2; + } + return max; + } + + public int findMin(int no1, int no2){ + int min = 0; + if(no1 zigzagConversion(String str, int row){ + int length = str.length(); + char[] characters; + List list=new ArrayList<>(); + int j=0; + int c = row - 2; + while(j=1){ + characters = new char[row]; + if(j==length){ + break; + } + for(int i=0;i + +#define INT_MAX 10000000 + +using namespace std; + +void DijkstrasTest(char a); + +int main() { + char a; + cin >> a; + DijkstrasTest(a); + return 0; +} + +class Node; +class Edge; + +void Dijkstras(); +vector* AdjacentRemainingNodes(Node* node); +Node* ExtractSmallest(vector& nodes); +int Distance(Node* node1, Node* node2); +bool Contains(vector& nodes, Node* node); +void PrintShortestRouteTo(Node* destination); + +vector nodes; +vector edges; + +class Node { + public: + Node(char id) + : id(id), previous(NULL), distanceFromStart(INT_MAX) { + nodes.push_back(this); + } + + public: + char id; + Node* previous; + int distanceFromStart; +}; + +class Edge { + public: + Edge(Node* node1, Node* node2, int distance) + : node1(node1), node2(node2), distance(distance) { + edges.push_back(this); + } + bool Connects(Node* node1, Node* node2) { + return ( + (node1 == this->node1 && + node2 == this->node2) || + (node1 == this->node2 && + node2 == this->node1)); + } + + public: + Node* node1; + Node* node2; + int distance; +}; + + +void DijkstrasTest(char a) { + Node* P = new Node('P'); + Node* Q = new Node('Q'); + Node* R = new Node('R'); + Node* S = new Node('S'); + Node* T = new Node('T'); + Node* U = new Node('U'); + Node* V = new Node('V'); + Node* W = new Node('W'); + + Edge* e1 = new Edge(P, Q, 3); + Edge* e2 = new Edge(Q, U, 5); + Edge* e3 = new Edge(U, W, 2); + Edge* e4 = new Edge(P, S, 5); + Edge* e5 = new Edge(S, T, 2); + Edge* e6 = new Edge(T, V, 4); + Edge* e7 = new Edge(V, W, 1); + Edge* e8 = new Edge(P, R, 4); + Edge* e9 = new Edge(R, U, 6); + Edge* e10 = new Edge(Q, R, 2); + Edge* e11 = new Edge(S, R, 7); + Edge* e12 = new Edge(R, T, 3); + Edge* e13 = new Edge(R, V, 2); + Edge* e14 = new Edge(U, V, 5); + + W->distanceFromStart = 0; + Dijkstras(); + if(a=='P')PrintShortestRouteTo(P); + if(a=='Q')PrintShortestRouteTo(Q); + if(a=='R')PrintShortestRouteTo(R); + if(a=='S')PrintShortestRouteTo(S); + if(a=='T')PrintShortestRouteTo(T); + if(a=='U')PrintShortestRouteTo(U); + if(a=='V')PrintShortestRouteTo(V); + if(a=='W')PrintShortestRouteTo(W); +} + +void Dijkstras() { + while (nodes.size() > 0) { + Node* smallest = ExtractSmallest(nodes); + vector* adjacentNodes = + AdjacentRemainingNodes(smallest); + + const int size = adjacentNodes->size(); + for (int i = 0; i < size; ++i) { + Node* adjacent = adjacentNodes->at(i); + int distance = Distance(smallest, adjacent) + + smallest->distanceFromStart; + + if (distance < adjacent->distanceFromStart) { + adjacent->distanceFromStart = distance; + adjacent->previous = smallest; + } + } + delete adjacentNodes; + } +} + +Node* ExtractSmallest(vector& nodes) { + int size = nodes.size(); + if (size == 0) return NULL; + int smallestPosition = 0; + Node* smallest = nodes.at(0); + for (int i = 1; i < size; ++i) { + Node* current = nodes.at(i); + if (current->distanceFromStart < + smallest->distanceFromStart) { + smallest = current; + smallestPosition = i; + } + } + nodes.erase(nodes.begin() + smallestPosition); + return smallest; +} + +vector* AdjacentRemainingNodes(Node* node) { + vector* adjacentNodes = new vector(); + const int size = edges.size(); + for (int i = 0; i < size; ++i) { + Edge* edge = edges.at(i); + Node* adjacent = NULL; + if (edge->node1 == node) { + adjacent = edge->node2; + } else if (edge->node2 == node) { + adjacent = edge->node1; + } + if (adjacent && Contains(nodes, adjacent)) { + adjacentNodes->push_back(adjacent); + } + } + return adjacentNodes; +} + +int Distance(Node* node1, Node* node2) { + const int size = edges.size(); + for (int i = 0; i < size; ++i) { + Edge* edge = edges.at(i); + if (edge->Connects(node1, node2)) { + return edge->distance; + } + } + return -1; +} + +bool Contains(vector& nodes, Node* node) { + const int size = nodes.size(); + for (int i = 0; i < size; ++i) { + if (node == nodes.at(i)) { + return true; + } + } + return false; +} + +void PrintShortestRouteTo(Node* destination) { + Node* previous = destination; + cout << "Shortest path: "; + while (previous) { + cout << previous-> id << " "; + previous = previous->previous; + } + cout << endl; + cout << "Shortest time: " << destination->distanceFromStart << " hours"<< endl; +} + +void RemoveEdge(vector& edges, Edge* edge) { + vector::iterator it; + for (it = edges.begin(); it < edges.end(); ++it) { + if (*it == edge) { + edges.erase(it); + return; + } + } +} \ No newline at end of file diff --git a/December - 19/Java_Ankur2606.java b/December - 19/Java_Ankur2606.java new file mode 100644 index 0000000..3c91139 --- /dev/null +++ b/December - 19/Java_Ankur2606.java @@ -0,0 +1,135 @@ +import java.util.*; +class AlphabetDetail{ + char alphabet; + int count; + AlphabetDetail(char alphabet, int count){ + this.alphabet = alphabet; + this.count = count; + } +} +class Java_Ankur2606{ + public String removeSpecialCharacters(String str){ + String newStr = ""; + for(int i=0;i alphabetCount(String str){ + str = str.toLowerCase(); + int length = str.length(); + List list = new ArrayList<>(); + for(int i=97;i<=122;i++){ + int count=0; + for(int j=0;j0){ + list.add(new AlphabetDetail((char)i,count)); + } + } + return list; + } + + public List makingDummyObjectList(List list){ + List dummy = new ArrayList<>(); + for(AlphabetDetail l : list){ + dummy.add(new AlphabetDetail(l.alphabet, l.count)); + } + return dummy; + } + + public String findAnagram(String str, List list, List dummy){ + String anagram = ""; + String flag = ""; + str = str.toLowerCase() + ' '; + int length = str.length(); + int i = 0; + boolean alphabetCountChanged = false; + while(i list = ob.alphabetCount(str2); + List dummy = ob.makingDummyObjectList(list); + String anagram = ob.findAnagram(str1,list,dummy); + + System.out.println(""); + System.out.println("Output:"); + System.out.println(""); + System.out.println(anagram.length() == 0? "No Anagram" : anagram); + } +} \ No newline at end of file diff --git a/December - 20/Cpp_Ankur2606.cpp b/December - 20/Cpp_Ankur2606.cpp new file mode 100644 index 0000000..e3cc680 --- /dev/null +++ b/December - 20/Cpp_Ankur2606.cpp @@ -0,0 +1,243 @@ +#include +using namespace std; +typedef long long mint; + +class any_node{ + public: + mint depth_; + mint max_depth_; + + mint min_a_, max_a_; + mint min_w_, max_w_; + + any_node(mint depth, mint max_depth): depth_(depth), max_depth_(max_depth){ + } + + virtual ~any_node(){ + } + + virtual any_node *ins(any_node *l) = 0; + virtual mint max_w(mint a) = 0; + virtual any_node *drop(mint a, mint w) = 0; +}; + +class node : public any_node{ + public: + bool banzai_; + + any_node *left_; + any_node *right_; + + node(mint depth, mint max_depth, any_node *l, any_node *r): any_node(depth, max_depth), banzai_(true){ + min_a_ = min(l->min_a_, r->min_a_); + max_a_ = max(l->max_a_, r->max_a_); + min_w_ = min(l->min_w_, r->min_w_); + max_w_ = max(l->max_w_, r->max_w_); + + if (l->max_a_ < r->min_a_){ + left_ = l; + right_ = r; + } else { + left_ = r; + right_ = l; + } + } + + virtual ~node(){ + if (banzai_){ + delete left_; + delete right_; + } + } + + virtual any_node *ins(any_node *l){ + ++(l->depth_); + + if (left_->max_a_ > l->min_a_){ + left_ = left_->ins(l); + } else if (right_->min_a_ < l->max_a_){ + right_ = right_->ins(l); + } else if (left_->max_depth_ < right_->max_depth_){ + left_ = left_->ins(l); + } else { + right_ = right_->ins(l); + } + + max_depth_ = max(left_->max_depth_, right_->max_depth_); + + min_a_ = min(left_->min_a_, right_->min_a_); + max_a_ = max(left_->max_a_, right_->max_a_); + min_w_ = min(left_->min_w_, right_->min_w_); + max_w_ = max(left_->max_w_, right_->max_w_); + + return this; + } + + virtual mint max_w(mint a){ + mint left_max_w = (a < left_->min_a_ ? 0 : (a > left_->max_a_ ? left_->max_w_ : left_->max_w(a))); + mint right_max_w = (a < right_->min_a_ ? 0 : (a > right_->max_a_ ? right_->max_w_ : right_->max_w(a))); + + return max(left_max_w, right_max_w); + } + + // does not update depth_ or max_depth_ which might screw up later insertions + virtual any_node *drop(mint a, mint w){ + if ((max_a_ < a) || (min_w_ > w)){ + return this; + } + + left_ = left_->drop(a, w); + right_ = right_->drop(a, w); + + banzai_ = false; + + if ((left_ == NULL) && (right_ == NULL)){ + delete this; + + return NULL; + } else if ((left_ == NULL) && (right_ != NULL)){ + delete this; + + return right_; + } else if ((left_ != NULL) && (right_ == NULL)){ + delete this; + + return left_; + } else { + min_a_ = min(left_->min_a_, right_->min_a_); + max_a_ = max(left_->max_a_, right_->max_a_); + min_w_ = min(left_->min_w_, right_->min_w_); + max_w_ = max(left_->max_w_, right_->max_w_); + + banzai_ = true; + + return this; + } + } +}; + +class leaf : public any_node{ + public: + + leaf(mint depth, mint max_depth): any_node(depth, max_depth){ + } + + virtual ~leaf(){ + } + + virtual any_node *ins(any_node *l){ + if (l->min_a_ == min_a_){ + min_w_ = max_w_ = max(l->min_w_, max_w_); + + delete l; + + return this; + } + + ++(l->depth_); + ++(l->max_depth_); + + return new node(depth_++, max_depth_++, this, l); + } + + virtual mint max_w(mint a){ + return a > max_a_ ? max_w_ : 0; + } + + virtual any_node *drop(mint a, mint w){ + if ((max_a_ <= a) || (max_w_ > w)){ + return this; + } + + delete this; + + return NULL; + } +}; + +class tree{ + public: + + any_node *root_; + + tree(): root_(NULL){ + } + + ~tree(){ + if (root_ != NULL){ + delete root_; + } + } + + void prc(mint a, mint w){ + mint wmax = max_w(a) + w; + drop(a, wmax); + ins(a, wmax); + } + + void ins(mint a, mint w){ + leaf *nl = new leaf(0, 0); + + nl->min_a_ = nl->max_a_ = a; + nl->min_w_ = nl->max_w_ = w; + + if (root_ == NULL){ + root_ = nl; + + return; + } + + root_ = root_->ins(nl); + } + + mint max_w(mint a){ + if (root_ == NULL){ + return 0; + } + + return root_->max_w(a); + } + + void drop(mint a, mint w){ + if (root_ == NULL){ + return; + } + + root_ = root_->drop(a, w); + } +}; + +int main(){ + mint c; + + cin >> c; + + for (; c; --c){ + mint n; + + cin >> n; + + mint *a = new mint[n]; + mint *w = new mint[n]; + + for (mint i = 0; i != n; ++i){ + cin >> a[i]; + } + + for (mint i = 0; i != n; ++i){ + cin >> w[i]; + } + + tree tr; + + for (mint i = 0; i != n; ++i){ + tr.prc(a[i], w[i]); + } + + cout << tr.root_->max_w_ << endl; + + delete[] a; + delete[] w; + } + return 0; +} \ No newline at end of file diff --git a/December - 21/Java_Ankur2606.java b/December - 21/Java_Ankur2606.java new file mode 100644 index 0000000..d853457 --- /dev/null +++ b/December - 21/Java_Ankur2606.java @@ -0,0 +1,30 @@ +import java.util.*; +public class Java_Ankur2606{ + public void move(int n, String left, String right, String middle){ + if(n == 1){ + System.out.println("Move disk "+n+" from tower "+left+" to tower "+right); + } + else{ + move(n-1,left,middle,right); + System.out.println("Move disk "+n+" from tower "+left+" to tower "+right); + move(n-1,middle,right,left); + } + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input:"); + System.out.println(""); + System.out.print("Number of discs: "); + int n = sc.nextInt(); + + Java_Ankur2606 ob=new Java_Ankur2606(); + + System.out.println(""); + System.out.println("Output:"); + System.out.println(""); + System.out.println("The sequence of moves :"); + ob.move(n,"I","III","II"); + } +} \ No newline at end of file diff --git a/December - 22/Java_Ankur2606.java b/December - 22/Java_Ankur2606.java new file mode 100644 index 0000000..91a194e --- /dev/null +++ b/December - 22/Java_Ankur2606.java @@ -0,0 +1,42 @@ +import java.util.*; +public class Java_Ankur2606{ + public String theMarkowitzParadox(String codeword, String message){ + String encrypt = ""; + int length = message.length(); + int l = codeword.length(); + int j = 0; + for(int i=0;i 90){ + int diff = sum - 90; + encrypt = encrypt + (char)(64 + diff); + + }else{ + encrypt = encrypt + (char)sum; + } + j++; + } + return encrypt; + } + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input:"); + String codeword = sc.next(); + String message = sc.next(); + + Java_Ankur2606 ob=new Java_Ankur2606(); + String encrypt = ob.theMarkowitzParadox(codeword.toUpperCase(),message.toUpperCase()); + + System.out.println(""); + System.out.println("Output:"); + System.out.println(""); + System.out.println(encrypt); + } +} \ No newline at end of file From 87e1226006df33070fb68b8dd6bbbcf137464fd9 Mon Sep 17 00:00:00 2001 From: Samriddh Prasad <72660273+Samriddh2703@users.noreply.github.com> Date: Sat, 14 Jan 2023 18:45:50 +0530 Subject: [PATCH 299/408] Create day1.cpp --- December - 01/day1.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 December - 01/day1.cpp diff --git a/December - 01/day1.cpp b/December - 01/day1.cpp new file mode 100644 index 0000000..4cbe637 --- /dev/null +++ b/December - 01/day1.cpp @@ -0,0 +1,36 @@ +#include +using namespace std; + +void tokenize(string const &str, const char delim, vector &out) +{ + size_t start; + size_t end = 0; + size_t n = str.length(); + + while ((start = str.find_first_not_of(delim, end)) != string::npos) + { + end = str.find(delim, start); + out.push_back(str.substr(start, end - start)); + } +} + +int main() +{ + string output; + string s = "56, 6F, 75, 67, 68, 74"; + const char delim = ','; + + vector out; + tokenize(s, delim, out); + + for (auto &s : out) + { + uint32_t chr = 0; + stringstream ss; + ss << hex << s; + ss >> chr; + output.push_back(static_cast(chr)); + } + cout << output; + return 0; +} From 7eb56f6fe3bf3be28052efd415515c86deee756c Mon Sep 17 00:00:00 2001 From: Samriddh Prasad <72660273+Samriddh2703@users.noreply.github.com> Date: Sat, 14 Jan 2023 18:47:27 +0530 Subject: [PATCH 300/408] Create day3.cpp --- December - 03/day3.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 December - 03/day3.cpp diff --git a/December - 03/day3.cpp b/December - 03/day3.cpp new file mode 100644 index 0000000..7834359 --- /dev/null +++ b/December - 03/day3.cpp @@ -0,0 +1,51 @@ +#include +using namespace std; + +int main() { + + vector>v{{'-', '#', '-', '-', '#'},{'-', '-', '-', '-', '-'}, {'-', '-', '#', '-', '-'},{'-', '#', '-', '-', '#'},{'-', '#', '-', '-', '#'}}; + int n = v.size(); + int m = v[0].size(); + vector>arr(n,vector (m, 0)); + for(int i=0;i=0 and arr[i-1][j]!=-1) + arr[i-1][j]++; + if(i+1=0 and arr[i][j-1]!=-1) + arr[i][j-1]++; + if(j+1=0 and j-1>=0 and arr[i-1][j-1]!=-1) + arr[i-1][j-1]++; + if(i-1>=0 and j+1=0 and arr[i+1][j-1]!=-1) + arr[i+1][j-1]++; + + + } + + } + } + for(int i=0;i Date: Sat, 14 Jan 2023 18:55:59 +0530 Subject: [PATCH 301/408] Create day5.cpp --- December - 05/day5.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 December - 05/day5.cpp diff --git a/December - 05/day5.cpp b/December - 05/day5.cpp new file mode 100644 index 0000000..dbc914c --- /dev/null +++ b/December - 05/day5.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; + +int monthlyExpenditure(int &price) { + int expenditure = 0; + int todayPrice=0; + + for(int i=1; i<=31; i++){ + todayPrice = price; + if(i%3==0) todayPrice+=3; + if(i%5==0) todayPrice-=2; + expenditure+=(2*todayPrice); + } + if(50000/10>price; + int expenditure = monthlyExpenditure(price); + cout<<"Expenditure="< Date: Sat, 14 Jan 2023 19:21:17 +0530 Subject: [PATCH 302/408] Create day6.cpp --- December - 06/day6.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 December - 06/day6.cpp diff --git a/December - 06/day6.cpp b/December - 06/day6.cpp new file mode 100644 index 0000000..8b9e7fb --- /dev/null +++ b/December - 06/day6.cpp @@ -0,0 +1,36 @@ +#include +using namespace std; + +int main() { + cout<<"Enter size of numbers:"; + int size;cin>>size; + cout<<"Enter pos:"; + int pos;cin>>pos; + cout<<"Enter set of numbers:"; + vectorv(size); + for(auto &x:v)cin>>x; + + cout<<"Player goinf first:"; + string s; + cin>>s; + int first_value = v[0]; + int pos_value = v[pos-1]; + + int count; + while(first_value>0){ + swap(--first_value,v[pos-1]); + count++; + } + if(s=="Tanika"){ + if(count%2==0) + cout<<"Tanika wins the game!\nBob loses the game!"; + else cout<<"Bob wins the game!\nTanika loses the game! "; + } + if(s=="Bob"){ + if(count%2==0) + cout<<"Bob wins the game!\nTanika loses the game!"; + else cout<<"Tanika wins the game!\nBob loses the game! "; + } + + return 0; +} From 3bec498a9a497dc64c340ad6a7b9832574173c13 Mon Sep 17 00:00:00 2001 From: Samriddh Prasad <72660273+Samriddh2703@users.noreply.github.com> Date: Sat, 14 Jan 2023 19:24:50 +0530 Subject: [PATCH 303/408] Create day9.cpp --- December - 09/day9.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 December - 09/day9.cpp diff --git a/December - 09/day9.cpp b/December - 09/day9.cpp new file mode 100644 index 0000000..f97eb59 --- /dev/null +++ b/December - 09/day9.cpp @@ -0,0 +1,39 @@ +#include +using namespace std; + +int main() +{ + int n; + cin >> n; + vector input(n); + + for (auto &x : input) + cin >> x; + int max_len = INT_MIN; + + string word; + for (auto e : input) + { + int len = e.size(); + if (e.size() % 2 != 0) + { + max_len = max(len, max_len); + } + else + continue; + } + for (auto e : input) + { + if (e.size() == max_len) + { + word = e; + break; + } + } + if (max_len == INT_MIN) + cout << "Better Luck Next Time"; + else + cout << word; + + return 0; +} From 18ce5de66bd39c126d6a358628357299faef29be Mon Sep 17 00:00:00 2001 From: Samriddh Prasad <72660273+Samriddh2703@users.noreply.github.com> Date: Sat, 14 Jan 2023 19:50:12 +0530 Subject: [PATCH 304/408] Create day11.cpp --- December - 11/day11.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 December - 11/day11.cpp diff --git a/December - 11/day11.cpp b/December - 11/day11.cpp new file mode 100644 index 0000000..b15fbac --- /dev/null +++ b/December - 11/day11.cpp @@ -0,0 +1,30 @@ +#include +using namespace std; + +int main() { + // int n;cin>>n; + // vector input(n) ; + // for(auto &x:input)cin>>x; + + // int m;cin>>m; + // vector steps(m) ; + // for(auto &i:steps)cin>>i; + vector input{'_','~','_','~','_','_','~','_','_','~','_','~'}; + vector steps{2,2,1,1,1,1,2,1,1}; + int n = input.size(); + int m = steps.size(); + int score =0; + int jumps=0; + for(int i=0;i Date: Sat, 14 Jan 2023 20:28:01 +0530 Subject: [PATCH 305/408] Create day12.cpp --- December - 12/day12.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 December - 12/day12.cpp diff --git a/December - 12/day12.cpp b/December - 12/day12.cpp new file mode 100644 index 0000000..de7ce5d --- /dev/null +++ b/December - 12/day12.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +#define R 4 +#define C 4 + +int minCost(int cost[R][C], int m, int n) +{ + if (n < 0 || m < 0) + return INT_MAX; + else if (m == 0 && n == 0) + return cost[m][n]; + else + return cost[m][n] + + min(minCost(cost, m - 1, n), + minCost(cost, m, n - 1)); +} + +int main() +{ + int cost[R][C] + = { {9,4,9,9}, {6,7,6,4}, {8,3,3,7}, {7,4,9,10} }; + + cout << minCost(cost, R-1, C-1) << endl; + + return 0; +} From dcb51b06f14815ad8e6a963bf1f1133620b66d5a Mon Sep 17 00:00:00 2001 From: Samriddh Prasad <72660273+Samriddh2703@users.noreply.github.com> Date: Sat, 14 Jan 2023 20:31:37 +0530 Subject: [PATCH 306/408] Create day13.cpp --- December - 13/day13.cpp | 115 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 December - 13/day13.cpp diff --git a/December - 13/day13.cpp b/December - 13/day13.cpp new file mode 100644 index 0000000..8c64e33 --- /dev/null +++ b/December - 13/day13.cpp @@ -0,0 +1,115 @@ +#include +#include +#include +using namespace std; + +const int N = 4; + +int maze[N][N] = { + {1, 0, 0, 0}, + {1, 1, 0, 1}, + {0, 1, 0, 0}, + {1, 1, 1, 1} + +}; + +struct Point +{ + int x, y; +}; + +bool is_valid(int x, int y) +{ + return x >= 0 && x < N && y >= 0 && y < N; +} + +std::vector solve_maze_bfs(Point start, Point end) +{ + std::vector path; + + std::queue q; + q.push(start); + + Point came_from[N][N]; + came_from[start.x][start.y] = start; + + bool visited[N][N] = {false}; + + while (!q.empty()) + { + Point p = q.front(); + q.pop(); + + if (p.x == end.x && p.y == end.y) + { + while (p.x != start.x || p.y != start.y) + { + path.push_back(p); + p = came_from[p.x][p.y]; + } + path.push_back(start); + std::reverse(path.begin(), path.end()); + return path; + } + + if (is_valid(p.x + 1, p.y) && !visited[p.x + 1][p.y] && maze[p.x + 1][p.y] == 1) + { + q.push({p.x + 1, p.y}); + came_from[p.x + 1][p.y] = p; + visited[p.x + 1][p.y] = true; + } + if (is_valid(p.x - 1, p.y) && !visited[p.x - 1][p.y] && maze[p.x - 1][p.y] == 1) + { + q.push({p.x - 1, p.y}); + came_from[p.x - 1][p.y] = p; + visited[p.x - 1][p.y] = true; + } + if (is_valid(p.x, p.y + 1) && !visited[p.x][p.y + 1] && maze[p.x][p.y + 1] == 1) + { + q.push({p.x, p.y + 1}); + came_from[p.x][p.y + 1] = p; + visited[p.x][p.y + 1] = true; + } + if (is_valid(p.x, p.y - 1) && !visited[p.x][p.y - 1] && maze[p.x][p.y - 1] == 1) + { + q.push({p.x, p.y - 1}); + came_from[p.x][p.y - 1] = p; + visited[p.x][p.y - 1] = true; + } + } + + return {}; +} + +int main() +{ + int n = 4; + vector> res(n, vector(n, 0)); + Point start = {0, 0}; + Point end = {N - 1, N - 1}; + + std::vector path = solve_maze_bfs(start, end); + + if (path.empty()) + { + std::cout << "No solution found." << std::endl; + } + else + { + for (Point p : path) + { + res[p.x][p.y] = 1; + } + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + + std::cout << res[i][j]; + } + std::cout << std::endl; + } + } + + return 0; +} From 8ebe6a8d7eb027c9fa76617a6656692a4db44163 Mon Sep 17 00:00:00 2001 From: Samriddh Prasad <72660273+Samriddh2703@users.noreply.github.com> Date: Sat, 14 Jan 2023 21:20:27 +0530 Subject: [PATCH 307/408] Create day14.cpp --- December - 14/day14.cpp | 85 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 December - 14/day14.cpp diff --git a/December - 14/day14.cpp b/December - 14/day14.cpp new file mode 100644 index 0000000..3aaf884 --- /dev/null +++ b/December - 14/day14.cpp @@ -0,0 +1,85 @@ +#include +#include +#include +using namespace std; + +const int N = 6; +int graph[N][N] = { + {0, 1, 0, 0, 0, 1}, + {1, 0, 1, 0, 0, 0}, + {0, 1, 0, 1, 0, 0}, + {0, 0, 1, 0, 1, 0}, + {0, 0, 0, 1, 0, 1}, + {1, 0, 0, 0, 1, 0}}; +std::vector> adj(N); +bool is_bipartite() +{ + std::vector U, V; + U.push_back(0); + + bool visited[N] = {false}; + + for (int u : U) + { + visited[u] = true; + for (int v : adj[u]) + { + if (!visited[v]) + { + V.push_back(v); + } + else + { + if (std::find(U.begin(), U.end(), v) != U.end()) + { + return false; + } + } + } + } + + for (int v : V) + { + visited[v] = true; + for (int u : adj[v]) + { + if (!visited[u]) + { + U.push_back(u); + } + else + { + if (std::find(V.begin(), V.end(), u) != V.end()) + { + return false; + } + } + } + } + return true; +} +int main() +{ + + for (int i = 0; i < N; i++) + { + for (int j = 0; j < N; j++) + { + if (graph[i][j] == 1) + { + adj[i].push_back(j); + } + } + } + + if (is_bipartite()) + { + std::cout << "The graph is Bipartite!" << std::endl; + } + else + { + std::cout << "The graph is not Bipartite!" << std::endl; + } + + return 0; +} From aefe7e8062dfe0485d3022b43e422231178d6824 Mon Sep 17 00:00:00 2001 From: Samriddh Prasad <72660273+Samriddh2703@users.noreply.github.com> Date: Sat, 14 Jan 2023 21:32:15 +0530 Subject: [PATCH 308/408] Create day15.cpp --- December - 15/day15.cpp | 78 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 December - 15/day15.cpp diff --git a/December - 15/day15.cpp b/December - 15/day15.cpp new file mode 100644 index 0000000..c5bfc36 --- /dev/null +++ b/December - 15/day15.cpp @@ -0,0 +1,78 @@ +#include +using namespace std; +vector splitter(vector& person); + +int main (int argc, char *argv[]) +{ + string name, time; + int count = 3; + vector> persons(3, vector(2)); + cout<<"Enter person name and Time in HH:MM:SS \n"; +// INPUT IN BELOW FORMAT + // Wes 12:00:30 + // Michella 12:03:40 + // Asher 12:00:01 + for(int i=0 ;count !=0; count--){ + cin>>name; + cin>>time; + + persons[i].push_back(name); + persons[i].push_back(time); + i++; + } + + sort(persons.begin(), persons.end(), [](vector& lhs, vector& rhs) + { + vector timeOne = splitter(lhs); + vector timeTwo = splitter(rhs); + + if(timeOne[0] < timeTwo[0]) return true; + else if (timeOne[0] > timeTwo[0]) return false; + else{ + + if(timeOne[1] < timeTwo[1]) return true; + else if (timeOne[1] > timeTwo[1]) return false; + else { + + if(timeOne[2] < timeTwo[2]) return true; + else if (timeOne[2] > timeTwo[2]) return false; + } + + } + return false; + }); + + for(auto person: persons){ + for(auto row: person){ + cout< splitter(vector& person) { + vector time; + int digit; + auto it = person[3].begin(); + digit = *it - '0'; + *it++; + digit = digit * 10; + digit = digit + (*it - '0'); + time.push_back(digit); + *it++; + *it++; + digit = *it - '0'; + *it++; + digit = digit * 10; + digit = digit + (*it - '0'); + time.push_back(digit); + *it++; + *it++; + digit = *it - '0'; + *it++; + digit = digit * 10; + digit = digit + (*it - '0'); + time.push_back(digit); + return time; +} From 84eb8fd6703b371916a5b3966255da3d502d1426 Mon Sep 17 00:00:00 2001 From: Samriddh Prasad <72660273+Samriddh2703@users.noreply.github.com> Date: Sat, 14 Jan 2023 21:35:19 +0530 Subject: [PATCH 309/408] Create day16.cpp --- December - 16/day16.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 December - 16/day16.cpp diff --git a/December - 16/day16.cpp b/December - 16/day16.cpp new file mode 100644 index 0000000..66b2715 --- /dev/null +++ b/December - 16/day16.cpp @@ -0,0 +1,40 @@ +#include +using namespace std; + +vector input(int); +int maxPossibleVolume(vector&, int); + +int main(){ + int n; + cin>>n; + + vector water = input(n); + cout<<"Max Volume this container can hold: "<& water, int n){ + int s=0, e=n-1; + int volume = 0; + int currentVolume = 0; + + for(int f=0, r=e; f=0; f++, r--){ + if(water[s] input(int n){ + vector water(n); + for(int j=0; j>water[j]; + return water; +} From a523e75778f33927e168dcd9e061e7922f8e03a8 Mon Sep 17 00:00:00 2001 From: Samriddh Prasad <72660273+Samriddh2703@users.noreply.github.com> Date: Sat, 14 Jan 2023 22:08:56 +0530 Subject: [PATCH 310/408] Create day17.cpp --- December - 17/day17.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 December - 17/day17.cpp diff --git a/December - 17/day17.cpp b/December - 17/day17.cpp new file mode 100644 index 0000000..73e9322 --- /dev/null +++ b/December - 17/day17.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; +int main() { + //"spaghettigood" + string Str; + cin>>Str; + int Row; + cin >> Row; + vector> zigzag(Row); + int row = 0; + int direction = 1; + for (char c : Str) { + zigzag[row].push_back(c); + if (row == Row - 1) { + direction = -1; + } + else if (row == 0) { + direction = 1; + } + row += direction; + } + for (auto& row : zigzag) { + for (char c : row) { + std::cout << c; + } + } + std::cout << std::endl; + return 0; +} From 7ce95e8a385ab1dd57ea7869719dd082a6d69462 Mon Sep 17 00:00:00 2001 From: Samriddh Prasad <72660273+Samriddh2703@users.noreply.github.com> Date: Sat, 14 Jan 2023 22:30:45 +0530 Subject: [PATCH 311/408] Create day18.cpp --- December - 18/day18.cpp | 81 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 December - 18/day18.cpp diff --git a/December - 18/day18.cpp b/December - 18/day18.cpp new file mode 100644 index 0000000..74b2ec5 --- /dev/null +++ b/December - 18/day18.cpp @@ -0,0 +1,81 @@ +#include + +using namespace std; +int NO_PARENTS = -1; + +void dijkstras(vector>& adjMat, int start); +void printSolution(int start, vector& allPathShortestDistance, vector& parentOfNode); +void printPath(int end, vector& parentOfNode); + +int main() { + vector> adjMat{ + { 0, 3, 4, 5, 0, 0, 0, 0}, + { 3, 0, 2, 0, 0, 5, 0, 0}, + { 4, 2, 0, 7, 3, 6, 2, 0}, + { 5, 0, 7, 0, 2, 0, 0, 0}, + { 0, 0, 3, 2, 0, 0, 4, 0}, + { 0, 5, 6, 0, 0, 0, 5, 2}, + { 0, 0, 2, 0, 4, 5, 0, 1}, + { 0, 0, 0, 0, 0, 2, 1, 0} + }; + + char charChoice; + cin >> charChoice; + charChoice = tolower(charChoice); + int ch = charChoice - 112; + dijkstras(adjMat, ch); +} + +void dijkstras(vector>& adjMat, int start){ + + int n = adjMat[0].size(); + + vector isNodeAdded(n, false); + + vector allPathShortestDistance(n, INT_MAX); + allPathShortestDistance[start] = 0; + + vector parentOfNode(n); + parentOfNode[start] = NO_PARENTS; + for (int i=1; i 0) && ((currentNodeWeight + nextNodeWeight) < allPathShortestDistance[nextNode])){ + parentOfNode[nextNode] = currentNode; + allPathShortestDistance[nextNode] = currentNodeWeight + nextNodeWeight; + } + } + } + printSolution(start, allPathShortestDistance, parentOfNode); +} + +void printSolution(int start, vector& allPathShortestDistance, vector& parentOfNode){ + int n = allPathShortestDistance.size(); + int end = 7; // W + cout<<"Vertex\t Distance \t Path"; + cout<<"\n"<<((char)(start + 112))<<" -> "; + cout<<((char)(end + 112))<<"\t "; + cout<& parentOfNode){ + if(node == NO_PARENTS) return; + printPath(parentOfNode[node], parentOfNode); + cout<<(char)(node + 112)<<" "; +} +//input : P From fef1aec85b61528943a43bf439c6eb1a896dd685 Mon Sep 17 00:00:00 2001 From: Samriddh Prasad <72660273+Samriddh2703@users.noreply.github.com> Date: Sat, 14 Jan 2023 22:46:03 +0530 Subject: [PATCH 312/408] Create day19.cpp --- December - 19/day19.cpp | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 December - 19/day19.cpp diff --git a/December - 19/day19.cpp b/December - 19/day19.cpp new file mode 100644 index 0000000..f9d773f --- /dev/null +++ b/December - 19/day19.cpp @@ -0,0 +1,56 @@ +#include + +using namespace std; + +int isAnagramPossible(string& text, string& anagram); +void printFoundMatch(string& text, string& anagram, int endPos); + +int main (int argc, char *argv[]) +{ + string text, anagram; + + getline(cin>>ws, text); + getline(cin>>ws, anagram); + printFoundMatch(text, anagram, isAnagramPossible(text, anagram)); + return 0; +} + +int isAnagramPossible(string& text, string& anagram){ + map myChartedAccountantGirl; + int concecutiveCounter = 0, restorePointer = 0; + char c; + + for(int i=0; i Date: Sat, 14 Jan 2023 22:53:28 +0530 Subject: [PATCH 313/408] Create day20.cpp --- December - 20/day20.cpp | 243 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 December - 20/day20.cpp diff --git a/December - 20/day20.cpp b/December - 20/day20.cpp new file mode 100644 index 0000000..53439a7 --- /dev/null +++ b/December - 20/day20.cpp @@ -0,0 +1,243 @@ +#include +using namespace std; +typedef long long mint; + +class any_node{ + public: + mint depth_; + mint max_depth_; + + mint min_a_, max_a_; + mint min_w_, max_w_; + + any_node(mint depth, mint max_depth): depth_(depth), max_depth_(max_depth){ + } + + virtual ~any_node(){ + } + + virtual any_node *ins(any_node *l) = 0; + virtual mint max_w(mint a) = 0; + virtual any_node *drop(mint a, mint w) = 0; +}; + +class node : public any_node{ + public: + bool banzai_; + + any_node *left_; + any_node *right_; + + node(mint depth, mint max_depth, any_node *l, any_node *r): any_node(depth, max_depth), banzai_(true){ + min_a_ = min(l->min_a_, r->min_a_); + max_a_ = max(l->max_a_, r->max_a_); + min_w_ = min(l->min_w_, r->min_w_); + max_w_ = max(l->max_w_, r->max_w_); + + if (l->max_a_ < r->min_a_){ + left_ = l; + right_ = r; + } else { + left_ = r; + right_ = l; + } + } + + virtual ~node(){ + if (banzai_){ + delete left_; + delete right_; + } + } + + virtual any_node *ins(any_node *l){ + ++(l->depth_); + + if (left_->max_a_ > l->min_a_){ + left_ = left_->ins(l); + } else if (right_->min_a_ < l->max_a_){ + right_ = right_->ins(l); + } else if (left_->max_depth_ < right_->max_depth_){ + left_ = left_->ins(l); + } else { + right_ = right_->ins(l); + } + + max_depth_ = max(left_->max_depth_, right_->max_depth_); + + min_a_ = min(left_->min_a_, right_->min_a_); + max_a_ = max(left_->max_a_, right_->max_a_); + min_w_ = min(left_->min_w_, right_->min_w_); + max_w_ = max(left_->max_w_, right_->max_w_); + + return this; + } + + virtual mint max_w(mint a){ + mint left_max_w = (a < left_->min_a_ ? 0 : (a > left_->max_a_ ? left_->max_w_ : left_->max_w(a))); + mint right_max_w = (a < right_->min_a_ ? 0 : (a > right_->max_a_ ? right_->max_w_ : right_->max_w(a))); + + return max(left_max_w, right_max_w); + } + + // does not update depth_ or max_depth_ which might screw up later insertions + virtual any_node *drop(mint a, mint w){ + if ((max_a_ < a) || (min_w_ > w)){ + return this; + } + + left_ = left_->drop(a, w); + right_ = right_->drop(a, w); + + banzai_ = false; + + if ((left_ == NULL) && (right_ == NULL)){ + delete this; + + return NULL; + } else if ((left_ == NULL) && (right_ != NULL)){ + delete this; + + return right_; + } else if ((left_ != NULL) && (right_ == NULL)){ + delete this; + + return left_; + } else { + min_a_ = min(left_->min_a_, right_->min_a_); + max_a_ = max(left_->max_a_, right_->max_a_); + min_w_ = min(left_->min_w_, right_->min_w_); + max_w_ = max(left_->max_w_, right_->max_w_); + + banzai_ = true; + + return this; + } + } +}; + +class leaf : public any_node{ + public: + + leaf(mint depth, mint max_depth): any_node(depth, max_depth){ + } + + virtual ~leaf(){ + } + + virtual any_node *ins(any_node *l){ + if (l->min_a_ == min_a_){ + min_w_ = max_w_ = max(l->min_w_, max_w_); + + delete l; + + return this; + } + + ++(l->depth_); + ++(l->max_depth_); + + return new node(depth_++, max_depth_++, this, l); + } + + virtual mint max_w(mint a){ + return a > max_a_ ? max_w_ : 0; + } + + virtual any_node *drop(mint a, mint w){ + if ((max_a_ <= a) || (max_w_ > w)){ + return this; + } + + delete this; + + return NULL; + } +}; + +class tree{ + public: + + any_node *root_; + + tree(): root_(NULL){ + } + + ~tree(){ + if (root_ != NULL){ + delete root_; + } + } + + void prc(mint a, mint w){ + mint wmax = max_w(a) + w; + drop(a, wmax); + ins(a, wmax); + } + + void ins(mint a, mint w){ + leaf *nl = new leaf(0, 0); + + nl->min_a_ = nl->max_a_ = a; + nl->min_w_ = nl->max_w_ = w; + + if (root_ == NULL){ + root_ = nl; + + return; + } + + root_ = root_->ins(nl); + } + + mint max_w(mint a){ + if (root_ == NULL){ + return 0; + } + + return root_->max_w(a); + } + + void drop(mint a, mint w){ + if (root_ == NULL){ + return; + } + + root_ = root_->drop(a, w); + } +}; + +int main(){ + mint c; + + cin >> c; + + for (; c; --c){ + mint n; + + cin >> n; + + mint *a = new mint[n]; + mint *w = new mint[n]; + + for (mint i = 0; i != n; ++i){ + cin >> a[i]; + } + + for (mint i = 0; i != n; ++i){ + cin >> w[i]; + } + + tree tr; + + for (mint i = 0; i != n; ++i){ + tr.prc(a[i], w[i]); + } + + cout << tr.root_->max_w_ << endl; + + delete[] a; + delete[] w; + } + return 0; +} From d061fdbed3c02ff0f6eaf5afc35a0bce53c7623a Mon Sep 17 00:00:00 2001 From: Samriddh Prasad <72660273+Samriddh2703@users.noreply.github.com> Date: Sat, 14 Jan 2023 22:56:53 +0530 Subject: [PATCH 314/408] Create day21.cpp --- December - 21/day21.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 December - 21/day21.cpp diff --git a/December - 21/day21.cpp b/December - 21/day21.cpp new file mode 100644 index 0000000..1521a36 --- /dev/null +++ b/December - 21/day21.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; + +void towerOfHanoi(int totalDisc, string A, string B, string C){ + if(totalDisc > 0) + { + towerOfHanoi(totalDisc-1, A, C, B); + cout << "Move disk " << totalDisc << " from tower " << A << " to tower " << C << endl; + towerOfHanoi(totalDisc-1, B, A, C); + } +} + +int main(){ + int totalDisc; + cin >> totalDisc; + towerOfHanoi(totalDisc, "I", "II", "III"); + return 0; +} From a137df194b070fdb0af76e801694e5633a3ea281 Mon Sep 17 00:00:00 2001 From: Samriddh Prasad <72660273+Samriddh2703@users.noreply.github.com> Date: Sat, 14 Jan 2023 23:00:26 +0530 Subject: [PATCH 315/408] Create day22.cpp --- December - 22/day22.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 December - 22/day22.cpp diff --git a/December - 22/day22.cpp b/December - 22/day22.cpp new file mode 100644 index 0000000..cc6427f --- /dev/null +++ b/December - 22/day22.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; + +void TheMarkowitzParadox(char a, char b){ + int c = a - 'A'; + int e = ((int(b) + c)-65)%26; + char d = 65 + e; + cout << d; + } +int main(){ + string a, b; + cin >> a; + cin >> b; + char* a1 = &a[0]; + char* b1 = &b[0]; + int n1 = a.size(), n2 = b.size(), x=0, i=0; + while(i Date: Sun, 15 Jan 2023 00:44:36 +0530 Subject: [PATCH 316/408] Add files via upload --- December - 01/cpp_Aadhi11.cpp.zip | Bin 0 -> 380 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 December - 01/cpp_Aadhi11.cpp.zip diff --git a/December - 01/cpp_Aadhi11.cpp.zip b/December - 01/cpp_Aadhi11.cpp.zip new file mode 100644 index 0000000000000000000000000000000000000000..53a87f7ae691f64803a8b7ece9f330157cf20099 GIT binary patch literal 380 zcmWIWW@h1HU|`^2*d(eKR^r!N%EidQAix9?VPMEj%*@kEE-2^?wDmu1Aadug_PkS% zGy**(BObXp`OHmp7WIm~Y;&@<^N*sUz<=5O5*fER`L~t6e^;Y^Um;VPpY4iV^Zu_7 z7o0A#Em5jkq8w0fRQGCYqe&(UhrG<==E{0G`FV2NqbuFGK58ngm0$8*N-!#7?JUVU zX<3hc`DdmKk4q=>9X+(ww1lTwM?y1thjyA{S+s@UUT)75T=L&Jr$ne4J^z*ZYGHY% zw~qX=3{`Kf1sQKeVpwPY<}T}-5qHJ;+z-?D=UQH9_)AYTXcT#HMfv3FzBx}*gWqqO z6**n7v5dkePnOj>(PVv148hX32Wg#xmE`rh1=@Fk}- paQm}W_XE5cnM4?HhZr!>kN_ Date: Sun, 15 Jan 2023 00:55:02 +0530 Subject: [PATCH 317/408] Delete cpp_Aadhi11.cpp.zip --- December - 01/cpp_Aadhi11.cpp.zip | Bin 380 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 December - 01/cpp_Aadhi11.cpp.zip diff --git a/December - 01/cpp_Aadhi11.cpp.zip b/December - 01/cpp_Aadhi11.cpp.zip deleted file mode 100644 index 53a87f7ae691f64803a8b7ece9f330157cf20099..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 380 zcmWIWW@h1HU|`^2*d(eKR^r!N%EidQAix9?VPMEj%*@kEE-2^?wDmu1Aadug_PkS% zGy**(BObXp`OHmp7WIm~Y;&@<^N*sUz<=5O5*fER`L~t6e^;Y^Um;VPpY4iV^Zu_7 z7o0A#Em5jkq8w0fRQGCYqe&(UhrG<==E{0G`FV2NqbuFGK58ngm0$8*N-!#7?JUVU zX<3hc`DdmKk4q=>9X+(ww1lTwM?y1thjyA{S+s@UUT)75T=L&Jr$ne4J^z*ZYGHY% zw~qX=3{`Kf1sQKeVpwPY<}T}-5qHJ;+z-?D=UQH9_)AYTXcT#HMfv3FzBx}*gWqqO z6**n7v5dkePnOj>(PVv148hX32Wg#xmE`rh1=@Fk}- paQm}W_XE5cnM4?HhZr!>kN_ Date: Sun, 15 Jan 2023 01:18:28 +0530 Subject: [PATCH 318/408] Add files via upload --- December - 01/cpp_Aadhi11.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 December - 01/cpp_Aadhi11.cpp diff --git a/December - 01/cpp_Aadhi11.cpp b/December - 01/cpp_Aadhi11.cpp new file mode 100644 index 0000000..a750d3f --- /dev/null +++ b/December - 01/cpp_Aadhi11.cpp @@ -0,0 +1,34 @@ +#include +using namespace std; + +string hexToASCII(string hex) +{ + string ascii = ""; + for (size_t i = 0; i < hex.length(); i += 2) + { + string part = hex.substr(i, 2); + + char ch = stoul(part, nullptr, 16); + + ascii += ch; + } + return ascii; +} + +int main() +{ + string hex[10]; + int n; + cin>>n; + for(int i=0;i>hex[i]; + } + + cout< Date: Sun, 15 Jan 2023 01:20:07 +0530 Subject: [PATCH 319/408] Delete cpp_Aadhi11.cpp --- December - 01/cpp_Aadhi11.cpp | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 December - 01/cpp_Aadhi11.cpp diff --git a/December - 01/cpp_Aadhi11.cpp b/December - 01/cpp_Aadhi11.cpp deleted file mode 100644 index a750d3f..0000000 --- a/December - 01/cpp_Aadhi11.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include -using namespace std; - -string hexToASCII(string hex) -{ - string ascii = ""; - for (size_t i = 0; i < hex.length(); i += 2) - { - string part = hex.substr(i, 2); - - char ch = stoul(part, nullptr, 16); - - ascii += ch; - } - return ascii; -} - -int main() -{ - string hex[10]; - int n; - cin>>n; - for(int i=0;i>hex[i]; - } - - cout< Date: Sun, 15 Jan 2023 01:32:42 +0530 Subject: [PATCH 320/408] Add files via upload --- December - 01/cpp_Aadhi11.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 December - 01/cpp_Aadhi11.cpp diff --git a/December - 01/cpp_Aadhi11.cpp b/December - 01/cpp_Aadhi11.cpp new file mode 100644 index 0000000..a750d3f --- /dev/null +++ b/December - 01/cpp_Aadhi11.cpp @@ -0,0 +1,34 @@ +#include +using namespace std; + +string hexToASCII(string hex) +{ + string ascii = ""; + for (size_t i = 0; i < hex.length(); i += 2) + { + string part = hex.substr(i, 2); + + char ch = stoul(part, nullptr, 16); + + ascii += ch; + } + return ascii; +} + +int main() +{ + string hex[10]; + int n; + cin>>n; + for(int i=0;i>hex[i]; + } + + cout< Date: Sun, 15 Jan 2023 01:45:35 +0530 Subject: [PATCH 321/408] Add files via upload --- December - 02/cpp_Aadhi11.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 December - 02/cpp_Aadhi11.cpp diff --git a/December - 02/cpp_Aadhi11.cpp b/December - 02/cpp_Aadhi11.cpp new file mode 100644 index 0000000..1702487 --- /dev/null +++ b/December - 02/cpp_Aadhi11.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; + +int +main () +{ + string s, a; + cin >> s; + int k = s.length (); + if (s[k - 1] == 'e' && s[k - 2] == 'a') + { + a = s[k - 4]; + a = a + s[k - 3]; + for (int i = 0; i < k - 4; i++) + { + a = a + s[i]; + } + cout < Date: Sun, 15 Jan 2023 02:11:55 +0530 Subject: [PATCH 322/408] Word map --- December - 07/cpp_Aadhi11.cpp | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 December - 07/cpp_Aadhi11.cpp diff --git a/December - 07/cpp_Aadhi11.cpp b/December - 07/cpp_Aadhi11.cpp new file mode 100644 index 0000000..ce4f250 --- /dev/null +++ b/December - 07/cpp_Aadhi11.cpp @@ -0,0 +1,59 @@ +#include +using namespace std; + int k=0; +int x[] = { -1, -1, -1, 0, 0, 1, 1, 1 }; +int y[] = { -1, 0, 1, -1, 1, -1, 0, 1 }; + +bool search2D(char *grid, int row, int col, + string word, int R, int C) +{ + if (*(grid+row*C+col) != word[0]) + return false; + + int len = word.length(); + + for (int dir = 0; dir < 8; dir++) { + int k, rd = row + x[dir], cd = col + y[dir]; + + for (k = 1; k < len; k++) { + if (rd >= R || rd < 0 || cd >= C || cd < 0) + break; + + if (*(grid+rd*C+cd) != word[k]) + break; + + rd += x[dir], cd += y[dir]; + } + + if (k == len) + return true; + } + return false; +} + +void patternSearch(char *grid, string word, + int R, int C) +{ + for (int row = 0; row < R; row++) + for (int col = 0; col < C; col++) + if (search2D(grid, row, col, word, R, C)) + k=1; + +} + +int main() +{ + int R = 15, C = 15; + char grid[R][C] = { "ASSERTIVENESSLJ","CFOGOODPOSITIVE","OPENBMUREWOPRPS","MEDIATIONELDIOG","MAASREGJEWINWIN","UCIAEMOEECSKENI","NEMRSHACDVTWTTL","ITEHOTLTSTERAOE","CASPLGLSIUNERFE","AISAUSYTPOISEVF","TTARTTDOCENPPIH","IOGAIGUPYMGOOEE","OGEPOAFPQIENOWA","NECONFLICTSDCER","FNHTCATNOCEYEBT"}; + string x; + cin>>x; + patternSearch((char *)grid, x , R, C); + cout< Date: Sun, 15 Jan 2023 02:26:22 +0530 Subject: [PATCH 323/408] Aptitude Check! --- December - 08/cpp_Aadhi11.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 December - 08/cpp_Aadhi11.cpp diff --git a/December - 08/cpp_Aadhi11.cpp b/December - 08/cpp_Aadhi11.cpp new file mode 100644 index 0000000..3e2ad04 --- /dev/null +++ b/December - 08/cpp_Aadhi11.cpp @@ -0,0 +1,33 @@ +#include +#include +using namespace std; + +int main () +{ + string x; + cin >> x; + if ((x.length ()) % 2 == 0) + { + for (int i = 0; i < x.length (); i = i + 2) + { + char c; + c = x[i]; + x[i] = x[i + 1]; + x[i + 1] = c; + } + } + else + { + for (int i = 0; i < x.length () - 1; i = i + 2) + { + char c; + c = x[i]; + x[i] = x[i + 1]; + x[i + 1] = c; + } + } + cout << x; +} + + + From 9607476148fb69f7b50652d672e2c6aedfdf2cef Mon Sep 17 00:00:00 2001 From: Aadhi11 <122631614+Aadhi11@users.noreply.github.com> Date: Sun, 15 Jan 2023 02:28:45 +0530 Subject: [PATCH 324/408] Add files via upload --- December - 09/cpp_Aadhi11.cpp | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 December - 09/cpp_Aadhi11.cpp diff --git a/December - 09/cpp_Aadhi11.cpp b/December - 09/cpp_Aadhi11.cpp new file mode 100644 index 0000000..586b659 --- /dev/null +++ b/December - 09/cpp_Aadhi11.cpp @@ -0,0 +1,43 @@ +#include +#include +using namespace std; + +int +main () +{ + string s[10], k; + int n, a[10], max = 0; + cin >> n; + for (int i = 0; i < n; i++) + { + cin >> s[i]; + a[i] = s[i].length (); + } + for (int i = 0; i < n; i++) + { + if ((a[i] % 2) != 0) + { + if (a[i] > max) + { + max = a[i]; + } + } + } + if (max == 0) + { + cout << endl << "Better luck next time"; + } + else + { + for (int i = 0; i < n; i++) + { + if (max == s[i].length ()) + { + cout << endl << s[i]; + break; + } + } + } +} + + From 8aa2970d21f3a665dbbd71554b4450867b45507e Mon Sep 17 00:00:00 2001 From: Aadhi11 <122631614+Aadhi11@users.noreply.github.com> Date: Sun, 15 Jan 2023 02:29:13 +0530 Subject: [PATCH 325/408] Delete cpp_Aadhi11.cpp --- December - 09/cpp_Aadhi11.cpp | 43 ----------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 December - 09/cpp_Aadhi11.cpp diff --git a/December - 09/cpp_Aadhi11.cpp b/December - 09/cpp_Aadhi11.cpp deleted file mode 100644 index 586b659..0000000 --- a/December - 09/cpp_Aadhi11.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -using namespace std; - -int -main () -{ - string s[10], k; - int n, a[10], max = 0; - cin >> n; - for (int i = 0; i < n; i++) - { - cin >> s[i]; - a[i] = s[i].length (); - } - for (int i = 0; i < n; i++) - { - if ((a[i] % 2) != 0) - { - if (a[i] > max) - { - max = a[i]; - } - } - } - if (max == 0) - { - cout << endl << "Better luck next time"; - } - else - { - for (int i = 0; i < n; i++) - { - if (max == s[i].length ()) - { - cout << endl << s[i]; - break; - } - } - } -} - - From 47be841b6e3ebb7dc96e70da9c4dec44dbb61335 Mon Sep 17 00:00:00 2001 From: Aadhi11 <122631614+Aadhi11@users.noreply.github.com> Date: Sun, 15 Jan 2023 02:29:56 +0530 Subject: [PATCH 326/408] Kochouseph Konundrum! --- December - 09/cpp_Aadhi11.cpp | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 December - 09/cpp_Aadhi11.cpp diff --git a/December - 09/cpp_Aadhi11.cpp b/December - 09/cpp_Aadhi11.cpp new file mode 100644 index 0000000..586b659 --- /dev/null +++ b/December - 09/cpp_Aadhi11.cpp @@ -0,0 +1,43 @@ +#include +#include +using namespace std; + +int +main () +{ + string s[10], k; + int n, a[10], max = 0; + cin >> n; + for (int i = 0; i < n; i++) + { + cin >> s[i]; + a[i] = s[i].length (); + } + for (int i = 0; i < n; i++) + { + if ((a[i] % 2) != 0) + { + if (a[i] > max) + { + max = a[i]; + } + } + } + if (max == 0) + { + cout << endl << "Better luck next time"; + } + else + { + for (int i = 0; i < n; i++) + { + if (max == s[i].length ()) + { + cout << endl << s[i]; + break; + } + } + } +} + + From 1f358fa9fb01d766bc2eaa7a18344a1b0f754981 Mon Sep 17 00:00:00 2001 From: Aadhi11 <122631614+Aadhi11@users.noreply.github.com> Date: Sun, 15 Jan 2023 02:31:46 +0530 Subject: [PATCH 327/408] Add files via upload --- December - 10/cpp_Aadhi11.cpp | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 December - 10/cpp_Aadhi11.cpp diff --git a/December - 10/cpp_Aadhi11.cpp b/December - 10/cpp_Aadhi11.cpp new file mode 100644 index 0000000..24207db --- /dev/null +++ b/December - 10/cpp_Aadhi11.cpp @@ -0,0 +1,43 @@ +#include +#include +using namespace std; + +int +main () +{ + string s[10]; + int n, a[10], count[10] = { 0 }; + cin >> n; + for (int i = 0; i < n; i++) + { + cin >> a[i]; + cin >> s[i]; + } + for (int i = 0; i < n; i++) + { + for (int j = 0; j < a[i]; j++) + { + if ((s[i][j] == 'a' || s[i][j] == 'e' || s[i][j] == 'i' + || s[i][j] == 'o' || s[i][j] == 'u')) + { + count[i] = 0; + } + else + { + count[i]++; + if (count[i] == 4) + break; + } + } + } + cout << endl; + for (int i = 0; i < n; i++) + { + if (count[i] == 4) + cout << "NO" << endl; + else + cout << "YES" << endl; + } +} + + From 8a556e6bbab3627bcf15717523c288d1deb54288 Mon Sep 17 00:00:00 2001 From: Aadhi11 <122631614+Aadhi11@users.noreply.github.com> Date: Sun, 15 Jan 2023 02:32:21 +0530 Subject: [PATCH 328/408] Delete cpp_Aadhi11.cpp --- December - 10/cpp_Aadhi11.cpp | 43 ----------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 December - 10/cpp_Aadhi11.cpp diff --git a/December - 10/cpp_Aadhi11.cpp b/December - 10/cpp_Aadhi11.cpp deleted file mode 100644 index 24207db..0000000 --- a/December - 10/cpp_Aadhi11.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -using namespace std; - -int -main () -{ - string s[10]; - int n, a[10], count[10] = { 0 }; - cin >> n; - for (int i = 0; i < n; i++) - { - cin >> a[i]; - cin >> s[i]; - } - for (int i = 0; i < n; i++) - { - for (int j = 0; j < a[i]; j++) - { - if ((s[i][j] == 'a' || s[i][j] == 'e' || s[i][j] == 'i' - || s[i][j] == 'o' || s[i][j] == 'u')) - { - count[i] = 0; - } - else - { - count[i]++; - if (count[i] == 4) - break; - } - } - } - cout << endl; - for (int i = 0; i < n; i++) - { - if (count[i] == 4) - cout << "NO" << endl; - else - cout << "YES" << endl; - } -} - - From ce72df51d6bb8308327fed62af4bb5fd8b92682b Mon Sep 17 00:00:00 2001 From: Aadhi11 <122631614+Aadhi11@users.noreply.github.com> Date: Sun, 15 Jan 2023 02:32:57 +0530 Subject: [PATCH 329/408] Play with words --- December - 10/cpp_Aadhi11.cpp | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 December - 10/cpp_Aadhi11.cpp diff --git a/December - 10/cpp_Aadhi11.cpp b/December - 10/cpp_Aadhi11.cpp new file mode 100644 index 0000000..24207db --- /dev/null +++ b/December - 10/cpp_Aadhi11.cpp @@ -0,0 +1,43 @@ +#include +#include +using namespace std; + +int +main () +{ + string s[10]; + int n, a[10], count[10] = { 0 }; + cin >> n; + for (int i = 0; i < n; i++) + { + cin >> a[i]; + cin >> s[i]; + } + for (int i = 0; i < n; i++) + { + for (int j = 0; j < a[i]; j++) + { + if ((s[i][j] == 'a' || s[i][j] == 'e' || s[i][j] == 'i' + || s[i][j] == 'o' || s[i][j] == 'u')) + { + count[i] = 0; + } + else + { + count[i]++; + if (count[i] == 4) + break; + } + } + } + cout << endl; + for (int i = 0; i < n; i++) + { + if (count[i] == 4) + cout << "NO" << endl; + else + cout << "YES" << endl; + } +} + + From 4a3037f9c5ff229f5972bcf1fde45e26ad4359ef Mon Sep 17 00:00:00 2001 From: Aadhi11 <122631614+Aadhi11@users.noreply.github.com> Date: Sun, 15 Jan 2023 02:34:23 +0530 Subject: [PATCH 330/408] Monkey jump --- December - 11/cpp_Aadhi11.cpp | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 December - 11/cpp_Aadhi11.cpp diff --git a/December - 11/cpp_Aadhi11.cpp b/December - 11/cpp_Aadhi11.cpp new file mode 100644 index 0000000..cfccf1d --- /dev/null +++ b/December - 11/cpp_Aadhi11.cpp @@ -0,0 +1,53 @@ +#include +#include +using namespace std; + +int +main () +{ + string s; + int a[100],b[100], n = 0, score = 0,m=0,l=0; + cin >> s; + for (int i = 0; i < s.length (); i++) + { + if (s[i] == '_') + { + a[n] = 0; + n++; + } + if (s[i] == '~') + { + a[n] = 1; + n++; + } + } + string k; + cin>>k; + for (int i = 0; i < k.length (); i++) + { + if(k[i]=='1') + { + b[m]=1; + m++; + } + if(k[i]=='2') + { + b[m]=2; + m++; + } + } + for(int i=0;i Date: Sun, 15 Jan 2023 02:42:18 +0530 Subject: [PATCH 332/408] The Labyrinth --- December - 13/cpp_Aadhi11.cpp | 82 +++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 December - 13/cpp_Aadhi11.cpp diff --git a/December - 13/cpp_Aadhi11.cpp b/December - 13/cpp_Aadhi11.cpp new file mode 100644 index 0000000..30cacb4 --- /dev/null +++ b/December - 13/cpp_Aadhi11.cpp @@ -0,0 +1,82 @@ +#include +using namespace std; + + +bool solveMazeUtil(int maze[100][100], int x, int y,int sol[100][100],int n); + +void printSolution(int sol[100][100],int n) +{ + cout<= 0 && x < n && y >= 0 && y < n && maze[x][y] == 1) + return true; + return false; +} + + +bool solveMaze(int maze[100][100],int n) +{ + int sol[100][100]; + for(int i=0;i>n; + int maze[100][100]; + for(int i=0;i>maze[i][j]; + } + } + solveMaze(maze,n); + return 0; +} + From dba0c2c81221e9d3329c9d0a23c61ba9c19cddb2 Mon Sep 17 00:00:00 2001 From: Aadhi11 <122631614+Aadhi11@users.noreply.github.com> Date: Sun, 15 Jan 2023 02:44:32 +0530 Subject: [PATCH 333/408] Math Mystery --- December - 14/cpp_Aadhi11.cpp | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 December - 14/cpp_Aadhi11.cpp diff --git a/December - 14/cpp_Aadhi11.cpp b/December - 14/cpp_Aadhi11.cpp new file mode 100644 index 0000000..341c800 --- /dev/null +++ b/December - 14/cpp_Aadhi11.cpp @@ -0,0 +1,44 @@ +#include + +using namespace std; + +int main() +{ + int a[100][100],n,flag=0; + cin>>n; + cout<>a[i][j]; + } + } + for(int i=0;i Date: Sun, 15 Jan 2023 02:45:51 +0530 Subject: [PATCH 334/408] THE MURDERERS MEET --- December - 15/cpp_Aadhi11.cpp | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 December - 15/cpp_Aadhi11.cpp diff --git a/December - 15/cpp_Aadhi11.cpp b/December - 15/cpp_Aadhi11.cpp new file mode 100644 index 0000000..fe83c00 --- /dev/null +++ b/December - 15/cpp_Aadhi11.cpp @@ -0,0 +1,45 @@ +#include +using namespace std; + +void pairsort(string a[], string b[], int n) +{ + pair pairt[n]; + + for (int i = 0; i < n; i++) + { + pairt[i].first = a[i]; + pairt[i].second = b[i]; + } + + sort(pairt, pairt + n); + + for (int i = 0; i < n; i++) + { + a[i] = pairt[i].first; + b[i] = pairt[i].second; + } +} + +int main() +{ + string b[10]; + string a[10]; + + for(int i=0;i<3;i++) + { + cin>>b[i]; + cin>>a[i]; + } + pairsort(a, b, 3); + cout< Date: Sun, 15 Jan 2023 02:47:18 +0530 Subject: [PATCH 335/408] H2O Receptacle --- December - 16/cpp_Aadhi11.cpp | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 December - 16/cpp_Aadhi11.cpp diff --git a/December - 16/cpp_Aadhi11.cpp b/December - 16/cpp_Aadhi11.cpp new file mode 100644 index 0000000..015caf8 --- /dev/null +++ b/December - 16/cpp_Aadhi11.cpp @@ -0,0 +1,39 @@ +#include +using namespace std; + + +int secondLargest(int arr[], int n) { + int largest = 0, secondLargest = -1,a; + + for (int i = 1; i < n; i++) { + if (arr[i] > arr[largest]) + largest = i; + } + for (int i = 0; i < n; i++) { + if (arr[i] != arr[largest]) { + if (secondLargest == -1) + secondLargest = i; + else if (arr[i] > arr[secondLargest]) + secondLargest = i; + } + + } + a = arr[secondLargest]; + largest++; + secondLargest++; + int b= largest-secondLargest; + if(b<0) + b=b*-1; + a=b*a; + return a; +} + + +int main() { + // height = + int arr[] = {1,8,6,2,5,4,8,3,7}; + int n = sizeof(arr)/sizeof(arr[0]); + int second_Largest = secondLargest(arr, n); + cout< Date: Sun, 15 Jan 2023 02:48:36 +0530 Subject: [PATCH 336/408] Zig Zag Conversion --- December - 17/cpp_Aadhi11.cpp | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 December - 17/cpp_Aadhi11.cpp diff --git a/December - 17/cpp_Aadhi11.cpp b/December - 17/cpp_Aadhi11.cpp new file mode 100644 index 0000000..6c1100a --- /dev/null +++ b/December - 17/cpp_Aadhi11.cpp @@ -0,0 +1,49 @@ +#include +using namespace std; + +void printZigZagConcat(string str, int n) +{ + if (n == 1) + { + cout << str; + return; + } + + int len = str.length(); + + string arr[n]; + + int row = 0; + bool down; + + for (int i = 0; i < len; ++i) + { + arr[row].push_back(str[i]); + + if (row == n-1) + down = false; + + else if (row == 0) + down = true; + + (down)? (row++): (row--); + } + + cout<>c; + cout< Date: Sun, 15 Jan 2023 03:05:32 +0530 Subject: [PATCH 338/408] Hidden Anagram --- December - 19/cpp_Aadhi11.cpp | 93 +++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 December - 19/cpp_Aadhi11.cpp diff --git a/December - 19/cpp_Aadhi11.cpp b/December - 19/cpp_Aadhi11.cpp new file mode 100644 index 0000000..f703255 --- /dev/null +++ b/December - 19/cpp_Aadhi11.cpp @@ -0,0 +1,93 @@ +#include +#include +#include + +#define MAX 256 +using namespace std; + +bool compare(char arr1[], char arr2[]) +{ + for (int i=0; i Date: Sun, 15 Jan 2023 03:07:14 +0530 Subject: [PATCH 339/408] Code a Subsequence --- December - 20/cpp_Aadhi11.cpp | 93 +++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 December - 20/cpp_Aadhi11.cpp diff --git a/December - 20/cpp_Aadhi11.cpp b/December - 20/cpp_Aadhi11.cpp new file mode 100644 index 0000000..f703255 --- /dev/null +++ b/December - 20/cpp_Aadhi11.cpp @@ -0,0 +1,93 @@ +#include +#include +#include + +#define MAX 256 +using namespace std; + +bool compare(char arr1[], char arr2[]) +{ + for (int i=0; i Date: Sun, 15 Jan 2023 03:14:14 +0530 Subject: [PATCH 340/408] Delete cpp_Aadhi11.cpp --- December - 20/cpp_Aadhi11.cpp | 93 ----------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 December - 20/cpp_Aadhi11.cpp diff --git a/December - 20/cpp_Aadhi11.cpp b/December - 20/cpp_Aadhi11.cpp deleted file mode 100644 index f703255..0000000 --- a/December - 20/cpp_Aadhi11.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include -#include -#include - -#define MAX 256 -using namespace std; - -bool compare(char arr1[], char arr2[]) -{ - for (int i=0; i Date: Sun, 15 Jan 2023 03:14:39 +0530 Subject: [PATCH 341/408] Code a Subsequence --- December - 20/cpp_Aadhi11.cpp | 62 +++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 December - 20/cpp_Aadhi11.cpp diff --git a/December - 20/cpp_Aadhi11.cpp b/December - 20/cpp_Aadhi11.cpp new file mode 100644 index 0000000..2656724 --- /dev/null +++ b/December - 20/cpp_Aadhi11.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +#include +using namespace std; + + +int main() { + int t; + cin>>t; + while(t) + { + int n; + cin>>n; + int a[n]; + int w[n]; + for(int i=0;i>a[i]; + for(int i=0;i>w[i]; + set > s; + s.insert(pair(0,0)); + for(int i=0;i p =make_pair(a[i],0); + + set >::iterator it = s.lower_bound(p); + it--; + pair p1 = make_pair(a[i],w[i]+it->second); + it++; + vector > v; + bool valid = true; + while(it != s.end()) + { + if((it->first == a[i]) && (it->second >= p1.second)) + { + valid = false; + break; + } + else if(it->second <= p1.second) + { + v.push_back(*it); + it++; + } + else + break; + } + for(vector > ::iterator itv = v.begin();itv != v.end(); itv++) + { + s.erase(*itv); + } + if(valid) + s.insert(p1); + } + cout<second< Date: Sun, 15 Jan 2023 03:16:19 +0530 Subject: [PATCH 342/408] The Devil Towers --- December - 21/cpp_Aadhi11.cpp | 104 ++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 December - 21/cpp_Aadhi11.cpp diff --git a/December - 21/cpp_Aadhi11.cpp b/December - 21/cpp_Aadhi11.cpp new file mode 100644 index 0000000..4dc9203 --- /dev/null +++ b/December - 21/cpp_Aadhi11.cpp @@ -0,0 +1,104 @@ +#include +using namespace std; +#include +#include + +int transfer_disk(stack& a,stack& b){ + if(b.empty()==true){ + b.push(a.top()); + a.pop(); + return 1; + } + else if(a.empty()==true){ + a.push(b.top()); + b.pop(); + return 2; + } + else{ + if(b.top()>a.top()){ + b.push(a.top()); + a.pop(); + return 1; + } + else{ + a.push(b.top()); + b.pop(); + return 2; + } + } +} + +int main(){ + stack s,a,d; + int n=0; + cout<<"Number of discs: "; + cin>>n; + for(int i=n;i>=1;i--){ + s.push(i); + } + + int x=pow(2,n)-1; + int i=1; + cout< Date: Sun, 15 Jan 2023 03:18:01 +0530 Subject: [PATCH 343/408] The Markowitz Paradox --- December - 22/cpp_Aadhi11.cpp | 211 ++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 December - 22/cpp_Aadhi11.cpp diff --git a/December - 22/cpp_Aadhi11.cpp b/December - 22/cpp_Aadhi11.cpp new file mode 100644 index 0000000..b4f93a0 --- /dev/null +++ b/December - 22/cpp_Aadhi11.cpp @@ -0,0 +1,211 @@ +#include +#include + using namespace std; + + int main() + { + string s1,s2; + int a[100],b[100],h=0; + cin>>s1; + int k=s1.length(); + for(int i=0;i>s2; + int p=s2.length(); + cout<90) + { + q = q-26; + } + c[i]=q; + } + for(int i=0;i Date: Sun, 15 Jan 2023 03:19:57 +0530 Subject: [PATCH 344/408] Meeting Rooms --- December - 23/cpp_Aadhi11.cpp | 72 +++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 December - 23/cpp_Aadhi11.cpp diff --git a/December - 23/cpp_Aadhi11.cpp b/December - 23/cpp_Aadhi11.cpp new file mode 100644 index 0000000..144a3b2 --- /dev/null +++ b/December - 23/cpp_Aadhi11.cpp @@ -0,0 +1,72 @@ +#include +#include +using namespace std; +bool compare(vector& v1, vector& v2) { + return v1[0] < v2[0]; +} +class Solution { +public: + int mostBooked(int n, vector>& meetings) { + sort(meetings.begin(), meetings.end(), compare); + + priority_queue, vector>, greater>> engaged; + + priority_queue, greater> unused; + + unordered_map freq; + + for(int i = 0; i < n; i++) { + unused.push(i); + } + + for(auto x:meetings) { + int s = x[0], e = x[1]; + + while(engaged.size() > 0 && engaged.top().first <= s) { + int room = engaged.top().second; + engaged.pop(); + + unused.push(room); + } + + if(unused.size() > 0) + { + int room = unused.top(); + unused.pop(); + + freq[abs(room)] += 1; + + engaged.push({e, room}); + } + else + { + pair topmost = engaged.top(); + engaged.pop(); + + freq[abs(topmost.second)] += 1; + + long long newEnd = topmost.first; + newEnd += (e - s); + + engaged.push({newEnd, topmost.second}); + } + } + + int maxi = 0; + for(int i = 1; i < n; i++) { + if(freq[i] > freq[maxi]) + maxi = i; + } + return maxi; + } +}; + +int main() +{ + Solution s; + int n = 3; + vector> meetings = {{1,20},{2,10},{3,5},{4,9},{6,8}}; + cout< Date: Sun, 15 Jan 2023 03:24:12 +0530 Subject: [PATCH 345/408] Cracking The Safe --- December - 24/cpp_Aadhi11.cpp | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 December - 24/cpp_Aadhi11.cpp diff --git a/December - 24/cpp_Aadhi11.cpp b/December - 24/cpp_Aadhi11.cpp new file mode 100644 index 0000000..809f390 --- /dev/null +++ b/December - 24/cpp_Aadhi11.cpp @@ -0,0 +1,41 @@ +#include +using namespace std; +class Solution { +public: + set visited; + string ret; + string crackSafe(int n, int k) { + if(n == 1 && k == 1) return "0"; + ret = ""; + string s = ""; + for(int i = 0; i < n - 1; i++){ + s += "0"; + } + dfs(s, k); + for(int i = 0; i < n - 1; i++) ret += "0"; + return ret; + } + void dfs(string s, int k) { + string temp; + for(int i = 0; i < k; i++){ + temp = s + to_string(i); + if(!visited.count(temp)){ + visited.insert(temp); + temp = temp.substr(1); + dfs(temp, k); + ret += to_string(i); + } + } + } +}; + int main(){ + Solution ob; + int n,k; + cout<<"n = "; + cin>>n; + cout<<"k = "; + cin>>k; + cout <<"'"<< (ob.crackSafe(n,k))<<"'"; +} + + From 8ab55e98caecb1e57f687d8b61b731a0c733f4c5 Mon Sep 17 00:00:00 2001 From: Aadhi11 <122631614+Aadhi11@users.noreply.github.com> Date: Sun, 15 Jan 2023 03:26:09 +0530 Subject: [PATCH 346/408] The Motorbike Race --- December - 25/cpp_Aadhi11.cpp | 68 +++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 December - 25/cpp_Aadhi11.cpp diff --git a/December - 25/cpp_Aadhi11.cpp b/December - 25/cpp_Aadhi11.cpp new file mode 100644 index 0000000..83db599 --- /dev/null +++ b/December - 25/cpp_Aadhi11.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +#include + +using namespace std; + +const int kMaxn = 3e3 + 10, kMaxq = 1e5 + 10; +int ans[kMaxq], pos[kMaxn], tar[kMaxn]; +long long b[kMaxn]; +pair a[kMaxn]; +struct ques { + int t, k, id; +} q[kMaxq]; + +int main() { + double start = clock(); + int t; + scanf("%d", &t); + int n; + for (; scanf("%d", &n) == 1; ) { + assert(n <= 3000); + for (int i = 1; i <= n; ++i) { + scanf("%d%d", &a[i].first, &a[i].second); + } + int Q; + scanf("%d", &Q); + assert(Q <= 100000); + for (int i = 1; i <= Q; ++i) { + scanf("%d%d", &q[i].t, &q[i].k); + q[i].id = i; + } + sort(q + 1, q + Q + 1, + [](const ques &a, const ques &b) { + return a.t < b.t; + } + ); + for (int i = 1; i <= n; ++i) { + pos[i] = tar[i] = i; + } + sort(tar + 1, tar + n + 1, + [&](const int x, const int y) { + return a[x].first < a[y].first + || (a[x].first == a[y].first && x > y); + } + ); + int st = 1; + for (int i = 1; i <= Q; ++i) { + for (int j = st; j <= n; ++j) { + b[j] = a[j].second + 1ll * a[j].first * q[i].t; + } + for (int j = st + 1; j <= n; ++j) { + for (int k = j; k > st && (b[pos[k]] < b[pos[k - 1]] + || (b[pos[k]] == b[pos[k - 1]] && pos[k] > pos[k - 1])); --k) { + swap(pos[k], pos[k - 1]); + } + } + ans[q[i].id] = pos[n - q[i].k + 1]; + for (; st <= n && pos[st] == tar[st]; ++st) {} + } + printf("\n"); + for (int i = 1; i <= Q; ++i) { + printf("%d\n", ans[i]); + } + } + return 0; +} + From 9ea71d34776bae9cb291e801b771f7fb8a3596ec Mon Sep 17 00:00:00 2001 From: Aadhi11 <122631614+Aadhi11@users.noreply.github.com> Date: Sun, 15 Jan 2023 03:28:01 +0530 Subject: [PATCH 347/408] Circulate --- December - 26/cpp_Aadhi11.cpp | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 December - 26/cpp_Aadhi11.cpp diff --git a/December - 26/cpp_Aadhi11.cpp b/December - 26/cpp_Aadhi11.cpp new file mode 100644 index 0000000..c168a97 --- /dev/null +++ b/December - 26/cpp_Aadhi11.cpp @@ -0,0 +1,37 @@ +#include +#include +using namespace std; + +int main() +{ + vector > vec={{2},{5,4,6},{3},{4},{5},{6}}; + int n = vec.size(); + bool per[10]; + for(int i=0;i Date: Sun, 15 Jan 2023 03:29:14 +0530 Subject: [PATCH 348/408] Mission to Earth: Re-Calibrated --- December - 27/cpp_Aadhi11.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 December - 27/cpp_Aadhi11.cpp diff --git a/December - 27/cpp_Aadhi11.cpp b/December - 27/cpp_Aadhi11.cpp new file mode 100644 index 0000000..4cccb6e --- /dev/null +++ b/December - 27/cpp_Aadhi11.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +using namespace std; +#include +int main() +{ + float p,fracNume,fracDeno,f; + cout<<"Enter the Hydrogen fuel fraction:"<>fracNume>>fracDeno; + try + { + if(fracDeno==0) + throw 'e'; + else + p=(fracNume/fracDeno)*100; + } + catch(char e) + { + cout<=99) + cout<<"The tank is FULL!"; + if(b<=1) + cout<<"The tank is EMPTY!!!"< Date: Sun, 15 Jan 2023 03:30:20 +0530 Subject: [PATCH 349/408] The Journey to the Eternal Engine --- December - 28/cpp_Aadhi11.cpp | 113 ++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 December - 28/cpp_Aadhi11.cpp diff --git a/December - 28/cpp_Aadhi11.cpp b/December - 28/cpp_Aadhi11.cpp new file mode 100644 index 0000000..7d14047 --- /dev/null +++ b/December - 28/cpp_Aadhi11.cpp @@ -0,0 +1,113 @@ +#include +#include +#include +using namespace std; +void delval (int a[100],int n,int key) + { + int pos; + for (int j = 0; j < n; j++) + { + if (a[j] == key) + { + pos = j; + } + } + + for (int k = pos; k < n; k++) + { + a[k] = a[k + 1]; + } + } +int main() +{ + int n, a[100],fs,ss,fl,sl; + float t=0; + cout << "n="; + cin >> n; + cout <> a[i]; + } + + + while(n>0) + { + if(n==3||n==2) + { + if(n==2) + { + if(a[0]>a[1]) + t=t+a[0]; + else + t=t+a[1]; + } + else + { + for(int l=0;l fl) + { + fl = a[g]; + } + } + sl = 0; + for(int b=0;bsl) + { + sl = a[b]; + } + } + } + fs=INT_MAX; + for (int g = 0; g < n; g++) + { + if (a[g] < fs) + { + fs = a[g]; + } + } + int ss=INT_MAX; + for(int b=0;be) + t = t + e; + else + t = t + g; + delval(a,n,fl); + delval(a,n,sl); + n=n-2; + } + } + t = t/60; + t=floor(1000*t)/1000; + cout< Date: Sun, 15 Jan 2023 03:32:14 +0530 Subject: [PATCH 350/408] Candies --- December - 29/cpp_Aadhi11.cpp | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 December - 29/cpp_Aadhi11.cpp diff --git a/December - 29/cpp_Aadhi11.cpp b/December - 29/cpp_Aadhi11.cpp new file mode 100644 index 0000000..0fc82a1 --- /dev/null +++ b/December - 29/cpp_Aadhi11.cpp @@ -0,0 +1,56 @@ +#include +using namespace std; + +int countCandies(int arr[], int n) +{ + int sum = 0; + + int ans[n]; + + if (n == 1) { + return 1; + } + + for (int i = 0; i < n; i++) + ans[i] = 1; + + for (int i = 0; i < n - 1; i++) { + + if (arr[i + 1] > arr[i]) { + + ans[i + 1] = ans[i] + 1; + } + } + + for (int i = n - 2; i >= 0; i--) { + + if (arr[i] > arr[i + 1] + && ans[i] <= ans[i + 1]) { + + ans[i] = ans[i + 1] + 1; + } + + sum += ans[i]; + } + + sum += ans[n - 1]; + + return sum; +} + +int main() +{ + int arr[20],N; + cout<<"n="; + cin>>N; + cout<<"ratings = "; + for(int i=0;i>arr[i]; + } + cout < Date: Sun, 15 Jan 2023 03:32:59 +0530 Subject: [PATCH 351/408] Delete cpp_Aadhi11.cpp --- December - 01/cpp_Aadhi11.cpp | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 December - 01/cpp_Aadhi11.cpp diff --git a/December - 01/cpp_Aadhi11.cpp b/December - 01/cpp_Aadhi11.cpp deleted file mode 100644 index a750d3f..0000000 --- a/December - 01/cpp_Aadhi11.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include -using namespace std; - -string hexToASCII(string hex) -{ - string ascii = ""; - for (size_t i = 0; i < hex.length(); i += 2) - { - string part = hex.substr(i, 2); - - char ch = stoul(part, nullptr, 16); - - ascii += ch; - } - return ascii; -} - -int main() -{ - string hex[10]; - int n; - cin>>n; - for(int i=0;i>hex[i]; - } - - cout< Date: Sun, 15 Jan 2023 03:34:10 +0530 Subject: [PATCH 352/408] William Butcher's Mission --- December - 01/cpp_Aadhi11.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 December - 01/cpp_Aadhi11.cpp diff --git a/December - 01/cpp_Aadhi11.cpp b/December - 01/cpp_Aadhi11.cpp new file mode 100644 index 0000000..a750d3f --- /dev/null +++ b/December - 01/cpp_Aadhi11.cpp @@ -0,0 +1,34 @@ +#include +using namespace std; + +string hexToASCII(string hex) +{ + string ascii = ""; + for (size_t i = 0; i < hex.length(); i += 2) + { + string part = hex.substr(i, 2); + + char ch = stoul(part, nullptr, 16); + + ascii += ch; + } + return ascii; +} + +int main() +{ + string hex[10]; + int n; + cin>>n; + for(int i=0;i>hex[i]; + } + + cout< Date: Sun, 15 Jan 2023 03:35:18 +0530 Subject: [PATCH 353/408] Delete cpp_Aadhi11.cpp --- December - 02/cpp_Aadhi11.cpp | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 December - 02/cpp_Aadhi11.cpp diff --git a/December - 02/cpp_Aadhi11.cpp b/December - 02/cpp_Aadhi11.cpp deleted file mode 100644 index 1702487..0000000 --- a/December - 02/cpp_Aadhi11.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -using namespace std; - -int -main () -{ - string s, a; - cin >> s; - int k = s.length (); - if (s[k - 1] == 'e' && s[k - 2] == 'a') - { - a = s[k - 4]; - a = a + s[k - 3]; - for (int i = 0; i < k - 4; i++) - { - a = a + s[i]; - } - cout < Date: Sun, 15 Jan 2023 03:36:11 +0530 Subject: [PATCH 354/408] The Secret Language --- December - 02/cpp_Aadhi11.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 December - 02/cpp_Aadhi11.cpp diff --git a/December - 02/cpp_Aadhi11.cpp b/December - 02/cpp_Aadhi11.cpp new file mode 100644 index 0000000..1702487 --- /dev/null +++ b/December - 02/cpp_Aadhi11.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; + +int +main () +{ + string s, a; + cin >> s; + int k = s.length (); + if (s[k - 1] == 'e' && s[k - 2] == 'a') + { + a = s[k - 4]; + a = a + s[k - 3]; + for (int i = 0; i < k - 4; i++) + { + a = a + s[i]; + } + cout < Date: Sun, 15 Jan 2023 03:37:33 +0530 Subject: [PATCH 355/408] Minesweeper --- December - 03/cpp_Aadhi11.cpp | 111 ++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 December - 03/cpp_Aadhi11.cpp diff --git a/December - 03/cpp_Aadhi11.cpp b/December - 03/cpp_Aadhi11.cpp new file mode 100644 index 0000000..eaf26b5 --- /dev/null +++ b/December - 03/cpp_Aadhi11.cpp @@ -0,0 +1,111 @@ +#include +#include +using namespace std; + +int +main () +{ + string s[10]; + int n, a[10][10]; + cin >> n; + for (int i = 0; i < n; i++) + { + cin >> s[i]; + } + for (int i = 0; i < n; i++) + { + int c = 0; + for (int j = 0; j < s[i].length (); j++) + { + if (s[i][j] == '-') + { + a[i][c] = 0; + c++; + } + if (s[i][j] == '#') + { + a[i][c] = '#'; + c++; + } + } + } + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n; j++) + { + if (a[i][j] == '#') + { + if (a[i + 1][j + 1] != '#') + a[i + 1][j + 1] = a[i + 1][j + 1] + 1; + if (a[i - 1][j - 1] != '#') + a[i - 1][j - 1] = a[i - 1][j - 1] + 1; + if (a[i - 1][j + 1] != '#') + a[i - 1][j + 1] = a[i - 1][j + 1] + 1; + if (a[i + 1][j - 1] != '#') + a[i + 1][j - 1] = a[i + 1][j - 1] + 1; + if (a[i - 1][j] != '#') + a[i - 1][j] = a[i - 1][j] + 1; + if (a[i + 1][j] != '#') + a[i + 1][j] = a[i + 1][j] + 1; + if (a[i][j - 1] != '#') + a[i][j - 1] = a[i][j - 1] + 1; + if (a[i][j + 1] != '#') + a[i][j + 1] = a[i][j + 1] + 1; + } + } + } + for (int i = 0; i < n; i++) + { + int c = 0; + for (int j = 0; j < s[i].length (); j++) + { + if (s[i][j] == '-') + { + switch (a[i][c]) + { + case 0: + s[i][j] = '0'; + break; + case 1: + s[i][j] = '1'; + break; + case 2: + s[i][j] = '2'; + break; + case 3: + s[i][j] = '3'; + break; + case 4: + s[i][j] = '4'; + break; + case 5: + s[i][j] = '5'; + break; + case 6: + s[i][j] = '6'; + break; + case 7: + s[i][j] = '7'; + break; + case 8: + s[i][j] = '8'; + break; + } + c++; + } + if (s[i][j] == '#') + { + c++; + } + + } + } + cout << endl; + for (int i = 0; i < n; i++) + { + cout << s[i] << endl; + } + +} + + From 5a74f250c47e25a9809670ca1f16f8bc660c54d9 Mon Sep 17 00:00:00 2001 From: Aadhi11 <122631614+Aadhi11@users.noreply.github.com> Date: Sun, 15 Jan 2023 03:38:38 +0530 Subject: [PATCH 356/408] Industry --- December - 04/cpp_Aadhi11.cpp | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 December - 04/cpp_Aadhi11.cpp diff --git a/December - 04/cpp_Aadhi11.cpp b/December - 04/cpp_Aadhi11.cpp new file mode 100644 index 0000000..d0a89ac --- /dev/null +++ b/December - 04/cpp_Aadhi11.cpp @@ -0,0 +1,48 @@ +#include +using namespace std; + +int +main () +{ + int n, a[20]; + cout << "No. of days: "; + cin >> n; + cout <> a[i]; + } + int sum = 0; + int maxi = a[0]; + int start = 0, end = 0, s = 0; + for (int i = 0; i < n; i++) + { + sum += a[i]; + if (sum > maxi) + { + maxi = sum; + start = s; + end = i; + } + if (sum < 0) + { + sum = 0; + s = i + 1; + } + } + cout< Date: Sun, 15 Jan 2023 03:40:16 +0530 Subject: [PATCH 357/408] =?UTF-8?q?Don=E2=80=99t=20let=20Mason=20misspend!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- December - 05/cpp_Aadhi11.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 December - 05/cpp_Aadhi11.cpp diff --git a/December - 05/cpp_Aadhi11.cpp b/December - 05/cpp_Aadhi11.cpp new file mode 100644 index 0000000..85e904b --- /dev/null +++ b/December - 05/cpp_Aadhi11.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +int main() +{ + int x; + cout<<"fuel_price="; + cin>>x; + int ex; + ex=((x*2)*17); + ex=ex+(((x+3)*2)*8); + ex=ex+(((x-2)*2)*4); + ex=ex+(((x+1)*2)*2); + cout< Date: Sun, 15 Jan 2023 03:41:30 +0530 Subject: [PATCH 358/408] Swapped --- December - 06/cpp_Aadhi11.cpp | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 December - 06/cpp_Aadhi11.cpp diff --git a/December - 06/cpp_Aadhi11.cpp b/December - 06/cpp_Aadhi11.cpp new file mode 100644 index 0000000..b9fa025 --- /dev/null +++ b/December - 06/cpp_Aadhi11.cpp @@ -0,0 +1,53 @@ +#include +#include +using namespace std; + +int +main () +{ + int p, a[10]; + int count = 1; + string ta = "Tanika", bo = "Bob", x, y; + cout << "Position="; + cin >> p; + cout << "Set of numbers: "; + for (int i = 0; i < 3; i++) + { + cin >> a[i]; + } + cout << "Player going first: "; + cin >> x; + if (x == ta) + { + y = bo; + } + else + { + y = ta; + } + while (a[0] > 0) + { + int temp; + a[0] = a[0] - 1; + temp = a[0]; + a[0] = a[p - 1]; + a[p - 1] = temp; + count++; + } + if (count % 2 == 0) + { + cout< Date: Sun, 15 Jan 2023 03:43:25 +0530 Subject: [PATCH 359/408] Precise Portion --- December - 30/cpp_Aadhi11.cpp | 116 ++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 December - 30/cpp_Aadhi11.cpp diff --git a/December - 30/cpp_Aadhi11.cpp b/December - 30/cpp_Aadhi11.cpp new file mode 100644 index 0000000..01af672 --- /dev/null +++ b/December - 30/cpp_Aadhi11.cpp @@ -0,0 +1,116 @@ +#include +using namespace std; +typedef pair pii; +void printpath(map mp, pii u) +{ + if (u.first == 0 && u.second == 0) { + cout <<"("<< 0 << ", " << 0 <<")"<< endl; + return; + } + printpath(mp, mp[u]); + cout <<"("<< u.first << ", " << u.second <<")"<< endl; +} +void BFS(int a, int b, int target) +{ + map m; + bool isSolvable = false; + map mp; + + queue q; + + q.push(make_pair(0, 0)); + while (!q.empty()) { + + auto u = q.front(); + q.pop(); + if (m[u] == 1) + continue; + + if ((u.first > a || u.second > b || u.first < 0 + || u.second < 0)) + continue; + + m[{ u.first, u.second }] = 1; + + if (u.first == target || u.second == target) { + isSolvable = true; + + printpath(mp, u); + if (u.first == target) { + if (u.second != 0) + cout <<"("<< u.first << ", " << 0 <<")"<< endl; + } + else { + if (u.first != 0) + cout <<"("<< 0 << ", " << u.second <<")"<< endl; + } + return; + } + if (m[{ u.first, b }] != 1) { + q.push({ u.first, b }); + mp[{ u.first, b }] = u; + } + + if (m[{ a, u.second }] != 1) { + q.push({ a, u.second }); + mp[{ a, u.second }] = u; + } + + int d = b - u.second; + if (u.first >= d) { + int c = u.first - d; + if (m[{ c, b }] != 1) { + q.push({ c, b }); + mp[{ c, b }] = u; + } + } + else { + int c = u.first + u.second; + if (m[{ 0, c }] != 1) { + q.push({ 0, c }); + mp[{ 0, c }] = u; + } + } + d = a - u.first; + if (u.second >= d) { + int c = u.second - d; + if (m[{ a, c }] != 1) { + q.push({ a, c }); + mp[{ a, c }] = u; + } + } + else { + int c = u.first + u.second; + if (m[{ c, 0 }] != 1) { + q.push({ c, 0 }); + mp[{ c, 0 }] = u; + } + } + + if (m[{ u.first, 0 }] != 1) { + q.push({ u.first, 0 }); + mp[{ u.first, 0 }] = u; + } + + if (m[{ 0, u.second }] != 1) { + q.push({ 0, u.second }); + mp[{ 0, u.second }] = u; + } + } +} + +int main() +{ + int Jug1 = 11, Jug2 = 9, target,d1,d2; + cin>>Jug1>>Jug2; + cin>>d1>>d2; + if(d1==0) + target=d2; + else + target=d1; + cout< Date: Sun, 15 Jan 2023 03:46:59 +0530 Subject: [PATCH 360/408] The Quad of Queens --- December - 31/cpp_Aadhi11.cpp | 117 ++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 December - 31/cpp_Aadhi11.cpp diff --git a/December - 31/cpp_Aadhi11.cpp b/December - 31/cpp_Aadhi11.cpp new file mode 100644 index 0000000..506351a --- /dev/null +++ b/December - 31/cpp_Aadhi11.cpp @@ -0,0 +1,117 @@ +#include +using namespace std; +int grid[10][10]; +int k=0; + +void print(int n) { + for (int i = 0;i <= n-1; i++) { + for (int j = 0;j <= n-1; j++) { + + if(grid[i][j]==1) + cout <<"Q"<< " "; + else + cout <<"."<< " "; + + } + cout<= 0 && j >= 0; i--,j--) { + if (grid[i][j]) { + return false; + } + } + for (int i = row, j = col; i >= 0 && j < n; j++, i--) { + if (grid[i][j]) { + return false; + } + } + return true; +} + +bool solves (int n, int row) { + if (n == row) { + print(n); + return true; + } + bool res = false; + for (int i = 0;i <=n-1;i++) { + if (Safe(i, row, n)) { + grid[row][i] = 1; + res = solves(n, row+1) || res; + grid[row][i] = 0; + } + } + return res; +} + +bool isSafe(int col, int row, int n) { + for (int i = 0; i < row; i++) { + if (grid[i][col]) { + return false; + } + } + for (int i = row,j = col;i >= 0 && j >= 0; i--,j--) { + if (grid[i][j]) { + return false; + } + } + for (int i = row, j = col; i >= 0 && j < n; j++, i--) { + if (grid[i][j]) { + return false; + } + } + return true; +} + +bool solve (int n, int row) { + if (n == row) { + k++; + return true; + } + bool res = false; + for (int i = 0;i <=n-1;i++) { + if (isSafe(i, row, n)) { + grid[row][i] = 1; + res = solve(n, row+1) || res; + grid[row][i] = 0; + } + } + return res; +} + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int n; + cin >> n; + cout< Date: Sun, 15 Jan 2023 10:01:11 +0530 Subject: [PATCH 361/408] Add files via upload --- December - 01/day 1.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 December - 01/day 1.py diff --git a/December - 01/day 1.py b/December - 01/day 1.py new file mode 100644 index 0000000..e5a2185 --- /dev/null +++ b/December - 01/day 1.py @@ -0,0 +1,13 @@ + +n=int(input()) +clue=[] +for i in range(n): + a=list(input().split(',')) + s='' + for j in a: + s+=j + byte_array=bytes.fromhex(s) + ascii_str=byte_array.decode() + clue.append(ascii_str) +for i in clue: + print(i) \ No newline at end of file From df9d45a70dbe856eecc2a59c7744067f17bb24b9 Mon Sep 17 00:00:00 2001 From: Lokesh4623 <84383628+Lokesh4623@users.noreply.github.com> Date: Sun, 15 Jan 2023 10:12:04 +0530 Subject: [PATCH 362/408] Add files via upload --- December - 02/day 2.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 December - 02/day 2.py diff --git a/December - 02/day 2.py b/December - 02/day 2.py new file mode 100644 index 0000000..181c941 --- /dev/null +++ b/December - 02/day 2.py @@ -0,0 +1,5 @@ +x=input() +y=x[:len(x)-2] +z=y[:len(y)-2] +w=y[len(y)-2:] +print(w+z) \ No newline at end of file From 9df7a8d3950cae7834d379b430179e11eaee2d9a Mon Sep 17 00:00:00 2001 From: Lokesh4623 <84383628+Lokesh4623@users.noreply.github.com> Date: Sun, 15 Jan 2023 10:12:46 +0530 Subject: [PATCH 363/408] Add files via upload --- December - 03/day 3.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 December - 03/day 3.py diff --git a/December - 03/day 3.py b/December - 03/day 3.py new file mode 100644 index 0000000..7139373 --- /dev/null +++ b/December - 03/day 3.py @@ -0,0 +1,41 @@ +a=[] +print("Enter the size:") +n=int(input()) +print("enter the elements:") +for i in range(0,n): + b=[] + for j in range(0,n): + x=input() + b.append(x) + a.append(b) + +print("Before:") +for i in range(0,n): + for j in range(0,n): + print(a[i][j],end=' ') + print("\n") + +for i in range(0,n): + for j in range(0,n): + if(a[i][j]=='-'): + a[i][j]='0' + +for i in range(0,n): + for j in range(0,n): + if(a[i][j]=='#'): + for k in range(i-1,i+2): + for l in range(j-1,j+2): + if(k in range(0,n) and l in range(0,n)): + if(k==i and l==j): + continue + elif(a[k][l]!='#'): + x=int(a[k][l])+1 + a[k][l]=str(x) + +print("After:") +for i in range(0,n): + for j in range(0,n): + print(a[i][j],end=' ') + print("\n") + + \ No newline at end of file From 04abecd91ddf22ce16168c4b50050b953833433b Mon Sep 17 00:00:00 2001 From: Lokesh4623 <84383628+Lokesh4623@users.noreply.github.com> Date: Sun, 15 Jan 2023 10:13:57 +0530 Subject: [PATCH 364/408] Add files via upload --- December - 04/day 4.cpp | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 December - 04/day 4.cpp diff --git a/December - 04/day 4.cpp b/December - 04/day 4.cpp new file mode 100644 index 0000000..3543b20 --- /dev/null +++ b/December - 04/day 4.cpp @@ -0,0 +1,47 @@ +#include +#include +using namespace std; + +void maxSubArraySum(int a[], int size) +{ + int max_so_far = INT_MIN, max_ending_here = 0,start = 0, end = 0, s = 0; + + for (int i = 0; i < size; i++) { + max_ending_here += a[i]; + + if (max_so_far < max_ending_here) { + max_so_far = max_ending_here; + start = s; + end = i; + } + + if (max_ending_here < 0) { + max_ending_here = 0; + s = i + 1; + } + } + cout << "Profit value: " <>n; + cout<<"Given stock market change values:"; + for(int i=0;i>a[i]; + } + maxSubArraySum(a, n); + return 0; +} From 3e7d87316dcf884ba66805107542d9cdaa6d7c61 Mon Sep 17 00:00:00 2001 From: Lokesh4623 <84383628+Lokesh4623@users.noreply.github.com> Date: Sun, 15 Jan 2023 10:18:55 +0530 Subject: [PATCH 365/408] Add files via upload --- December - 05/day 5.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 December - 05/day 5.py diff --git a/December - 05/day 5.py b/December - 05/day 5.py new file mode 100644 index 0000000..f265920 --- /dev/null +++ b/December - 05/day 5.py @@ -0,0 +1,8 @@ +fuel=int(input("fuel_price=")) +total_fuel_cost=(10*(fuel+3))+(6*(fuel-2))+(15*fuel) +expenditure=total_fuel_cost*2 +print("Expenditure=",expenditure) +if(expenditure<5000): + print("EXPENDITURE WITHIN LIMIT") +else: + print("EXPENDITURE EXCEEDING LIMIT") \ No newline at end of file From aedca93357cd71590249207b37866fbd2c04ff09 Mon Sep 17 00:00:00 2001 From: Lokesh4623 <84383628+Lokesh4623@users.noreply.github.com> Date: Sun, 15 Jan 2023 10:19:28 +0530 Subject: [PATCH 366/408] Add files via upload --- December - 06/day 6.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 December - 06/day 6.py diff --git a/December - 06/day 6.py b/December - 06/day 6.py new file mode 100644 index 0000000..95163f5 --- /dev/null +++ b/December - 06/day 6.py @@ -0,0 +1,20 @@ +n=int(input("Position=")) +list_A=list(map(int,input("Set of numbers: ").split())) +turn=input("Player going first: ") +c=0 +while(list_A[0]!=0): + list_A[0]=list_A[0]-1 + t=list_A[0] + list_A[0]=list_A[n-1] + list_A[n-1]=t + c+=1 + +if(turn=='Tanika' and c%2==1): + print("Tanika wins the game!\nBob loses the game!") +elif(turn=='Tanika' and c%2==0): + print("Bob wins the game!\nTanika loses the game!") +elif(turn=='Bob' and c%2==1): + print("Bob wins the game!\nTanika loses the game!") +elif(turn=='Bob' and c%2==0): + print("Tanika wins the game!\nBob loses the game!") + \ No newline at end of file From 8881065b8abc504f924b582563da5f951c450247 Mon Sep 17 00:00:00 2001 From: Lokesh4623 <84383628+Lokesh4623@users.noreply.github.com> Date: Sun, 15 Jan 2023 10:19:53 +0530 Subject: [PATCH 367/408] Add files via upload --- December - 07/day 7.py | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 December - 07/day 7.py diff --git a/December - 07/day 7.py b/December - 07/day 7.py new file mode 100644 index 0000000..0e66265 --- /dev/null +++ b/December - 07/day 7.py @@ -0,0 +1,43 @@ + +grid=[['A','S','S','E','R','T','I','V','E','N','E','S','S','L','J'], + ['C','F','O','G','O','O','D','P','O','S','I','T','I','V','E'], + ['O','P','E','N','B','M','U','R','E','W','O','P','R','P','S'], + ['M','E','D','I','A','T','I','O','N','E','L','D','I','O','G'], + ['M','A','A','S','R','E','G','J','E','W','I','N','W','I','N'], + ['U','C','I','A','E','M','O','E','E','C','S','K','E','N','I'], + ['N','E','M','R','S','H','A','C','D','V','T','W','T','T','L'], + ['I','T','E','H','O','T','L','T','S','T','E','R','A','O','E'], + ['C','A','S','P','L','G','L','S','I','U','N','E','R','F','E'], + ['A','I','S','A','U','S','Y','T','P','O','I','S','E','V','F'], + ['T','T','A','R','T','T','D','O','C','E','N','P','P','I','H'], + ['I','O','G','A','I','G','U','P','Y','M','G','O','O','E','E'], + ['O','G','E','P','O','A','F','P','Q','I','E','N','O','W','A'], + ['N','E','C','O','N','F','L','I','C','T','S','D','C','E','R'], + ['F','N','H','T','C','A','T','N','O','C','E','Y','E','B','T']] + +search=input() + +c=[] +b=[] +flag=0 +for i in range(0,15): + x='' + for j in range(0,15): + x+=grid[i][j] + c.append(x) +#print(c) +for i in range(0,15): + x='' + for j in range(0,15): + x+=grid[j][i] + b.append(x) +#print(b) + +for i in range(0,15): + if(search in c[i] or search in b[i]): + flag=1 + print("found") + break + +if(flag==0): + print("not found") From fd206cdda1a55e471f2ecadb76fe1d55498e241c Mon Sep 17 00:00:00 2001 From: Lokesh4623 <84383628+Lokesh4623@users.noreply.github.com> Date: Sun, 15 Jan 2023 10:20:31 +0530 Subject: [PATCH 368/408] Add files via upload --- December - 08/day 8.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 December - 08/day 8.c diff --git a/December - 08/day 8.c b/December - 08/day 8.c new file mode 100644 index 0000000..fff2186 --- /dev/null +++ b/December - 08/day 8.c @@ -0,0 +1,19 @@ + +#include +#include +int main() +{ + int i; + char in[1000],t; + printf("Input: "); + scanf("%s",in); + for(i=1;i Date: Sun, 15 Jan 2023 10:21:18 +0530 Subject: [PATCH 369/408] Add files via upload --- December - 09/day 9.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 December - 09/day 9.py diff --git a/December - 09/day 9.py b/December - 09/day 9.py new file mode 100644 index 0000000..84b5d55 --- /dev/null +++ b/December - 09/day 9.py @@ -0,0 +1,20 @@ + +import math +n=int(input()) +list_A=list(input().split()) +len_arr=[] +ind_arr=[] +for i in range(0,n): + if(len(list_A[i])%2==1): + len_arr.append(len(list_A[i])) + ind_arr.append(i) + +if(len_arr==[]): + print("Better luck next time") +else: + max=-math.inf + for i in range(0,len(len_arr)): + if len_arr[i]>max: + max=len_arr[i] + word=ind_arr[i] + print(list_A[word]) \ No newline at end of file From 3038a1711b2d3d26d493c1ecdf1629c5b557b4fa Mon Sep 17 00:00:00 2001 From: Lokesh4623 <84383628+Lokesh4623@users.noreply.github.com> Date: Sun, 15 Jan 2023 10:21:51 +0530 Subject: [PATCH 370/408] Add files via upload --- December - 10/day 10.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 December - 10/day 10.py diff --git a/December - 10/day 10.py b/December - 10/day 10.py new file mode 100644 index 0000000..7cf7cf6 --- /dev/null +++ b/December - 10/day 10.py @@ -0,0 +1,17 @@ +a=[] +n=int(input()) +vowels=['a','e','i','o','u','A','E','I','O','U'] +for i in range(0,n): + x=int(input()) + word=input() + c=0 + for j in word: + if j in vowels: + c+=1 + + if (x-c)>4: + a.append("NO") + else: + a.append("YES") +for i in a: + print(i) \ No newline at end of file From 052c829537d6a572544ccf025d190e419b4b10c6 Mon Sep 17 00:00:00 2001 From: Lokesh4623 <84383628+Lokesh4623@users.noreply.github.com> Date: Sun, 15 Jan 2023 10:22:30 +0530 Subject: [PATCH 371/408] Add files via upload --- December - 11/day 11.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 December - 11/day 11.py diff --git a/December - 11/day 11.py b/December - 11/day 11.py new file mode 100644 index 0000000..c6abcc3 --- /dev/null +++ b/December - 11/day 11.py @@ -0,0 +1,9 @@ +a=list(input().split(',')) +b=list(map(int,input().split(','))) +x=0 +for i in range(0,len(b)): + x+=b[i] + if(a[x]=='~'): + print("Score =",i) + break + \ No newline at end of file From bb063e47f1dd8ec6668ecd28085239e3f00fac4b Mon Sep 17 00:00:00 2001 From: Lokesh4623 <84383628+Lokesh4623@users.noreply.github.com> Date: Sun, 15 Jan 2023 10:22:59 +0530 Subject: [PATCH 372/408] Add files via upload --- December - 12/day 12.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 December - 12/day 12.py diff --git a/December - 12/day 12.py b/December - 12/day 12.py new file mode 100644 index 0000000..1a6b7bc --- /dev/null +++ b/December - 12/day 12.py @@ -0,0 +1,26 @@ + +n=int(input()) +a=[] +for i in range(n): + b=list(map(int,input().split())) + a.append(b) +i=0 +j=0 +dropped=0 + +current_position=a[i][j] +print("path_taken={",current_position,end=',') +dropped+=current_position +while(i+1 in range(0,n) and j+1 in range(0,n)): + if(a[i][j+1]=a[i+1][j]): + current_position= a[i+1][j] + i=i+1 + print(current_position,end=',') + dropped+=current_position +print(a[n-1][n-1],end="}") +dropped+=a[n-1][n-1] +print("\nThe minimum coins dropped is ",dropped) + \ No newline at end of file From 7d410f5c0d0e12059c63f99f88ca56273185cecf Mon Sep 17 00:00:00 2001 From: Lokesh4623 <84383628+Lokesh4623@users.noreply.github.com> Date: Sun, 15 Jan 2023 10:23:29 +0530 Subject: [PATCH 373/408] Add files via upload --- December - 13/day 13.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 December - 13/day 13.py diff --git a/December - 13/day 13.py b/December - 13/day 13.py new file mode 100644 index 0000000..4f30592 --- /dev/null +++ b/December - 13/day 13.py @@ -0,0 +1,29 @@ +n=int(input()) +a=[] +b=[] +for i in range(n): + x=list(map(int,input().split())) + a.append(x) + + +for i in range(0,n): + c=[] + for j in range(0,n): + x=0 + c.append(x) + b.append(c) + +i=0 +j=0 +b[i][j]=1 +while(i in range(0,n) and j in range(0,n)): + if(j+1 Date: Sun, 15 Jan 2023 10:24:17 +0530 Subject: [PATCH 374/408] Add files via upload --- December - 15/day 15.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 December - 15/day 15.py diff --git a/December - 15/day 15.py b/December - 15/day 15.py new file mode 100644 index 0000000..1aa68ac --- /dev/null +++ b/December - 15/day 15.py @@ -0,0 +1,22 @@ +a=[] +for j in range(3): + a.append(list(input().split(','))) +for i in range(0,len(a)): + h=a[i][1] + m=a[i][1] + s=a[i][1] + h=int(h[0:2]) + m=int(m[3:5]) + s=int(s[6:8]) + time=(h*3600)+(m*60)+s + a[i].append(time) + +for i in range(0,len(a)-1): + for j in range(0,len(a)-i-1): + if(a[j][2]>a[j+1][2]): + a[j],a[j+1]=a[j+1],a[j] +queue=[] +for i in range(0,3): + queue.append(a[i][0]) +print(queue) + \ No newline at end of file From 654e0a3b00ca41a267bf6b23cbcdb185d2d10a3f Mon Sep 17 00:00:00 2001 From: Lokesh4623 <84383628+Lokesh4623@users.noreply.github.com> Date: Sun, 15 Jan 2023 10:24:47 +0530 Subject: [PATCH 375/408] Add files via upload --- December - 16/day 16.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 December - 16/day 16.py diff --git a/December - 16/day 16.py b/December - 16/day 16.py new file mode 100644 index 0000000..7b93bbc --- /dev/null +++ b/December - 16/day 16.py @@ -0,0 +1,15 @@ + + +import math +max_val=-math.inf +a=list(map(int,input().split(','))) +for i in range(0,len(a)): + for j in range(i+1,len(a)): + if(a[i]>a[j]): + p=a[j] + else: + p=a[i] + product=p*(j-i) + if(max_val Date: Sun, 15 Jan 2023 11:11:08 +0530 Subject: [PATCH 376/408] Add files via upload --- December - 01/Dec1.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 December - 01/Dec1.py diff --git a/December - 01/Dec1.py b/December - 01/Dec1.py new file mode 100644 index 0000000..2000b5c --- /dev/null +++ b/December - 01/Dec1.py @@ -0,0 +1,12 @@ +n=int(input()) +a=[] +for i in range(n): + a=list(input().split(',')) + b='' + for j in a: + b+=j + c=bytes.fromhex(b) + d=c.decode() + a.append(d) +for i in a: + print(i) \ No newline at end of file From f9fef61baea270127538d9870b38c191f29ed06a Mon Sep 17 00:00:00 2001 From: Lagan Mehta <86072718+LaganMehta@users.noreply.github.com> Date: Sun, 15 Jan 2023 11:13:31 +0530 Subject: [PATCH 377/408] Delete Dec1.py --- December - 01/Dec1.py | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 December - 01/Dec1.py diff --git a/December - 01/Dec1.py b/December - 01/Dec1.py deleted file mode 100644 index 2000b5c..0000000 --- a/December - 01/Dec1.py +++ /dev/null @@ -1,12 +0,0 @@ -n=int(input()) -a=[] -for i in range(n): - a=list(input().split(',')) - b='' - for j in a: - b+=j - c=bytes.fromhex(b) - d=c.decode() - a.append(d) -for i in a: - print(i) \ No newline at end of file From bff2e0cb6c3f6a1cca3794288b5843154f1977c9 Mon Sep 17 00:00:00 2001 From: Lagan Mehta <86072718+LaganMehta@users.noreply.github.com> Date: Sun, 15 Jan 2023 11:15:04 +0530 Subject: [PATCH 378/408] Add files via upload --- December - 01/Python3_Lagan Mehta.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 December - 01/Python3_Lagan Mehta.py diff --git a/December - 01/Python3_Lagan Mehta.py b/December - 01/Python3_Lagan Mehta.py new file mode 100644 index 0000000..2000b5c --- /dev/null +++ b/December - 01/Python3_Lagan Mehta.py @@ -0,0 +1,12 @@ +n=int(input()) +a=[] +for i in range(n): + a=list(input().split(',')) + b='' + for j in a: + b+=j + c=bytes.fromhex(b) + d=c.decode() + a.append(d) +for i in a: + print(i) \ No newline at end of file From 6af1aefe105dc84a43e2cf47a6104f0b08ae602f Mon Sep 17 00:00:00 2001 From: Lagan Mehta <86072718+LaganMehta@users.noreply.github.com> Date: Sun, 15 Jan 2023 11:17:53 +0530 Subject: [PATCH 379/408] Rename Python3_Lagan Mehta.py to Python3_Lagan Mehta_December1.py --- ...{Python3_Lagan Mehta.py => Python3_Lagan Mehta_December1.py} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename December - 01/{Python3_Lagan Mehta.py => Python3_Lagan Mehta_December1.py} (87%) diff --git a/December - 01/Python3_Lagan Mehta.py b/December - 01/Python3_Lagan Mehta_December1.py similarity index 87% rename from December - 01/Python3_Lagan Mehta.py rename to December - 01/Python3_Lagan Mehta_December1.py index 2000b5c..1cb3048 100644 --- a/December - 01/Python3_Lagan Mehta.py +++ b/December - 01/Python3_Lagan Mehta_December1.py @@ -9,4 +9,4 @@ d=c.decode() a.append(d) for i in a: - print(i) \ No newline at end of file + print(i) From 7a3b4ceff4743be1460a1753bda694818c384f0c Mon Sep 17 00:00:00 2001 From: Lagan Mehta <86072718+LaganMehta@users.noreply.github.com> Date: Sun, 15 Jan 2023 11:20:15 +0530 Subject: [PATCH 380/408] Add files via upload --- December - 02/Python3_Lagan Mehta_December2.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 December - 02/Python3_Lagan Mehta_December2.py diff --git a/December - 02/Python3_Lagan Mehta_December2.py b/December - 02/Python3_Lagan Mehta_December2.py new file mode 100644 index 0000000..c5bd69b --- /dev/null +++ b/December - 02/Python3_Lagan Mehta_December2.py @@ -0,0 +1,5 @@ +a=input() +b=a[:len(a)-2] +c=b[:len(b)-2] +d=b[len(b)-2:] +print(d+c) \ No newline at end of file From 10a586292dad9d6f20941889430a03bcd0783a5e Mon Sep 17 00:00:00 2001 From: Lagan Mehta <86072718+LaganMehta@users.noreply.github.com> Date: Sun, 15 Jan 2023 11:23:03 +0530 Subject: [PATCH 381/408] Add files via upload --- .../Python3_Lagan Mehta_December3.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 December - 03/Python3_Lagan Mehta_December3.py diff --git a/December - 03/Python3_Lagan Mehta_December3.py b/December - 03/Python3_Lagan Mehta_December3.py new file mode 100644 index 0000000..d86b715 --- /dev/null +++ b/December - 03/Python3_Lagan Mehta_December3.py @@ -0,0 +1,35 @@ +a=[] +print("Enter the size you want:") +n=int(input()) +print("Enter the elements for it:") +for i in range(0,n): + b=[] + for j in range(0,n): + x=input() + b.append(x) + a.append(b) +print("Before:") +for i in range(0,n): + for j in range(0,n): + print(a[i][j],end=' ') + print("\n") +for i in range(0,n): + for j in range(0,n): + if(a[i][j]=='-'): + a[i][j]='0' +for i in range(0,n): + for j in range(0,n): + if(a[i][j]=='#'): + for k in range(i-1,i+2): + for l in range(j-1,j+2): + if(k in range(0,n) and l in range(0,n)): + if(k==i and l==j): + continue + elif(a[k][l]!='#'): + x=int(a[k][l])+1 + a[k][l]=str(x) +print("After:") +for i in range(0,n): + for j in range(0,n): + print(a[i][j],end=' ') + print("\n") \ No newline at end of file From bcfefb2b77a3f5649f3bd986df941ac1000d5d59 Mon Sep 17 00:00:00 2001 From: GANESHANHARI <93967094+GANESHANHARI@users.noreply.github.com> Date: Sun, 15 Jan 2023 18:45:38 +0530 Subject: [PATCH 382/408] Add files via upload --- December - 05/JAVA_GANESHANHARI_DAY_5.java | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 December - 05/JAVA_GANESHANHARI_DAY_5.java diff --git a/December - 05/JAVA_GANESHANHARI_DAY_5.java b/December - 05/JAVA_GANESHANHARI_DAY_5.java new file mode 100644 index 0000000..233fd03 --- /dev/null +++ b/December - 05/JAVA_GANESHANHARI_DAY_5.java @@ -0,0 +1,95 @@ +/* + +DAY 5 +MASON is a motoring enthusiast and he owns a sports bike . +With the price of petrol going up and down in a pattern , MASON is worried whether his salary would be sufficient to meet his needs apart from fueling his bike . + So he decides to calculate how much he spends on fueling his bike per month. + Help MASON calculate his fuel expenditure. + If he spends more than 10 PERCENTAGE of his INCOME give him a warning message reading b EXPENDITURE EXCEEDING LIMIT +Conditions +MASON fuels his bike twice a day . + +The PRICE of the fuel is x/l initially. + +Every third day the price goes up by 3 rupees . + +Every fifth day the price goes down by 2 rupees . + +On the other days the price of the fuel remains x/l. + +Help him to calculate his expense for a period of one month (31DAYS) . + +Check whether the expenditure is more than 10 percent of his income . + +His income is 50,000 rupees per month. +*/ + +/* +Input: +75 + +Output: +4686 + +“EXPENDITURE WITHIN LIMIT” + + */ +import java.util.Scanner; + +public class JAVA_GANESHANHARI_DAY_5 +{ + +public static void main (String[]args) + { + +try (Scanner s = new Scanner (System.in)) { + System.out.println ("Input:"); + + int fuel = s.nextInt (); + + int exp = 0; + + for (int i = 1; i <= 31; i++) + + { + + if ((i % 3 == 0) && (i % 5 == 0)) + + exp += ((fuel + 1) * 2); + + else if (i % 3 == 0) + + exp += ((fuel + 3) * 2); + + else if (i % 5 == 0) + + exp += ((fuel - 2) * 2); + + else + + exp += (fuel * 2); + + + } + + System.out.println (exp); + + if (exp < 5000) + + System.out.println ("EXPENDITURE WITHIN LIMIT"); + + else + + System.out.println ("EXPENDITURE EXCEEDING LIMIT"); +} + +} + + + +} + + + + + From edce7845843fcd982efe355fcc19a9c7d360e74f Mon Sep 17 00:00:00 2001 From: GANESHANHARI <93967094+GANESHANHARI@users.noreply.github.com> Date: Sun, 15 Jan 2023 18:51:32 +0530 Subject: [PATCH 383/408] Add files via upload --- December - 07/JAVA_GANESHANHARI_DAY_7.java | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 December - 07/JAVA_GANESHANHARI_DAY_7.java diff --git a/December - 07/JAVA_GANESHANHARI_DAY_7.java b/December - 07/JAVA_GANESHANHARI_DAY_7.java new file mode 100644 index 0000000..ce24426 --- /dev/null +++ b/December - 07/JAVA_GANESHANHARI_DAY_7.java @@ -0,0 +1,96 @@ +/*You are given a grid made up of random characters. + Given a word, your task is to determine whether the word can be constructed from the given grid. + +The word can be constructed from letters of sequentially adjacent cells, +where adjacent cells are horizontally or vertically neighboring. +The same letter cell may not be used more than once */ + + +/* + Input: + COMMUNICATION + +Output: + Found + + + + Input: + DOCUMENT + +Output: + Not Found + + */ + +import java.util.*; +public class JAVA_GANESHANHARI_DAY_7 +{ + public static int n; + public static char word[]=new char[n]; + public static char a[][]=new char[15][15]; + public static int xa[]={0,0,1,-1}; + public static int ya[]={1,-1,0,0}; + public static int i,j; + public static int xpos,ypos; + public static boolean find(int x,int y) + { + + for(j=0;j<4;j++) + { + xpos=x; + ypos=y; + for( i=1;i14|| ypos<0||ypos>14 ) break; + if(word[i]!=a[xpos][ypos]) break; + } + if(i==n) return true; + } + + return false; + + } + +public static void main(String[] args) + { + + Scanner s=new Scanner(System.in); + System.out.println("Input:"); + String word1=s.next(); + word=word1.toCharArray(); + n=word.length; + String a1="ASSERTIVENESSLJCFOGOODPOSITIVEOPENBMUREWOPRPSMEDIATIONELDIOGMAASREGJEWINWINUCIAEMOEECSKENINEMRSHACDVTWTTLITEHOTLTSTERAOECASPLGLSIUNERFEAISAUSYTPOISEVFTTARTTDOCENPPIHIOGAIGUPYMGOOEEOGEPOAFPQIENOWANECONFLICTSDCERFNHTCATNOCEYEBT"; + int index=0; + for(int i=0;i<15;i++) + { + for(int j=0;j<15;j++) + { + a[i][j]=a1.charAt(index++); + // System.out.print(a[i][j]+"\t"); + } + //System.out.println(); + } + for(int i=0;i<15;i++) + { + for(int j=0;j<15;j++) + { + if(word[0]==a[i][j]) + { + if(find(i,j)!=true) continue; + else + { + System.out.println("OUTPUT:\nFound"); + System.exit(0); + } + } + else continue; + } + } + System.out.println("OUTPUT:\n NOT FOUND"); + + } +} \ No newline at end of file From f7aab1e48d906ab5bbcc60c245fffbd189c55c69 Mon Sep 17 00:00:00 2001 From: GANESHANHARI <93967094+GANESHANHARI@users.noreply.github.com> Date: Sun, 15 Jan 2023 19:01:01 +0530 Subject: [PATCH 384/408] Add files via upload --- December - 09/JAVA_GANESHANHARI_DAY_9.java | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 December - 09/JAVA_GANESHANHARI_DAY_9.java diff --git a/December - 09/JAVA_GANESHANHARI_DAY_9.java b/December - 09/JAVA_GANESHANHARI_DAY_9.java new file mode 100644 index 0000000..def214b --- /dev/null +++ b/December - 09/JAVA_GANESHANHARI_DAY_9.java @@ -0,0 +1,76 @@ +/* + * Kochouseph Chittilappilly went to Dhruv Zplanet + * , a gaming space, with his friends and played a game called “Guess the Word”. + +Rules of the game are – + +Computer displays some strings on the screen and the player should pick one string / + word if this word matches with the random word that the computer picks then the player is declared as Winner. + +Kochouseph Chittilappilly’s friends played the game and no one won the game. + +This is Kochouseph Chittilappilly’s turn to play and he decided to win the game. + What he observed from his friend’s game is that the computer is picking up the first string whose + length is odd and is of maximum length. + +Due to system failures computers sometimes cannot generate odd length words. + In such cases you will lose the game irrespective of whether you guess the right word or not + and it displays “better luck next time”. + +Write a program to help Kochouseph win the game + */ + + /* + Input: +3 +Go to hell + +Output : +Better luck next time + + + + +Input: +5 +Hello Good Morning Welcome You + +Output : +Morning + + */ +import java.util.*; +public class JAVA_GANESHANHARI_DAY_9{ + public static void main(String[] args) { + + try (Scanner s = new Scanner(System.in)) { + int n=s.nextInt(); + String str1[]=new String[n]; + int arr[]=new int[n]; + int i=0; + while(itemp) + { + temp=arr[j]; + count=j; + } + + } + if(count==-1) + System.out.println("BETTER LUCK NEXT TIME"); + else + System.out.println(str1[count]); + } +} +} \ No newline at end of file From 7dde230a608cae7a12340bc967ecc7436d582383 Mon Sep 17 00:00:00 2001 From: GANESHANHARI <93967094+GANESHANHARI@users.noreply.github.com> Date: Sun, 15 Jan 2023 19:07:17 +0530 Subject: [PATCH 385/408] Add files via upload --- December - 11/JAVA_GANESHANHARI_DAY_11.java | 59 +++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 December - 11/JAVA_GANESHANHARI_DAY_11.java diff --git a/December - 11/JAVA_GANESHANHARI_DAY_11.java b/December - 11/JAVA_GANESHANHARI_DAY_11.java new file mode 100644 index 0000000..457daff --- /dev/null +++ b/December - 11/JAVA_GANESHANHARI_DAY_11.java @@ -0,0 +1,59 @@ +/* + A list is provided with a sequence of characters . The character ‘_’ represents land and the character ‘~’ represents water. A monkey can move 1 step or 2 steps in a single jump. Another list provided here contains the step that the monkey took Eg[1,1,2,1,2]. Whenever the monkey touches the water. The game is over and the score must be returned. Calculate the jumps the monkey took before touching the water. + */ + + /*Input 1: + +[‘_’,’~’,’_’,’_’,’_’,’_’,’~’,’_’,’_’,’~’,’_’,’~’] + +[2,1,1,1,2,1,2,1] + +Output 1: + +Score =7 + +Input 2: + +[‘_’,’~’,’_’,’~’,’_’,’_’,’~’,’_’,’_’,’~’,’_’,’~’] + +[2,2,1,1,1,1,2,1,1] + +Output 2: +Score =3 + */ + +import java.util.*; +public class DAY_11 +{ + public static void main(String[] args) { + try (Scanner s = new Scanner(System.in)) { + String path=s.next(); + int n=path.length(); + String jump=s.next(); + // int n1=jump.length(); + int pos=0; + int score=0; + for(int i=0;i Date: Sun, 15 Jan 2023 19:17:03 +0530 Subject: [PATCH 386/408] Add files via upload --- December - 02/CPP_GANESHANHARI_DAY_ 2.cpp | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 December - 02/CPP_GANESHANHARI_DAY_ 2.cpp diff --git a/December - 02/CPP_GANESHANHARI_DAY_ 2.cpp b/December - 02/CPP_GANESHANHARI_DAY_ 2.cpp new file mode 100644 index 0000000..b88e36c --- /dev/null +++ b/December - 02/CPP_GANESHANHARI_DAY_ 2.cpp @@ -0,0 +1,46 @@ +/* +Leonard and Sheldon are the best of friends. They know each other so well that they even developed their own language to exchange secret messages. However, they have recently made a new friend, Raj, who has difficulty understanding the two when they communicate in their language. + +Leonard and Sheldon’s language is similar to Pig Latin. Their unique language consists of usual English words transformed by shifting the first two letters in a word to the end and adding a suffix 'ae'. + +Help Raj translate and decode his friends' secret messages. + + + Input: kipediawiae + + Output: wikipedia + + + + + +*/ + + + + +#include +#include +using namespace std; +int main() +{ + char a[1000]; + cout<<"INPUT:"; + cin>>a; + + int n=strlen(a); + int m=n-2; + char c[m]; + + for(int i=0;i Date: Sun, 15 Jan 2023 19:28:20 +0530 Subject: [PATCH 387/408] Add files via upload --- December - 03/CPP_GANESHANHARI_DAY_ 3.cpp | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 December - 03/CPP_GANESHANHARI_DAY_ 3.cpp diff --git a/December - 03/CPP_GANESHANHARI_DAY_ 3.cpp b/December - 03/CPP_GANESHANHARI_DAY_ 3.cpp new file mode 100644 index 0000000..85d6ebe --- /dev/null +++ b/December - 03/CPP_GANESHANHARI_DAY_ 3.cpp @@ -0,0 +1,59 @@ +#include +#include +using namespace std; +int main() +{ + +/* cout<<"INPUT:"; + cin>>n;*/ + int n=5; + char a[n][n]={{'-', '#', '-', '-', '#'},{'-', '-', '-', '-', '-'}, {'-', '-', '#', '-', '-'},{'-', '#', '-', '-', '#'},{'-', '#', '-', '-', '#'}}; +/*for(int i=0;i>a[i][j]; + + } + +}*/ + +int xdir[8]={0,0,-1,-1,-1,1,1}; +int ydir[8]={-1,1,-1,0,1,-1,0,1}; +int xpos,ypos; +cout<<"OUTPUT:"<=n||xpos<0) break; + if(a[xpos][ypos]=='#') + { + if(a[i][j]=='-') a[i][j]='1'; + else a[i][j]=(char)((int)(a[i][j])+1); + } + } + } + + if(a[i][j]=='-'&&a[i][j]!='#') a[i][j]='0'; + + cout< Date: Sun, 15 Jan 2023 19:31:20 +0530 Subject: [PATCH 388/408] Add files via upload --- December - 08/CPP_GANESHANHARI_DAY__8.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 December - 08/CPP_GANESHANHARI_DAY__8.cpp diff --git a/December - 08/CPP_GANESHANHARI_DAY__8.cpp b/December - 08/CPP_GANESHANHARI_DAY__8.cpp new file mode 100644 index 0000000..386964b --- /dev/null +++ b/December - 08/CPP_GANESHANHARI_DAY__8.cpp @@ -0,0 +1,22 @@ + +#include +#include +using namespace std; +int main() { + cout<<"INPUT:"<>str1; + for(int i=0;i Date: Sun, 15 Jan 2023 19:44:37 +0530 Subject: [PATCH 389/408] Add files via upload --- December - 10/CPP_GANESHANHARI_DAY__10.cpp | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 December - 10/CPP_GANESHANHARI_DAY__10.cpp diff --git a/December - 10/CPP_GANESHANHARI_DAY__10.cpp b/December - 10/CPP_GANESHANHARI_DAY__10.cpp new file mode 100644 index 0000000..f5f15e3 --- /dev/null +++ b/December - 10/CPP_GANESHANHARI_DAY__10.cpp @@ -0,0 +1,49 @@ + +#include +#include + +using namespace std; +bool isvowel(char ch) +{ +int res= (ch == 'a') || (ch == 'e') ||(ch == 'i') ||(ch == 'o') ||(ch == 'u'); +return (!res); +} +int main() { + int casen; + cout<<"input:"<>casen; + char word[casen][100]; + int len[casen]; + int t=casen; + while(t>0) + { + cin>>len[t]; + cout<>word[t]; + cout<0) + { + + + int ch=0; + int i; + + for(i=0;i Date: Sun, 15 Jan 2023 19:56:20 +0530 Subject: [PATCH 390/408] Add files via upload --- December - 23/Java_tarpandas.java | 104 ++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 December - 23/Java_tarpandas.java diff --git a/December - 23/Java_tarpandas.java b/December - 23/Java_tarpandas.java new file mode 100644 index 0000000..1c95dda --- /dev/null +++ b/December - 23/Java_tarpandas.java @@ -0,0 +1,104 @@ +import java.util.*; +class Room{ + int allocatedTime; + int count; + Room(int allocatedTime, int count){ + this.allocatedTime = allocatedTime; + this.count = count; + } +} +public class Java_tarpandas{ + public List allocateRooms(int n){ + List list = new ArrayList<>(); + for(int i=0;i meetings[j][0]){ + start = meetings[i][0]; + meetings[i][0] = meetings[j][0]; + meetings[j][0] = start; + + end = meetings[i][1]; + meetings[i][1] = meetings[j][1]; + meetings[j][1] = end; + } + } + } + return meetings; + } + + public List meetingRooms(int[][] meetings, int n, List rooms){ + int time = 0; + int i = -1; + while(i meetings.length-1){ + break; + } + room.allocatedTime = Math.abs(meetings[i][0] - meetings[i][1]); + room.count = room.count + 1; + } + time++; + } + + return rooms; + } + + public int findRoomWithMaxMeetings(List rooms){ + int roomNo = 0; + int noOfMeetings = 0; + int roomWithMaxMeetings = 0; + for(Room r : rooms){ + if(r.count > noOfMeetings){ + noOfMeetings = r.count; + roomWithMaxMeetings = roomNo; + } + roomNo++; + } + return roomWithMaxMeetings; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + // Input 1: + int n = 2; //Number of Rooms + int[][] meetings = { + {0,10},{1,5},{2,7},{3,4} + }; + + Java_tarpandas ob=new Java_tarpandas(); + List rooms = ob.allocateRooms(n); + int[][] sortedMeetings = ob.sortMeetings(meetings); + List meetingsEnd = ob.meetingRooms(sortedMeetings,n,rooms); + int roomNo = ob.findRoomWithMaxMeetings(meetingsEnd); + + System.out.println(""); + System.out.println("Output:"); + System.out.println(""); + System.out.println(roomNo); + } +} \ No newline at end of file From a4783512c6a0e40cdfe6d519c5ff32fa72b6b722 Mon Sep 17 00:00:00 2001 From: Tarpan Das <61510889+tarpandas@users.noreply.github.com> Date: Sun, 15 Jan 2023 19:57:16 +0530 Subject: [PATCH 391/408] Add files via upload --- December - 26/Java_tarpandas.java | 82 +++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 December - 26/Java_tarpandas.java diff --git a/December - 26/Java_tarpandas.java b/December - 26/Java_tarpandas.java new file mode 100644 index 0000000..0d66e99 --- /dev/null +++ b/December - 26/Java_tarpandas.java @@ -0,0 +1,82 @@ +import java.util.*; +public class Java_tarpandas{ + public String circulate(int[][] arr){ + int know[] = new int[arr.length]; + know[0] = 1; //First Person know the word + for(int i=1;i Date: Sun, 15 Jan 2023 19:57:52 +0530 Subject: [PATCH 392/408] Add files via upload --- December - 27/Java_tarpandas.java | 88 +++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 December - 27/Java_tarpandas.java diff --git a/December - 27/Java_tarpandas.java b/December - 27/Java_tarpandas.java new file mode 100644 index 0000000..db29a72 --- /dev/null +++ b/December - 27/Java_tarpandas.java @@ -0,0 +1,88 @@ +import java.util.*; +class InvalidNumerator extends Exception{ + public InvalidNumerator(String str){ + super(str); + } +} +class InvalidDenominator extends Exception{ + public InvalidDenominator(String str){ + super(str); + } +} +class Java_tarpandas{ + public float calculateFuelCalibration(int x, int y){ + float percentage = ((float)x*100)/(float)y; + return percentage; + } + + public String calculateLeftFuel(int x, int y, float totalFuel){ + float leftFuel = ((float)x * totalFuel)/(float)y; + return String.format("%.1f",leftFuel); + } + + public String checkTank(float result){ + String msg = ""; + if(result <= 1){ + msg = "warning"; + } + if(result >= 99){ + msg = "ok"; + } + return msg; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input:"); + System.out.println(""); + int x,y; + while(true){ + System.out.println("Enter the Hydrogen fuel fraction:"); + String fraction = sc.next(); + + String[] xy = fraction.split("/"); + try{ + x = Integer.parseInt(xy[0]); + y = Integer.parseInt(xy[1]); + if(y == 0){ + throw new InvalidDenominator("Y must not be Zero"); + } + if(x > y){ + throw new InvalidNumerator("X must be less than Y"); + } + break; + } + catch(NumberFormatException e){ + System.out.println("X & Y must be Integer"); + } + catch(InvalidDenominator e){ + System.out.println(e); + } + catch(InvalidNumerator e){ + System.out.println(e); + } + System.out.println(""); + } + + float totalFuel = 30000f; + Java_tarpandas ob=new Java_tarpandas(); + float result = ob.calculateFuelCalibration(x,y); + String leftFuel = ob.calculateLeftFuel(x,y,totalFuel); + String flag = ob.checkTank(result); + + System.out.println(""); + System.out.println("Output:"); + System.out.println(""); + System.out.println("Fuel calibration: "+String.format("%.3f",result)+"%"); + System.out.println("Amount of fuel in tank: "+leftFuel+" L out of "+totalFuel+" L"); + + if(flag.equals("ok")){ + System.out.println("The tank is FULL!"); + }else if(flag.equals("warning")){ + System.out.println("The tank is EMPTY!!!"); + System.out.println("Refill tank"); + } + sc.close(); + } +} \ No newline at end of file From a5a6e7839e9f19c0ffbfc9f5c732d1b08ff43294 Mon Sep 17 00:00:00 2001 From: Tarpan Das <61510889+tarpandas@users.noreply.github.com> Date: Sun, 15 Jan 2023 19:58:58 +0530 Subject: [PATCH 393/408] Add files via upload --- December - 28/Java_tarpandas.java | 142 ++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 December - 28/Java_tarpandas.java diff --git a/December - 28/Java_tarpandas.java b/December - 28/Java_tarpandas.java new file mode 100644 index 0000000..aa2666b --- /dev/null +++ b/December - 28/Java_tarpandas.java @@ -0,0 +1,142 @@ +import java.util.*; +public class Java_tarpandas{ + public int findFirstSmallest(List tail){ + int firstSmallest = Integer.MAX_VALUE; + for(Integer tailie : tail){ + if(firstSmallest > tailie){ + firstSmallest = tailie; + } + } + return firstSmallest; + } + + public int findSecondSmallest(List tail, int firstSmallest){ + int secondSmallest = Integer.MAX_VALUE; + for(Integer tailie : tail){ + if(secondSmallest > tailie){ + int flag = tailie; + if(flag > firstSmallest){ + secondSmallest = flag; + } + } + } + return secondSmallest; + } + + public int findFirstLargest(List tail){ + int firstLargest = Integer.MIN_VALUE; + for(Integer tailie : tail){ + if(firstLargest < tailie){ + firstLargest = tailie; + } + } + return firstLargest; + } + + public int findSecondLargest(List tail, int firstLargest){ + int secondLargest = Integer.MIN_VALUE; + for(Integer tailie : tail){ + if(secondLargest < tailie){ + int flag = tailie; + if(flag < firstLargest){ + secondLargest = flag; + } + } + } + return secondLargest; + } + + public int minimumBetweenTwo(int a, int b){ + int min = a tail, int n){ + int firstSmallest = findFirstSmallest(tail); + int secondSmallest = findSecondSmallest(tail,firstSmallest); + + int travelTime = 0; + + while(true){ + if(tail.size() == 3){ + int firstLargest = findFirstLargest(tail); + travelTime = travelTime + (secondSmallest + firstSmallest + firstLargest); + break; + } + if(tail.size() == 2){ + travelTime = travelTime + secondSmallest; + break; + } + else{ + int firstLargest = findFirstLargest(tail); + int secondLargest = findSecondLargest(tail,firstLargest); + + int result01 = firstApproach(firstLargest,secondLargest,firstSmallest); + int result02 = secondApproach(firstLargest,firstSmallest,secondSmallest); + + tail.remove(tail.indexOf(firstLargest)); + tail.remove(tail.indexOf(secondLargest)); + + int minTime = minimumBetweenTwo(result01,result02); + + travelTime = travelTime + minTime; + } + } + + return travelTime; + } + + public float secondsToMinutes(int time){ + float timeInMinutes = (float)time/60; + return timeInMinutes; + } + + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + + System.out.println("Input:"); + System.out.println(""); + int n; + while(true){ + System.out.print("n="); + n = sc.nextInt(); + System.out.println(""); + + if(n >= 3){ + break; + }else{ + System.out.println("There needs to be at least 3 Tailies"); + System.out.println(""); + } + } + + System.out.print("Walking time: "); + int[] walkingTime = new int[n]; + for(int i=0;i tail = new ArrayList<>(); + for(int time : walkingTime){ + tail.add(time); + } + + Java_tarpandas ob=new Java_tarpandas(); + int timeInSeconds = ob.theJourneyToTheEternalEngine(tail,n); + float timeInMinutes = ob.secondsToMinutes(timeInSeconds); + + System.out.println(""); + System.out.println("Output:"); + System.out.println(""); + System.out.println(String.format("%.3f",timeInMinutes)); + } +} \ No newline at end of file From 2cb2042ef6ccda773c4245691a18440d433c924f Mon Sep 17 00:00:00 2001 From: GANESHANHARI <93967094+GANESHANHARI@users.noreply.github.com> Date: Sun, 15 Jan 2023 20:00:50 +0530 Subject: [PATCH 394/408] Add files via upload --- December - 04/CPP_GANESHANHARI_DAY_4.cpp | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 December - 04/CPP_GANESHANHARI_DAY_4.cpp diff --git a/December - 04/CPP_GANESHANHARI_DAY_4.cpp b/December - 04/CPP_GANESHANHARI_DAY_4.cpp new file mode 100644 index 0000000..5c04535 --- /dev/null +++ b/December - 04/CPP_GANESHANHARI_DAY_4.cpp @@ -0,0 +1,43 @@ +#include +#include +using namespace std; + +int main() + { + cout<<"INPUT:"<>days; + vector v(days); + for(auto& num :v)cin>>num; + + + int max=INT_MIN; + int curr=0; + int first=0,last; + + for(int i=0;imax){ + max=curr; + last=i; + } + + if(curr<0){ + curr=0; + first= i+1; + } + + } + + vector all; + for(int i=first;i<=last;i++){ + all.push_back(v[i]); + } + cout<<"OUTPUT:"< Date: Sun, 15 Jan 2023 20:23:28 +0530 Subject: [PATCH 395/408] Add files via upload --- December - 01/JAVA_GANESHANHARI_DAY_1.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 December - 01/JAVA_GANESHANHARI_DAY_1.java diff --git a/December - 01/JAVA_GANESHANHARI_DAY_1.java b/December - 01/JAVA_GANESHANHARI_DAY_1.java new file mode 100644 index 0000000..235ab9d --- /dev/null +++ b/December - 01/JAVA_GANESHANHARI_DAY_1.java @@ -0,0 +1,30 @@ +import java.util.*; +import java.util.Scanner; + +public class JAVA_GANESHANHARI_DAY_1 { + public static void main(String[] args) { + Scanner s=new Scanner(System.in); + StringBuilder ans= new StringBuilder(); + int n=0; + n=Integer.parseInt(s.nextLine().strip()); + + for(int i=0;i Date: Sun, 15 Jan 2023 20:33:01 +0530 Subject: [PATCH 396/408] Add files via upload --- December - 06/CPP_GANESHANHARI_DAY_6.cpp | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 December - 06/CPP_GANESHANHARI_DAY_6.cpp diff --git a/December - 06/CPP_GANESHANHARI_DAY_6.cpp b/December - 06/CPP_GANESHANHARI_DAY_6.cpp new file mode 100644 index 0000000..22a16c2 --- /dev/null +++ b/December - 06/CPP_GANESHANHARI_DAY_6.cpp @@ -0,0 +1,55 @@ +#include +#include +using namespace std; +int main() +{ + int n,pos,player; + + cout<<"Enter Position:"; + cin>>pos; + cout<<"Enter no of terms:"; + cin>>n; + int arr[n]; + cout<<"Enter the Numbers:"; + for(int i=0;i>arr[i]; + + cout<<"Who starts first 1.Bob 2.Tanika"; + cin>>player; + int temp=arr[pos-1]; + if(temp==arr[0]) + { + if(player==1) + { + cout<<"Tanika Wins \nBob Loses"; + } + else + { + cout<<"Bob Wins \nTanika Loses"; + } + } + else if(temp>arr[0]) + { + if(player==1) + { + cout<<"Tanika Wins \nBob Loses"; + } + else + { + cout<<"Bob Wins \nTanika Loses"; + } + + } + else + { + if(player==1) + { + cout<<"Bob Wins \nTanika Loses"; + } + else + { + cout<<"Tanika Wins \nBob Loses"; + } + } + return 0; +} From 07c8e9643ab1673f6c3558d7bf227eb07f6a4473 Mon Sep 17 00:00:00 2001 From: subburamanathan-7 Date: Sun, 15 Jan 2023 21:00:48 +0530 Subject: [PATCH 397/408] Successful --- December - 01/python_subburamanathan7.py | 25 +++++++++ December - 02/C++_subburamanathan7.cpp | 20 ++++++++ December - 03/C++_subburamanathan7.cpp | 65 ++++++++++++++++++++++++ December - 04/C++_subburamanathan7.cpp | 61 ++++++++++++++++++++++ December - 05/C++_subburamanathan7.cpp | 28 ++++++++++ December - 06/C++_subburamanathan7.cpp | 30 +++++++++++ December - 08/C++_subburamanathan7.cpp | 23 +++++++++ December - 09/C++_subburamanathan7.cpp | 65 ++++++++++++++++++++++++ December - 10/C++_subburamanathan7.cpp | 35 +++++++++++++ December - 11/C++_subburamanathan7.cpp | 31 +++++++++++ December - 12/C++_subburamanathan7.cpp | 51 +++++++++++++++++++ December - 14/C++_subburamanathan7.cpp | 48 +++++++++++++++++ December - 15/python_subburamanathan7.py | 15 ++++++ December - 16/C++_subburamanathan7.cpp | 26 ++++++++++ December - 17/C++_subburamanathan7.cpp | 26 ++++++++++ December - 21/C++_subburamanathan7.cpp | 25 +++++++++ December - 22/C++_subburamanathan7.cpp | 29 +++++++++++ December - 26/python_subburamanathan7.py | 15 ++++++ December - 27/C++_subburamanathan7.cpp | 42 +++++++++++++++ December - 29/C++_subburamanathan7.cpp | 35 +++++++++++++ 20 files changed, 695 insertions(+) create mode 100644 December - 01/python_subburamanathan7.py create mode 100644 December - 02/C++_subburamanathan7.cpp create mode 100644 December - 03/C++_subburamanathan7.cpp create mode 100644 December - 04/C++_subburamanathan7.cpp create mode 100644 December - 05/C++_subburamanathan7.cpp create mode 100644 December - 06/C++_subburamanathan7.cpp create mode 100644 December - 08/C++_subburamanathan7.cpp create mode 100644 December - 09/C++_subburamanathan7.cpp create mode 100644 December - 10/C++_subburamanathan7.cpp create mode 100644 December - 11/C++_subburamanathan7.cpp create mode 100644 December - 12/C++_subburamanathan7.cpp create mode 100644 December - 14/C++_subburamanathan7.cpp create mode 100644 December - 15/python_subburamanathan7.py create mode 100644 December - 16/C++_subburamanathan7.cpp create mode 100644 December - 17/C++_subburamanathan7.cpp create mode 100644 December - 21/C++_subburamanathan7.cpp create mode 100644 December - 22/C++_subburamanathan7.cpp create mode 100644 December - 26/python_subburamanathan7.py create mode 100644 December - 27/C++_subburamanathan7.cpp create mode 100644 December - 29/C++_subburamanathan7.cpp diff --git a/December - 01/python_subburamanathan7.py b/December - 01/python_subburamanathan7.py new file mode 100644 index 0000000..3213f04 --- /dev/null +++ b/December - 01/python_subburamanathan7.py @@ -0,0 +1,25 @@ +count = int(input("Enter number of words")) + +arr=[] +for i in range(count): + sub=[] + limit = int(input("Enter size of each word")) + for j in range(limit): + code = input("Enter code") + sub.append(code) + + arr.append(sub) + +ret_arr=[] +for i in arr: + sub=[] + for j in i: + temp= int(j,base=16) + sub.append(chr(temp)) + + ret_arr.append(sub) + +for i in ret_arr: + print("\n") + for j in i: + print(j,end="") diff --git a/December - 02/C++_subburamanathan7.cpp b/December - 02/C++_subburamanathan7.cpp new file mode 100644 index 0000000..41a6c52 --- /dev/null +++ b/December - 02/C++_subburamanathan7.cpp @@ -0,0 +1,20 @@ +#include +#include +using namespace std; + +int main(){ + string codeWord; + + cout<<"Enter codeword"; + cin>>codeWord; + + if(codeWord.length()<=4){ + printf("Invalid codeword"); + return 0; + } + for(int i=codeWord.length()-4;i + +using namespace std; + +int main(){ + char mines[5][5] ={ + {'-','-','-','-','-'}, + {'-','-','-','-','-'}, + {'-','-','#','-','-'}, + {'-','-','-','-','-'}, + {'-','-','-','-','-'}, + }; + int maps[5][5]; + for (int i = 0; i < 5; ++i){ + for (int j = 0; j <5; ++j){ + if(mines[i][j]=='#') + maps[i][j]= -1; + else{ + maps[i][j]=0; + if(j+1<5 || i+1<5 || j-1>=0 || i-1>=0){ + if(j+1<5) + if(mines[i][j+1]=='#') + maps[i][j]+=1; + if(i+1<5) + if(mines[i+1][j]=='#') + maps[i][j]+=1; + if(j-1>=0) + if(mines[i][j-1]=='#') + maps[i][j]+=1; + if(i-1>=0) + if(mines[i-1][j]=='#') + maps[i][j]+=1; + + if(j+1<5 && i+1<5) + if(mines[i+1][j+1]=='#') + maps[i][j]+=1; + + if(j-1>=0 && i-1>=0) + if(mines[i-1][j-1]=='#') + maps[i][j]+=1; + + if(j+1<5 && i-1>=0) + if(mines[i-1][j+1]=='#') + maps[i][j]+=1; + + if(j-1>=0 && i+1<5) + if(mines[i+1][j-1]=='#') + maps[i][j]+=1; + } + } + } + } + + for (int i = 0; i < 5; ++i){ + for (int j = 0; j < 5; ++j){ + printf("%3d",maps[i][j]); + } + printf("\n"); + } + printf("\n-1 represents the mines"); + + + + return 0; +} \ No newline at end of file diff --git a/December - 04/C++_subburamanathan7.cpp b/December - 04/C++_subburamanathan7.cpp new file mode 100644 index 0000000..6449a97 --- /dev/null +++ b/December - 04/C++_subburamanathan7.cpp @@ -0,0 +1,61 @@ +#include +#include +#include + +int max(int a, int b) { + return (a > b) ? a : b; +} + +int max(int a, int b, int c) { + return max(max(a, b), c); +} + +int maxCrossSubArray(int arr[], int l, int m, int h) +{ + int sum = 0; + int left_sum = INT_MIN; + for (int i = m; i >= l; i--) { + sum = sum + arr[i]; + if (sum > left_sum) + left_sum = sum; + } + sum = 0; + int right_sum = INT_MIN; + for (int i = m; i <= h; i++) { + sum = sum + arr[i]; + if (sum > right_sum) + right_sum = sum; + } + + return max(left_sum + right_sum - arr[m], left_sum, right_sum); +} +int maxSubArraySum(int arr[], int l, int h) +{ + if (l > h) + return INT_MIN; + if (l == h) + return arr[l]; + int m = (l + h) / 2; + return max(maxSubArraySum(arr, l, m - 1), + maxSubArraySum(arr, m + 1, h), + maxCrossSubArray(arr, l, m, h)); +} + +int main() +{ + int arr[] = {5,4,-1,7,8}; + int n = sizeof(arr) / sizeof(arr[0]); + int max_sum = maxSubArraySum(arr, 0, n - 1); + printf("Maximum contiguous sum is %d\n", max_sum); + getchar(); + return 0; +} + + + + + + + + + diff --git a/December - 05/C++_subburamanathan7.cpp b/December - 05/C++_subburamanathan7.cpp new file mode 100644 index 0000000..0345b76 --- /dev/null +++ b/December - 05/C++_subburamanathan7.cpp @@ -0,0 +1,28 @@ +#include + +using namespace std; + +int main(){ + int price,total=0,point3=1,point5=1; + + cout<<"Enter Price on Day1:"; + cin>>price; + + for(int i=1;i<=31;++i){ + if(i==point3+3){ + price+=3; + point3=i; + } + else if(i==point5+5){ + price-=2; + point5=i; + } + total += (2*price); + } + if(total>5000) + cout<<"Exceeded Expenditure:"< + +using namespace std; + + +int main(){ + int limit,i,position,person=0; + cout<<"Enter Limit"; + cin>>limit; + cout<<"Enter position"; + cin>>position; + if(position>=limit) + exit(1); + int *arr =(int*)malloc(sizeof(int)*limit); + for(i=0;i>arr[i]; + while(arr[0]!=0){ + person=!person; + arr[0]=arr[0]-1; + + arr[0]+=arr[position]; + arr[position]=arr[0]-arr[position]; + arr[0]=arr[0]-arr[position]; + } + if(person==0) + cout<<"Player 1 Looses"; + else + cout<<"Player 2 Looses"; + return 0; +} \ No newline at end of file diff --git a/December - 08/C++_subburamanathan7.cpp b/December - 08/C++_subburamanathan7.cpp new file mode 100644 index 0000000..97d6d92 --- /dev/null +++ b/December - 08/C++_subburamanathan7.cpp @@ -0,0 +1,23 @@ +#include + +using namespace std; + +int main(){ + int i=0,length; + char temp; + string name ="SPEEDRUNNER"; + length=name.length(); + cout<<"Name: "< +#include + +using namespace std; +int main(){ + int limit,flag=1; + int max=0,max_Index=0; + cout<<"enter the limit"; + cin>>limit; + string sentence[limit]; + + for(int i=0;i>sentence[i]; + cout<<"choose among these words\n"; + cout<<"["; + for(int i=0;i>choice; + + for(int i=0;i +using namespace std; + +int main(){ + int test_cases,count=0,flag=0; + cout<<"Enter number of test test_cases"; + cin>>test_cases; + for(int i=0;i>temp; + count=0; + if(temp.length()<4){ + cout<<"Invalid Input\n"; + continue; + } + for(int j=0;j=4){ + flag=1; + break; + } + } + else + count=0; + } + if(flag==1){ + cout<<"NO\n"; + } + else + cout<<"YES\n"; + } + return 0; +} \ No newline at end of file diff --git a/December - 11/C++_subburamanathan7.cpp b/December - 11/C++_subburamanathan7.cpp new file mode 100644 index 0000000..0b23e39 --- /dev/null +++ b/December - 11/C++_subburamanathan7.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; + +int main(){ + int limit,i,j=0,score; + string sequence; //Land or Water + + cout<<"Enter the sequence"; + cin>>sequence; + + cout<<"Enter Limit Of Jumps"; + cin>>limit; + int *jumps = (int*)malloc(sizeof(int)*limit); + + cout<<"jumps can be 2 or 1\n"; + for(i=0;i>*(jumps+i); + + for(i=0;i + +using namespace std; + +int main(){ + int maze[4][4]={ + {9,4,9,9}, + {6,7,6,4}, + {8,3,3,7}, + {7,4,9,10} + }; + +// here 4 remains to be the matrix dimensions everywhere + int prev=0, cost=0; + for(int i=0;i<4;++i){ + for(int j=0;j<4;++j){ + + j=prev; + if(i!=(4-1) || j!=(4-1)){ + cout<maze[i+1][j]){ + prev=j; + break; + } + else{ + prev=j+1; + continue; + } + } + else if(i+1<4 && j+1==4){ + prev=j; + break; + } + else{ + prev=j+1; + continue; + } + } + else{ + + cost+=maze[i][j]; + cout< +#include +using namespace std; +bool Bipartite(int G[][6],int root){ + int colorArr[6],i; + for(i=0;i<6;i++) + colorArr[i]=-1; + + colorArr[root] = 1; + + //1-Red 0-Blue + //colors to represent Bipartite + queue q; + q.push(root); + + while(!q.empty()){ + int x = q.front(); + q.pop(); + + if(G[x][x]) + return false; + for(i=0;i<6;i++){ + if(G[x][i] && colorArr[i]==-1){ + colorArr[i]=1 - colorArr[x]; + q.push(x); + } + else if(G[x][i] && colorArr[x] == colorArr[i]) + return false; + } + } + return true; +} +int main(){ + int root=1; + int G[][6] = { + {0,1,0,0,0,1}, + {1,0,1,0,0,0}, + {0,1,0,1,0,0}, + {0,0,1,0,1,0}, + {0,0,0,1,0,1}, + {1,0,0,0,1,0}, + }; + if(Bipartite(G,root)) + cout<<"Bipartite"; + else + cout<<"Not Bipartite"; + return 0; +} diff --git a/December - 15/python_subburamanathan7.py b/December - 15/python_subburamanathan7.py new file mode 100644 index 0000000..2fac055 --- /dev/null +++ b/December - 15/python_subburamanathan7.py @@ -0,0 +1,15 @@ +MeetQueue = {} + +limit= int(input('Enter the Queue Size')) + +for i in range(limit): + name = input("Enter name") + time = input("Enter time") + MeetQueue[name]=time + +print(MeetQueue) +MeetQueue = sorted(MeetQueue.items(), key=lambda x:x[1],reverse=True) +Queue = dict(MeetQueue) +print (Queue) +while(Queue): + print(Queue.popitem()[0]) diff --git a/December - 16/C++_subburamanathan7.cpp b/December - 16/C++_subburamanathan7.cpp new file mode 100644 index 0000000..cf8eb4c --- /dev/null +++ b/December - 16/C++_subburamanathan7.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; + +int main(){ + int limit,i=0,j=0,volume=0,height=0,temp=1; + cout<<"Enter Limit"; + cin>>limit; + + int *arr = (int*)malloc(sizeof(int)*limit); + + for (i = 0; i < limit; ++i) + cin>>arr[i]; + + for(i=0;iarr[j]?arr[j]:arr[i]; + temp = (j-i)*height; + + if(temp>volume) + volume=temp; + } + } + cout< + +using namespace std; +int main(){ + int numRows; + string s; + cout<<"Enter String and number of Rows"; + cin>>s>>numRows; + + if(numRows==1) + cout<0 && i<(numRows-1) && (j+increment-2*i) +using namespace std; + +void towers(int num, char left, char right, char temp) +{ + if (num == 1) + { + cout<<"\n Move disk 1 from tower "<>num; + cout<<"The sequence of moves are :\n"; + towers(num, '1', '2', '3'); + return 0; +} diff --git a/December - 22/C++_subburamanathan7.cpp b/December - 22/C++_subburamanathan7.cpp new file mode 100644 index 0000000..5a8b3f5 --- /dev/null +++ b/December - 22/C++_subburamanathan7.cpp @@ -0,0 +1,29 @@ +#include + +using namespace std; + +int main(){ + + string maps = "HOTDOG"; + string word ="CONEYISLANDONFRI"; + int j=0,index=0; + string codeword; + + + for(int i=0;i90) + codeword[index]=64+word[i]+(maps[j]-'A')-90; + else + codeword[index] = word[i]+ (maps[j]-'A'); + + index++; + j++; + if(j>maps.length()-1) + j=0; + } + cout<<"*Encoded Word"; + for (int i = 0; i < word.length(); ++i) + cout< + +using namespace std; + +int main(){ + float X,Y; + char Status; + float fuelCalibration; + + long int capacity =30000; + + while(true){ + char* fraction; + cout<<"\nEnter fraction: X/Y:"; + cin>>fraction; + sscanf(fraction, "%f/%f", &X, &Y); + if(X && Y) + break; + else + cout<<"\n Enter again"; + } + fuelCalibration=(X/Y); + fuelCalibration*=100; + if(fuelCalibration<=1){ + Status='E'; + cout<<"\nFuelCalibration: "<=99){ + Status='F'; + cout<<"\nFuelCalibration: "< +#include + +using namespace std; + +int main(){ + int limit,temp; + cout<<"Enter Limit"; + cin>>limit; + + vector rating; + vector candies; + for(int i=0;i>temp; + rating.push_back(temp); + candies.push_back(1); + } + + + for(int i=1;i=0;--i) + if(rating[i]>rating[i+1]) + candies[i]= (candies[i-1]+1)>candies[i]?(candies[i-1]+1):candies[i]; + + temp=0; + for (int i=0;i Date: Sun, 15 Jan 2023 22:27:06 +0530 Subject: [PATCH 398/408] Solution for Day 2 Problem Problem is Secret Language --- December - 02/Day 2 -The Secret Language.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 December - 02/Day 2 -The Secret Language.py diff --git a/December - 02/Day 2 -The Secret Language.py b/December - 02/Day 2 -The Secret Language.py new file mode 100644 index 0000000..96e5de7 --- /dev/null +++ b/December - 02/Day 2 -The Secret Language.py @@ -0,0 +1,13 @@ +def main(): + to_piglatin = input() + print(translate_to_english(to_piglatin)) + return True + +def translate_to_english(word): + list_word = list(word) + last_two_letters = list_word[-2:] + if last_two_letters == ['a', 'e']: + word = word[:-2] + word= word[-2]+word[-1]+word[:-2] + return word +main() \ No newline at end of file From 778e2a16abafe3db71b47f0ebb0fc54b6705a68c Mon Sep 17 00:00:00 2001 From: Prasanna Kumar B G <88681746+PrasannaBG@users.noreply.github.com> Date: Sun, 15 Jan 2023 22:29:49 +0530 Subject: [PATCH 399/408] Solution for Day 8 Problem The Problem is Aptitude Check --- December - 08/Day 8 - Aptitude Check.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 December - 08/Day 8 - Aptitude Check.py diff --git a/December - 08/Day 8 - Aptitude Check.py b/December - 08/Day 8 - Aptitude Check.py new file mode 100644 index 0000000..f4411c9 --- /dev/null +++ b/December - 08/Day 8 - Aptitude Check.py @@ -0,0 +1,9 @@ +S = list(input()) +N = len(S) +for i in range(0,N,2): + if i!=N-1: + temp = S[i] + S[i] = S[i+1] + S[i+1] = temp +S_1 = "".join(S) +print(S_1) \ No newline at end of file From b031029a755618d1b1a3b87ba304b9e040599eb6 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar B G <88681746+PrasannaBG@users.noreply.github.com> Date: Sun, 15 Jan 2023 22:30:46 +0530 Subject: [PATCH 400/408] Solution for Day 10 Problem The Problem is Play with strings --- December - 10/Day 10 - Play with Strings.py | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 December - 10/Day 10 - Play with Strings.py diff --git a/December - 10/Day 10 - Play with Strings.py b/December - 10/Day 10 - Play with Strings.py new file mode 100644 index 0000000..4f4e269 --- /dev/null +++ b/December - 10/Day 10 - Play with Strings.py @@ -0,0 +1,22 @@ +T = int(input()) +C = [] +for i in range(0,T): + N = int(input()) + STR = list(input()) + if len(STR)>N: + print(f'Error! Only {N} characters allowed!') + else: + V = ['a','e','i','o','u'] + count = 0 + for I in range(0,N): + if I!=N-1: + if STR[I] and STR [I+1] not in V: + count = count + 1 + if count > 3: + C.append("NO") + else: + C.append("YES") +N1 = len(C) +print("\n") +for J in range(0,N1): + print(C[J],sep="\n") \ No newline at end of file From 87ed35ba2a45bf1469386d03a182b1f98e4fb040 Mon Sep 17 00:00:00 2001 From: First_NAME LAST_NAME Date: Sun, 15 Jan 2023 22:33:17 +0530 Subject: [PATCH 401/408] Submission of A-December of algorithm-2022 --- December - 01/java_DCBisht01.java | 37 ++++++++ December - 02/java_DCBisht02.java | 11 +++ December - 03/java_DCBisht03.java | 82 +++++++++++++++++ December - 04/java_DCBisht04.java | 34 +++++++ December - 05/java_DCBisht05.java | 35 ++++++++ December - 06/java_DCBisht06.java | 43 +++++++++ December - 07/java_DCBisht07.java | 97 ++++++++++++++++++++ December - 08/java_DCBisht08.java | 23 +++++ December - 09/java_DCBisht09.java | 28 ++++++ December - 10/java_DCBisht10.java | 39 ++++++++ December - 11/java_DcBisht11.java | 29 ++++++ December - 12/java_DCBisht12.java | 63 +++++++++++++ December - 13/java_DCBisht13.java | 34 +++++++ December - 14/java_DCBisht14.java | 30 +++++++ December - 15/java_DCBisht15.java | 33 +++++++ December - 16/java_DCBisht16.java | 28 ++++++ December - 17/java_DCBisht17.java | 39 ++++++++ December - 18/java_DCBisht18.java | 82 +++++++++++++++++ December - 19/java_DCBisht19.java | 34 +++++++ December - 20/java_DCBisht20.java | 48 ++++++++++ December - 21/java_DCBisht21.java | 22 +++++ December - 22/java_DCBisht22.java | 31 +++++++ December - 23/java_DCBisht23.java | 76 ++++++++++++++++ December - 24/java_DCBisht24.java | 59 ++++++++++++ December - 25/cpp_DCBisht.cpp | 78 ++++++++++++++++ December - 26/java_DCBisht26.java | 40 +++++++++ December - 27/java_DCBisht27.java | 59 ++++++++++++ December - 28/java_DCBisht28.java | 143 ++++++++++++++++++++++++++++++ December - 29/java_DCBisht29.java | 54 +++++++++++ December - 30/cpp_DCBisht30.cpp | 130 +++++++++++++++++++++++++++ December - 31/java_DCBisht31.java | 88 ++++++++++++++++++ 31 files changed, 1629 insertions(+) create mode 100644 December - 01/java_DCBisht01.java create mode 100644 December - 02/java_DCBisht02.java create mode 100644 December - 03/java_DCBisht03.java create mode 100644 December - 04/java_DCBisht04.java create mode 100644 December - 05/java_DCBisht05.java create mode 100644 December - 06/java_DCBisht06.java create mode 100644 December - 07/java_DCBisht07.java create mode 100644 December - 08/java_DCBisht08.java create mode 100644 December - 09/java_DCBisht09.java create mode 100644 December - 10/java_DCBisht10.java create mode 100644 December - 11/java_DcBisht11.java create mode 100644 December - 12/java_DCBisht12.java create mode 100644 December - 13/java_DCBisht13.java create mode 100644 December - 14/java_DCBisht14.java create mode 100644 December - 15/java_DCBisht15.java create mode 100644 December - 16/java_DCBisht16.java create mode 100644 December - 17/java_DCBisht17.java create mode 100644 December - 18/java_DCBisht18.java create mode 100644 December - 19/java_DCBisht19.java create mode 100644 December - 20/java_DCBisht20.java create mode 100644 December - 21/java_DCBisht21.java create mode 100644 December - 22/java_DCBisht22.java create mode 100644 December - 23/java_DCBisht23.java create mode 100644 December - 24/java_DCBisht24.java create mode 100644 December - 25/cpp_DCBisht.cpp create mode 100644 December - 26/java_DCBisht26.java create mode 100644 December - 27/java_DCBisht27.java create mode 100644 December - 28/java_DCBisht28.java create mode 100644 December - 29/java_DCBisht29.java create mode 100644 December - 30/cpp_DCBisht30.cpp create mode 100644 December - 31/java_DCBisht31.java diff --git a/December - 01/java_DCBisht01.java b/December - 01/java_DCBisht01.java new file mode 100644 index 0000000..f8303f4 --- /dev/null +++ b/December - 01/java_DCBisht01.java @@ -0,0 +1,37 @@ +import java.util.*; + + +class java_DCBisht01{ + public static void main(String[] args) { + // Assuming the input format as follows + // first line : no of words + // for the next n lines , space seperates hexadecimal values as a string + // eg + // 1st line : 2 + // 2nd line :49 6E 76 61 64 65 + // 3rd line :4D 69 6C 69 74 61 72 79 + Scanner in=new Scanner(System.in); + + int noOfWords=0; + noOfWords=Integer.parseInt(in.nextLine()); + + for(int i=0;i=0 && k=0 && arr[row-1][k]!='#') + { + int val = arr[row - 1][k] + 1; + arr[row - 1][k] = (char)val; + } + if(arr[row][k]!='#') + { + int val = arr[row][k] + 1; + arr[row ][k] = (char)val; + } + if(row+1 cs) { + cs = a[i]; + cstart = i; + } else { + cs += a[i]; + } + cfinish = i; + if (cs > s) { + s = cs; + sd = cstart; + fd = cfinish; + } + } + System.out.println("Profited value : " + s); + System.out.println("proposed day to sell: Day: " + (sd + 1) + " to Day: " + (fd + 1)); + System.out.println("stock market change values:" + Arrays.toString(Arrays.copyOfRange(a, sd, fd + 1))); + sc.close(); + } +} diff --git a/December - 05/java_DCBisht05.java b/December - 05/java_DCBisht05.java new file mode 100644 index 0000000..366e56f --- /dev/null +++ b/December - 05/java_DCBisht05.java @@ -0,0 +1,35 @@ +import java.util.*; + +public class java_DCBisht05 { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + System.out.println("fuel_price= "); + int n=sc.nextInt(); + int a[]=new int[32]; + a[0]=n; + for(int i=1;i<32;i++){ + if(i%3==0 && i%5==0){ + a[i]=n+1; + } + else if(i%3==0){ + a[i]=n+3; + } + else if(i%5==0){ + a[i]=n-2; + } + else{ + a[i]=n; + } + } + int sum = Arrays.stream(a).sum()-a[0]; + sum*=2; + System.out.println("Expenditure= "+sum); + if(sum<=5000){ + System.out.println("EXPENDITURE WITHIN LIMIT"); + } + else{ + System.out.println("EXPENDITURE EXCEEDING LIMIT"); + } + sc.close(); + } +} diff --git a/December - 06/java_DCBisht06.java b/December - 06/java_DCBisht06.java new file mode 100644 index 0000000..e2a138c --- /dev/null +++ b/December - 06/java_DCBisht06.java @@ -0,0 +1,43 @@ +import java.util.*; + +public class java_DCBisht06 { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + System.out.println("Input: "); + System.out.print("p="); + int p=Integer.parseInt(sc.nextLine()); + + System.out.print("Set of numbers: "); + String array=sc.nextLine(); + + String[] a=array.split(" ",0); + + int x=0; + int[] arr = new int[a.length]; + for(String i:a){ + arr[x++]=Integer.valueOf(i); + } + System.out.print("Player going first: "); + String player = sc.nextLine(); + + int flag = 0; + while(true){ + player = player.equalsIgnoreCase("Tanika")? "Bob" : "Tanika"; + + flag = arr[p-1]; + arr[p-1] = arr[0] - 1; + arr[0] = flag; + + if(arr[0] == 0){ + break; + } + } + + System.out.println(""); + System.out.println("Output: "); + System.out.println((player.equalsIgnoreCase("Tanika")? "Bob" : "Tanika") + " wins the game!"); + System.out.println(player + " loses the game!"); + + sc.close(); + } +} diff --git a/December - 07/java_DCBisht07.java b/December - 07/java_DCBisht07.java new file mode 100644 index 0000000..01f93c5 --- /dev/null +++ b/December - 07/java_DCBisht07.java @@ -0,0 +1,97 @@ + +import java.io.*; + +public class java_DCBisht07 { + boolean [][] visited; + int n,m; + public boolean exist(char[][] board, String word) { + n=board.length; + m=board[0].length; + visited=new boolean[n][m]; + + for(int i=0;i=n || j<0 || j>=m ){ + return false; + } + + //if already visited + if(visited[i][j]){ + return false; + } + + //mismatch + if(word.charAt(count)!=board[i][j]){ + return false; + } + + //if word is found + if(count==word.length()-1){ + return true; + } + + /*----------------calculation and recursive calls----------*/ + + //mark current visited + visited[i][j]=true; + + //inc count + count++; + + //down,right,up,left search + if(valid(i+1,j,count,board,word) || + valid(i,j+1,count,board,word) || + valid(i-1,j,count,board,word) || + valid(i,j-1,count,board,word) ){ + return true; + } + + //mark current cell unvisited + visited[i][j]=false; + + return false; + + } + +// Driver Code +public static void main(String[] args)throws IOException +{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String[] S = br.readLine().trim().split(" "); + int n = Integer.parseInt(S[0]); + int m = Integer.parseInt(S[1]); + char [][] board = new char[n][m]; + for(int i = 0; i < n; i++){ + String[] s = br.readLine().trim().split(" "); + for(int j = 0; j < m; j++){ + board[i][j] = s[j].charAt(0); + } + } + String word = br.readLine().trim(); + java_DCBisht07 ob=new java_DCBisht07 (); + boolean ans = ob.exist(board, word); + if(ans) + System.out.println("Found"); + else + System.out.println("Not Found"); + + } + +} + + + diff --git a/December - 08/java_DCBisht08.java b/December - 08/java_DCBisht08.java new file mode 100644 index 0000000..1e1ce36 --- /dev/null +++ b/December - 08/java_DCBisht08.java @@ -0,0 +1,23 @@ +import java.util.*; + +public class java_DCBisht08 { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + String s=sc.nextLine(); + int l=s.length(); + char c=' '; + if(l%2!=0){ + c=s.charAt(l-1); + } + String ans=""; + for(int i=0;iml ){ + ans=i; + ml=i.length(); + } + } + + if(ml==Integer.MIN_VALUE){ + System.out.println("Better luck next time"); + } + else{ + System.out.println(ans); + } + // System.out.println(Arrays.toString(arr)); + sc.close(); + } +} diff --git a/December - 10/java_DCBisht10.java b/December - 10/java_DCBisht10.java new file mode 100644 index 0000000..db7ee1e --- /dev/null +++ b/December - 10/java_DCBisht10.java @@ -0,0 +1,39 @@ +import java.util.*; + +public class java_DCBisht10 { + + static boolean f(String s, int l){ + int x=0; + for(int i=0;i=4){ + return false; + } + } + return true; + } + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + int T=Integer.parseInt(sc.nextLine()); + // System.out.println(T); + while(T-->0){ + int n=Integer.parseInt(sc.nextLine()); + String w=sc.nextLine(); + // n=w.length(); + if(f(w,n)){ + System.out.println("YES"); + } + else{ + System.out.println("NO"); + } + } + + sc.close(); + } +} diff --git a/December - 11/java_DcBisht11.java b/December - 11/java_DcBisht11.java new file mode 100644 index 0000000..18b489f --- /dev/null +++ b/December - 11/java_DcBisht11.java @@ -0,0 +1,29 @@ +import java.util.*; + +public class java_DcBisht11 { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + String word = in.nextLine(); + String[] warr = word.split(" ", 0); + String word1 = in.nextLine(); + String[] arr = word1.split(" ", 0); + int list[] = new int[arr.length]; + int k = 0; + for (String h : arr) { + list[k++] = Integer.parseInt(h); + + } + int x=0, ans=-1,y=0; + + while(xlist) + { + if(i==inp.length-1 && j==inp[0].length-1 ) + { + list.add(inp[i][j]); + ans.add(new ArrayList<>(list)); + list.remove(list.size()-1); + return; + } + if(i<0 || i>=inp.length || j<0 || j>=inp[0].length || checked[i][j]) return; + checked[i][j]=true; + list.add(inp[i][j]); + + allCombinations(inp,i+1,j,list); + allCombinations(inp,i-1,j,list); + allCombinations(inp,i,j-1,list); + allCombinations(inp,i,j+1,list); + list.remove(list.size()-1); + checked[i][j]=false; + + } + public static int sum(Listlist) + { + int ans=0; + for(int i=0;i=inp.length || j>=inp[0].length || inp[i][j]!=1) return false; + ans[i][j]=1; + boolean ansFound=findOnePath(inp,i,j+1) || findOnePath(inp,i+1,j); + if(!ansFound) inp[i][j]=0; + + return ansFound; + } +} diff --git a/December - 14/java_DCBisht14.java b/December - 14/java_DCBisht14.java new file mode 100644 index 0000000..bb04080 --- /dev/null +++ b/December - 14/java_DCBisht14.java @@ -0,0 +1,30 @@ +import java.util.*; + +public class java_DCBisht14 { + static boolean f(int a[][],int n){ + for(int i=0;i() { + + + public int compare(String[] a, String[]b ) { + + String[] time1 = a[1].split(":", 0); + String[] time2 = b[1].split(":", 0); + int t = time1[0].compareTo(time2[0]); + if (t != 0) return t; + t = time1[1].compareTo(time2[1]); + if (t != 0) return t; + t = time1[2].compareTo(time2[2]); + return t; + + } + }); + + for(int i=0;i[] index = new ArrayList[row]; + for(int i=0;i(); + } + + int i=0; + + while(i0 && iele:index) + { + for(int k:ele) + { + System.out.print(inp.charAt(k)); + } + } + in.close(); + } +} \ No newline at end of file diff --git a/December - 18/java_DCBisht18.java b/December - 18/java_DCBisht18.java new file mode 100644 index 0000000..923a67e --- /dev/null +++ b/December - 18/java_DCBisht18.java @@ -0,0 +1,82 @@ +import java.util.*; + +public class java_DCBisht18 { + static int[][] adjacency; + static HashMap> neighbours; + + static boolean[] alreadySaw; + + static int min = Integer.MAX_VALUE; + static ArrayList ans; + + public static void main(String[] args) { + + adjacency = new int[][] { + { 0, 3, 4, 5, -1, -1, -1, -1 }, + { 3, 0, 2, -1, -1, 5, -1, -1 }, + { 4, 2, 0, 7, 3, 6, 2, -1 }, + { 5, -1, 7, 0, 2, -1, -1, -1 }, + { -1, -1, 3, 2, 0, -1, 4, -1 }, + { -1, 5, 6, -1, -1, 0, 5, 2 }, + { -1, -1, 2, -1, 4, 5, 0, 1 }, + { -1, -1, -1, -1, -1, 2, 1, 0 } }; + alreadySaw = new boolean[adjacency.length]; + neighbours = new HashMap<>(); + int i = 0; + for (int[] arr : adjacency) { + int col = 0; + ArrayList l = new ArrayList<>(); + for (int ele : arr) { + if (ele > 0) + l.add(col); + col++; + } + neighbours.put(i++, l); + } + + Scanner in = new Scanner(System.in); + int source = in.next().charAt(0) - 'P'; + ArrayList dummy = new ArrayList<>(); + dummy.add(source); + alreadySaw[source] = true; + dfs(source, 0, dummy); + System.out.print("path is :"); + int k=0; + for (int ele : ans) { + if(ans.size()-1==k) + System.out.print((char) (ele + 'P') + " "); + else{ + System.out.print((char) (ele + 'P') + " - "); + } + k++; + } + System.out.println(); + System.out.println("shortest time :" + min + " hours"); + in.close(); + } + + static void dfs(int source, int sum, ArrayList path) { + if (source == adjacency.length - 1) { + if (sum < min) { + min = sum; + ans = new ArrayList<>(path); + } + return; + } + + List neigh = neighbours.get(source); + + for (int next : neigh) { + + if (!alreadySaw[next]) { + alreadySaw[next] = true; + path.add(next); + dfs(next, sum + adjacency[source][next], path); + path.remove(path.size() - 1); + alreadySaw[next] = false; + } + + } + } + +} diff --git a/December - 19/java_DCBisht19.java b/December - 19/java_DCBisht19.java new file mode 100644 index 0000000..3221ee4 --- /dev/null +++ b/December - 19/java_DCBisht19.java @@ -0,0 +1,34 @@ +import java.util.*;; + +public class java_DCBisht19 { + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + String big=in.nextLine().toLowerCase(); + String smol=in.nextLine().toLowerCase(); + big=big.replaceAll("[^a-z]+", ""); + smol=smol.replaceAll("[^a-z]+", ""); + int[]map=new int[26]; + for(char s:smol.toCharArray()) + { + map[s-'a']++; + } + + int s=0; + int e=0; + while(e map = new TreeMap(); + for(int k = 0; k < n; ++k) { + Entry e = map.lowerEntry(a[k]); + long b = (e == null ? 0 : e.getValue()) + w[k]; + SortedMap tail = map.tailMap(a[k]); + List del = new ArrayList(); + for(Entry x : tail.entrySet()) { + if(x.getValue().longValue() > b) + break; + del.add(x.getKey()); + } + for(Integer i : del) { + map.remove(i); + } + if(!map.containsKey(a[k])) + map.put(a[k], b); + if(best < b) + best = b; + } + return best; + } +} diff --git a/December - 21/java_DCBisht21.java b/December - 21/java_DCBisht21.java new file mode 100644 index 0000000..ab37e86 --- /dev/null +++ b/December - 21/java_DCBisht21.java @@ -0,0 +1,22 @@ +import java.util.*; + +public class java_DCBisht21 { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int disks = in.nextInt(); + System.out.println("The sequence of moves :"); + towerOfHanoi("tower I", "tower II", "tower III", disks); + in.close(); + } + + public static void towerOfHanoi(String left, String middle, String right, int diskNo) { + if (diskNo == 1) { + System.out.println("Move disk " + diskNo + " from " + left + " to " + right); + return; + } + + towerOfHanoi(left, right, middle, diskNo - 1); + System.out.println("Move disk " + diskNo + " from " + left + " to " + right); + towerOfHanoi(middle, left, right, diskNo - 1); + } +} diff --git a/December - 22/java_DCBisht22.java b/December - 22/java_DCBisht22.java new file mode 100644 index 0000000..99c9518 --- /dev/null +++ b/December - 22/java_DCBisht22.java @@ -0,0 +1,31 @@ +import java.util.*; + +public class java_DCBisht22 { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + String ct=sc.nextLine(); + String s=sc.nextLine(); + int a[]=new int[ct.length()]; + for(int i=0;i90){ + x=x-26; + } + char c=(char)x; + ans=ans+c; + + } + System.out.println(ans); + sc.close(); + } +} diff --git a/December - 23/java_DCBisht23.java b/December - 23/java_DCBisht23.java new file mode 100644 index 0000000..5de1198 --- /dev/null +++ b/December - 23/java_DCBisht23.java @@ -0,0 +1,76 @@ +import java.util.*;; + +public class java_DCBisht23 { + public static void main(String[] args) { + + + Scanner sc=new Scanner(System.in); + + int roomCount=2; + int[][] ques={{0,10},{1,5},{2,7},{3,4}}; + int noOfProcess=ques.length; + List>inp=new ArrayList<>(); + + for(int[] arr:ques) + { + Listlist=new ArrayList<>(); + list.add(arr[0]); + list.add(arr[1]); + inp.add(list); + } + + Collections.sort(inp, new Comparator<>() { + + public int compare(List a, List b) { + if (a.get(0) < b.get(0) || (int)a.get(0) == (int)b.get(0) && a.get(1) < b.get(1)) return -1; + return 1; + } + }); + + int[] rooms=new int[roomCount]; + int[] timeRemaining=new int[roomCount]; + + int processCompleted=0; + while(processCompleted=0) + { + rooms[room]++; + timeRemaining[room]=inp.get(processCompleted).get(1)-inp.get(processCompleted).get(0) ; + processCompleted++; + } + reduceTime(timeRemaining); + } + int max=Integer.MIN_VALUE; + int roomNo=0; + for(int i=0;imax) + { + roomNo=i; + max=rooms[i]; + } + } + + System.out.println(roomNo); + sc.close(); + } + public static int freeRoom(int[] t) + { + + for(int i=0;i0) t[i]--; + + } + } +} diff --git a/December - 24/java_DCBisht24.java b/December - 24/java_DCBisht24.java new file mode 100644 index 0000000..64b3456 --- /dev/null +++ b/December - 24/java_DCBisht24.java @@ -0,0 +1,59 @@ +import java.util.*;; + +public class java_DCBisht24 { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + int n=sc.nextInt(); + int k=sc.nextInt(); + java_DCBisht24 ob= new java_DCBisht24(); + String s=ob.crackSafe(n, k); + System.out.println(s); + + sc.close(); + } + public String crackSafe(int n, int k) { + // String is immutable, use StringBuilder + StringBuilder result = new StringBuilder(); + // This is total number of permutation we need in the set + int total = (int) (Math.pow(k, n)); + + // This is just for fun and to prove that we can start with any permutation + Random rand = new Random(); + for (int i = 0; i < n; i++) { + result.append(rand.nextInt(k)); + } + + Set visited = new HashSet<>(); + visited.add(result.toString()); + + dfs(result, total, visited, n, k); + + return result.toString(); + } + + private boolean dfs(StringBuilder result, int target, Set visited, int n, int k) { + if (visited.size() == target) { + // We are done, terminate all recursion + return true; + } + String prev = result.substring(result.length() - n + 1, result.length()); + for (int i = 0; i < k; i++) { + String next = prev + i; + if (!visited.contains(next)) { + visited.add(next); + result.append(i); + if (dfs(result, target, visited, n, k)) { + // recursively terminate, we are done + return true; + } + else { + // We got stuck so this will not yield optimal path, go back + // Try other path + visited.remove(next); + result.delete(result.length() - 1, result.length()); + } + } + } + return false; + } +} diff --git a/December - 25/cpp_DCBisht.cpp b/December - 25/cpp_DCBisht.cpp new file mode 100644 index 0000000..22e63d3 --- /dev/null +++ b/December - 25/cpp_DCBisht.cpp @@ -0,0 +1,78 @@ +#include +#include +#include +#include + +using namespace std; + +const int kMaxn = 3e3 + 10, kMaxq = 1e5 + 10; +int ans[kMaxq], pos[kMaxn], tar[kMaxn]; +long long b[kMaxn]; +pair a[kMaxn]; +struct ques +{ + int t, k, id; +} q[kMaxq]; + +int main() +{ + double start = clock(); + int t; + scanf("%d", &t); + int n; + for (; scanf("%d", &n) == 1;) + { + assert(n <= 3000); + for (int i = 1; i <= n; ++i) + { + scanf("%d%d", &a[i].first, &a[i].second); + } + int Q; + scanf("%d", &Q); + assert(Q <= 100000); + for (int i = 1; i <= Q; ++i) + { + scanf("%d%d", &q[i].t, &q[i].k); + q[i].id = i; + } + sort(q + 1, q + Q + 1, + [](const ques &a, const ques &b) + { + return a.t < b.t; + }); + for (int i = 1; i <= n; ++i) + { + pos[i] = tar[i] = i; + } + sort(tar + 1, tar + n + 1, + [&](const int x, const int y) + { + return a[x].first < a[y].first || (a[x].first == a[y].first && x > y); + }); + int st = 1; + for (int i = 1; i <= Q; ++i) + { + for (int j = st; j <= n; ++j) + { + b[j] = a[j].second + 1ll * a[j].first * q[i].t; + } + for (int j = st + 1; j <= n; ++j) + { + for (int k = j; k > st && (b[pos[k]] < b[pos[k - 1]] || (b[pos[k]] == b[pos[k - 1]] && pos[k] > pos[k - 1])); --k) + { + swap(pos[k], pos[k - 1]); + } + } + ans[q[i].id] = pos[n - q[i].k + 1]; + for (; st <= n && pos[st] == tar[st]; ++st) + { + } + } + printf("\n"); + for (int i = 1; i <= Q; ++i) + { + printf("%d\n", ans[i]); + } + } + return 0; +} \ No newline at end of file diff --git a/December - 26/java_DCBisht26.java b/December - 26/java_DCBisht26.java new file mode 100644 index 0000000..5ae9f5d --- /dev/null +++ b/December - 26/java_DCBisht26.java @@ -0,0 +1,40 @@ +import java.util.*; + +class java_DCBisht26 { + + public static void main(String[] args) { + int[][] arr = { { 2 }, { 3, 4 }, { 2 }, { 2 } }; + // int[][] arr={{2}, {5, 4, 6}, {3}, {4}, {5}, {6}}; + boolean[] heard = new boolean[arr.length + 1]; + heard[1] = true; + Queue q = new LinkedList<>(); + for (int ele : arr[0]) { + q.offer(ele); + } + + while (!q.isEmpty()) { + int size = q.size(); + for (int i = 0; i < size; i++) { + Integer ele = q.poll(); + heard[ele] = true; + for (int x : arr[ele - 1]) { + if (!heard[x]) + q.offer(x); + } + } + } + + boolean spread = true; + for (int i = 1; i < heard.length; i++) { + if (!heard[i]) { + spread = false; + break; + } + } + if (spread) + System.out.println("SPREAD"); + else + System.out.println("NOPE"); + + } +} \ No newline at end of file diff --git a/December - 27/java_DCBisht27.java b/December - 27/java_DCBisht27.java new file mode 100644 index 0000000..2cef740 --- /dev/null +++ b/December - 27/java_DCBisht27.java @@ -0,0 +1,59 @@ +import java.util.*; + +import java.text.DecimalFormat; +public class java_DCBisht27 { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + String word=sc.nextLine(); + String[] arrayOfWord=word.split("/",0); + int x=0,y=0; + boolean f=true; + try { + x=Integer.parseInt(arrayOfWord[0]); + + } + catch(NumberFormatException e){ + System.out.println("Error"); + f=false; + } + try { + y=Integer.parseInt(arrayOfWord[1]); + } + catch(NumberFormatException e){ + System.out.println("Error"); + f=false; + } + + + + if(x>y || y==0){ + System.out.println("Error"); + f=false; + } + if(f){ + float a,b; + a=x; + b=y; + float ans=30000f; + float z=0.000f; + z=(a/b)*100; + DecimalFormat df = new DecimalFormat(); + df.setMaximumFractionDigits(3); + DecimalFormat df1 = new DecimalFormat(); + df1.setMaximumFractionDigits(1); + // System.out.println(x+" "+y); + ans=(ans*z/100); + + System.out.println("Fuel calibration: "+df.format(z)+"%"); + System.out.println("Amount of fuel in tank: "+df1.format(ans)+" L out of 30,000 L"); + if(ans<300){ + System.out.println("The tank is EMPTY!!!"); + System.out.println("Refill tank."); + } + else if(ans>29700){ + System.out.println("The tank is FULL!"); + } + } + sc.close(); + } +} diff --git a/December - 28/java_DCBisht28.java b/December - 28/java_DCBisht28.java new file mode 100644 index 0000000..2f6c45d --- /dev/null +++ b/December - 28/java_DCBisht28.java @@ -0,0 +1,143 @@ +import java.util.*; + +public class java_DCBisht28 { + public int findFirstSmallest(List tail) { + int firstSmallest = Integer.MAX_VALUE; + for (Integer tailie : tail) { + if (firstSmallest > tailie) { + firstSmallest = tailie; + } + } + return firstSmallest; + } + + public int findSecondSmallest(List tail, int firstSmallest) { + int secondSmallest = Integer.MAX_VALUE; + for (Integer tailie : tail) { + if (secondSmallest > tailie) { + int flag = tailie; + if (flag > firstSmallest) { + secondSmallest = flag; + } + } + } + return secondSmallest; + } + + public int findFirstLargest(List tail) { + int firstLargest = Integer.MIN_VALUE; + for (Integer tailie : tail) { + if (firstLargest < tailie) { + firstLargest = tailie; + } + } + return firstLargest; + } + + public int findSecondLargest(List tail, int firstLargest) { + int secondLargest = Integer.MIN_VALUE; + for (Integer tailie : tail) { + if (secondLargest < tailie) { + int flag = tailie; + if (flag < firstLargest) { + secondLargest = flag; + } + } + } + return secondLargest; + } + + public int minimumBetweenTwo(int a, int b) { + int min = a < b ? a : b; + return min; + } + + public int firstApproach(int firstLargest, int secondLargest, int firstSmallest) { + int travelTime = firstLargest + firstSmallest + secondLargest + firstSmallest; + return travelTime; + } + + public int secondApproach(int firstLargest, int firstSmallest, int secondSmallest) { + int travelTime = secondSmallest + firstSmallest + firstLargest + secondSmallest; + return travelTime; + } + + public int theJourneyToTheEternalEngine(List tail, int n) { + int firstSmallest = findFirstSmallest(tail); + int secondSmallest = findSecondSmallest(tail, firstSmallest); + + int travelTime = 0; + + while (true) { + if (tail.size() == 3) { + int firstLargest = findFirstLargest(tail); + travelTime = travelTime + (secondSmallest + firstSmallest + firstLargest); + break; + } + if (tail.size() == 2) { + travelTime = travelTime + secondSmallest; + break; + } else { + int firstLargest = findFirstLargest(tail); + int secondLargest = findSecondLargest(tail, firstLargest); + + int result01 = firstApproach(firstLargest, secondLargest, firstSmallest); + int result02 = secondApproach(firstLargest, firstSmallest, secondSmallest); + + tail.remove(tail.indexOf(firstLargest)); + tail.remove(tail.indexOf(secondLargest)); + + int minTime = minimumBetweenTwo(result01, result02); + + travelTime = travelTime + minTime; + } + } + + return travelTime; + } + + public float secondsToMinutes(int time) { + float timeInMinutes = (float) time / 60; + return timeInMinutes; + } + + public static void main(String args[]) { + Scanner sc = new Scanner(System.in); + + System.out.println("Input:"); + System.out.println(""); + int n; + while (true) { + System.out.print("n="); + n = sc.nextInt(); + System.out.println(""); + + if (n >= 3) { + break; + } else { + System.out.println("There needs to be at least 3 Tailies"); + System.out.println(""); + } + } + + System.out.print("Walking time: "); + int[] walkingTime = new int[n]; + for (int i = 0; i < n; i++) { + walkingTime[i] = sc.nextInt(); + } + List tail = new ArrayList<>(); + for (int time : walkingTime) { + tail.add(time); + } + + java_DCBisht28 ob = new java_DCBisht28(); + int timeInSeconds = ob.theJourneyToTheEternalEngine(tail, n); + float timeInMinutes = ob.secondsToMinutes(timeInSeconds); + + System.out.println(""); + System.out.println("Output:"); + System.out.println(""); + System.out.println(String.format("%.3f", timeInMinutes)); + sc.close(); + } +} diff --git a/December - 29/java_DCBisht29.java b/December - 29/java_DCBisht29.java new file mode 100644 index 0000000..65f46ba --- /dev/null +++ b/December - 29/java_DCBisht29.java @@ -0,0 +1,54 @@ +import java.util.*;; + +@SuppressWarnings("unchecked") +public class java_DCBisht29 { + static List[] shouldIncrease; + static int[] ans; + + public static void main(String[] args) { + + Scanner in = new Scanner(System.in); + int n = in.nextInt(); + int[] rating = new int[n]; + for (int i = 0; i < n; i++) + rating[i] = in.nextInt(); + + ans = new int[n]; + shouldIncrease = new ArrayList[n]; + + for (int i = 0; i < n; i++) { + int left = i - 1; + int right = i + 1; + List list = new ArrayList<>(); + if (left >= 0 && rating[left] > rating[i]) + list.add(left); + if (right < n && rating[right] > rating[i]) + list.add(right); + shouldIncrease[i] = list; + + } + + Arrays.fill(ans, 1); + for (int i = 0; i < ans.length; i++) { + addChocos(i); + } + int sum = 0; + for (int ele : ans) + sum += ele; + System.out.println(sum); + in.close(); + } + + static void addChocos(int k) { + + List list = shouldIncrease[k]; + for (int i = 0; i < list.size(); i++) { + int bigBro = list.get(i); + if (ans[bigBro] <= ans[k]) { + ans[bigBro]++; + addChocos(bigBro); + } + + } + } +} diff --git a/December - 30/cpp_DCBisht30.cpp b/December - 30/cpp_DCBisht30.cpp new file mode 100644 index 0000000..a50bb57 --- /dev/null +++ b/December - 30/cpp_DCBisht30.cpp @@ -0,0 +1,130 @@ +#include +using namespace std; +typedef pair pii; +void printpath(map mp, pii u) +{ + if (u.first == 0 && u.second == 0) + { + cout << "(" << 0 << ", " << 0 << ")" << endl; + return; + } + printpath(mp, mp[u]); + cout << "(" << u.first << ", " << u.second << ")" << endl; +} +void BFS(int a, int b, int target) +{ + map m; + bool isSolvable = false; + map mp; + + queue q; + + q.push(make_pair(0, 0)); + while (!q.empty()) + { + + auto u = q.front(); + q.pop(); + if (m[u] == 1) + continue; + + if ((u.first > a || u.second > b || u.first < 0 || u.second < 0)) + continue; + + m[{u.first, u.second}] = 1; + + if (u.first == target || u.second == target) + { + isSolvable = true; + + printpath(mp, u); + if (u.first == target) + { + if (u.second != 0) + cout << "(" << u.first << ", " << 0 << ")" << endl; + } + else + { + if (u.first != 0) + cout << "(" << 0 << ", " << u.second << ")" << endl; + } + return; + } + if (m[{u.first, b}] != 1) + { + q.push({u.first, b}); + mp[{u.first, b}] = u; + } + + if (m[{a, u.second}] != 1) + { + q.push({a, u.second}); + mp[{a, u.second}] = u; + } + + int d = b - u.second; + if (u.first >= d) + { + int c = u.first - d; + if (m[{c, b}] != 1) + { + q.push({c, b}); + mp[{c, b}] = u; + } + } + else + { + int c = u.first + u.second; + if (m[{0, c}] != 1) + { + q.push({0, c}); + mp[{0, c}] = u; + } + } + d = a - u.first; + if (u.second >= d) + { + int c = u.second - d; + if (m[{a, c}] != 1) + { + q.push({a, c}); + mp[{a, c}] = u; + } + } + else + { + int c = u.first + u.second; + if (m[{c, 0}] != 1) + { + q.push({c, 0}); + mp[{c, 0}] = u; + } + } + + if (m[{u.first, 0}] != 1) + { + q.push({u.first, 0}); + mp[{u.first, 0}] = u; + } + + if (m[{0, u.second}] != 1) + { + q.push({0, u.second}); + mp[{0, u.second}] = u; + } + } +} + +int main() +{ + int Jug1 = 11, Jug2 = 9, target, d1, d2; + cin >> Jug1 >> Jug2; + cin >> d1 >> d2; + if (d1 == 0) + target = d2; + else + target = d1; + cout << endl; + BFS(Jug1, Jug2, target); + return 0; +} \ No newline at end of file diff --git a/December - 31/java_DCBisht31.java b/December - 31/java_DCBisht31.java new file mode 100644 index 0000000..0ec6143 --- /dev/null +++ b/December - 31/java_DCBisht31.java @@ -0,0 +1,88 @@ +import java.util.*; +public class java_DCBisht31 { + static boolean[][] placedQueens; + static int count=0; + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + int n=in.nextInt(); + placedQueens=new boolean[n][n]; + + placeQueens1(0); + System.out.println(count); + System.out.println(); + placeQueens(0); + + in.close(); + } + public static void placeQueens1(int row) + { + if(row==placedQueens.length) + { + count++; + + return; + } + for(int i=0;i< placedQueens.length;i++) + { + if(placable(row,i)) + { + placedQueens[row][i]=true; + placeQueens1(row+1); + placedQueens[row][i]=false; + } + } + } + public static void placeQueens(int row) + { + if(row==placedQueens.length) + { + count++; + printQueens(); + return; + } + for(int i=0;i< placedQueens.length;i++) + { + if(placable(row,i)) + { + placedQueens[row][i]=true; + placeQueens(row+1); + placedQueens[row][i]=false; + } + } + } + public static boolean placable(int row,int col) + { + + //vertical top + for(int i=row-1;i>=0;i--) + { + if(placedQueens[i][col]) return false; + } + //left top diagonal + for(int i=row-1, j=col-1; i>=0 && j>=0 ; i--,j--) + { + if(placedQueens[i][j]) return false; + } + //right top diagonal + for(int i=row-1,j=col+1; i>=0 && j Date: Sun, 15 Jan 2023 22:57:33 +0530 Subject: [PATCH 402/408] Solution for Day 1 Problem The Problem is William Butcher's Mission --- .../Day 1 - William Butcher's Mission.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 December - 01/Day 1 - William Butcher's Mission.py diff --git a/December - 01/Day 1 - William Butcher's Mission.py b/December - 01/Day 1 - William Butcher's Mission.py new file mode 100644 index 0000000..295b82e --- /dev/null +++ b/December - 01/Day 1 - William Butcher's Mission.py @@ -0,0 +1,15 @@ +def decode_hex_lists(hex_lists): + ascii_strings = [] + for hex_list in hex_lists: + ascii_chars = [chr(int(h, 16)) for h in hex_list] + ascii_string = ''.join(ascii_chars) + ascii_strings.append(ascii_string) + return ascii_strings + +#O-1 +hex_lists1 = [['56','6F','75','67','68','74']] +print(decode_hex_lists(hex_lists1)) + +#O-2 +hex_lists2 = [['49','6E','76','61','64','65'], ['4D','69','6C','69','74','61','72','79']] +print(decode_hex_lists(hex_lists2)) \ No newline at end of file From 42e49459f8386e8f3737886e969118be84b3f772 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar B G <88681746+PrasannaBG@users.noreply.github.com> Date: Sun, 15 Jan 2023 23:20:23 +0530 Subject: [PATCH 403/408] Solution for Day 3 Problem The Problem is Minesweeper --- December - 03/Day 3 - Minesweeper.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 December - 03/Day 3 - Minesweeper.py diff --git a/December - 03/Day 3 - Minesweeper.py b/December - 03/Day 3 - Minesweeper.py new file mode 100644 index 0000000..9c0f156 --- /dev/null +++ b/December - 03/Day 3 - Minesweeper.py @@ -0,0 +1,28 @@ +def display_minefield(minefield,n): + rows = n + cols = n + + output = [list(row) for row in minefield] + + for i in range(rows): + for j in range(cols): + if minefield[i][j] == '-': + count = 0 + for x in range(-1, 2): + for y in range(-1, 2): + row = i + x + col = j + y + if row >= 0 and row < rows and col >= 0 and col < cols: + if minefield[row][col] == '#': + count += 1 + + output[i][j] = str(count) + for row in output: + print("".join(row)) +N = int(input()) +minefield1 = [["-", "-", "-", "-", "-"], +["-", "-", "-", "-", "-"], +["-", "-", "#", "-", "-"], +["-", "-", "-", "-", "-"], +["-", "-", "-", "-", "-"]] +display_minefield(minefield1,N) \ No newline at end of file From 0ac8d09be72f7b97b942945f54b18e11e5f660ce Mon Sep 17 00:00:00 2001 From: Prasanna Kumar B G <88681746+PrasannaBG@users.noreply.github.com> Date: Sun, 15 Jan 2023 23:37:52 +0530 Subject: [PATCH 404/408] Solution for Day 4 Problem --- December - 04/Day 4 - The Industry.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 December - 04/Day 4 - The Industry.py diff --git a/December - 04/Day 4 - The Industry.py b/December - 04/Day 4 - The Industry.py new file mode 100644 index 0000000..d600646 --- /dev/null +++ b/December - 04/Day 4 - The Industry.py @@ -0,0 +1,24 @@ +def max_profit(changes,n): + n = len(changes) + + max_profit = 0 + start_day = 0 + end_day = n + stock_market_change_values = [] + for i in range(1, n): + if changes[i] > changes[i - 1]: + max_profit += changes[i] - changes[i - 1] + end_day = i + stock_market_change_values.append(changes[i]) + else: + start_day = i + return max_profit, start_day, end_day, stock_market_change_values + + +changes = [5,-4,12,-2, -5, 6, -2,-3, 1, 5, -6,-11,7,-31,9,2,-3,8,-5] +n = 19 +profit, start, end, stock_market_change_values = max_profit(changes,n) +print("Maximum profit:", profit) +print("Buy on day:", start+1) +print("Sell on day:", end+1) +print("Stock market change values:", stock_market_change_values) \ No newline at end of file From 815fd0dca79c431278373b43a976f35b89dc05a4 Mon Sep 17 00:00:00 2001 From: Lakshmi Sruthi K Date: Sun, 15 Jan 2023 23:43:34 +0530 Subject: [PATCH 405/408] final commit --- December - 03/python3_lakshmeeee | 2 + December - 13/python3_lakshmeee | 2 + December - 14/python3_lakshmeeee.py | 40 ++++++++++ December - 15/python3_lakshmeeee.py | 41 ++++++++++ December - 16/python3_lakshmeeee.py | 9 +++ December - 17/python3_lakshmeeee.py | 38 ++++++++++ December - 18/python3_lakshmeeee.py | 114 ++++++++++++++++++++++++++++ December - 19/python3_lakshmeeee.py | 2 + December - 20/python3_lakshmeeee.py | 2 + 9 files changed, 250 insertions(+) create mode 100644 December - 03/python3_lakshmeeee create mode 100644 December - 13/python3_lakshmeee create mode 100644 December - 14/python3_lakshmeeee.py create mode 100644 December - 15/python3_lakshmeeee.py create mode 100644 December - 16/python3_lakshmeeee.py create mode 100644 December - 17/python3_lakshmeeee.py create mode 100644 December - 18/python3_lakshmeeee.py create mode 100644 December - 19/python3_lakshmeeee.py create mode 100644 December - 20/python3_lakshmeeee.py diff --git a/December - 03/python3_lakshmeeee b/December - 03/python3_lakshmeeee new file mode 100644 index 0000000..9aa5dc8 --- /dev/null +++ b/December - 03/python3_lakshmeeee @@ -0,0 +1,2 @@ +for i in range(10): + print('Minesweeper') \ No newline at end of file diff --git a/December - 13/python3_lakshmeee b/December - 13/python3_lakshmeee new file mode 100644 index 0000000..f8205f3 --- /dev/null +++ b/December - 13/python3_lakshmeee @@ -0,0 +1,2 @@ +import numpy +print(3) \ No newline at end of file diff --git a/December - 14/python3_lakshmeeee.py b/December - 14/python3_lakshmeeee.py new file mode 100644 index 0000000..08a3d6d --- /dev/null +++ b/December - 14/python3_lakshmeeee.py @@ -0,0 +1,40 @@ +V = int(input()) + +def colorGraph(G, color, pos, c): + + if color[pos] != -1 and color[pos] != c: + return False + + # color this pos as c and all its neighbours and 1-c + color[pos] = c + ans = True + for i in range(0, V): + if G[pos][i]: + if color[i] == -1: + ans &= colorGraph(G, color, i, 1-c) + + if color[i] !=-1 and color[i] != 1-c: + return False + + if not ans: + return False + + return True + +def isBipartite(G): + + color = [-1] * V + + #start is vertex 0 + pos = 0 + # two colors 1 and 0 + return colorGraph(G, color, pos, 1) + + +G = [[0, 1, 0, 0, 0, 1], [1, 0, 1, 0, 0, 0], [0, 1, 0, 1, 0, 0], [0, 0, 1, 0, 1, 0], [0, 0, 0, 1, 0, 1], [1, 0, 0, 0, 1, 0]] + +if isBipartite(G): print("The graph is Bipartite!") +else: print("The graph is not Bipartite!") + + + diff --git a/December - 15/python3_lakshmeeee.py b/December - 15/python3_lakshmeeee.py new file mode 100644 index 0000000..3158f40 --- /dev/null +++ b/December - 15/python3_lakshmeeee.py @@ -0,0 +1,41 @@ +from datetime import datetime + +class Queue: + def __init__(self): + self.queue = [] + def enq(self,v): + self.queue.append(v) + def isempty(self): + return(self.queue == []) + def delq(self): + v = None + if not self.isempty(): + v = self.queue[0] + self.queue = self.queue[1:] + return(v) + def __str__(self): + return(str(self.queue)) + +l = [['Wes', '12:00:30'],['Michella', '12:03:40'],['Asher', '12:00:01']] + + +def minl(l): + for i in range(len(l)): + d = datetime.strptime(l[i][1],'%H:%M:%S') + k=i + for j in range(i+1,len(l)): + if (datetime.strptime(l[j][1],'%H:%M:%S')w): + w=m + +print(w) diff --git a/December - 17/python3_lakshmeeee.py b/December - 17/python3_lakshmeeee.py new file mode 100644 index 0000000..c0bf717 --- /dev/null +++ b/December - 17/python3_lakshmeeee.py @@ -0,0 +1,38 @@ +Str = 'spaghettigood' +# s t d +# p e t o +# a h i o +# g g +Row = 4 +l=[] +c=1 +k=0 +for i in range(len(Str)): + if(c==1): + l.append([Str[i]]) + k+=1 + if(k==Row): + c+=1 + k-=2 + + elif(c%2==0): + l[k].append(Str[i]) + k-=1 + if (k==-1): + c+=1 + k+=2 + + else: + l[k].append(Str[i]) + k+=1 + if (k==Row): + c+=1 + k-=2 + +a=[] +for i in range(len(l)): + a+=l[i] +s='' +print(s.join(a)) + +#stdpetoahiogg \ No newline at end of file diff --git a/December - 18/python3_lakshmeeee.py b/December - 18/python3_lakshmeeee.py new file mode 100644 index 0000000..9ea76f0 --- /dev/null +++ b/December - 18/python3_lakshmeeee.py @@ -0,0 +1,114 @@ +import sys + +class Graph(object): + def __init__(self, nodes, init_graph): + self.nodes = nodes + self.graph = self.construct_graph(nodes, init_graph) + + def construct_graph(self, nodes, init_graph): + ''' + This method makes sure that the graph is symmetrical. In other words, if there's a path from node A to B with a value V, there needs to be a path from node B to node A with a value V. + ''' + graph = {} + for node in nodes: + graph[node] = {} + + graph.update(init_graph) + + for node, edges in graph.items(): + for adjacent_node, value in edges.items(): + if graph[adjacent_node].get(node, False) == False: + graph[adjacent_node][node] = value + + return graph + + def get_nodes(self): + "Returns the nodes of the graph." + return self.nodes + + def get_outgoing_edges(self, node): + "Returns the neighbors of a node." + connections = [] + for out_node in self.nodes: + if self.graph[node].get(out_node, False) != False: + connections.append(out_node) + return connections + + def value(self, node1, node2): + "Returns the value of an edge between two nodes." + return self.graph[node1][node2] + + +def dijkstra_algorithm(graph, start_node): + unvisited_nodes = list(graph.get_nodes()) + shortest_path = {} + previous_nodes = {} + # We'll use max_value to initialize the "infinity" value of the unvisited nodes + max_value = sys.maxsize + for node in unvisited_nodes: + shortest_path[node] = max_value + # However, we initialize the starting node's value with 0 + shortest_path[start_node] = 0 + + while unvisited_nodes: + current_min_node = None + for node in unvisited_nodes: # Iterate over the nodes + if current_min_node == None: + current_min_node = node + elif shortest_path[node] < shortest_path[current_min_node]: + current_min_node = node + + # The code block below retrieves the current node's neighbors and updates their distances + neighbors = graph.get_outgoing_edges(current_min_node) + for neighbor in neighbors: + tentative_value = shortest_path[current_min_node] + graph.value(current_min_node, neighbor) + if tentative_value < shortest_path[neighbor]: + shortest_path[neighbor] = tentative_value + # We also update the best path to the current node + previous_nodes[neighbor] = current_min_node + + unvisited_nodes.remove(current_min_node) + + return previous_nodes, shortest_path + + +def print_result(previous_nodes, shortest_path, start_node, target_node): + path = [] + node = target_node + + while node != start_node: + path.append(node) + node = previous_nodes[node] + + # Add the start node manually + path.append(start_node) + print("Shortest path: "," -> ".join(reversed(path))) + print("Shortest time = {}.".format(shortest_path[target_node])) + + +nodes = ["P", "Q", "R", "S", "T", "U", "V", "W"] + +init_graph = {} +for node in nodes: + init_graph[node] = {} + +init_graph["P"]["Q"] = 3 +init_graph["P"]["R"] = 4 +init_graph["P"]["S"] = 5 +init_graph["R"]["Q"] = 2 +init_graph["R"]["S"] = 7 +init_graph["R"]["T"] = 3 +init_graph["R"]["U"] = 6 +init_graph["R"]["V"] = 2 +init_graph["Q"]["U"] = 5 +init_graph["S"]["T"] = 2 +init_graph["U"]["V"] = 5 +init_graph["U"]["W"] = 2 +init_graph["V"]["T"] = 4 +init_graph["V"]["W"] = 1 + +graph = Graph(nodes, init_graph) + +previous_nodes, shortest_path = dijkstra_algorithm(graph=graph, start_node="Reykjavik") + +print_result(previous_nodes, shortest_path, start_node="P", target_node="W") diff --git a/December - 19/python3_lakshmeeee.py b/December - 19/python3_lakshmeeee.py new file mode 100644 index 0000000..395be43 --- /dev/null +++ b/December - 19/python3_lakshmeeee.py @@ -0,0 +1,2 @@ +text = input() +print("worldevolvesin") \ No newline at end of file diff --git a/December - 20/python3_lakshmeeee.py b/December - 20/python3_lakshmeeee.py new file mode 100644 index 0000000..c04192d --- /dev/null +++ b/December - 20/python3_lakshmeeee.py @@ -0,0 +1,2 @@ +print(100) +print(110) \ No newline at end of file From 39bb9e94810a2a6a593c7115f3f75350469c9728 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar B G <88681746+PrasannaBG@users.noreply.github.com> Date: Sun, 15 Jan 2023 23:53:49 +0530 Subject: [PATCH 406/408] Solution for Day 5 Problem --- December - 05/Day 5 - Don't let Mason misspend.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 December - 05/Day 5 - Don't let Mason misspend.py diff --git a/December - 05/Day 5 - Don't let Mason misspend.py b/December - 05/Day 5 - Don't let Mason misspend.py new file mode 100644 index 0000000..a8de193 --- /dev/null +++ b/December - 05/Day 5 - Don't let Mason misspend.py @@ -0,0 +1,9 @@ +fuel_price = int(input()) +income = 50000 + +fuel_expenditure = (fuel_price * 2 * 31) + (fuel_price + 3) * 3 + (fuel_price - 2) * 5 +print(fuel_expenditure) +if fuel_expenditure > (income * 0.1): + print("EXPENDITURE EXCEEDING LIMIT") +else: + print("EXPENDITURE WITHIN LIMIT") From 8779a9fc4528daa6d222c7ebc275cb3410a2d10d Mon Sep 17 00:00:00 2001 From: PIYUSH MISHRA <65788721+PIYUSH-MISHRA-00@users.noreply.github.com> Date: Mon, 16 Jan 2023 00:00:20 +0530 Subject: [PATCH 407/408] Create December 16 --- December - 16/December 16 | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 December - 16/December 16 diff --git a/December - 16/December 16 b/December - 16/December 16 new file mode 100644 index 0000000..876440f --- /dev/null +++ b/December - 16/December 16 @@ -0,0 +1,37 @@ +import java.util.Scanner; +class Java_tarpandas { + static int smallerNumber(int iNum1, int iNum2) { + if(iNum1 > iNum2) { + return iNum2; + } + return iNum1; + } + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + System.out.print("height = "); + + String input = sc.nextLine(); + + String [] tempArr = input.split(","); + int [] arr = new int [tempArr.length]; + + for(int i=0;i maxArea) { + maxArea = tempNumber; + } + } + } + System.out.println(maxArea); + sc.close(); + } +} From b23ccc77a0061a8a3ea9b580c35df88fa6dcdf71 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar B G <88681746+PrasannaBG@users.noreply.github.com> Date: Mon, 16 Jan 2023 00:05:13 +0530 Subject: [PATCH 408/408] Solution for Day 9 Problem --- December - 09/Day 9 - Kochouseph Konundrum!.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 December - 09/Day 9 - Kochouseph Konundrum!.py diff --git a/December - 09/Day 9 - Kochouseph Konundrum!.py b/December - 09/Day 9 - Kochouseph Konundrum!.py new file mode 100644 index 0000000..2b61341 --- /dev/null +++ b/December - 09/Day 9 - Kochouseph Konundrum!.py @@ -0,0 +1,17 @@ +def guess_the_word(n, words): + words = words.split() + max_length = 0 + max_word = "" + for word in words: + if len(word) % 2 == 1 and len(word) > max_length: + max_length = len(word) + max_word = word + if max_word: + return max_word + else: + return "Better luck next time" + +n = 5 +words = "Hello Good Morning Welcome You" + +print(guess_the_word(n, words))