├── .gitignore ├── .idea ├── hackerrank-30-days-of-code.iml ├── misc.xml ├── modules.xml └── vcs.xml ├── LICENSE ├── README.md ├── day-00 ├── README.md ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-01 ├── README.md ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-02 ├── README.md ├── solution.py ├── test-0-input.txt ├── test-0-output.txt ├── test-1-input.txt └── test-1-output.txt ├── day-03 ├── README.md ├── solution.py ├── test-0-input.txt ├── test-0-output.txt ├── test-1-input.txt └── test-1-output.txt ├── day-04 ├── README.md ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-05 ├── README.md ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-06 ├── README.md ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-07 ├── README.md ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-08 ├── README.md ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-09 ├── README.md ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-10 ├── README.md ├── solution.py ├── test-0-input.txt ├── test-0-output.txt ├── test-1-input.txt └── test-1-output.txt ├── day-11 ├── README.md ├── solution.py ├── test-0-input.txt ├── test-0-output.txt ├── test-1-input.txt ├── test-1-output.txt ├── test-2-input.txt └── test-2-output.txt ├── day-12 ├── README.md ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-13 ├── README.md ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-14 ├── README.md ├── solution.py ├── test-0-input.txt ├── test-0-output.txt ├── test-1-input.txt ├── test-1-output.txt ├── test-2-input.txt └── test-2-output.txt ├── day-15 ├── REAMDME.md ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-16 ├── README.md ├── solution.py ├── test-0-input.txt ├── test-0-output.txt ├── test-1-input.txt ├── test-1-output.txt ├── test-2-input.txt ├── test-2-output.txt ├── test-3-input.txt └── test-3-output.txt ├── day-17 ├── README.md ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-18 ├── README.md ├── solution.py ├── test-0-input.txt ├── test-0-output.txt ├── test-1-input.txt └── test-1-output.txt ├── day-19 ├── README.md ├── solution.java ├── solution.py ├── test-0-input.txt ├── test-0-output.txt ├── test-1-input.txt ├── test-1-output.txt ├── test-2-input.txt └── test-2-output.txt ├── day-20 ├── README.md ├── solution.py ├── test-0-input.txt ├── test-0-output.txt ├── test-1-input.txt └── test-1-output.txt ├── day-21 ├── README.md ├── Solution.java ├── test-0-input.txt └── test-0-output.txt ├── day-22 ├── README.md ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-23 ├── README.md ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-24 ├── README.md ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-25 ├── solution.py ├── test-0-input.txt ├── test-0-output.txt ├── test-1-input.txt └── test-1-output.txt ├── day-26 ├── README.md ├── SOLUTION.md ├── solution.py ├── test-0-input.txt ├── test-0-output.txt ├── test-1-input.txt └── test-1-output.txt ├── day-27 ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-28 ├── solution.py ├── test-0-input.txt └── test-0-output.txt ├── day-29 ├── solution.py ├── test-0-input.txt ├── test-0-output.txt ├── test-1-input.txt ├── test-1-output.txt ├── test-2-input.txt └── test-2-output.txt └── test-solution.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | 103 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 104 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 105 | 106 | # User-specific stuff: 107 | .idea/**/workspace.xml 108 | .idea/**/tasks.xml 109 | .idea/dictionaries 110 | 111 | # Sensitive or high-churn files: 112 | .idea/**/dataSources/ 113 | .idea/**/dataSources.ids 114 | .idea/**/dataSources.xml 115 | .idea/**/dataSources.local.xml 116 | .idea/**/sqlDataSources.xml 117 | .idea/**/dynamic.xml 118 | .idea/**/uiDesigner.xml 119 | 120 | # Gradle: 121 | .idea/**/gradle.xml 122 | .idea/**/libraries 123 | 124 | # CMake 125 | cmake-build-debug/ 126 | cmake-build-release/ 127 | 128 | # Mongo Explorer plugin: 129 | .idea/**/mongoSettings.xml 130 | 131 | ## File-based project format: 132 | *.iws 133 | 134 | ## Plugin-specific files: 135 | 136 | # IntelliJ 137 | out/ 138 | 139 | # mpeltonen/sbt-idea plugin 140 | .idea_modules/ 141 | 142 | # JIRA plugin 143 | atlassian-ide-plugin.xml 144 | 145 | # Cursive Clojure plugin 146 | .idea/replstate.xml 147 | 148 | # Crashlytics plugin (for Android Studio and IntelliJ) 149 | com_crashlytics_export_strings.xml 150 | crashlytics.properties 151 | crashlytics-build.properties 152 | fabric.properties 153 | 154 | # Ignore pycharm files 155 | .idea/ 156 | 157 | # java gitignore 158 | # Compiled class file 159 | *.class 160 | 161 | # Log file 162 | *.log 163 | 164 | # BlueJ files 165 | *.ctxt 166 | 167 | # Mobile Tools for Java (J2ME) 168 | .mtj.tmp/ 169 | 170 | # Package Files # 171 | *.jar 172 | *.war 173 | *.ear 174 | *.zip 175 | *.tar.gz 176 | *.rar 177 | 178 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 179 | hs_err_pid* 180 | -------------------------------------------------------------------------------- /.idea/hackerrank-30-days-of-code.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 13 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Joshua Wang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hackerrank-30-days-of-code 2 | My solutions to HackerRank's 30 days of code challenge. 3 | -------------------------------------------------------------------------------- /day-00/README.md: -------------------------------------------------------------------------------- 1 | # Day 0: Hello, World. 2 | 3 | ### Objective 4 | 5 | In this challenge, we review some basic concepts that will get you started with this series. 6 | You will need to use the same (or similar) syntax to read input and write output in challenges throughout HackerRank. 7 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-hello-world/tutorial) 8 | tab for learning materials and an instructional video! 9 | 10 | ### Task 11 | 12 | To complete this challenge, you must save a line of input from stdin to a variable, 13 | print `Hello, World.` on a single line, 14 | and finally print the value of your variable on a second line. 15 | 16 | You've got this! 17 | 18 | ### Input Format 19 | 20 | A single line of text denoting _inputString_. 21 | 22 | ### Output Format 23 | 24 | Print `Hello, World.` on the first line, 25 | and the contents of _inputString_ on the second line. 26 | 27 | ### Sample Input 28 | ``` 29 | Welcome to 30 Days of Code! 30 | ``` 31 | ### Sample Output 32 | ``` 33 | Hello, World. 34 | Welcome to 30 Days of Code! 35 | ``` 36 | -------------------------------------------------------------------------------- /day-00/solution.py: -------------------------------------------------------------------------------- 1 | # Read a full line of input from stdin and save it to our dynamically typed variable, input_string. 2 | input_string = input() 3 | 4 | # Print a string literal saying "Hello, World." to stdout. 5 | print('Hello, World.') 6 | 7 | # Print the contents of input_string to stdout. 8 | print(input_string) 9 | -------------------------------------------------------------------------------- /day-00/test-0-input.txt: -------------------------------------------------------------------------------- 1 | Welcome to 30 Days of Code! -------------------------------------------------------------------------------- /day-00/test-0-output.txt: -------------------------------------------------------------------------------- 1 | Hello, World. 2 | Welcome to 30 Days of Code! 3 | -------------------------------------------------------------------------------- /day-01/README.md: -------------------------------------------------------------------------------- 1 | # Day 1: Data Types 2 | 3 | ### Objective 4 | 5 | Today, we're discussing data types. 6 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-data-types/tutorial) 7 | tab for learning materials and an instructional video! 8 | 9 | ### Task 10 | 11 | The variables _i_, _d_, and _s_ are already declared and initialized. 12 | You must: 13 | 14 | 1. Declare 3 variables: one of type _int_, one of type _doubhle_, and one of type _String_. 15 | 2. Read 3 lines of input from stdin and initialize your 3 variables 16 | 3. Use the `+` operator to perform the following operations: 17 | 1. Print he sum of _i_ plus your int variable on a new line. 18 | 2. Print the sum of _d_ plus your double variable to a scale of one decimal place on a new line. 19 | 3. Concatenate _s_ with the string you read as input and print the result on a new line. 20 | 21 | ### Input Format 22 | 23 | The first line contains an integer that you must sum with _i_. 24 | The second line contains a double that you must sum with _d_. 25 | The third line contains a string that you must concatenate with _s_. 26 | 27 | ### Output Format 28 | 29 | Print the sum of both integers on the first line, 30 | the sum of both doubles (scaled to 1 decimal place) on the second line, 31 | and then the two concatenated strings on the third line. 32 | 33 | ### Sample Input 34 | ``` 35 | 12 36 | 4.0 37 | is the best place to learn and practice coding! 38 | ``` 39 | ### Sample Output 40 | ``` 41 | 16 42 | 8.0 43 | HackerRank is the best place to learn and practice coding! 44 | ``` 45 | -------------------------------------------------------------------------------- /day-01/solution.py: -------------------------------------------------------------------------------- 1 | i = 4 2 | d = 4.0 3 | s = 'HackerRank ' 4 | 5 | # Declare second integer, double, and String variables. 6 | 7 | # Read and save an integer, double, and String to your variables. 8 | input_int = int(input()) 9 | input_double = float(input()) 10 | input_string = str(input()) 11 | 12 | # Print the sum of both integer variables on a new line. 13 | print(i + input_int) 14 | 15 | # Print the sum of the double variables on a new line. 16 | print(round(d + input_double, 1)) 17 | 18 | # Concatenate and print the String variables on a new line 19 | # The 's' variable above should be printed first. 20 | print(s + input_string) 21 | -------------------------------------------------------------------------------- /day-01/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 12 2 | 4.0 3 | is the best place to learn and practice coding! -------------------------------------------------------------------------------- /day-01/test-0-output.txt: -------------------------------------------------------------------------------- 1 | 16 2 | 8.0 3 | HackerRank is the best place to learn and practice coding! -------------------------------------------------------------------------------- /day-02/README.md: -------------------------------------------------------------------------------- 1 | # Day 2: Operators 2 | 3 | ### Objective 4 | 5 | In this challenge, you'll work on arithmetic operators. 6 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-operators/tutorial) 7 | tab for learning materials and an instructional video! 8 | 9 | ### Task 10 | 11 | Given the _meal_ price (base cost of a meal), 12 | _tip percent_ (percentage of the meal price being added as tip), 13 | and _tax percent_ (the percentage of the meal price being added as tax) for a meal, 14 | find and print the meal's _total cost_. 15 | 16 | ### Input Format 17 | 18 | There are 3 lines of numeric input: 19 | The first line has a double, _mealCost_ 20 | The second line has an integer _tipPercent_ 21 | The third line has an integer _tax Percent_ 22 | 23 | ### Output Format 24 | 25 | Print `The total meal cost is totalCost dollars.`, 26 | where _totalCost_ is the rounded integer result of the entire bill. 27 | 28 | ### Sample Input 29 | ``` 30 | 12.00 31 | 20 32 | 8 33 | ``` 34 | ### Sample Output 35 | ``` 36 | The total meal cost is 15 dollars. 37 | ``` 38 | -------------------------------------------------------------------------------- /day-02/solution.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | meal_cost = float(input().strip()) 3 | tip_percent = int(input().strip()) 4 | tax_percent = int(input().strip()) 5 | tip_amount = meal_cost * tip_percent / 100 6 | tax_amount = meal_cost * tax_percent / 100 7 | total_cost = round(meal_cost + tip_amount + tax_amount) 8 | print("The total meal cost is " + str(total_cost) + " dollars.") 9 | -------------------------------------------------------------------------------- /day-02/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 12.00 2 | 20 3 | 8 -------------------------------------------------------------------------------- /day-02/test-0-output.txt: -------------------------------------------------------------------------------- 1 | The total meal cost is 15 dollars. 2 | -------------------------------------------------------------------------------- /day-02/test-1-input.txt: -------------------------------------------------------------------------------- 1 | 15.50 2 | 15 3 | 10 -------------------------------------------------------------------------------- /day-02/test-1-output.txt: -------------------------------------------------------------------------------- 1 | The total meal cost is 19 dollars. 2 | -------------------------------------------------------------------------------- /day-03/README.md: -------------------------------------------------------------------------------- 1 | # Day 3: Intro to Conditional Statements 2 | 3 | ### Objective 4 | 5 | In this challenge, we're getting started with conditional statements. 6 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-conditional-statements/tutorial) 7 | tab for learning materials and an instructional video! 8 | 9 | ### Task 10 | 11 | Given an integer, _n_, perform the following conditional actions: 12 | 13 | * If _n_ is odd, print `Weird` 14 | * If _n_ is even and in the inclusive range of 2 to 5, print `Not Weird` 15 | * If _n_ is even an in the inclusive range of 6 to 20, print `Weird` 16 | * If _n_ is even and greater than 20, print `Not Weird` 17 | 18 | Complete the code to print whether or not _n_ is weird. 19 | 20 | ### Input Format 21 | 22 | A single line containing a positive integer, _n_. 23 | 24 | ### Constraints 25 | 26 | * 1 ≤ _n_ ≤ 100 27 | 28 | ### Output Format 29 | 30 | Print `Weird` if the number is weird; otherwise, print `Not Weird`. 31 | 32 | 33 | ### Sample Input 0 34 | ``` 35 | Weird 36 | ``` 37 | ### Sample Output 0 38 | ``` 39 | Weird 40 | ``` 41 | ### Sample Input 1 42 | ``` 43 | 24 44 | ``` 45 | ### Sample Output 0 46 | ``` 47 | Not Weird 48 | ``` 49 | 50 | -------------------------------------------------------------------------------- /day-03/solution.py: -------------------------------------------------------------------------------- 1 | N = int(input().strip()) 2 | 3 | if N % 2 == 1: 4 | print('Weird') 5 | elif N < 5: 6 | print('Not Weird') 7 | elif N <= 20: 8 | print('Weird') 9 | else: 10 | print('Not Weird') 11 | -------------------------------------------------------------------------------- /day-03/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 3 -------------------------------------------------------------------------------- /day-03/test-0-output.txt: -------------------------------------------------------------------------------- 1 | Weird -------------------------------------------------------------------------------- /day-03/test-1-input.txt: -------------------------------------------------------------------------------- 1 | 24 -------------------------------------------------------------------------------- /day-03/test-1-output.txt: -------------------------------------------------------------------------------- 1 | Not Weird -------------------------------------------------------------------------------- /day-04/README.md: -------------------------------------------------------------------------------- 1 | # Day 4: Class vs. Instance 2 | 3 | ### Objective 4 | 5 | In this challenge, we're going to learn about the difference between a _class_ and an _instance; 6 | because this is an _Object Oriented_ concept, it's only enabled in certain languages. 7 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-class-vs-instance/tutorial) 8 | tab for learning materials and an instructional video! 9 | 10 | ### Task 11 | 12 | Write a _Person_ class with an instance variable, _age_, 13 | and a constructor that takes an integer, _initialAge_, 14 | as a parameter. 15 | The constructor must assign _initialAge_ to _age_ 16 | after confirming the argument passed as _initialAge_ is non negative; 17 | if a negative argument is passed as _initial_Age, 18 | the constructor should set _age_ to 0 19 | and print `Age is not valid, setting age to 0.`. 20 | In addition, you must write the following instance methods: 21 | 22 | 1. _yearPasses()_ should increase the _age_ instance variable by 1. 23 | 2. _amIOld()_ should perform the following conditional actions: 24 | * If _age_ < 13, print `You are young.` 25 | * If _age_ ≥ 13 and _age < 18, print `You are a teenager.` 26 | * Otherwise, print `You are old.` 27 | 28 | ### Input Format 29 | 30 | The first line contains an integer, _T_, 31 | and the _T_ subsequent lines each contain an integer denoting the _age_ of a Person instance 32 | 33 | ### Constraints 34 | 35 | * 1 ≤ _T_ ≤ 4 36 | * -5 ≤ _age_ ≤ 30 37 | 38 | ### Output Format 39 | 40 | Complete the method definitions to meet the specifications outlined above. 41 | If your methods are implemented correctly, each test case will print 2 or 3 lines 42 | (depending on whether or not a valid _initialAge_ was passed to the constructor). 43 | 44 | ### Sample Input 45 | ``` 46 | 4 47 | -1 48 | 10 49 | 16 50 | 18 51 | ``` 52 | ### Sample Output 53 | ``` 54 | Age is not valid, setting age to 0. 55 | You are young. 56 | You are young. 57 | 58 | You are young. 59 | You are a teenager. 60 | 61 | You are a teenager. 62 | You are old. 63 | 64 | You are old. 65 | You are old. 66 | ``` 67 | -------------------------------------------------------------------------------- /day-04/solution.py: -------------------------------------------------------------------------------- 1 | class Person: 2 | def __init__(self,initialAge): 3 | # Add some more code to run some checks on initialAge 4 | if initialAge < 0: 5 | print("Age is not valid, setting age to 0.") 6 | self.age = 0 7 | else: 8 | self.age = initialAge 9 | def amIOld(self): 10 | # Do some computations in here and print out the correct statement to the console 11 | if self.age < 13: 12 | print("You are young.") 13 | elif self.age < 18: 14 | print("You are a teenager.") 15 | else: 16 | print("You are old.") 17 | def yearPasses(self): 18 | # Increment the age of the person in here 19 | self.age += 1 20 | t = int(input()) 21 | for i in range(0, t): 22 | age = int(input()) 23 | p = Person(age) 24 | p.amIOld() 25 | for j in range(0, 3): 26 | p.yearPasses() 27 | p.amIOld() 28 | print("") 29 | -------------------------------------------------------------------------------- /day-04/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 4 2 | -1 3 | 10 4 | 16 5 | 18 -------------------------------------------------------------------------------- /day-04/test-0-output.txt: -------------------------------------------------------------------------------- 1 | Age is not valid, setting age to 0. 2 | You are young. 3 | You are young. 4 | 5 | You are young. 6 | You are a teenager. 7 | 8 | You are a teenager. 9 | You are old. 10 | 11 | You are old. 12 | You are old. -------------------------------------------------------------------------------- /day-05/README.md: -------------------------------------------------------------------------------- 1 | # Day 5: Loops 2 | 3 | ### Objective 4 | 5 | In this challenge, we're going to use loops to help us do some simple math. 6 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-loops/tutorial) 7 | tab to learn more. 8 | 9 | ### Task 10 | 11 | Given an integer, _n_, print its first 10 multiples. 12 | Each multiple _n x i_ where 1 ≤ i ≤ 10 should be printed on a new line 13 | in the form: `n x i = result`. 14 | 15 | ### Input Format 16 | 17 | A single integer, _n_. 18 | 19 | ### Constraints 20 | 21 | * 2 ≤ _n_ ≤ 20 22 | 23 | ### Output Format 24 | 25 | Print 10 lines of output; 26 | each line _i_ where 1 ≤ i ≤ 10 contains the _result_ of _n_ x _i_ in the form: 27 | `n x i = result`. 28 | 29 | ### Sample Input 30 | ``` 31 | 2 32 | ``` 33 | ### Sample Output 34 | ``` 35 | 2 x 1 = 2 36 | 2 x 2 = 4 37 | 2 x 3 = 6 38 | 2 x 4 = 8 39 | 2 x 5 = 10 40 | 2 x 6 = 12 41 | 2 x 7 = 14 42 | 2 x 8 = 16 43 | 2 x 9 = 18 44 | 2 x 10 = 20 45 | ``` 46 | -------------------------------------------------------------------------------- /day-05/solution.py: -------------------------------------------------------------------------------- 1 | n = int(input().strip()) 2 | for i in range(1, 11): 3 | product = n * i 4 | print('{} x {} = {}'.format(n, i, product)) 5 | -------------------------------------------------------------------------------- /day-05/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 2 -------------------------------------------------------------------------------- /day-05/test-0-output.txt: -------------------------------------------------------------------------------- 1 | 2 x 1 = 2 2 | 2 x 2 = 4 3 | 2 x 3 = 6 4 | 2 x 4 = 8 5 | 2 x 5 = 10 6 | 2 x 6 = 12 7 | 2 x 7 = 14 8 | 2 x 8 = 16 9 | 2 x 9 = 18 10 | 2 x 10 = 20 -------------------------------------------------------------------------------- /day-06/README.md: -------------------------------------------------------------------------------- 1 | # Day 6: Let's Review 2 | 3 | ### Objective 4 | 5 | Today we're expanding our knowledge of Strings 6 | and combining it what we've already learned about loops. 7 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-review-loop/tutorial) 8 | tab for learning materials and an instructional video! 9 | 10 | ### Task 11 | 12 | Given a string, _S_, of length _N_ that is indexed from 0 to _N_ - 1, 13 | print its _even-indexed_ and _odd-indexed_ characters 14 | as 2 space-separated strings on a single line. 15 | 16 | ### Input Format 17 | 18 | The first line contains an integer, _T_ (the number of test cases). 19 | Each line _i_ of the _T_ subsequent lines contain a String, _S_. 20 | 21 | ### Constraints 22 | 23 | * 1 ≤ _T_ ≤ 10 24 | * 2 ≤ length of _S_ ≤ 10000 25 | 26 | ### Output Format 27 | 28 | For each String _S_\[_j_\], print _S_\[_j_\]'s 29 | _even-indexed_ characters, followed by a space, 30 | followed by _S_\[_j_\]'s _odd-indexed_ characters. 31 | 32 | ### Sample Input 33 | ``` 34 | 2 35 | Hacker 36 | Rank 37 | ``` 38 | ### Sample Output 39 | ``` 40 | Hce akr 41 | Rn ak 42 | ``` 43 | -------------------------------------------------------------------------------- /day-06/solution.py: -------------------------------------------------------------------------------- 1 | num_test_cases = int(input()) 2 | 3 | for i in range(num_test_cases): 4 | test_string = input() 5 | even_indexed_characters = '' 6 | odd_indexed_characters = '' 7 | for j in range(len(test_string)): 8 | if j % 2 == 0: 9 | even_indexed_characters += test_string[j] 10 | else: 11 | odd_indexed_characters += test_string[j] 12 | 13 | print('{} {}'.format(even_indexed_characters, odd_indexed_characters)) 14 | -------------------------------------------------------------------------------- /day-06/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 2 2 | Hacker 3 | Rank -------------------------------------------------------------------------------- /day-06/test-0-output.txt: -------------------------------------------------------------------------------- 1 | Hce akr 2 | Rn ak -------------------------------------------------------------------------------- /day-07/README.md: -------------------------------------------------------------------------------- 1 | ### Objective 2 | 3 | Today, we're learning about the Array data structure. 4 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-arrays/tutorial) tab for learning materials and an instructional video! 5 | 6 | ### Task 7 | 8 | Given an array, `A`, of `N` integers, print `A`'s elements in reverse order as a single line of space-separated numbers. 9 | 10 | ### Input Format 11 | 12 | The first line contains an integer, `N` (the size of our array). 13 | The second line contains `N` space-separated integers describing array `A`'s elements. 14 | 15 | ### Constraints 16 | 17 | * `1 <= N <= 1000` 18 | * `1 <= A[i] <= 10000`, where `A[i]` is the `i`th integer in the array. 19 | 20 | ### Output Format 21 | 22 | Print the elements of array in reverse order as a single line of space-separated numbers. 23 | 24 | ### Sample Input 25 | 26 | ``` 27 | 4 28 | 1 4 3 2 29 | ``` 30 | 31 | ### Sample Output 32 | 33 | ``` 34 | 2 3 4 1 35 | ``` 36 | -------------------------------------------------------------------------------- /day-07/solution.py: -------------------------------------------------------------------------------- 1 | n = int(input().strip()) 2 | arr = [int(arr_temp) for arr_temp in input().strip().split(' ')] 3 | 4 | reversed_array = [] 5 | for i in range(len(arr)): 6 | reversed_array.append(arr[n-i-1]) 7 | 8 | # print(' '.join(str(i) for i in reversed_array)) 9 | 10 | output_string = '' 11 | for i in range(len(reversed_array)): 12 | output_string += str(reversed_array[i]) + ' ' 13 | 14 | print(output_string) 15 | -------------------------------------------------------------------------------- /day-07/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 1 4 3 2 -------------------------------------------------------------------------------- /day-07/test-0-output.txt: -------------------------------------------------------------------------------- 1 | 2 3 4 1 2 | -------------------------------------------------------------------------------- /day-08/README.md: -------------------------------------------------------------------------------- 1 | # Day 8: Dictionaries and Maps 2 | 3 | ### Objective 4 | Today, we're learning about Key-Value pair mappings using a _Map_ or _Dictionary_ data structure. 5 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-dictionaries-and-maps/tutorial) tab for learning materials and an instructional video! 6 | 7 | ### Task 8 | Given _n_ names and phone numbers, assemble a phone book that maps friends' names to their respective phone numbers. 9 | You will then be given an unknown number of names to query your phone book for. 10 | For each _name_ queried, print the associated entry from your phone book on a new line in the form `name=phoneNumber`; 11 | if an entry for _name_ is not found, print `Not found` instead. 12 | 13 | **Note:** Your phone book should be a Dictionary/Map/HashMap data structure. 14 | 15 | ### Input Format 16 | 17 | The first line contains an integer, _n_, denoting the number of entries in the phone book. 18 | 19 | Each of the _n_ subsequent lines describes an entry in the form of 2 space-separated values on a single line. 20 | The first value is a friend's name, and the second value is an 8-digit phone number. 21 | 22 | After the _n_ lines of phone book entries, there are _an unknown number of lines of queries_. 23 | Each line (query) contains a _name_ to look up, and you must continue reading lines until there is no more input. 24 | 25 | **Note:** Names consist of lowercase English alphabetic letters and are first names only. 26 | 27 | ### Constraints 28 | 29 | * `1 ≤ n ≤ 10^5` 30 | * `1 ≤ queries ≤ 10^5` 31 | 32 | ### Output Format 33 | 34 | On a new line for each query, print `Not found` if the name has no corresponding entry in the phone book; 35 | otherwise, print the full _name_ and _phoneNumber_ in the format `name=phoneNumber`. 36 | 37 | ### Sample Input 38 | 39 | ``` 40 | 3 41 | sam 99912222 42 | tom 11122222 43 | harry 12299933 44 | sam 45 | edward 46 | harry 47 | ``` 48 | 49 | ### Sample Output 50 | 51 | ``` 52 | sam=99912222 53 | Not found 54 | harry=12299933 55 | ``` 56 | 57 | ### Explanation 58 | 59 | We add the following _n=3 (Key,Value)_ pairs to our map so it looks like this: 60 | 61 | ``` 62 | phoneBook = {(sam,99912222),(tom,11122222),(harry,12299933)} 63 | ``` 64 | 65 | We then process each query and print `key=value` if the queried _key_ is found in the map; otherwise, we print `Not found`. 66 | 67 | _Query 0_: `sam` 68 | Sam is one of the keys in our dictionary, so we print `sam=99912222`. 69 | 70 | _Query 1_: `edward` 71 | Edward is not one of the keys in our dictionary, so we print `Not found`. 72 | 73 | _Query 2_: `harry` 74 | Harry is one of the keys in our dictionary, so we print `harry=12299933`. -------------------------------------------------------------------------------- /day-08/solution.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | n = int(sys.stdin.readline().strip()) 4 | phoneBook = dict() 5 | 6 | for i in range(0, n): 7 | entry = sys.stdin.readline().strip().split(' ') 8 | phoneBook[entry[0]] = entry[1] 9 | 10 | query = sys.stdin.readline().strip() 11 | while query: 12 | phoneNumber = phoneBook.get(query) 13 | if phoneNumber: 14 | print(query + '=' + phoneNumber) 15 | else: 16 | print('Not found') 17 | query = sys.stdin.readline().strip() 18 | -------------------------------------------------------------------------------- /day-08/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 3 2 | sam 99912222 3 | tom 11122222 4 | harry 12299933 5 | sam 6 | edward 7 | harry -------------------------------------------------------------------------------- /day-08/test-0-output.txt: -------------------------------------------------------------------------------- 1 | sam=99912222 2 | Not found 3 | harry=12299933 4 | -------------------------------------------------------------------------------- /day-09/README.md: -------------------------------------------------------------------------------- 1 | # Day 9: Recursion 2 | 3 | ### Objective 4 | Today, we're learning and practicing an algorithmic concept called _Recursion_. 5 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-recursion/tutorial) tab for learning materials and an instructional video! 6 | 7 | ### Recursive Method for Calculating Factorial 8 | ``` 9 | factorial(N) is 1 if N ≤ 1 10 | factorial(N) is N*factorial(N-1) otherwise 11 | ``` 12 | 13 | ### Task 14 | Write a _factorial_ function that takes a positive integer, 15 | _N_ as a parameter and prints the result of _N!_ (_N_ factorial). 16 | 17 | **Note:** If you fail to use recursion 18 | or fail to name your recursive function _factorial_, you will get a score of 0. 19 | 20 | ### Input Format 21 | A single integer, _N_ (the argument to pass to _factorial_). 22 | 23 | ### Constraints 24 | * `2 ≤ N ≤ 12` 25 | * Your submission must contain a recursive function named _factorial_. 26 | 27 | ### Output Format 28 | Print a single integer denoting _N!_. 29 | 30 | ### Sample Input 31 | ``` 32 | 3 33 | ``` 34 | 35 | ### Sample Output 36 | ``` 37 | 6 38 | ``` 39 | -------------------------------------------------------------------------------- /day-09/solution.py: -------------------------------------------------------------------------------- 1 | def factorial(n): 2 | if n <= 1: 3 | return 1 4 | else: 5 | return n * factorial(n-1) 6 | 7 | if __name__ == "__main__": 8 | n = int(input().strip()) 9 | result = factorial(n) 10 | print(result) 11 | -------------------------------------------------------------------------------- /day-09/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 3 -------------------------------------------------------------------------------- /day-09/test-0-output.txt: -------------------------------------------------------------------------------- 1 | 6 2 | -------------------------------------------------------------------------------- /day-10/README.md: -------------------------------------------------------------------------------- 1 | # Day 10: Binary Numbers 2 | 3 | ### Objective 4 | Today, we're working with binary numbers. 5 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-binary-numbers/tutorial) 6 | tab for learning materials and an instructional video! 7 | 8 | ### Task 9 | Given a base-10 integer, _n_, convert it to binary. 10 | Then find and print the base-10 integer denoting the maximum number of consecutive 1's in _n_'s binary representation. 11 | 12 | ### Input Format 13 | A single integer, _n_. 14 | 15 | ### Constraints 16 | * 1 ≤ _n_ ≤ 10^6 17 | 18 | ### Output Format 19 | Print a single base-10 integer denoting the maximum number of consecutive 1's in the binary representation of _n_. 20 | 21 | ### Sample Input 1 22 | ``` 23 | 5 24 | ``` 25 | ### Sample Output 1 26 | ``` 27 | 1 28 | ``` 29 | ### Sample Input 2 30 | ``` 31 | 13 32 | ``` 33 | ### Sample Output 2 34 | ``` 35 | 2 36 | ``` 37 | ### Explanation 38 | #### Sample Case 1: 39 | The binary representation of 5 is 101, 40 | so the maximum number of consecutive 1's is 1. 41 | #### Sample Case 2: 42 | The binary representation of 13 is 1101, 43 | so the maximum number of consecutive 1's is 2. 44 | -------------------------------------------------------------------------------- /day-10/solution.py: -------------------------------------------------------------------------------- 1 | n = int(input().strip()) 2 | 3 | current_consecutive_1s = 0 4 | max_consecutive_1s = 0 5 | while n > 0: 6 | remainder = n % 2 7 | n = n // 2 8 | if remainder == 1: 9 | current_consecutive_1s += 1 10 | if current_consecutive_1s > max_consecutive_1s: 11 | max_consecutive_1s = current_consecutive_1s 12 | else: 13 | current_consecutive_1s = 0 14 | 15 | print(max_consecutive_1s) 16 | -------------------------------------------------------------------------------- /day-10/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /day-10/test-0-output.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /day-10/test-1-input.txt: -------------------------------------------------------------------------------- 1 | 13 2 | -------------------------------------------------------------------------------- /day-10/test-1-output.txt: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /day-11/README.md: -------------------------------------------------------------------------------- 1 | # Day 11: 2D Arrays 2 | ### Objective 3 | Today, we're building on our knowledge of Arrays by adding another dimension. 4 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-2d-arrays/tutorial) 5 | tab for learning materials and an instructional video! 6 | ### Context 7 | Given a 6x6 _2D Array, A_: 8 | ``` 9 | 1 1 1 0 0 0 10 | 0 1 0 0 0 0 11 | 1 1 1 0 0 0 12 | 0 0 0 0 0 0 13 | 0 0 0 0 0 0 14 | 0 0 0 0 0 0 15 | ``` 16 | We define an hourglass in _A_ to be a subset of values with indices falling in this pattern in A's graphical representation: 17 | ``` 18 | a b c 19 | d 20 | e f g 21 | ``` 22 | There are 16 hourglasses in _A_, 23 | and an _hourglass sum_ is the sum of an hourglass' values. 24 | ### Task 25 | Calculate the hourglass sum for every hourglass in _A_, 26 | then print the maximum hourglass sum. 27 | ### Input Format 28 | There are 6 lines of input, where each line contains 6 space separated integers describing _2D Array *A*_; 29 | every value in _*A*_ will be in the inclusive range of -9 to 9. 30 | ### Constraints 31 | * -9≤A\[i]\[j]≤9 32 | * 0≤i,j≤5 33 | ### Output Format 34 | Print the largest (maximum) hourglass sum found in _*A*_. 35 | ### Sample Input 36 | ``` 37 | 1 1 1 0 0 0 38 | 0 1 0 0 0 0 39 | 1 1 1 0 0 0 40 | 0 0 2 4 4 0 41 | 0 0 0 2 0 0 42 | 0 0 1 2 4 0 43 | ``` 44 | ### Sample Output 45 | ``` 46 | 19 47 | ``` 48 | ### Explanation 49 | _*A*_ contains the following hourglasses: 50 | ``` 51 | 1 1 1 1 1 0 1 0 0 0 0 0 52 | 1 0 0 0 53 | 1 1 1 1 1 0 1 0 0 0 0 0 54 | 55 | 0 1 0 1 0 0 0 0 0 0 0 0 56 | 1 1 0 0 57 | 0 0 2 0 2 4 2 4 4 4 4 0 58 | 59 | 1 1 1 1 1 0 1 0 0 0 0 0 60 | 0 2 4 4 61 | 0 0 0 0 0 2 0 2 0 2 0 0 62 | 63 | 0 0 2 0 2 4 2 4 4 4 4 0 64 | 0 0 2 0 65 | 0 0 1 0 1 2 1 2 4 2 4 0 66 | ``` 67 | The hourglass with the maximum sum (19) is: 68 | ``` 69 | 2 4 4 70 | 2 71 | 1 2 4 72 | ``` 73 | -------------------------------------------------------------------------------- /day-11/solution.py: -------------------------------------------------------------------------------- 1 | grid = list() 2 | 3 | for i in range(6): 4 | row = input().strip().split(' ') 5 | row = list(map(int, row)) 6 | grid.append(row) 7 | 8 | def _get_hourglass_sum(grid, i, j): 9 | sum = 0 10 | sum += grid[i-1][j-1] 11 | sum += grid[i-1][j] 12 | sum += grid[i-1][j+1] 13 | sum += grid[i][j] 14 | sum += grid[i+1][j-1] 15 | sum += grid[i+1][j] 16 | sum += grid[i+1][j+1] 17 | return sum 18 | 19 | # start max_hourglass_sum at smallest possible hourglass 20 | max_hourglass_sum = -63 21 | for i in range(1,5): 22 | for j in range(1, 5): 23 | current_hourglass_sum = _get_hourglass_sum(grid, i, j) 24 | if current_hourglass_sum > max_hourglass_sum: 25 | max_hourglass_sum = current_hourglass_sum 26 | 27 | print(max_hourglass_sum) 28 | -------------------------------------------------------------------------------- /day-11/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 1 1 1 0 0 0 2 | 0 1 0 0 0 0 3 | 1 1 1 0 0 0 4 | 0 0 2 4 4 0 5 | 0 0 0 2 0 0 6 | 0 0 1 2 4 0 7 | -------------------------------------------------------------------------------- /day-11/test-0-output.txt: -------------------------------------------------------------------------------- 1 | 19 2 | -------------------------------------------------------------------------------- /day-11/test-1-input.txt: -------------------------------------------------------------------------------- 1 | 1 1 1 0 0 0 2 | 0 1 0 0 0 0 3 | 1 1 1 0 0 0 4 | 0 0 0 0 0 0 5 | 0 0 0 0 0 0 6 | 0 0 0 0 0 0 7 | -------------------------------------------------------------------------------- /day-11/test-1-output.txt: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /day-11/test-2-input.txt: -------------------------------------------------------------------------------- 1 | -1 -1 -1 -1 -1 -1 2 | -1 -1 -1 -1 -1 -1 3 | -1 -1 -1 -1 -1 -1 4 | -1 -1 -1 -1 -1 -1 5 | -1 -1 -1 -1 -1 -1 6 | -1 -1 -1 -1 -1 -1 7 | -------------------------------------------------------------------------------- /day-11/test-2-output.txt: -------------------------------------------------------------------------------- 1 | -7 2 | -------------------------------------------------------------------------------- /day-12/README.md: -------------------------------------------------------------------------------- 1 | # Day 12: Inheritance 2 | ### Objective 3 | Today, we're delving into inheritance. 4 | Checkout the attached [tutorial](https://www.hackerrank.com/challenges/30-inheritance/topics/java-inheritance) 5 | for learning materials and an instructional video! 6 | ### Task 7 | You are given two classes, _Person_ and _Student_, 8 | where _Person_ is the base class and _Student_ is the derived class. 9 | Completed code for _Person_ and a declaration for _Student_ are provided for you in the editor. 10 | Observe that _Student_ inherits all the properties of _Person. 11 | 12 | Complete the _Student_ class by writing the following: 13 | * A _Student_ class constructor, which has 4 parameters: 14 | 1. A string, _firstName_. 15 | 2. A string, _lastName_. 16 | 3. An integer, _id_. 17 | 4. An integer array (or vector) of test scores, _scores_. 18 | * A _char_calculate()_ method that calculates a Student object's average 19 | and returns the grade character representative of their calculated average: 20 | 21 | **Grading Scale** 22 | 23 | | Letter | Average(a) | 24 | | ------ | ---------- | 25 | | **O** | 90≤_a_≤100 | 26 | | **E** | 80≤_a_<90 | 27 | | **A** | 70≤_a_<80 | 28 | | **P** | 55≤_a_<70 | 29 | | **D** | 40≤_a_<55 | 30 | | **T** | _a_<40 | 31 | 32 | ### Input Format 33 | Read the following input from stdin: 34 | The first line contains _firstName_, _lastName_, and _id_, respectively. 35 | The second line contains the number of test scores. 36 | The third line of space-separated integers describes _scores_. 37 | ### Constraints 38 | * 1≤|_firstName_|,|_lastName_|≤10 39 | * |_id_|===7 40 | * 0≤_score_,_average_≤100 41 | ### Sample Input 42 | ``` 43 | Heraldo Memelli 8135627 44 | 2 45 | 100 80 46 | ``` 47 | ### Sample Output 48 | ``` 49 | Name: Memelli, Heraldo 50 | ID: 8135627 51 | Grade: O 52 | ``` 53 | -------------------------------------------------------------------------------- /day-12/solution.py: -------------------------------------------------------------------------------- 1 | class Person: 2 | def __init__(self, firstName, lastName, idNumber): 3 | self.firstName = firstName 4 | self.lastName = lastName 5 | self.idNumber = idNumber 6 | 7 | def printPerson(self): 8 | print("Name:", self.lastName + ",", self.firstName) 9 | print("ID:", self.idNumber) 10 | 11 | 12 | class Student(Person): 13 | # Class Constructor 14 | # 15 | # Parameters: 16 | # firstName - A string denoting the Person's first name. 17 | # lastName - A string denoting the Person's last name. 18 | # id - An integer denoting the Person's ID number. 19 | # scores - An array of integers denoting the Person's test scores. 20 | def __init__(self, firstName, lastName, idNumber, scores): 21 | Person.__init__(self, firstName, lastName, idNumber) 22 | self.scores = scores 23 | 24 | # Function Name: calculate 25 | # Return: A character denoting the grade. 26 | def calculate(self): 27 | sum=0 28 | for score in scores: 29 | sum += score 30 | average = sum/len(scores) 31 | if average < 40: 32 | return 'T' 33 | elif average < 55: 34 | return 'D' 35 | elif average < 70: 36 | return 'P' 37 | elif average < 80: 38 | return 'A' 39 | elif average < 90: 40 | return 'E' 41 | else: 42 | return 'O' 43 | 44 | line = input().split() 45 | firstName = line[0] 46 | lastName = line[1] 47 | idNum = line[2] 48 | numScores = int(input()) # not needed for Python 49 | scores = list(map(int, input().split())) 50 | s = Student(firstName, lastName, idNum, scores) 51 | s.printPerson() 52 | print("Grade:", s.calculate()) -------------------------------------------------------------------------------- /day-12/test-0-input.txt: -------------------------------------------------------------------------------- 1 | Heraldo Memelli 8135627 2 | 2 3 | 100 80 4 | -------------------------------------------------------------------------------- /day-12/test-0-output.txt: -------------------------------------------------------------------------------- 1 | Name: Memelli, Heraldo 2 | ID: 8135627 3 | Grade: O 4 | -------------------------------------------------------------------------------- /day-13/README.md: -------------------------------------------------------------------------------- 1 | # Day 13: Abstract Class 2 | ### Objective 3 | Today, we're taking what we learned yesterday about _Inheritance_ and extending it to _Abstract Classes_. 4 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-abstract-classes/tutorial) 5 | tab for learning materials and an instructional video. 6 | ### Task 7 | Given a _Book_ class and a _Solution_ class, write a _MyBook_ class that does the following: 8 | * Inherits from a _Book_ 9 | * Has a parameterized constructor taking these 3 parameters: 10 | 1. string _title_ 11 | 2. string _author_ 12 | 3. int _price_ 13 | * Implements the _Book_ class' abstract _display()_ method so it prints these 3 lines: 14 | 1. `Title:`, a space, and then the current instance's _title_. 15 | 2. `Author:`, a space, and then the current instance's _author_. 16 | 3. `Price:`, a space, and then the current instance's _price_. 17 | 18 | ### Input Format 19 | The _Solution_ class creates a _Book_ object and calls the _MyBook_ class constructor. 20 | It then calls the _display_ method on the _Book_ object. 21 | ### Output Format 22 | The _display()_ method should print and label the respective _title_, _author_, and _price_ of the _MyBook_ object's instance like so: 23 | ``` 24 | Title: $title 25 | Author: $author 26 | Price: $price 27 | ``` 28 | ### Sample Input 29 | ``` 30 | The Alchemist 31 | Paulo Coelho 32 | 248 33 | ``` 34 | ### Sample Output 35 | ``` 36 | Title: The Alchemist 37 | Author: Paulo Coelho 38 | Price: 248 39 | ``` 40 | -------------------------------------------------------------------------------- /day-13/solution.py: -------------------------------------------------------------------------------- 1 | from abc import ABCMeta, abstractmethod 2 | class Book(object, metaclass = ABCMeta): 3 | def __init__(self, title, author): 4 | self.title = title 5 | self.author = author 6 | @abstractmethod 7 | def display(): pass 8 | 9 | 10 | class MyBook(Book): 11 | def __init__(self, title, author, price): 12 | Book.__init__(self, title, author) 13 | self.price = price 14 | 15 | def display(self): 16 | print('Title: ' + self.title) 17 | print('Author: ' + self.author) 18 | print('Price: ' + str(self.price)) 19 | 20 | 21 | title=input() 22 | author=input() 23 | price=int(input()) 24 | new_novel=MyBook(title,author,price) 25 | new_novel.display() -------------------------------------------------------------------------------- /day-13/test-0-input.txt: -------------------------------------------------------------------------------- 1 | The Alchemist 2 | Paulo Coelho 3 | 248 4 | -------------------------------------------------------------------------------- /day-13/test-0-output.txt: -------------------------------------------------------------------------------- 1 | Title: The Alchemist 2 | Author: Paulo Coelho 3 | Price: 248 4 | -------------------------------------------------------------------------------- /day-14/README.md: -------------------------------------------------------------------------------- 1 | # Day 14: Scope 2 | 3 | ### Objective 4 | 5 | Today we're discussing _scope_. Check out the [Tutorial](https://www.hackerrank.com/challenges/30-scope/tutorial) 6 | tab for learning materials and an instructional video! 7 | 8 | The _absolute difference_ between two integers, _a_ and _b_, is written as |_a - b_|. 9 | The _maximum absolute difference_ between two integers in a set of positive integers, _elements_, 10 | is the largest absolute difference between any two integers in _elements_. 11 | 12 | The _Difference_ class is started for you in the editor. 13 | It has a private integer array (_elements_) for storing _N_ non-negative integers, 14 | and a public integer (_maximumDifference_) for storing the maximum absolute difference. 15 | 16 | ### Task complete teh _Difference_ class by writing the following: 17 | 18 | * A class constructor that takes an array of integers as a parameter 19 | and saves it tot he _elements_ instance variable. 20 | * A _computeDifference_ method that finds the maximum absolute difference between any 2 numbers in _N_ 21 | and stores it in the _maximumDifference_ instance variable. 22 | 23 | ### Input Format 24 | 25 | The _Solution_ class read in 2 lines of input; 26 | the first line contains _N_, 27 | and the second line describes the _elements_ array. 28 | 29 | ### Constraints 30 | 31 | * 1 ≤ _N_ ≤ 10 32 | * 1 ≤ _elements_\[_i_\]_ ≤ 100, where 0 ≤ _i_ ≤ _N_ - 1 33 | 34 | ### Output Format 35 | 36 | The _Solution_ class will print he value of the _maximumDifference_ instance variable. 37 | 38 | ### Sample Input 39 | ``` 40 | 3 41 | 1 2 5 42 | ``` 43 | ### Sample Output 44 | ``` 45 | 4 46 | ``` 47 | -------------------------------------------------------------------------------- /day-14/solution.py: -------------------------------------------------------------------------------- 1 | class Difference: 2 | def __init__(self, a): 3 | self.__elements = a 4 | self.maximumDifference = 0 5 | 6 | def computeDifference(self): 7 | min_element = 101 8 | max_element = 0 9 | for element in self.__elements: 10 | if element < min_element: 11 | min_element = element 12 | if element > max_element: 13 | max_element = element 14 | 15 | self.maximumDifference = max_element - min_element 16 | 17 | 18 | _ = input() 19 | a = [int(e) for e in input().split(' ')] 20 | 21 | d = Difference(a) 22 | d.computeDifference() 23 | 24 | print(d.maximumDifference) -------------------------------------------------------------------------------- /day-14/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 3 2 | 1 2 5 3 | -------------------------------------------------------------------------------- /day-14/test-0-output.txt: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /day-14/test-1-input.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 8 19 3 2 7 3 | -------------------------------------------------------------------------------- /day-14/test-1-output.txt: -------------------------------------------------------------------------------- 1 | 17 2 | -------------------------------------------------------------------------------- /day-14/test-2-input.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 8 8 8 8 8 3 | -------------------------------------------------------------------------------- /day-14/test-2-output.txt: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /day-15/REAMDME.md: -------------------------------------------------------------------------------- 1 | # Day 15: Linked List 2 | 3 | ### Objective 4 | 5 | Today we're working with _Linked Lists_. 6 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-linked-list/tutorial) 7 | tab for learning materials and an instructional video! 8 | 9 | A _Node_ class is provided for you in the editor. 10 | A _Node_ obect has an integer data field, _data_, and a _Node_ instance pointer, _next_, pointing to another node. 11 | 12 | A _Node_ _insert_ function is also declared in your editor. 13 | It has two parameters: a pointer, _head_, pointing to the first node of a linked list, 14 | and an integer _data_ value that must be added to the end of the list as a new _Node_ object. 15 | 16 | Complete the _insert_ function in your editor so that it creates a new _Node_ 17 | (pass _data_ as the _Node_ constructor argument) 18 | and inserts it at the tail of the linked list reference by the _head_ parameters. 19 | Once the new node is added, return the reference to the _head_ node. 20 | 21 | **Note:** If the _head_ argument passed to the _insert_ function is _null_, 22 | then the initial list is empty. 23 | 24 | ### Input Format 25 | 26 | The _insert_ function has 2 parameters: a pointer to a _Node_ hamed _head, 27 | and an integer value, _data_. 28 | The constructor for _node_ has 1 parameter: an integer value for the _data_ field. 29 | 30 | ### Output Format 31 | 32 | Your _insert_ function should return a reference to the _head_ node of the linked list. 33 | 34 | ### Sample Input 35 | 36 | The first line contains _T_, the number of test cases. 37 | The _T_ subsequent lines of test cases each contain an integer to be inserted at the list's tail. 38 | 39 | ``` 40 | 4 41 | 2 42 | 3 43 | 4 44 | 1 45 | ``` 46 | 47 | ### Sample Output 48 | 49 | Print the ordered data values for each element in your list as a single line of space separated integers: 50 | 51 | ``` 52 | 2 3 4 1 53 | ``` 54 | -------------------------------------------------------------------------------- /day-15/solution.py: -------------------------------------------------------------------------------- 1 | class Node: 2 | def __init__(self,data): 3 | self.data = data 4 | self.next = None 5 | 6 | 7 | class Solution: 8 | def display(self,head): 9 | current = head 10 | while current: 11 | print(current.data,end=' ') 12 | current = current.next 13 | 14 | def insert(self, head, data): 15 | newNode = Node(data) 16 | if not head: 17 | return newNode 18 | current = head 19 | while current.next: 20 | current = current.next 21 | current.next = newNode 22 | return head 23 | 24 | 25 | mylist = Solution() 26 | T = int(input()) 27 | head = None 28 | for i in range(T): 29 | data = int(input()) 30 | head = mylist.insert(head, data) 31 | mylist.display(head) 32 | -------------------------------------------------------------------------------- /day-15/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 2 3 | 3 4 | 4 5 | 1 6 | -------------------------------------------------------------------------------- /day-15/test-0-output.txt: -------------------------------------------------------------------------------- 1 | 2 3 4 1 2 | -------------------------------------------------------------------------------- /day-16/README.md: -------------------------------------------------------------------------------- 1 | # Day 16: Exceptions - String to Integer 2 | 3 | ### Objective 4 | 5 | Today, we're getting started with _Exceptions_ by learning how to parse an integer from a string 6 | and print a custom error message. 7 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-exceptions-string-to-integer/tutorial) 8 | tab for learning materials and an instructional video! 9 | 10 | ### Task 11 | Read a string, _S_, and print its integer value; 12 | if _S_ cannot be converted to an integer, print `Bad String`. 13 | 14 | **Note:** You _must_ use the String-to_integer and exception handling constructs built into your submission language. 15 | 16 | ### Input Format 17 | 18 | A single string, _S_. 19 | 20 | ### Constraints 21 | 22 | * 1 ≤ |_S_| ≤ 6, where |_S_| is the length of string _S_. 23 | * _S_ is composed of either lower case letters (a-z) or decimal digits (0-9). 24 | 25 | ### Output Format 26 | 27 | Print the parsed integer value of _S_, or `Bad String` if _S_ cannot be converted to an integer. 28 | 29 | ### Sample Input 0 30 | ``` 31 | 3 32 | ``` 33 | ### Sample Output 0 34 | ``` 35 | 3 36 | ``` 37 | ### Sample Input 1 38 | ``` 39 | za 40 | ``` 41 | ### Sample Output 1 42 | ``` 43 | Bad String 44 | ``` 45 | -------------------------------------------------------------------------------- /day-16/solution.py: -------------------------------------------------------------------------------- 1 | S = input().strip() 2 | 3 | try: 4 | integer_value = int(S) 5 | print(integer_value) 6 | except ValueError: 7 | print('Bad String') 8 | -------------------------------------------------------------------------------- /day-16/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 3 -------------------------------------------------------------------------------- /day-16/test-0-output.txt: -------------------------------------------------------------------------------- 1 | 3 -------------------------------------------------------------------------------- /day-16/test-1-input.txt: -------------------------------------------------------------------------------- 1 | za -------------------------------------------------------------------------------- /day-16/test-1-output.txt: -------------------------------------------------------------------------------- 1 | Bad String 2 | -------------------------------------------------------------------------------- /day-16/test-2-input.txt: -------------------------------------------------------------------------------- 1 | 3134 -------------------------------------------------------------------------------- /day-16/test-2-output.txt: -------------------------------------------------------------------------------- 1 | 3134 -------------------------------------------------------------------------------- /day-16/test-3-input.txt: -------------------------------------------------------------------------------- 1 | abc -------------------------------------------------------------------------------- /day-16/test-3-output.txt: -------------------------------------------------------------------------------- 1 | Bad String -------------------------------------------------------------------------------- /day-17/README.md: -------------------------------------------------------------------------------- 1 | # Day 17: More Exceptions 2 | 3 | ### Objective 4 | 5 | Yesterday's challenge taught you to manage exceptional situtations by using _try_ and _catch_ blocks. 6 | In today's challenge, you're going to practice throwing and propogating an exception. 7 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-more-exceptions/tutorial) 8 | tab for learning materials and an instructional video! 9 | 10 | ### Task 11 | 12 | Write a _Calculator_ class with a single method: _int power(int, int)_. 13 | The _power_ method takes two integers, _n_ and _p_, as parameters and returns the integer result of _n^p_. 14 | If either _n_ or _p_ is negative, 15 | then the method must throw an exception must throw an exception with the message: 16 | `n and p should be non-negative`. 17 | 18 | ### Input Format 19 | 20 | The first line contains an integer, _T_, the number of test cases. 21 | Each of the _T_ subsequent lines describes a test case in 2 space-separated integers denoting _n_ and _p_ respectively. 22 | 23 | ### Constraints 24 | 25 | * No test case will result in overflow for correctly written code. 26 | 27 | ### Output Format 28 | 29 | There are _T_ lines of output, 30 | where each line contains the result of _n^p_ as calculated by your _Calculator_ class' _power_ method. 31 | 32 | ### Sample Input 33 | ``` 34 | 4 35 | 3 5 36 | 2 4 37 | -1 -2 38 | -1 3 39 | ``` 40 | ### Sample Output 41 | ``` 42 | 243 43 | 16 44 | n and p should be non-negative 45 | n and p should be non-negative 46 | ``` -------------------------------------------------------------------------------- /day-17/solution.py: -------------------------------------------------------------------------------- 1 | class Calculator: 2 | def power(self, n, p): 3 | if n < 0 or p < 0 : 4 | raise Exception("n and p should be non-negative") 5 | else: 6 | return pow(n, p) 7 | 8 | 9 | myCalculator=Calculator() 10 | T=int(input()) 11 | for i in range(T): 12 | n,p = map(int, input().split()) 13 | try: 14 | ans=myCalculator.power(n,p) 15 | print(ans) 16 | except Exception as e: 17 | print(e) -------------------------------------------------------------------------------- /day-17/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 3 5 3 | 2 4 4 | -1 -2 5 | -1 3 -------------------------------------------------------------------------------- /day-17/test-0-output.txt: -------------------------------------------------------------------------------- 1 | 243 2 | 16 3 | n and p should be non-negative 4 | n and p should be non-negative -------------------------------------------------------------------------------- /day-18/README.md: -------------------------------------------------------------------------------- 1 | # Day 18: Queues and Stacks 2 | 3 | Welcome to day 18! Today we're learning about Stacks and Queues. 4 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-queues-stacks/tutorial) 5 | tab for learning materials and an instructional video! 6 | 7 | A _palindrome_ is a word, phrase, number, or other sequence of characters which reads the same backwards and forwards. 8 | Can you determine if a given string, _s_, is a palindrome? 9 | 10 | To solve this challenge, we must first take each character _s_, enqueue it in a queue, 11 | and also push that same character onto a stack. 12 | Once that's done, we must dequeue the first character from the queue and pop the top character off the stack, 13 | then compare the two characters to see if they are the same; 14 | as long as the characters match, 15 | we continue dequeueing, popping, and comparing each character until our containers are empty. 16 | 17 | Write the following declarations and implmentations: 18 | 19 | 1. Two instance variables: one for your _stack_ and one for your _queue_. 20 | 2. A _void pushCharacter(char ch)_ method that pushes a character onto a stack. 21 | 3. A _void enqueueCharacter(char ch)_ method that enqueues a character int he _queue_ instance variable. 22 | 4. A _char popCharacter()_ method that pops and returns the character at the top of the _stack_ instance variable. 23 | 5. A _char dequeueCharacter()_ method that dqueues and returns the first character in the _queue_ instance variable. 24 | 25 | ### Input Format 26 | 27 | Read a single line containing string _s_. 28 | Then call the methods specified above to pass each character to your instance variables. 29 | 30 | ### Constraints 31 | 32 | * _s_ is composed of lowercase English letters. 33 | 34 | ### Output Format 35 | 36 | If your code is correctly written and _s_ is a palindrome, 37 | print `The word, s, is a palindrome.`; 38 | otherwise, print `The word, s, is not a palindrome`. 39 | 40 | ### Sample Input 41 | ``` 42 | racecar 43 | ``` 44 | ### Sample Output 45 | ``` 46 | The word, racecar, is a palindrome. 47 | ``` 48 | -------------------------------------------------------------------------------- /day-18/solution.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | 3 | 4 | class Solution: 5 | def __init__(self): 6 | self.queue = deque() 7 | self.stack = list() 8 | 9 | def pushCharacter(self, character): 10 | self.stack.append(character) 11 | 12 | def enqueueCharacter(self, character): 13 | self.queue.append(character) 14 | 15 | def popCharacter(self): 16 | return self.stack.pop() 17 | 18 | def dequeueCharacter(self): 19 | return self.queue.popleft() 20 | 21 | 22 | # read the string s 23 | s = input() 24 | # Create the Solution class object 25 | obj = Solution() 26 | 27 | l = len(s) 28 | # push/enqueue all the characters of string s to stack 29 | for i in range(l): 30 | obj.pushCharacter(s[i]) 31 | obj.enqueueCharacter(s[i]) 32 | 33 | isPalindrome = True 34 | ''' 35 | pop the top character from stack 36 | dequeue the first character from queue 37 | compare both the characters 38 | ''' 39 | for i in range(l // 2): 40 | if obj.popCharacter() != obj.dequeueCharacter(): 41 | isPalindrome = False 42 | break 43 | # finally print whether string s is palindrome or not. 44 | if isPalindrome: 45 | print("The word, " + s + ", is a palindrome.") 46 | else: 47 | print("The word, " + s + ", is not a palindrome.") -------------------------------------------------------------------------------- /day-18/test-0-input.txt: -------------------------------------------------------------------------------- 1 | racecar -------------------------------------------------------------------------------- /day-18/test-0-output.txt: -------------------------------------------------------------------------------- 1 | The word, racecar, is a palindrome. 2 | -------------------------------------------------------------------------------- /day-18/test-1-input.txt: -------------------------------------------------------------------------------- 1 | yes -------------------------------------------------------------------------------- /day-18/test-1-output.txt: -------------------------------------------------------------------------------- 1 | The word, yes, is not a palindrome. 2 | -------------------------------------------------------------------------------- /day-19/README.md: -------------------------------------------------------------------------------- 1 | # Day 19: Interfaces 2 | 3 | ### Objective 4 | 5 | Today, we're learning about Interfaces. 6 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-interfaces/tutorial) 7 | tab for learning materials and an instructional video! 8 | 9 | ### Task 10 | 11 | The _AdvancedArithmetic_ interface and the method declaration for the abstract _int divisorSum(int n) method are provided for you. 12 | Write the _Calculator_ class, which implements the _AdvancedArithmetic_ interface. 13 | The implementation for the _divisorSum_ method must be _public_ 14 | and take an integer parameter, _n_, and return the sum of all its divisors. 15 | 16 | ### Input Format 17 | 18 | A single line containing an integer _n_. 19 | 20 | ### Constraints 21 | 22 | * 1 ≤ _n_ ≤ 1000 23 | 24 | ### Sample Input 25 | ``` 26 | 6 27 | ``` 28 | ### Sample Output 29 | ``` 30 | I implmented: AdvancedArithmetic 31 | 12 32 | ``` 33 | -------------------------------------------------------------------------------- /day-19/solution.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | interface AdvancedArithmetic { 5 | int divisorSum(int n); 6 | } 7 | 8 | class Calculator implements AdvancedArithmetic { 9 | public int divisorSum(int n) { 10 | int sum = 0; 11 | for (int i = 1; i <= n; i++) { 12 | if (n%i == 0) { 13 | sum += i; 14 | } 15 | } 16 | return sum; 17 | } 18 | } 19 | 20 | class Solution { 21 | 22 | public static void main(String[] args) { 23 | Scanner scan = new Scanner(System.in ); 24 | int n = scan.nextInt(); 25 | scan.close(); 26 | 27 | AdvancedArithmetic myCalculator = new Calculator(); 28 | int sum = myCalculator.divisorSum(n); 29 | System.out.println("I implemented: " + myCalculator.getClass().getInterfaces()[0].getName() ); 30 | System.out.println(sum); 31 | } 32 | } -------------------------------------------------------------------------------- /day-19/solution.py: -------------------------------------------------------------------------------- 1 | class AdvancedArithmetic(object): 2 | def divisorSum(n): 3 | raise NotImplementedError 4 | 5 | 6 | class Calculator(AdvancedArithmetic): 7 | def divisorSum(n): 8 | divisor_sum = 0 9 | for i in range(1, n+1): 10 | if n%i == 0: 11 | divisor_sum += i 12 | return divisor_sum 13 | 14 | 15 | n = int(input()) 16 | my_calculator = Calculator() 17 | s = my_calculator.divisorSum(n) 18 | print("I implemented: " + type(my_calculator).__bases__[0].__name__) 19 | print(s) -------------------------------------------------------------------------------- /day-19/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 6 -------------------------------------------------------------------------------- /day-19/test-0-output.txt: -------------------------------------------------------------------------------- 1 | I implemented: AdvancedArithmetic 2 | 12 3 | -------------------------------------------------------------------------------- /day-19/test-1-input.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /day-19/test-1-output.txt: -------------------------------------------------------------------------------- 1 | I implemented: AdvancedArithmetic 2 | 1 3 | -------------------------------------------------------------------------------- /day-19/test-2-input.txt: -------------------------------------------------------------------------------- 1 | 20 -------------------------------------------------------------------------------- /day-19/test-2-output.txt: -------------------------------------------------------------------------------- 1 | I implemented: AdvancedArithmetic 2 | 42 3 | -------------------------------------------------------------------------------- /day-20/README.md: -------------------------------------------------------------------------------- 1 | # Day 20: Sorting 2 | 3 | ### Objective 4 | 5 | Today, we're discussing a simple sorting algorithm called _Bubble Sort_. 6 | Checkout the [Tutorial](https://www.hackerrank.com/challenges/30-sorting/topics) 7 | tab for learning materials and an instructional video! 8 | 9 | Consider the following version of Bubble Sort: 10 | ```java 11 | for (int i = 0; i < n; i++) { 12 | // Track number of elements swapped during a single array traversal 13 | int numberOfSwaps = 0; 14 | 15 | for (int j = 0; j < n - 1; j++) { 16 | // Swap adjacent elements if they are in decreasing order 17 | if (a[j] > a[j + 1]) { 18 | swap(a[j], a[j + 1]); 19 | numberOfSwaps++; 20 | } 21 | } 22 | 23 | // If no elements were swapped during a traversal, array is sorted 24 | if (numberOfSwaps == 0) { 25 | break; 26 | } 27 | } 28 | ``` 29 | ### Task 30 | 31 | Given an array, _a_, of size _n_ distinct elements, 32 | sort the array in _ascending_ order using the _Bubble Sort_ algorithm above. 33 | Once sorted, print the following 3 lines: 34 | 35 | 1. `Array is sorted in numSwaps swaps.` 36 | where _numSwaps_ is the number of swaps that took place. 37 | 2. `First Element: firstElement` 38 | where _firstElement_ is the _first_ element in the sorted array. 39 | 3. `Last Element: lastElement` 40 | where _lastElement_ is the _last_ element in the sorted array. 41 | 42 | **Hint:** To complete this challenge, you will need to add a variable that keeps a running tally of _all_ swaps that occur during execution. 43 | 44 | ### Input Format 45 | 46 | The first line contains an integer, _n_, denoting the number of elements in array _a_. 47 | The second line contains _n_ space-separated integers describing the respective values of elements of _a_. 48 | 49 | ### Constraints 50 | 51 | * 2 ≤ _n_ ≤ 600 52 | * 1 ≤ _a_\[_i_\] ≤ 1,000,000, where 0 ≤ _i_ ≤ _n_ 53 | 54 | ### Output Format 55 | 56 | Print the following 3 lines of output: 57 | 58 | 1. `Array is sorted in numSwaps swaps.` 59 | where _numSwaps_ is the number of swaps that took place. 60 | 2. `First Element: firstElement` 61 | where _firstElement_ is the _first_ element in the sorted array. 62 | 3. `Last Element: lastElement` 63 | where _lastElement_ is the _last_ element in the sorted array. 64 | 65 | ### Sample Input 0 66 | ``` 67 | 3 68 | 1 2 3 69 | ``` 70 | ### Sample Output 0 71 | ``` 72 | Array is sorted in 0 swaps. 73 | First Element: 1 74 | Last Element: 3 75 | ``` 76 | ### Sample Input 1 77 | ``` 78 | 3 79 | 3 2 1 80 | ``` 81 | ### Sample Output 1 82 | ``` 83 | Array is sorted in 3 swaps. 84 | First Element: 1 85 | Last Element: 3 86 | ``` -------------------------------------------------------------------------------- /day-20/solution.py: -------------------------------------------------------------------------------- 1 | n = int(input().strip()) 2 | a = list(map(int, input().strip().split(' '))) 3 | 4 | numSwaps = 0 5 | for i in range(n): 6 | currentSwaps = 0 7 | for j in range(n-1): 8 | if a[j] > a[j+1]: 9 | tmp = a[j] 10 | a[j] = a[j+1] 11 | a[j+1] = tmp 12 | numSwaps += 1 13 | currentSwaps += 1 14 | 15 | if currentSwaps == 0: 16 | break 17 | 18 | print('Array is sorted in ' + str(numSwaps) + ' swaps.') 19 | print('First Element: ' + str(a[0])) 20 | print('Last Element: ' + str(a[n-1])) 21 | -------------------------------------------------------------------------------- /day-20/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 3 2 | 1 2 3 -------------------------------------------------------------------------------- /day-20/test-0-output.txt: -------------------------------------------------------------------------------- 1 | Array is sorted in 0 swaps. 2 | First Element: 1 3 | Last Element: 3 4 | -------------------------------------------------------------------------------- /day-20/test-1-input.txt: -------------------------------------------------------------------------------- 1 | 3 2 | 3 2 1 -------------------------------------------------------------------------------- /day-20/test-1-output.txt: -------------------------------------------------------------------------------- 1 | Array is sorted in 3 swaps. 2 | First Element: 1 3 | Last Element: 3 4 | -------------------------------------------------------------------------------- /day-21/README.md: -------------------------------------------------------------------------------- 1 | # Day 21: Generics 2 | 3 | ### Objective 4 | 5 | Today we're discussing Generics; be aware that not all languages support this construct. 6 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-generics/tutorial) 7 | tab for learning materials and an instructional video! 8 | 9 | ### Task 10 | 11 | Write a single generic function named _printArray_; 12 | this function must take an array of generic elements as a parameter. 13 | The locked Solution class in your editor tests your function. 14 | 15 | ### Input Format 16 | 17 | The _Solution_ class will pass different types of arrays to your _printArray_ function. 18 | 19 | ### Constraints 20 | 21 | * You must have exactly 1 function named _printArray_. 22 | 23 | ### OutputFormat 24 | 25 | Your _printArray_ ffunctionshould print each element of its generic array parameter on a new line. 26 | 27 | -------------------------------------------------------------------------------- /day-21/Solution.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Printer { 4 | public void printArray(T[] elements) { 5 | for (T element : elements) { 6 | System.out.println(element); 7 | } 8 | } 9 | } 10 | 11 | public class Solution { 12 | 13 | public static void main(String args[]){ 14 | Scanner scanner = new Scanner(System.in); 15 | int n = scanner.nextInt(); 16 | Integer[] intArray = new Integer[n]; 17 | for (int i = 0; i < n; i++) { 18 | intArray[i] = scanner.nextInt(); 19 | } 20 | 21 | n = scanner.nextInt(); 22 | String[] stringArray = new String[n]; 23 | for (int i = 0; i < n; i++) { 24 | stringArray[i] = scanner.next(); 25 | } 26 | 27 | Printer intPrinter = new Printer(); 28 | Printer stringPrinter = new Printer(); 29 | intPrinter.printArray( intArray ); 30 | stringPrinter.printArray( stringArray ); 31 | if(Printer.class.getDeclaredMethods().length > 1){ 32 | System.out.println("The Printer class should only have 1 method named printArray."); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /day-21/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 3 2 | 1 3 | 2 4 | 3 5 | 2 6 | Hello 7 | World -------------------------------------------------------------------------------- /day-21/test-0-output.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | Hello 5 | World -------------------------------------------------------------------------------- /day-22/README.md: -------------------------------------------------------------------------------- 1 | # Day 22: Binary Search Trees 2 | 3 | ### Objective 4 | 5 | Today, we're working with Binary Search Trees (BSTs). 6 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-binary-search-trees/tutorial) 7 | tab for learning materials and an instructional video! 8 | 9 | ### Task 10 | 11 | The height of a binary search tree is the number of edges between the tree's root and its furthest leaf. 12 | You are given a pointer, _root_, pointing to the root of a binary search tree. 13 | Complete the _getHeight_ function so that it returns the height of the binary search tree. 14 | 15 | ### Input Format 16 | 17 | Read the inputs and assemble them into a binary search tree: 18 | The first line contains an integer, _n_, denoting the number of nodes in the tree. 19 | Each of the _n_ subsequent lines contains an integer, _data_, 20 | denoting the value of an element that must be added to the BST. 21 | 22 | ### Output Format 23 | 24 | The locked stub code in your editor will print the integer returned by your _getHeight_ function denoting the height of the BST. 25 | 26 | ### Sample Input 27 | ``` 28 | 7 29 | 3 30 | 5 31 | 2 32 | 1 33 | 4 34 | 6 35 | 7 36 | ``` 37 | ### Sample Output 38 | ``` 39 | 3 40 | ``` -------------------------------------------------------------------------------- /day-22/solution.py: -------------------------------------------------------------------------------- 1 | class Node: 2 | def __init__(self,data): 3 | self.right=self.left=None 4 | self.data = data 5 | 6 | 7 | class Solution: 8 | def insert(self,root,data): 9 | if root==None: 10 | return Node(data) 11 | else: 12 | if data<=root.data: 13 | cur=self.insert(root.left,data) 14 | root.left=cur 15 | else: 16 | cur=self.insert(root.right,data) 17 | root.right=cur 18 | return root 19 | 20 | def getHeight(self, root): 21 | if not root: 22 | return -1 23 | elif not root.left and not root.right: 24 | return 0 25 | left_height = self.getHeight(root.left) 26 | right_height = self.getHeight(root.right) 27 | return max(left_height, right_height) + 1 28 | 29 | 30 | T = int(input()) 31 | myTree = Solution() 32 | root = None 33 | for i in range(T): 34 | data = int(input()) 35 | root = myTree.insert(root, data) 36 | height = myTree.getHeight(root) 37 | print(height) 38 | -------------------------------------------------------------------------------- /day-22/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 3 3 | 5 4 | 2 5 | 1 6 | 4 7 | 6 8 | 7 -------------------------------------------------------------------------------- /day-22/test-0-output.txt: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /day-23/README.md: -------------------------------------------------------------------------------- 1 | # Day 23: BST Level-Order Traversal 2 | 3 | ### Objective 4 | 5 | Today, we're going further with Binary Search Trees. 6 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-binary-trees/tutorial) 7 | tab for learning materials and an instructional video! 8 | 9 | ### Task 10 | 11 | A level-order traversal, also known as a breadth-first search, 12 | visits each level of a tree's nodes from left to right, top to bottom. 13 | You are given a pointer, _root_, pointing to the root of a binary search tree. 14 | Complete the _levelOrder_ function so that it prints the level-order traversal of the binary search tree. 15 | 16 | ### Input Format 17 | 18 | Assemble the input into a BST: 19 | The first line contains an integer, _T_ (the number of test cases). 20 | The _T_ subsequent lines each contain an integer, _data_, denoting the value of an element that must be added to the BST. 21 | 22 | ### Output Format 23 | 24 | Print the _data_ value of each node in the tree's level-order traversal 25 | as a single line of _N_ space-separated integers. 26 | -------------------------------------------------------------------------------- /day-23/solution.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | class Node: 4 | def __init__(self, data): 5 | self.right=self.left=None 6 | self.data = data 7 | 8 | class Solution: 9 | def insert(self, root, data): 10 | if root == None: 11 | return Node(data) 12 | else: 13 | if data<=root.data: 14 | cur=self.insert(root.left,data) 15 | root.left=cur 16 | else: 17 | cur=self.insert(root.right,data) 18 | root.right=cur 19 | return root 20 | 21 | def levelOrder(self, root): 22 | # Write your code here 23 | nodes_to_search = list() 24 | nodes_to_search.append(root) 25 | nodes_searched = '' 26 | while len(nodes_to_search) > 0: 27 | node = nodes_to_search.pop(0) 28 | if node.left: 29 | nodes_to_search.append(node.left) 30 | if node.right: 31 | nodes_to_search.append(node.right) 32 | nodes_searched += str(node.data) + ' ' 33 | print(nodes_searched) 34 | 35 | 36 | 37 | T = int(input()) 38 | myTree = Solution() 39 | root = None 40 | for i in range(T): 41 | data = int(input()) 42 | root = myTree.insert(root, data) 43 | myTree.levelOrder(root) -------------------------------------------------------------------------------- /day-23/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 3 3 | 5 4 | 4 5 | 7 6 | 2 7 | 1 -------------------------------------------------------------------------------- /day-23/test-0-output.txt: -------------------------------------------------------------------------------- 1 | 3 2 5 1 4 7 2 | -------------------------------------------------------------------------------- /day-24/README.md: -------------------------------------------------------------------------------- 1 | # Day 24: More Linked Lists 2 | 3 | ### Objective 4 | 5 | Check out the [Tutorial](https://www.hackerrank.com/challenges/30-linked-list-deletion/tutorial) 6 | tab for learning materials and an instructional video! 7 | 8 | ### Task 9 | 10 | A _Node_ class is provided for you in the editor. 11 | A _Node_ object has an integer data field, _data_, and a Node instance pointer, _next_, pointing to another node. 12 | 13 | A _removeDuplicates_ function is declared in your editor, 14 | which takes a pointer to the _head_ node of a linked list as a parameter. 15 | Complete _removeDuplicates_ so that it deletes any duplicate nodes from the list 16 | and returns the head of the updated list. 17 | 18 | ### Input Format 19 | 20 | The first line contains an integer, _N_, the number of nodes to be inserted. 21 | The _N_ subsequent lines each contain an integer describing the _data_ value of a node being inserted at the list's tail. 22 | 23 | ### Constraints 24 | 25 | * The data elements of the linked list argument will always be in non-decreasing order. 26 | 27 | ### Output Format 28 | 29 | Your _removeDuplicates_ function should return the head of the update linked list. 30 | The output should be printed as a space separated list of integers on one line. 31 | -------------------------------------------------------------------------------- /day-24/solution.py: -------------------------------------------------------------------------------- 1 | class Node: 2 | def __init__(self, data): 3 | self.data = data 4 | self.next = None 5 | 6 | 7 | class Solution: 8 | def insert(self, head, data): 9 | p = Node(data) 10 | if head == None: 11 | head = p 12 | elif head.next == None: 13 | head.next = p 14 | else: 15 | start = head 16 | while (start.next != None): 17 | start = start.next 18 | start.next = p 19 | return head 20 | 21 | def display(self, head): 22 | current = head 23 | while current: 24 | print(current.data, end=' ') 25 | current = current.next 26 | 27 | def removeDuplicates(self, head): 28 | # Write your code here 29 | if not head: 30 | return None 31 | current = head 32 | while current.next: 33 | if current.next.data == current.data: 34 | current.next = current.next.next 35 | else: 36 | current = current.next 37 | return head 38 | 39 | 40 | 41 | 42 | mylist = Solution() 43 | T = int(input()) 44 | head = None 45 | for i in range(T): 46 | data = int(input()) 47 | head = mylist.insert(head, data) 48 | head = mylist.removeDuplicates(head) 49 | mylist.display(head); -------------------------------------------------------------------------------- /day-24/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 1 3 | 2 4 | 2 5 | 3 6 | 3 7 | 4 -------------------------------------------------------------------------------- /day-24/test-0-output.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 -------------------------------------------------------------------------------- /day-25/solution.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def isPrime(n): 4 | if n <= 1: 5 | return False 6 | sqrt_n = math.sqrt(n) 7 | if sqrt_n.is_integer(): 8 | return False 9 | for i in range(2, int(sqrt_n)+1): 10 | if n%i == 0: 11 | return False 12 | return True 13 | 14 | 15 | num_test_cases = int(input()) 16 | for i in range(num_test_cases): 17 | n = int(input()) 18 | if isPrime(n): 19 | print('Prime') 20 | else: 21 | print('Not prime') 22 | -------------------------------------------------------------------------------- /day-25/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 3 2 | 12 3 | 5 4 | 7 -------------------------------------------------------------------------------- /day-25/test-0-output.txt: -------------------------------------------------------------------------------- 1 | Not prime 2 | Prime 3 | Prime 4 | -------------------------------------------------------------------------------- /day-25/test-1-input.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 31 3 | 33 -------------------------------------------------------------------------------- /day-25/test-1-output.txt: -------------------------------------------------------------------------------- 1 | Prime 2 | Not prime 3 | -------------------------------------------------------------------------------- /day-26/README.md: -------------------------------------------------------------------------------- 1 | # Day 26: Nested Logic 2 | 3 | ### Objective 4 | 5 | Today's challenge put's your understanding of nested conditional statements to the test. 6 | You already have the knowledge to complete this challenge, 7 | but checkout the [Tutorial](https://www.hackerrank.com/challenges/30-nested-logic/tutorial) 8 | tab for a video on testing! 9 | 10 | ### Task 11 | 12 | Your local library needs your help! 13 | Given the expected and actual returns dates for a library book, create a program that calculates the fine (if any). 14 | The fee structure is as follows: 15 | 1. If the book is returned on or before the expected return _day_, no fine will be charged (_fine_ = 0). 16 | 2. If the book is returned after the expected return date but still within the same calendar month and year as the expected return date, 17 | _fine_ = 15 Hackos x (the number of days late). 18 | 3. If the book is returned after the expected return _month_ but still within the same calendar year as the expected return date, 19 | the _fine_ = 500 Hackos x (the number of months late). 20 | 4. If the book is returned after the calendar _year_ in which it was expected, there is a fixed fine of 10000 Hackos. 21 | 22 | ### Input Format 23 | 24 | The first line contains 3 space-separated integers denoting the respective _day_, _month_, and _year_ on which the book was expected to be returned. 25 | 26 | ### Constraints 27 | 28 | * 1 ≤ _D_ ≤ 31 29 | * 1 ≤ _M_ ≤ 12 30 | * 1 ≤ _Y_ ≤ 3000 31 | * It is guaranteed that the dates will be valid Gregorian calendar dates. 32 | 33 | ### Output Format 34 | 35 | Print a single integer denoting the library fine for the book received as input. 36 | 37 | ### Sample Input 38 | ``` 39 | 9 6 2015 40 | 6 6 2015 41 | ``` 42 | ### Sample Output 43 | ``` 44 | 45 45 | ``` 46 | -------------------------------------------------------------------------------- /day-26/SOLUTION.md: -------------------------------------------------------------------------------- 1 | # Day 26: Nested Logic 2 | 3 | ## Objective 4 | Today we're being challenged on nested conditional statements. Check out day 3's video if you aren't familiar with conditional statements. 5 | 6 | ## Task 7 | 8 | Our task today is to help calculate the late return fines for a library. When a book is returned, we will calculate the return cost based on the following structure: 9 | 10 | 1. If the book is returned on or before the expected return date, no fine will be charged. (fine = 0). 11 | 2. If the book is returned after the expected return day but still within the same calendar month and year as the expected return date, _fine = 15 Hackos x (the number of days late)_. 12 | 3. If the book is returned after the expected return month but still within the same calendar year as the expected return date, the _fine = 500 Hackos x (the number of months late)_. 13 | 4. If the book is returned after the calendar year in which it was expected, there is a fixed fine of _10000 Hackos_. 14 | 15 | ### Input Format 16 | 17 | The first line will contain 3 space-separated integers denoting the respective _day_, _month_, and _year_ on which the book was actually returned. 18 | The second line contains the 3 space-separated integers denoting the respective _day_, _month_, and _year_ on which the book was expected to be returned (due date). 19 | 20 | Dates will be valid Gregorian calendar dates 21 | 1 <= D <= 31 22 | 1 <= M <= 12 23 | 1 <= Y <= 3000 24 | 25 | ### Output Format 26 | 27 | Print a single integer denoting the library fine for the book received as input. 28 | 29 | ## Solution 30 | 31 | We have 4 states we could be in. There is no due date, the book is a few days late, the book is months late, or the book is a year late. There are also 3 categories we are checking based on--year, month, and date. We are going to nest our conditional statements since a year contains months and a month contains days. 32 | 33 | We will first check if the book is returned in a previous year, the same year, or a later year. If the book was returned in a previous year than the due year, then we do not need to pay a fine. If the book was returned in the same year as the due year, we will need to check month and date. Otherwise, if the book was returned in a year after the due year, we will print 10000. 34 | 35 | In the case that the book was returned in the same calendar year as the due date, we need to check the month and day. First we check if the book was returned in a previous month, if so, we do not need to pay a fine. If the book was returned in the same calendar month, then we need to check the day. Otherwise the fine is the number of months behind the book was multiplied by 500. 36 | 37 | If the book was returned in the same year and month, we need to check for the return day. If the book was returned on or before the due date, we do not need to pay a fine so we will print 0. Otherwise we will print the number of days behind the book was multiplied by 15. 38 | 39 | ## Implementation 40 | 41 | First, we need to parse the input strings into variables. We will capture the first line of input, strip whitespace on the ends, and split it on spaces. We can use python list interpretation to split the array of strings into its elements, and cast them to integers, then store them in the `return_day`, `return_month` and `return_year` variables. You can read the docs [here](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions). We will do the same for the second line of input to get the due dates. 42 | 43 | Then we will check if the return year is less than the due year. If it is, we print 0. We will also make an elif condition if the return year is the same as the due year and check months later. We also need to fill in the else case where the return year is greater than the due year and print 10000. 44 | 45 | In the case where the return year is the same as the due year, we will check to see if the return month is before the due month. In this case, we print 0. We also need an elif condition to see if the return month is equal to the due month. We will check return date in this case. We also need to fill in the else case where the return month is greater than the due month and print 500 by the number of months late. 46 | 47 | In the most nested case, we check the return date. If it is on or before the due date, we will print 0 since we do not need to pay a fine. Otherwise, we will print 15 by the number of days late. 48 | -------------------------------------------------------------------------------- /day-26/solution.py: -------------------------------------------------------------------------------- 1 | # use list comprehension https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions 2 | return_day, return_month, return_year = [int(e) for e in input().strip().split(' ')] 3 | due_day, due_month, due_year = [int(e) for e in input().strip().split(' ')] 4 | 5 | # Check the biggest category: year 6 | if return_year < due_year: 7 | print(0) 8 | elif return_year == due_year: 9 | # Check the next biggest category: month 10 | if return_month < due_month: 11 | print(0) 12 | elif return_month == due_month: 13 | # Check the last category: day 14 | if return_day <= due_day: 15 | print(0) 16 | else: 17 | print(str((return_day - due_day) * 15)) 18 | else: 19 | print(str((return_month - due_month) * 500)) 20 | else: 21 | print('10000') 22 | 23 | -------------------------------------------------------------------------------- /day-26/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 9 6 2015 2 | 6 6 2015 -------------------------------------------------------------------------------- /day-26/test-0-output.txt: -------------------------------------------------------------------------------- 1 | 45 -------------------------------------------------------------------------------- /day-26/test-1-input.txt: -------------------------------------------------------------------------------- 1 | 23 12 1234 2 | 19 9 2468 -------------------------------------------------------------------------------- /day-26/test-1-output.txt: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /day-27/solution.py: -------------------------------------------------------------------------------- 1 | def minimum_index(seq): 2 | if len(seq) == 0: 3 | raise ValueError("Cannot get the minimum value index from an empty sequence") 4 | min_idx = 0 5 | for i in range(1, len(seq)): 6 | if seq[i] < seq[min_idx]: 7 | min_idx = i 8 | return min_idx 9 | 10 | 11 | class TestDataEmptyArray(object): 12 | 13 | @staticmethod 14 | def get_array(): 15 | # complete this function 16 | return [] 17 | 18 | 19 | class TestDataUniqueValues(object): 20 | 21 | @staticmethod 22 | def get_array(): 23 | # complete this function 24 | return [3, 1, 2] 25 | 26 | @staticmethod 27 | def get_expected_result(): 28 | # complete this function 29 | return 1 30 | 31 | 32 | class TestDataExactlyTwoDifferentMinimums(object): 33 | 34 | @staticmethod 35 | def get_array(): 36 | # complete this function 37 | return [3, 1, 1] 38 | 39 | @staticmethod 40 | def get_expected_result(): 41 | # complete this function 42 | return 1 43 | 44 | def TestWithEmptyArray(): 45 | try: 46 | seq = TestDataEmptyArray.get_array() 47 | result = minimum_index(seq) 48 | except ValueError as e: 49 | pass 50 | else: 51 | assert False 52 | 53 | def TestWithUniqueValues(): 54 | seq = TestDataUniqueValues.get_array() 55 | assert len(seq) >= 2 56 | 57 | assert len(list(set(seq))) == len(seq) 58 | 59 | expected_result = TestDataUniqueValues.get_expected_result() 60 | result = minimum_index(seq) 61 | assert result == expected_result 62 | 63 | def TestiWithExactyTwoDifferentMinimums(): 64 | seq = TestDataExactlyTwoDifferentMinimums.get_array() 65 | assert len(seq) >= 2 66 | tmp = sorted(seq) 67 | assert tmp[0] == tmp[1] and (len(tmp) == 2 or tmp[1] < tmp[2]) 68 | 69 | expected_result = TestDataExactlyTwoDifferentMinimums.get_expected_result() 70 | result = minimum_index(seq) 71 | assert result == expected_result 72 | 73 | TestWithEmptyArray() 74 | TestWithUniqueValues() 75 | TestiWithExactyTwoDifferentMinimums() 76 | print("OK") 77 | -------------------------------------------------------------------------------- /day-27/test-0-input.txt: -------------------------------------------------------------------------------- 1 | Dummy input provided, as this is unit testing problem only. If you don't see any errors and exceptions thrown, then you code runs correctly. 2 | -------------------------------------------------------------------------------- /day-27/test-0-output.txt: -------------------------------------------------------------------------------- 1 | OK 2 | -------------------------------------------------------------------------------- /day-28/solution.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import re 4 | 5 | if __name__ == '__main__': 6 | N = int(input()) 7 | 8 | pattern = r"@gmail\.com$" 9 | regex = re.compile(pattern) 10 | firstNames = [] 11 | 12 | for N_itr in range(N): 13 | firstNameEmailID = input().split() 14 | 15 | firstName = firstNameEmailID[0] 16 | 17 | emailID = firstNameEmailID[1] 18 | 19 | if regex.search(emailID): 20 | firstNames.append(firstName) 21 | 22 | firstNames.sort() 23 | 24 | for name in firstNames: 25 | print(name) 26 | -------------------------------------------------------------------------------- /day-28/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 6 2 | riya riya@gmail.com 3 | julia julia@julia.me 4 | julia sjulia@gmail.com 5 | julia julia@gmail.com 6 | samantha samantha@gmail.com 7 | tanya tanya@gmail.com -------------------------------------------------------------------------------- /day-28/test-0-output.txt: -------------------------------------------------------------------------------- 1 | julia 2 | julia 3 | riya 4 | samantha 5 | tanya -------------------------------------------------------------------------------- /day-29/solution.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | def find_max_bitwise(n, k): 11 | max_bitwise = 0 12 | for i in range(1, n + 1): 13 | for j in range(1, i): 14 | bitwise = i & j 15 | if max_bitwise < bitwise < k: 16 | max_bitwise = bitwise 17 | if max_bitwise == k - 1: 18 | return max_bitwise 19 | 20 | return max_bitwise 21 | 22 | 23 | if __name__ == '__main__': 24 | t = int(input()) 25 | 26 | for t_itr in range(t): 27 | nk = input().split() 28 | 29 | n = int(nk[0]) 30 | 31 | k = int(nk[1]) 32 | 33 | print(find_max_bitwise(n, k)) 34 | -------------------------------------------------------------------------------- /day-29/test-0-input.txt: -------------------------------------------------------------------------------- 1 | 3 2 | 5 2 3 | 8 5 4 | 2 2 -------------------------------------------------------------------------------- /day-29/test-0-output.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 4 3 | 0 -------------------------------------------------------------------------------- /day-29/test-1-input.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 9 2 3 | 8 3 -------------------------------------------------------------------------------- /day-29/test-1-output.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 -------------------------------------------------------------------------------- /day-29/test-2-input.txt: -------------------------------------------------------------------------------- 1 | 996 2 | 955 236 3 | 132 107 4 | 178 104 5 | 394 378 6 | 773 29 7 | 159 117 8 | 928 443 9 | 250 146 10 | 730 468 11 | 601 278 12 | 535 449 13 | 293 109 14 | 239 87 15 | 559 168 16 | 601 435 17 | 199 41 18 | 297 50 19 | 407 143 20 | 107 33 21 | 227 39 22 | 674 86 23 | 153 134 24 | 302 53 25 | 823 436 26 | 532 125 27 | 149 86 28 | 140 133 29 | 887 166 30 | 646 496 31 | 481 208 32 | 308 190 33 | 467 452 34 | 411 130 35 | 835 88 36 | 412 192 37 | 174 123 38 | 848 390 39 | 435 169 40 | 286 50 41 | 906 806 42 | 203 148 43 | 145 64 44 | 604 358 45 | 217 175 46 | 983 977 47 | 979 290 48 | 748 134 49 | 974 260 50 | 773 681 51 | 563 130 52 | 136 25 53 | 591 397 54 | 174 6 55 | 552 32 56 | 985 66 57 | 118 117 58 | 627 308 59 | 117 8 60 | 138 90 61 | 843 451 62 | 725 59 63 | 787 334 64 | 825 22 65 | 516 362 66 | 148 30 67 | 663 632 68 | 555 108 69 | 676 555 70 | 301 118 71 | 122 71 72 | 365 261 73 | 253 212 74 | 300 212 75 | 134 29 76 | 560 275 77 | 784 631 78 | 401 364 79 | 148 132 80 | 333 196 81 | 502 356 82 | 850 580 83 | 759 689 84 | 719 390 85 | 245 159 86 | 421 186 87 | 224 161 88 | 132 46 89 | 299 57 90 | 600 223 91 | 140 26 92 | 634 192 93 | 942 258 94 | 131 57 95 | 763 188 96 | 156 4 97 | 780 376 98 | 928 619 99 | 150 123 100 | 164 152 101 | 866 159 102 | 676 223 103 | 840 649 104 | 220 185 105 | 199 67 106 | 712 704 107 | 401 240 108 | 291 259 109 | 291 274 110 | 449 107 111 | 392 234 112 | 130 51 113 | 142 10 114 | 660 530 115 | 159 2 116 | 198 85 117 | 882 380 118 | 155 33 119 | 214 86 120 | 686 476 121 | 430 127 122 | 841 24 123 | 339 11 124 | 982 684 125 | 425 125 126 | 279 137 127 | 294 9 128 | 423 379 129 | 860 723 130 | 425 339 131 | 426 353 132 | 218 145 133 | 859 302 134 | 873 867 135 | 815 192 136 | 469 374 137 | 110 16 138 | 993 703 139 | 212 211 140 | 139 70 141 | 624 318 142 | 151 34 143 | 343 182 144 | 779 401 145 | 941 720 146 | 663 301 147 | 841 348 148 | 562 186 149 | 599 162 150 | 737 525 151 | 162 64 152 | 456 301 153 | 184 160 154 | 127 15 155 | 769 62 156 | 702 114 157 | 397 63 158 | 945 263 159 | 865 256 160 | 197 164 161 | 198 149 162 | 307 260 163 | 762 541 164 | 519 177 165 | 410 388 166 | 234 172 167 | 449 8 168 | 179 157 169 | 582 257 170 | 913 363 171 | 116 112 172 | 116 50 173 | 276 250 174 | 381 199 175 | 655 225 176 | 225 5 177 | 424 141 178 | 247 97 179 | 118 24 180 | 156 52 181 | 614 327 182 | 614 327 183 | 160 38 184 | 884 855 185 | 336 201 186 | 127 76 187 | 785 635 188 | 529 52 189 | 417 27 190 | 934 502 191 | 157 128 192 | 670 172 193 | 412 108 194 | 239 173 195 | 457 100 196 | 879 588 197 | 117 90 198 | 974 331 199 | 195 62 200 | 188 125 201 | 773 510 202 | 843 531 203 | 661 204 204 | 169 14 205 | 253 78 206 | 990 39 207 | 731 715 208 | 523 328 209 | 260 53 210 | 979 401 211 | 393 108 212 | 266 161 213 | 348 2 214 | 824 135 215 | 466 325 216 | 117 9 217 | 385 47 218 | 285 41 219 | 541 106 220 | 175 125 221 | 223 48 222 | 877 853 223 | 711 274 224 | 434 189 225 | 157 42 226 | 785 305 227 | 515 61 228 | 260 220 229 | 961 406 230 | 102 59 231 | 774 154 232 | 555 374 233 | 103 88 234 | 915 722 235 | 415 40 236 | 117 32 237 | 146 123 238 | 338 49 239 | 871 108 240 | 167 127 241 | 140 106 242 | 226 109 243 | 693 637 244 | 519 286 245 | 431 300 246 | 174 49 247 | 101 41 248 | 306 23 249 | 397 126 250 | 144 17 251 | 547 334 252 | 768 204 253 | 983 753 254 | 520 87 255 | 281 237 256 | 671 269 257 | 544 129 258 | 306 179 259 | 757 724 260 | 493 285 261 | 700 596 262 | 189 103 263 | 291 58 264 | 331 284 265 | 347 304 266 | 992 856 267 | 944 487 268 | 725 325 269 | 163 140 270 | 288 216 271 | 885 57 272 | 913 42 273 | 401 154 274 | 160 18 275 | 575 193 276 | 772 595 277 | 123 100 278 | 562 132 279 | 523 69 280 | 381 68 281 | 512 109 282 | 440 209 283 | 479 423 284 | 818 572 285 | 917 26 286 | 681 435 287 | 645 419 288 | 312 241 289 | 526 446 290 | 201 155 291 | 738 440 292 | 127 64 293 | 794 395 294 | 438 373 295 | 761 278 296 | 139 82 297 | 568 527 298 | 735 454 299 | 527 428 300 | 318 311 301 | 739 377 302 | 179 98 303 | 951 88 304 | 451 182 305 | 858 154 306 | 124 77 307 | 180 107 308 | 472 458 309 | 899 254 310 | 527 476 311 | 553 335 312 | 149 78 313 | 982 666 314 | 359 249 315 | 191 13 316 | 667 237 317 | 449 439 318 | 139 33 319 | 528 183 320 | 827 107 321 | 112 91 322 | 298 213 323 | 278 262 324 | 729 96 325 | 271 75 326 | 894 540 327 | 683 664 328 | 824 417 329 | 231 98 330 | 206 25 331 | 178 89 332 | 605 112 333 | 486 121 334 | 475 192 335 | 753 89 336 | 898 820 337 | 450 218 338 | 711 371 339 | 684 251 340 | 134 5 341 | 674 127 342 | 164 123 343 | 754 108 344 | 410 398 345 | 163 53 346 | 631 33 347 | 440 170 348 | 658 600 349 | 184 3 350 | 479 357 351 | 346 287 352 | 559 261 353 | 576 214 354 | 214 55 355 | 952 426 356 | 844 288 357 | 938 366 358 | 743 547 359 | 360 310 360 | 355 84 361 | 195 29 362 | 631 488 363 | 700 15 364 | 565 28 365 | 641 600 366 | 797 717 367 | 551 92 368 | 628 64 369 | 400 213 370 | 321 194 371 | 228 191 372 | 132 24 373 | 520 92 374 | 132 126 375 | 152 31 376 | 906 219 377 | 272 165 378 | 410 385 379 | 865 190 380 | 341 239 381 | 933 900 382 | 387 264 383 | 743 350 384 | 929 216 385 | 686 94 386 | 227 168 387 | 554 168 388 | 168 74 389 | 778 302 390 | 706 39 391 | 328 138 392 | 792 432 393 | 372 2 394 | 589 477 395 | 436 241 396 | 419 346 397 | 184 105 398 | 946 214 399 | 769 267 400 | 745 411 401 | 108 82 402 | 506 228 403 | 203 191 404 | 104 81 405 | 391 44 406 | 343 196 407 | 824 775 408 | 253 175 409 | 912 214 410 | 911 274 411 | 924 458 412 | 250 143 413 | 875 494 414 | 966 336 415 | 698 249 416 | 370 128 417 | 578 20 418 | 517 89 419 | 625 67 420 | 180 62 421 | 561 97 422 | 113 70 423 | 837 61 424 | 390 99 425 | 970 687 426 | 584 284 427 | 476 198 428 | 819 284 429 | 106 44 430 | 966 889 431 | 375 239 432 | 635 118 433 | 174 96 434 | 340 185 435 | 127 67 436 | 859 784 437 | 865 811 438 | 334 266 439 | 698 438 440 | 339 330 441 | 281 234 442 | 826 275 443 | 968 774 444 | 750 87 445 | 277 2 446 | 237 209 447 | 750 266 448 | 196 56 449 | 590 179 450 | 524 384 451 | 240 24 452 | 918 155 453 | 666 256 454 | 470 383 455 | 106 73 456 | 908 536 457 | 147 116 458 | 595 482 459 | 744 100 460 | 178 28 461 | 699 128 462 | 189 53 463 | 872 349 464 | 988 575 465 | 989 970 466 | 123 28 467 | 924 222 468 | 422 136 469 | 347 131 470 | 648 293 471 | 476 386 472 | 777 380 473 | 633 129 474 | 445 53 475 | 202 63 476 | 188 75 477 | 225 147 478 | 961 896 479 | 123 122 480 | 187 178 481 | 838 650 482 | 607 306 483 | 244 99 484 | 191 55 485 | 634 349 486 | 787 599 487 | 303 221 488 | 862 543 489 | 426 162 490 | 908 173 491 | 559 525 492 | 707 406 493 | 130 61 494 | 548 533 495 | 459 155 496 | 435 378 497 | 653 279 498 | 114 9 499 | 131 7 500 | 393 347 501 | 162 45 502 | 844 813 503 | 562 522 504 | 731 328 505 | 630 612 506 | 487 434 507 | 398 304 508 | 157 89 509 | 583 329 510 | 947 566 511 | 979 594 512 | 190 27 513 | 359 198 514 | 969 231 515 | 468 422 516 | 413 76 517 | 998 80 518 | 443 153 519 | 635 282 520 | 843 744 521 | 560 349 522 | 272 150 523 | 905 714 524 | 176 126 525 | 323 147 526 | 291 124 527 | 799 665 528 | 488 392 529 | 953 409 530 | 533 365 531 | 680 259 532 | 815 556 533 | 598 209 534 | 411 258 535 | 755 72 536 | 422 244 537 | 845 687 538 | 846 21 539 | 272 29 540 | 693 537 541 | 881 236 542 | 154 35 543 | 197 3 544 | 151 55 545 | 663 346 546 | 685 252 547 | 603 287 548 | 114 29 549 | 884 391 550 | 110 8 551 | 107 54 552 | 159 101 553 | 669 517 554 | 842 109 555 | 568 332 556 | 503 51 557 | 114 7 558 | 605 35 559 | 387 246 560 | 387 130 561 | 167 47 562 | 486 307 563 | 538 345 564 | 177 176 565 | 732 309 566 | 771 221 567 | 146 30 568 | 264 3 569 | 114 79 570 | 818 633 571 | 215 133 572 | 191 151 573 | 180 170 574 | 936 814 575 | 396 7 576 | 311 3 577 | 737 210 578 | 512 440 579 | 296 25 580 | 723 356 581 | 353 171 582 | 610 316 583 | 383 2 584 | 132 61 585 | 457 210 586 | 752 678 587 | 766 301 588 | 168 53 589 | 793 753 590 | 487 199 591 | 422 41 592 | 370 306 593 | 857 435 594 | 362 31 595 | 462 384 596 | 727 648 597 | 963 812 598 | 103 6 599 | 336 183 600 | 188 91 601 | 136 16 602 | 137 9 603 | 343 257 604 | 138 119 605 | 683 570 606 | 706 55 607 | 877 700 608 | 175 102 609 | 280 2 610 | 976 794 611 | 613 473 612 | 189 119 613 | 376 26 614 | 497 69 615 | 976 899 616 | 890 197 617 | 925 388 618 | 165 22 619 | 142 109 620 | 626 2 621 | 316 127 622 | 101 29 623 | 473 361 624 | 779 540 625 | 693 174 626 | 566 44 627 | 182 8 628 | 829 191 629 | 261 98 630 | 670 529 631 | 603 190 632 | 128 60 633 | 663 176 634 | 717 438 635 | 439 139 636 | 666 98 637 | 664 337 638 | 166 16 639 | 738 411 640 | 287 75 641 | 773 523 642 | 547 523 643 | 996 621 644 | 524 12 645 | 406 30 646 | 999 737 647 | 841 91 648 | 600 323 649 | 799 499 650 | 376 61 651 | 268 148 652 | 358 162 653 | 838 565 654 | 178 39 655 | 149 38 656 | 164 76 657 | 933 309 658 | 636 134 659 | 977 482 660 | 943 556 661 | 325 148 662 | 571 125 663 | 876 501 664 | 530 490 665 | 192 70 666 | 724 604 667 | 212 37 668 | 586 466 669 | 300 148 670 | 179 120 671 | 116 114 672 | 934 786 673 | 509 15 674 | 120 92 675 | 670 617 676 | 575 435 677 | 747 645 678 | 949 890 679 | 179 77 680 | 959 77 681 | 904 291 682 | 867 14 683 | 722 370 684 | 170 112 685 | 151 114 686 | 654 274 687 | 521 228 688 | 679 341 689 | 714 13 690 | 487 399 691 | 436 233 692 | 659 533 693 | 284 136 694 | 618 19 695 | 503 433 696 | 876 231 697 | 391 104 698 | 234 24 699 | 871 387 700 | 373 31 701 | 596 512 702 | 867 79 703 | 654 323 704 | 711 184 705 | 261 142 706 | 273 95 707 | 874 131 708 | 140 100 709 | 123 30 710 | 527 198 711 | 740 573 712 | 688 389 713 | 119 87 714 | 881 612 715 | 594 85 716 | 984 692 717 | 110 18 718 | 839 78 719 | 584 169 720 | 152 118 721 | 149 140 722 | 426 232 723 | 402 136 724 | 752 538 725 | 729 577 726 | 355 225 727 | 871 498 728 | 652 651 729 | 362 158 730 | 417 235 731 | 474 11 732 | 292 103 733 | 409 257 734 | 256 53 735 | 780 204 736 | 160 141 737 | 795 352 738 | 326 177 739 | 173 2 740 | 125 121 741 | 798 548 742 | 567 492 743 | 788 637 744 | 176 145 745 | 645 181 746 | 971 141 747 | 309 181 748 | 605 83 749 | 177 131 750 | 576 424 751 | 522 134 752 | 455 449 753 | 134 18 754 | 244 201 755 | 173 5 756 | 149 68 757 | 876 225 758 | 671 650 759 | 360 38 760 | 876 453 761 | 465 77 762 | 123 87 763 | 594 432 764 | 552 34 765 | 617 330 766 | 650 144 767 | 760 145 768 | 291 75 769 | 150 71 770 | 804 90 771 | 561 187 772 | 917 646 773 | 960 333 774 | 601 108 775 | 809 17 776 | 478 83 777 | 135 41 778 | 181 29 779 | 823 377 780 | 270 164 781 | 302 147 782 | 845 613 783 | 864 290 784 | 565 194 785 | 290 5 786 | 956 896 787 | 344 211 788 | 155 102 789 | 406 71 790 | 352 151 791 | 378 281 792 | 317 268 793 | 759 17 794 | 259 184 795 | 570 226 796 | 326 39 797 | 797 604 798 | 446 352 799 | 367 94 800 | 842 725 801 | 827 548 802 | 116 91 803 | 758 297 804 | 545 141 805 | 180 168 806 | 885 533 807 | 940 810 808 | 735 150 809 | 775 294 810 | 855 666 811 | 854 749 812 | 872 735 813 | 787 748 814 | 228 164 815 | 608 197 816 | 114 11 817 | 645 84 818 | 233 150 819 | 723 64 820 | 532 293 821 | 626 603 822 | 778 180 823 | 392 291 824 | 151 79 825 | 827 303 826 | 192 6 827 | 152 34 828 | 319 44 829 | 717 309 830 | 863 675 831 | 217 7 832 | 126 36 833 | 538 514 834 | 729 428 835 | 903 501 836 | 199 115 837 | 153 68 838 | 959 327 839 | 939 461 840 | 754 538 841 | 906 153 842 | 842 326 843 | 113 32 844 | 851 282 845 | 507 464 846 | 944 898 847 | 759 743 848 | 600 2 849 | 987 465 850 | 521 474 851 | 663 521 852 | 494 171 853 | 441 240 854 | 227 101 855 | 451 281 856 | 522 410 857 | 870 749 858 | 272 35 859 | 471 15 860 | 529 493 861 | 393 52 862 | 969 919 863 | 945 423 864 | 663 78 865 | 457 259 866 | 196 87 867 | 105 89 868 | 869 829 869 | 105 71 870 | 178 133 871 | 185 112 872 | 140 104 873 | 651 43 874 | 253 171 875 | 930 489 876 | 814 759 877 | 534 374 878 | 386 376 879 | 983 896 880 | 538 495 881 | 150 22 882 | 974 826 883 | 728 554 884 | 899 795 885 | 702 465 886 | 212 15 887 | 113 17 888 | 828 290 889 | 632 494 890 | 100 17 891 | 524 137 892 | 586 116 893 | 225 56 894 | 545 364 895 | 267 168 896 | 606 363 897 | 285 260 898 | 223 145 899 | 149 21 900 | 720 415 901 | 682 598 902 | 937 274 903 | 743 511 904 | 751 650 905 | 223 184 906 | 247 118 907 | 459 125 908 | 479 374 909 | 117 5 910 | 814 341 911 | 961 274 912 | 620 74 913 | 145 56 914 | 588 379 915 | 634 268 916 | 612 501 917 | 987 697 918 | 286 116 919 | 596 467 920 | 756 67 921 | 273 145 922 | 103 100 923 | 918 596 924 | 517 218 925 | 954 837 926 | 248 200 927 | 829 711 928 | 423 166 929 | 581 124 930 | 887 415 931 | 601 378 932 | 531 8 933 | 645 387 934 | 829 569 935 | 561 306 936 | 945 897 937 | 467 450 938 | 577 282 939 | 708 473 940 | 996 576 941 | 669 314 942 | 777 62 943 | 672 616 944 | 614 39 945 | 426 277 946 | 522 46 947 | 577 254 948 | 133 76 949 | 938 697 950 | 124 89 951 | 312 151 952 | 352 37 953 | 747 469 954 | 736 401 955 | 504 181 956 | 134 51 957 | 962 936 958 | 408 281 959 | 188 170 960 | 471 470 961 | 877 746 962 | 516 485 963 | 740 362 964 | 704 157 965 | 411 114 966 | 765 307 967 | 789 3 968 | 467 382 969 | 319 26 970 | 344 105 971 | 804 305 972 | 108 26 973 | 122 8 974 | 928 658 975 | 197 7 976 | 109 85 977 | 347 316 978 | 129 3 979 | 200 164 980 | 616 405 981 | 145 141 982 | 565 304 983 | 100 17 984 | 169 56 985 | 294 152 986 | 934 95 987 | 954 441 988 | 776 191 989 | 190 41 990 | 768 388 991 | 960 768 992 | 885 102 993 | 890 885 994 | 416 259 995 | 341 52 996 | 104 46 997 | 376 185 -------------------------------------------------------------------------------- /day-29/test-2-output.txt: -------------------------------------------------------------------------------- 1 | 235 2 | 106 3 | 103 4 | 377 5 | 28 6 | 116 7 | 442 8 | 145 9 | 467 10 | 277 11 | 448 12 | 108 13 | 86 14 | 167 15 | 434 16 | 40 17 | 49 18 | 142 19 | 32 20 | 38 21 | 85 22 | 133 23 | 52 24 | 435 25 | 124 26 | 85 27 | 132 28 | 165 29 | 495 30 | 207 31 | 189 32 | 451 33 | 129 34 | 87 35 | 191 36 | 122 37 | 389 38 | 168 39 | 49 40 | 805 41 | 147 42 | 63 43 | 357 44 | 174 45 | 976 46 | 289 47 | 133 48 | 259 49 | 680 50 | 129 51 | 24 52 | 396 53 | 5 54 | 31 55 | 65 56 | 116 57 | 307 58 | 7 59 | 89 60 | 450 61 | 58 62 | 333 63 | 21 64 | 361 65 | 29 66 | 631 67 | 107 68 | 554 69 | 117 70 | 70 71 | 260 72 | 211 73 | 211 74 | 28 75 | 274 76 | 630 77 | 363 78 | 131 79 | 195 80 | 355 81 | 579 82 | 688 83 | 389 84 | 158 85 | 185 86 | 160 87 | 45 88 | 56 89 | 222 90 | 25 91 | 191 92 | 257 93 | 56 94 | 187 95 | 3 96 | 375 97 | 618 98 | 122 99 | 151 100 | 158 101 | 222 102 | 648 103 | 184 104 | 66 105 | 702 106 | 239 107 | 258 108 | 273 109 | 106 110 | 233 111 | 50 112 | 9 113 | 529 114 | 1 115 | 84 116 | 379 117 | 32 118 | 85 119 | 475 120 | 126 121 | 23 122 | 10 123 | 683 124 | 124 125 | 136 126 | 8 127 | 378 128 | 722 129 | 338 130 | 352 131 | 144 132 | 301 133 | 866 134 | 191 135 | 373 136 | 15 137 | 702 138 | 210 139 | 69 140 | 317 141 | 33 142 | 181 143 | 400 144 | 719 145 | 300 146 | 347 147 | 185 148 | 161 149 | 524 150 | 63 151 | 300 152 | 158 153 | 14 154 | 61 155 | 113 156 | 62 157 | 262 158 | 255 159 | 163 160 | 148 161 | 259 162 | 540 163 | 176 164 | 387 165 | 171 166 | 7 167 | 156 168 | 256 169 | 362 170 | 110 171 | 49 172 | 249 173 | 198 174 | 224 175 | 4 176 | 140 177 | 96 178 | 23 179 | 51 180 | 326 181 | 326 182 | 37 183 | 854 184 | 200 185 | 75 186 | 634 187 | 51 188 | 26 189 | 501 190 | 126 191 | 171 192 | 107 193 | 172 194 | 99 195 | 587 196 | 89 197 | 330 198 | 61 199 | 124 200 | 509 201 | 530 202 | 203 203 | 13 204 | 77 205 | 38 206 | 714 207 | 327 208 | 52 209 | 400 210 | 107 211 | 160 212 | 1 213 | 134 214 | 324 215 | 8 216 | 46 217 | 40 218 | 105 219 | 124 220 | 47 221 | 852 222 | 273 223 | 188 224 | 41 225 | 304 226 | 60 227 | 219 228 | 405 229 | 58 230 | 153 231 | 373 232 | 87 233 | 721 234 | 39 235 | 31 236 | 122 237 | 48 238 | 107 239 | 126 240 | 105 241 | 108 242 | 636 243 | 285 244 | 299 245 | 48 246 | 40 247 | 22 248 | 125 249 | 16 250 | 333 251 | 203 252 | 752 253 | 86 254 | 236 255 | 268 256 | 128 257 | 178 258 | 723 259 | 284 260 | 595 261 | 102 262 | 57 263 | 283 264 | 303 265 | 855 266 | 486 267 | 324 268 | 139 269 | 215 270 | 56 271 | 41 272 | 153 273 | 17 274 | 192 275 | 594 276 | 99 277 | 131 278 | 68 279 | 67 280 | 108 281 | 208 282 | 422 283 | 571 284 | 25 285 | 434 286 | 418 287 | 240 288 | 445 289 | 154 290 | 439 291 | 63 292 | 394 293 | 372 294 | 277 295 | 81 296 | 526 297 | 453 298 | 427 299 | 310 300 | 376 301 | 97 302 | 87 303 | 181 304 | 153 305 | 76 306 | 106 307 | 457 308 | 253 309 | 475 310 | 334 311 | 77 312 | 665 313 | 248 314 | 12 315 | 236 316 | 438 317 | 32 318 | 182 319 | 106 320 | 90 321 | 212 322 | 261 323 | 95 324 | 74 325 | 539 326 | 663 327 | 416 328 | 97 329 | 24 330 | 88 331 | 111 332 | 120 333 | 191 334 | 88 335 | 819 336 | 217 337 | 370 338 | 250 339 | 4 340 | 126 341 | 122 342 | 107 343 | 397 344 | 52 345 | 32 346 | 169 347 | 599 348 | 2 349 | 356 350 | 286 351 | 260 352 | 213 353 | 54 354 | 425 355 | 287 356 | 365 357 | 546 358 | 309 359 | 83 360 | 28 361 | 487 362 | 14 363 | 27 364 | 599 365 | 716 366 | 91 367 | 63 368 | 212 369 | 193 370 | 190 371 | 23 372 | 91 373 | 125 374 | 30 375 | 218 376 | 164 377 | 384 378 | 189 379 | 238 380 | 899 381 | 263 382 | 349 383 | 215 384 | 93 385 | 167 386 | 167 387 | 73 388 | 301 389 | 38 390 | 137 391 | 431 392 | 1 393 | 476 394 | 240 395 | 345 396 | 104 397 | 213 398 | 266 399 | 410 400 | 81 401 | 227 402 | 190 403 | 80 404 | 43 405 | 195 406 | 774 407 | 174 408 | 213 409 | 273 410 | 457 411 | 142 412 | 493 413 | 335 414 | 248 415 | 127 416 | 19 417 | 88 418 | 66 419 | 61 420 | 96 421 | 69 422 | 60 423 | 98 424 | 686 425 | 283 426 | 197 427 | 283 428 | 43 429 | 888 430 | 238 431 | 117 432 | 95 433 | 184 434 | 66 435 | 783 436 | 810 437 | 265 438 | 437 439 | 329 440 | 233 441 | 274 442 | 773 443 | 86 444 | 1 445 | 208 446 | 265 447 | 55 448 | 178 449 | 383 450 | 23 451 | 154 452 | 255 453 | 382 454 | 72 455 | 535 456 | 115 457 | 481 458 | 99 459 | 27 460 | 127 461 | 52 462 | 348 463 | 574 464 | 969 465 | 27 466 | 221 467 | 135 468 | 130 469 | 292 470 | 385 471 | 379 472 | 128 473 | 52 474 | 62 475 | 74 476 | 146 477 | 894 478 | 121 479 | 177 480 | 649 481 | 305 482 | 98 483 | 54 484 | 348 485 | 598 486 | 220 487 | 542 488 | 161 489 | 172 490 | 524 491 | 405 492 | 60 493 | 532 494 | 154 495 | 377 496 | 278 497 | 8 498 | 6 499 | 346 500 | 44 501 | 812 502 | 521 503 | 327 504 | 611 505 | 433 506 | 303 507 | 88 508 | 328 509 | 565 510 | 593 511 | 26 512 | 197 513 | 230 514 | 421 515 | 75 516 | 79 517 | 152 518 | 281 519 | 743 520 | 348 521 | 149 522 | 713 523 | 125 524 | 146 525 | 123 526 | 664 527 | 391 528 | 408 529 | 364 530 | 258 531 | 555 532 | 208 533 | 257 534 | 71 535 | 243 536 | 686 537 | 20 538 | 28 539 | 536 540 | 235 541 | 34 542 | 2 543 | 54 544 | 345 545 | 251 546 | 286 547 | 28 548 | 390 549 | 7 550 | 53 551 | 100 552 | 516 553 | 108 554 | 331 555 | 50 556 | 6 557 | 34 558 | 245 559 | 129 560 | 46 561 | 306 562 | 344 563 | 174 564 | 308 565 | 220 566 | 29 567 | 2 568 | 78 569 | 632 570 | 132 571 | 150 572 | 169 573 | 813 574 | 6 575 | 2 576 | 209 577 | 439 578 | 24 579 | 355 580 | 170 581 | 315 582 | 1 583 | 60 584 | 209 585 | 677 586 | 300 587 | 52 588 | 752 589 | 198 590 | 40 591 | 305 592 | 434 593 | 30 594 | 382 595 | 647 596 | 811 597 | 5 598 | 182 599 | 90 600 | 15 601 | 8 602 | 256 603 | 118 604 | 569 605 | 54 606 | 699 607 | 101 608 | 1 609 | 793 610 | 472 611 | 118 612 | 25 613 | 68 614 | 898 615 | 196 616 | 387 617 | 21 618 | 108 619 | 1 620 | 126 621 | 28 622 | 360 623 | 539 624 | 173 625 | 43 626 | 7 627 | 190 628 | 97 629 | 528 630 | 189 631 | 59 632 | 175 633 | 437 634 | 138 635 | 97 636 | 336 637 | 15 638 | 410 639 | 74 640 | 522 641 | 522 642 | 620 643 | 11 644 | 29 645 | 736 646 | 90 647 | 322 648 | 498 649 | 60 650 | 147 651 | 161 652 | 564 653 | 38 654 | 37 655 | 75 656 | 308 657 | 133 658 | 481 659 | 555 660 | 147 661 | 124 662 | 500 663 | 489 664 | 69 665 | 603 666 | 36 667 | 465 668 | 147 669 | 119 670 | 113 671 | 785 672 | 14 673 | 91 674 | 616 675 | 434 676 | 644 677 | 889 678 | 76 679 | 76 680 | 290 681 | 13 682 | 369 683 | 111 684 | 113 685 | 273 686 | 227 687 | 340 688 | 12 689 | 398 690 | 232 691 | 532 692 | 135 693 | 18 694 | 432 695 | 230 696 | 103 697 | 23 698 | 386 699 | 30 700 | 510 701 | 78 702 | 322 703 | 183 704 | 141 705 | 94 706 | 130 707 | 99 708 | 29 709 | 197 710 | 572 711 | 388 712 | 86 713 | 611 714 | 84 715 | 691 716 | 17 717 | 77 718 | 168 719 | 117 720 | 139 721 | 231 722 | 135 723 | 537 724 | 576 725 | 224 726 | 497 727 | 650 728 | 157 729 | 234 730 | 10 731 | 102 732 | 256 733 | 52 734 | 203 735 | 140 736 | 351 737 | 176 738 | 1 739 | 120 740 | 547 741 | 491 742 | 636 743 | 144 744 | 180 745 | 140 746 | 180 747 | 82 748 | 130 749 | 423 750 | 133 751 | 448 752 | 17 753 | 200 754 | 4 755 | 67 756 | 224 757 | 649 758 | 37 759 | 452 760 | 76 761 | 86 762 | 431 763 | 33 764 | 329 765 | 143 766 | 144 767 | 74 768 | 70 769 | 89 770 | 186 771 | 645 772 | 332 773 | 107 774 | 16 775 | 82 776 | 40 777 | 28 778 | 376 779 | 163 780 | 146 781 | 612 782 | 289 783 | 193 784 | 4 785 | 894 786 | 210 787 | 101 788 | 70 789 | 150 790 | 280 791 | 267 792 | 16 793 | 183 794 | 225 795 | 38 796 | 603 797 | 351 798 | 93 799 | 724 800 | 547 801 | 90 802 | 296 803 | 140 804 | 167 805 | 532 806 | 809 807 | 149 808 | 293 809 | 665 810 | 748 811 | 734 812 | 747 813 | 163 814 | 196 815 | 10 816 | 83 817 | 149 818 | 63 819 | 292 820 | 602 821 | 179 822 | 290 823 | 78 824 | 302 825 | 5 826 | 33 827 | 43 828 | 308 829 | 674 830 | 6 831 | 35 832 | 513 833 | 427 834 | 500 835 | 114 836 | 67 837 | 326 838 | 460 839 | 537 840 | 152 841 | 325 842 | 31 843 | 281 844 | 463 845 | 897 846 | 742 847 | 1 848 | 464 849 | 473 850 | 520 851 | 170 852 | 239 853 | 100 854 | 280 855 | 409 856 | 748 857 | 34 858 | 14 859 | 492 860 | 51 861 | 918 862 | 422 863 | 77 864 | 258 865 | 86 866 | 88 867 | 828 868 | 70 869 | 132 870 | 111 871 | 103 872 | 42 873 | 170 874 | 488 875 | 758 876 | 373 877 | 375 878 | 894 879 | 494 880 | 21 881 | 825 882 | 553 883 | 794 884 | 464 885 | 14 886 | 16 887 | 289 888 | 493 889 | 16 890 | 136 891 | 115 892 | 55 893 | 363 894 | 167 895 | 362 896 | 259 897 | 144 898 | 20 899 | 414 900 | 597 901 | 273 902 | 510 903 | 649 904 | 183 905 | 117 906 | 124 907 | 373 908 | 4 909 | 340 910 | 273 911 | 73 912 | 55 913 | 378 914 | 267 915 | 500 916 | 696 917 | 115 918 | 466 919 | 66 920 | 144 921 | 99 922 | 595 923 | 217 924 | 836 925 | 199 926 | 710 927 | 165 928 | 123 929 | 414 930 | 377 931 | 7 932 | 386 933 | 568 934 | 305 935 | 896 936 | 449 937 | 281 938 | 472 939 | 575 940 | 313 941 | 61 942 | 615 943 | 38 944 | 276 945 | 45 946 | 253 947 | 75 948 | 696 949 | 88 950 | 150 951 | 36 952 | 468 953 | 400 954 | 180 955 | 50 956 | 935 957 | 280 958 | 169 959 | 469 960 | 745 961 | 484 962 | 361 963 | 156 964 | 113 965 | 306 966 | 2 967 | 381 968 | 25 969 | 104 970 | 304 971 | 25 972 | 7 973 | 657 974 | 6 975 | 84 976 | 315 977 | 2 978 | 163 979 | 404 980 | 140 981 | 303 982 | 16 983 | 55 984 | 151 985 | 94 986 | 440 987 | 190 988 | 40 989 | 387 990 | 766 991 | 101 992 | 884 993 | 258 994 | 51 995 | 45 996 | 184 -------------------------------------------------------------------------------- /test-solution.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Which day would you like to test?" 4 | read TEST_DIR 5 | 6 | cd $TEST_DIR 7 | 8 | SOLUTION_LANGUAGE=python 9 | 10 | # check if solution class is java or python 11 | if [ -e Solution.java ] 12 | then 13 | javac Solution.java 14 | SOLUTION_LANGUAGE=java 15 | fi 16 | 17 | TEST_INPUTS=$(find . -name "test-*-input.txt") 18 | TEST_NUM=0 19 | for TEST_INPUT in $TEST_INPUTS 20 | do 21 | STARTTIME=$(gdate +%s.%3N) 22 | if [ $SOLUTION_LANGUAGE == java ] 23 | then 24 | ACTUAL_OUTPUT=$(cat $TEST_INPUT | java Solution) 25 | elif [ $SOLUTION_LANGUAGE == python ] 26 | then 27 | ACTUAL_OUTPUT=$(cat $TEST_INPUT | python3 solution.py) 28 | fi 29 | TEST_DIFF=$(diff -w <(echo "$ACTUAL_OUTPUT") test-$TEST_NUM-output.txt) 30 | ENDTIME=$(gdate +%s.%3N) 31 | 32 | DURATION=$(echo "$ENDTIME-$STARTTIME" | bc) 33 | 34 | if [ $? -ne "0" ]; then 35 | echo "Test $TEST_NUM FAILED in $DURATION seconds" 36 | echo "$TEST_DIFF" 37 | exit 1 38 | else 39 | echo "TEST $TEST_NUM PASSED $DURATION seconds" 40 | fi 41 | 42 | TEST_NUM=$((TEST_NUM+1)) 43 | 44 | done 45 | --------------------------------------------------------------------------------