From 1179e569ee9edfc1ca90da5eaba3854df9e36ecb Mon Sep 17 00:00:00 2001 From: Dom Sec <54043553+dom-sec@users.noreply.github.com> Date: Thu, 23 Mar 2023 21:14:34 -0400 Subject: [PATCH] Add files via upload --- .../Day-29_Traffic-Light-Checker/README.md | 42 +++++++++ Week-05/Day-30_The-Maximum-Value/README.md | 16 ++++ Week-05/Day-31_The-Time-In-Words/README.md | 29 ++++++ .../Day-32_Climbing-The-Leaderboard/README.md | 29 ++++++ Week-05/Day-33_WERTYU/README.md | 27 ++++++ Week-05/Day-34_Primary-Arithmetic/README.md | 30 ++++++ Week-05/Day-35_Dog-And-Gopher/README.md | 92 +++++++++++++++++++ Week-06/Day-36_LCD-Display/README.md | 24 +++++ Week-06/Day-37_Breaking-The-Records/README.md | 28 ++++++ Week-06/Day-38_Electronics-Shop/README.md | 19 ++++ Week-06/Day-39_Halloween-Sale/README.md | 22 +++++ Week-06/Day-40_Larrys-Array/README.md | 21 +++++ Week-06/Day-41_Sales-By-Match/README.md | 7 ++ Week-06/Day-42_Drawing-Book/README.md | 25 +++++ Week-07/Day-43_Area-Of-A-Triangle/README.md | 13 +++ .../README.md | 13 +++ .../README.md | 26 ++++++ .../Day-46_Hot-Pics-Of-Danny-Devito/README.md | 21 +++++ Week-07/Day-47_Zip-It/README.md | 23 +++++ Week-07/Day-48_Christmas-Tree/README.md | 25 +++++ Week-07/Day-49_Swimming-Pool/README.md | 49 ++++++++++ Week-08/Day-50_Tic-Tac-Toe/README.md | 24 +++++ Week-08/Day-51_Asteroid-Collision/README.md | 31 +++++++ .../Day-52_Switch-On-The-Gravity/README.md | 40 ++++++++ .../Day-53_Javelin-Parabolic-Throw/README.md | 17 ++++ .../README.md | 15 +++ .../README.md | 19 ++++ Week-08/Day-56_Convert-To-Hex/README.md | 16 ++++ 28 files changed, 743 insertions(+) create mode 100644 Week-05/Day-29_Traffic-Light-Checker/README.md create mode 100644 Week-05/Day-30_The-Maximum-Value/README.md create mode 100644 Week-05/Day-31_The-Time-In-Words/README.md create mode 100644 Week-05/Day-32_Climbing-The-Leaderboard/README.md create mode 100644 Week-05/Day-33_WERTYU/README.md create mode 100644 Week-05/Day-34_Primary-Arithmetic/README.md create mode 100644 Week-05/Day-35_Dog-And-Gopher/README.md create mode 100644 Week-06/Day-36_LCD-Display/README.md create mode 100644 Week-06/Day-37_Breaking-The-Records/README.md create mode 100644 Week-06/Day-38_Electronics-Shop/README.md create mode 100644 Week-06/Day-39_Halloween-Sale/README.md create mode 100644 Week-06/Day-40_Larrys-Array/README.md create mode 100644 Week-06/Day-41_Sales-By-Match/README.md create mode 100644 Week-06/Day-42_Drawing-Book/README.md create mode 100644 Week-07/Day-43_Area-Of-A-Triangle/README.md create mode 100644 Week-07/Day-44_Maximum-Edge-Of-A-Triangle/README.md create mode 100644 Week-07/Day-45_Subtract-The-Swapped-Bits-Without-Temp-Storage/README.md create mode 100644 Week-07/Day-46_Hot-Pics-Of-Danny-Devito/README.md create mode 100644 Week-07/Day-47_Zip-It/README.md create mode 100644 Week-07/Day-48_Christmas-Tree/README.md create mode 100644 Week-07/Day-49_Swimming-Pool/README.md create mode 100644 Week-08/Day-50_Tic-Tac-Toe/README.md create mode 100644 Week-08/Day-51_Asteroid-Collision/README.md create mode 100644 Week-08/Day-52_Switch-On-The-Gravity/README.md create mode 100644 Week-08/Day-53_Javelin-Parabolic-Throw/README.md create mode 100644 Week-08/Day-54_RGB-To-Hex-Color-Converter/README.md create mode 100644 Week-08/Day-55_Filter_Repeating-Character-Strings/README.md create mode 100644 Week-08/Day-56_Convert-To-Hex/README.md diff --git a/Week-05/Day-29_Traffic-Light-Checker/README.md b/Week-05/Day-29_Traffic-Light-Checker/README.md new file mode 100644 index 0000000..02bfb77 --- /dev/null +++ b/Week-05/Day-29_Traffic-Light-Checker/README.md @@ -0,0 +1,42 @@ +## Traffic Light Checker + +A three-color traffic light must switch lights in the following order: red, green, yellow, red. + +To indicate when crossing slowly without a stop is permitted, the yellow signal may be flashed. To indicate when crossing immediately after a full stop is permitted, the red signal may be flashed. + +Either flash sequence may only be started after the red light is lit and must be followed with a red. All lights are initially off. All sequences must begin a red light. Lighting any light causes all other lights to turn off. No color may be repeated: e.g., red, red is not allowed. + +## The problem + +Write a program that checks a sequence of light codes and determines if that sequence follows or violates the traffic light rules. + +Input Read from STDIN a sequence of the follow codes: R (red), Y (yellow), G (Green), P (Pause - flash red), C (Caution - flash yellow), and X (off). Each code must be separated with a space. The entire sequence is submitted by an end-of-line (e.g., pressing the Enter key.) A sequence must have no more than 15 codes in total. + +## Examples + +```text +1 - Input: R G Y R C R G Y R Output: ACCEPT +2 - Input: G Y R G Y R Output: REJECT +3 - Input: R Y G P Output: REJECT +4 - Input: R G Y Output: ERROR +5 - Input: X 8 S Output: ERROR +6 - Input: R G Y R C R P R G Y R G Y R G Y R Output: ERROR +``` + +**Explanation** +1 - Correct +2 - Doesn’t start with R +3 - Invalid sequence +4 - Undefined code +5 - Undefined Codes e.g. X is not part of the grammar +6 - The input is malformed – undefined code, too short, too long, etc + +## Contraints + +Output Write to STDOUT an evaluation of the sequence: + +- ACCEPT >> The entire input sequence meets all rules. + +- REJECT >> The input sequence violates any sequence constraint; for example G Y. + +- ERROR >> The input is malformed – undefined code, too short, too long, etc. diff --git a/Week-05/Day-30_The-Maximum-Value/README.md b/Week-05/Day-30_The-Maximum-Value/README.md new file mode 100644 index 0000000..4b73015 --- /dev/null +++ b/Week-05/Day-30_The-Maximum-Value/README.md @@ -0,0 +1,16 @@ +# The Maximum Value + +Write a function that returns the maximum possible value obtained by inserting any single digit inside the decimal representation of integer N. + +## Details + +Write a function that returns the maximum possible value obtained by inserting one single digit inside the decimal representation of integer N. + +_Example_ + +```text +Given N = 276, Digit = 3, function should return 3276 +Given N = -999, Digit = 4, function should return -4999 +Given N = 0, Digit = 3, function should return 30 +Given N = 860, Digit = 7, function should return 8760 +``` diff --git a/Week-05/Day-31_The-Time-In-Words/README.md b/Week-05/Day-31_The-Time-In-Words/README.md new file mode 100644 index 0000000..4407685 --- /dev/null +++ b/Week-05/Day-31_The-Time-In-Words/README.md @@ -0,0 +1,29 @@ +# The Time in Words + +Given the time in numerals we may convert it into words, as shown below: + +

+ The Time in Words +

+ +## Details + +At *minutes = 0*, use o' clock. For *1 <= minutes <= 30*, use past, and for *30 < minutes* use to. Note the space between the apostrophe and clock in o' clock. + +Write a **timeInWords** function which prints the time in words for the input given in the format described. +The function has the following parameters: +- **h**: an integer representing hour of the day +- **m**: an integer representing minutes after the hour + +## Constraints +- *1 <= h <= 12* +- *0 <= m < 60* + +### Examples +```text +timeInWords(5, 47) ➞ thirteen minutes to six +timeInWords(3, 00) ➞ three o' clock +timeInWords(7, 15) ➞ quarter past seven +timeInWords(5, 30) ➞ half past five +timeInWords(5, 01) ➞ one minute past five +``` diff --git a/Week-05/Day-32_Climbing-The-Leaderboard/README.md b/Week-05/Day-32_Climbing-The-Leaderboard/README.md new file mode 100644 index 0000000..500ca1f --- /dev/null +++ b/Week-05/Day-32_Climbing-The-Leaderboard/README.md @@ -0,0 +1,29 @@ +# Climbing the Leaderboard + +An arcade game player wants to climb to the top of the leaderboard and track their ranking. + +The game uses [Dense Ranking][1], so its leaderboard works like this: +- The player with the highest score is ranked number 1 on the leaderboard. +- Players who have equal scores receive the same ranking number, and the next player(s) receive the immediately following ranking number. + + +Create a function with the following input parameters, in this order: +- **rankedScores**: leaderboard scores as an integer list +- **playerScores**: the scores of the games of the player as an integer list + +Returns: +- The player's rank after each new score, as an integer list + +### Example +```text +playerRank([100, 90, 90, 80], [70, 80, 105]) ➞ [4, 3, 1] +``` + +In the above example, ranked players will have ranks **1**, **2**, **2**, and **3**, respectively. If the player's scores are **70**, **80** and **105**, their rankings after each game are **4***th*, **3***th* and **1***th*. Return **[4, 3, 1]**. + +### Additional Example +```text +playerRank([100, 90, 90, 80], [106, 107, 105]) ➞ [1, 1, 1] +``` + +[1]: https://en.wikipedia.org/wiki/Ranking#Dense_ranking_(%221223%22_ranking) \ No newline at end of file diff --git a/Week-05/Day-33_WERTYU/README.md b/Week-05/Day-33_WERTYU/README.md new file mode 100644 index 0000000..78f9481 --- /dev/null +++ b/Week-05/Day-33_WERTYU/README.md @@ -0,0 +1,27 @@ +# WERTYU + +A common typing error is to place your hands on the keyboard one row to the right of the correct position. Then “Q” is typed as “W” and “J” is typed as “K” and so on. + +

+ Keyboard +

+ +Your task is to decode a message typed in this manner. + +## Details + +Write a **keyboardMistakeFix** function which prints the corret string for the input given. +The function has the following parameter: +- **input**: may contain digits, spaces, uppercaseletters (except “Q”, “A”, “Z”), or punctuation shown above [except back-quote (‘)]. + +Returns: +- You are to replace each letter or punctuation symbol by the one immediately to its lefton the QWERTY keyboard shown above. Spaces in the input should be echoed in the output. + +## Constraints +- Keys labeled with words [Tab,BackSp,Control, etc.] are not represented in the input. + + +### Example +```text +keyboardMistakeFix("O S, GOMR YPFSU/") ➞ "I AM FINE TODAY." +``` diff --git a/Week-05/Day-34_Primary-Arithmetic/README.md b/Week-05/Day-34_Primary-Arithmetic/README.md new file mode 100644 index 0000000..95b5cd2 --- /dev/null +++ b/Week-05/Day-34_Primary-Arithmetic/README.md @@ -0,0 +1,30 @@ +# Primary Arithmetic + +Children are taught to add multi-digit numbers from right to left, one digit at a time. +Many find the “carry” operation, wherea 1 is carried from one digit position to the next, to be a significant challenge. + +Your job is to count the number of carry operations for each of a set of addition problems so that educators may assess their difficulty. + +## Details + +Write a **carryOperations** function. +The function has the following parameters: +- **num1**: first integer to sum +- **num2**: second integer to sum + +Returns: +- Number of carry operations as an integer + +## Constraints +- Input parameters are unsigned integers less than 10 digits. + + +### Example +```text +carryOperations(123, 456) ➞ 0 +carryOperations(555, 555) ➞ 3 +carryOperations(123, 594) ➞ 1 +carryOperations(555, 545) ➞ 3 +carryOperations(1, 20000) ➞ 0 +carryOperations(1, 2) ➞ 0 +``` diff --git a/Week-05/Day-35_Dog-And-Gopher/README.md b/Week-05/Day-35_Dog-And-Gopher/README.md new file mode 100644 index 0000000..d7846cb --- /dev/null +++ b/Week-05/Day-35_Dog-And-Gopher/README.md @@ -0,0 +1,92 @@ +# Dog and Gopher + +A large field has a dog and a gopher. + +The dog wants to eat the gopher, while the gopher wants to run to safety through one of several gopher holes dug in the surface ofthe field. + +Neither the dog nor the gopher is a math major; however, neither is entirely stupid. + +The gopher decides on a particular gopher hole and heads for that hole in a straight line at a fixed speed. The dog, which is very good at reading body language, anticipates which hole the gopher has chosen. + +The dog heads at double the speed of the gopher to the hole. If the dog reaches the hole first, the gopher gets gobbled up; otherwise, the gopher escapes. + +## Objective +You have been retained by the gopher to **select a hole through which it can escape**, if such a hole exists, by **reading a file with a variable set of scenarios**. + +Some sample files are already provided to help the tests: +```text +assets/day-35_sample_1_valid.txt +assets/day-35_sample_2_valid.txt +assets/day-35_sample_3_invalid.txt +assets/day-35_sample_4_invalid.txt +assets/day-35_sample_5_invalid.txt +assets/day-35_sample_6_invalid.txt +``` + +Write a **gopherEscapePlan** function which returns a list/array of strings, with one entry per result of each set of scenarios. + +The function has one input parameter: +- **filename**: a string representing the path to the file + +The function returns: +- List/array of strings, with one entry per result of each set of scenarios or a BAD FILE! message if the file is invalid or inaccessible. See section **Output** below for more details. + +## Input file format + +The input file contains several sets of input. The first line of each set contains **one integer** and **four floating point numbers**. + +The integer **n** denotes how many holes are in the set. +The **four floating point numbers** denote the **(x, y) coordinates of the gopher** followed by the **(x, y) coordinates of the dog**. + +The subsequent **n** lines of input each contain **two floating point numbers**: the **(x, y) coordinates of a gopher hole**. All distances are in meters to the nearest millimeter. + +The input is **terminated by end of file** and **there is a blank line between two consecutive sets**. + +The input file is still considered **valid** if there is more than one **blank line between two consecutive sets** or if there are **blank lines at the beginning of the file** as well. + +## Output +Return a single line for *each set* of input. + +If the gopher can escape, the output line should read, _“The gopher can escape through the hole at (x, y).”_ while identifying the appropriate hole to the nearest millimeter. + +Otherwise, the output line should read, _“The gopher cannot escape.”_ + +If the gopher can escape through more than one hole, report the one that appears **first in the input**. + +if the file is **inaccessible or invalid** (for example, **number of holes** found don't match **n** or there are more or less fields found on a line in the file), return just an **["BAD FILE!"]**. + + + +## Constraints +There are at most 1,000 gopher holes in a set of input and all coordinates range between –10,000 and +10,000. + + + +### Example of input file +```text +1.000 1.000 2.000 2.000 +1.500 1.500 + +2 2.000 2.000 1.000 1.000 +1.500 1.500 +2.500 2.500 +``` + +### Expected return +```text +["The gopher cannot escape.", "The gopher can escape through the hole at (2.500,2.500)."] +``` + + +### Examples with the provided sample files avaliable at 'assets' folder +```text +gopherEscapePlan("...assets/day-35_sample_1_valid.txt") ➞ ["The gopher cannot escape.", "The gopher can escape through the hole at (2.500000,2.500000)."] + +gopherEscapePlan("...assets/day-35_sample_2_valid.txt") ➞ ["The gopher cannot escape.", "The gopher can escape through the hole at (2.500000,2.500000)."] + +gopherEscapePlan("...assets/day-35_sample_3_invalid.txt") ➞ ["BAD FILE!"] + +gopherEscapePlan("...assets/day-35_sample_4_invalid.txt") ➞ ["BAD FILE!"] + +gopherEscapePlan("...assets/day-35_sample_5_invalid.txt") ➞ ["BAD FILE!"] +``` \ No newline at end of file diff --git a/Week-06/Day-36_LCD-Display/README.md b/Week-06/Day-36_LCD-Display/README.md new file mode 100644 index 0000000..c5a9bc0 --- /dev/null +++ b/Week-06/Day-36_LCD-Display/README.md @@ -0,0 +1,24 @@ +# LCD Display + +A friend of yours has just bought a new computer. Before this, the most powerful machine he ever used was a pocket calculator. He is a little disappointed because he liked the LCD display of his calculator more than the screen on his new computer! To make him happy, write a program that prints numbers in LCD display style. + +## Objective +Write a **toLCD** function which returns a LCD display representation as a string. + +The function has one input parameter: +- **n**: integer to be converted to LCD display +- **s**: size as number of signs + +The function returns: +- LCD display representation as a string + +Print the number specified in the input in an LCD display-style using s “-” signs for the horizontal segments ands “|” signs for the vertical ones. Each digit occupies exactly s + 2 columns and 2s + 3 rows. + +Be sure to fill all the white space occupied by the digits with blanks, including the last digit. There must be exactly one column of blanks between two digits. + +### Examples for input (n=12345, s=2) and (n=67890, s=3): +

+ LCD +

+ + diff --git a/Week-06/Day-37_Breaking-The-Records/README.md b/Week-06/Day-37_Breaking-The-Records/README.md new file mode 100644 index 0000000..e724ac1 --- /dev/null +++ b/Week-06/Day-37_Breaking-The-Records/README.md @@ -0,0 +1,28 @@ +# Breaking the Records + +Maria plays college basketball and wants to go pro. Each season she maintains a record of her play. She tabulates the number of times she breaks her season record for most points and least points in a game. Points scored in the first game establish her record for the season, and she begins counting from there. + +For example, assume her scores for the season are represented in the array *scores = [12, 24, 10, 24]*. Scores are in the same order as the games played. She would tabulate her results as follows: + +```text + Count +Game Score Minimum Maximum Min Max + 0 12 12 12 0 0 + 1 24 12 24 0 1 + 2 10 10 24 1 1 + 3 24 10 24 1 1 +``` + +## Objective +Given the scores for a season, find and print the number of times Maria breaks her records for most and least points scored during the season. + +Create a **breakingRecords** function. It must return an integer array containing the numbers of times she broke her records. Index 0 is for breaking most points records, and index 1 is for breaking least points records. + +**breakingRecords** has the following parameter(s): + scores: an array of integers + + +## Example +```text +breakingRecords([10,5,20,20,4,5,2,25,1]) ➞ [2,4] +``` \ No newline at end of file diff --git a/Week-06/Day-38_Electronics-Shop/README.md b/Week-06/Day-38_Electronics-Shop/README.md new file mode 100644 index 0000000..120f926 --- /dev/null +++ b/Week-06/Day-38_Electronics-Shop/README.md @@ -0,0 +1,19 @@ +# Electronics Shop + +A person wants to determine the most expensive computer keyboard and USB drive that can be purchased with a give budget. Given price lists for keyboards and USB drives and a budget, find the cost to buy them. If it is not possible to buy both items, return -1. + +## Objective +Create a **getMoneySpent** function, it has the following parameter(s): +- int keyboards[]: the keyboard prices +- int drives[]: the drive prices +- int b: the budget + +Returns +- int: the maximum that can be spent, or -1 if it is not possible to buy both items. + +## Example +```text +getMoneySpent([40,50,60],[5,8,12],60) ➞ 58 +``` + +In the example above, the person can buy a *40 keyboard + 12 USB drive = 52* or a *50 keyboard + 8 USB drive = 58*. Choose the latter as the more expensive option and return *58*. \ No newline at end of file diff --git a/Week-06/Day-39_Halloween-Sale/README.md b/Week-06/Day-39_Halloween-Sale/README.md new file mode 100644 index 0000000..a35676a --- /dev/null +++ b/Week-06/Day-39_Halloween-Sale/README.md @@ -0,0 +1,22 @@ +# Halloween Sale + +You wish to buy video games from the famous online video game store Mist. + +Usually, all games are sold at the same price,*p* dollars. However, they are planning to have the seasonal Halloween Sale next month in which you can buy games at a cheaper price. Specifically, the first game you buy during the sale will be sold at *p* dollars, but every subsequent game you buy will be sold at exactly *d* dollars less than the cost of the previous one you bought. This will continue until the cost becomes less than or equal to *m* dollars, after which every game you buy will cost *m* dollars each. + +You have *s* dollars in your Mist wallet. How many games can you buy during the Halloween Sale? + +## Objective +Create a **howManyGames** function, it has the following parameter(s): +- int p Normal price of games +- int d The discount +- int m Minimium vale per game +- int s The budget + +Returns +- int: the number of games you can buy + +## Example +```text +howManyGames(20, 3, 6, 80) ➞ 6 +``` \ No newline at end of file diff --git a/Week-06/Day-40_Larrys-Array/README.md b/Week-06/Day-40_Larrys-Array/README.md new file mode 100644 index 0000000..2f4fa8d --- /dev/null +++ b/Week-06/Day-40_Larrys-Array/README.md @@ -0,0 +1,21 @@ +# Larry's Array + +Larry has been given a permutation of a sequence of natural numbers incrementing from 1 as an array. + +He must determine whether the array can be sorted using the following operation any number of times: +- Choose any **3** consecutive indices and rotate their elements in such a way that **ABC ➞ BCA ➞ CAB ➞ ABC**. + +## Example +```textV +A = {1, 6, 5, 2, 4, 3} + +A rotate +[1,6,5,2,4,3] [6,5,2] +[1,5,2,6,4,3] [5,2,6] +[1,2,6,5,4,3] [5,4,3] +[1,2,6,3,5,4] [6,3,5] +[1,2,3,5,6,4] [5,6,4] +[1,2,3,4,5,6] + +true +``` \ No newline at end of file diff --git a/Week-06/Day-41_Sales-By-Match/README.md b/Week-06/Day-41_Sales-By-Match/README.md new file mode 100644 index 0000000..2d5808f --- /dev/null +++ b/Week-06/Day-41_Sales-By-Match/README.md @@ -0,0 +1,7 @@ +# Sales by Match + +Alex works at a clothing store. There is a large pile of socks that must be paired by color for sale. Given **an array of integers representing the color of each sock**, determine **how many pairs of socks with matching colors there are**. + +For example, there are *n = 7* socks with colors *ar = [1,2,1,2,1,3,2]*. There is one pair of color **1** and one of color **2**. + +The number of pairs is **2**. \ No newline at end of file diff --git a/Week-06/Day-42_Drawing-Book/README.md b/Week-06/Day-42_Drawing-Book/README.md new file mode 100644 index 0000000..a363654 --- /dev/null +++ b/Week-06/Day-42_Drawing-Book/README.md @@ -0,0 +1,25 @@ +# Drawing Book + +A teacher asks the class to open their books to a page number. A student can either start turning pages from the front of the book or from the back of the book. They always turn pages one at a time. When they open the book, page *1* is always on the right side: + +

+ page1 +

+ +When they flip page *1* , they see pages *2* and *3*. Each page except the last page will always be printed on both sides. The last page may only be printed on the front, given the length of the book. + +If the book is *n* pages long, and a student wants to turn to page *p*, **what is the minimum number of pages to turn?** They can start at the beginning or the end of the book. + +Given *n* and *p*, find and return the minimum number of pages that must be turned in order to arrive at page *p*. + +## Example +```text +Considering n = 5 and p = 3: + +minPages(5, 3) ➞ 1 +``` +

+ page1 +

+ +Using the diagram above, if the student wants to get to page *3*, they open the book to page *1*, flip *1* page and they are on the correct page. If they open the book to the last page, page *5*, they turn *1* page and are at the correct page. Return *1*. diff --git a/Week-07/Day-43_Area-Of-A-Triangle/README.md b/Week-07/Day-43_Area-Of-A-Triangle/README.md new file mode 100644 index 0000000..bc99c2c --- /dev/null +++ b/Week-07/Day-43_Area-Of-A-Triangle/README.md @@ -0,0 +1,13 @@ +# Area of a Triangle + +Write a function that takes the base and height of a triangle and return its area. + +## Example +```text +triArea(3, 2) ➞ 3 +triArea(5, 4) ➞ 10 +triArea(7, 4) ➞ 14 +triArea(10, 10) ➞ 50 +triArea(12, 11) ➞ 66 +triArea(0, 60) ➞ 0 +``` diff --git a/Week-07/Day-44_Maximum-Edge-Of-A-Triangle/README.md b/Week-07/Day-44_Maximum-Edge-Of-A-Triangle/README.md new file mode 100644 index 0000000..f9495f8 --- /dev/null +++ b/Week-07/Day-44_Maximum-Edge-Of-A-Triangle/README.md @@ -0,0 +1,13 @@ +# Maximum Edge of a Triangle + +Create a function that finds the maximum range of a triangle's third edge, where the side lengths are all integers. + +## Example +```text +nextEdge(8, 10) ➞ 17 +nextEdge(5, 7) ➞ 11 +nextEdge(9, 2) ➞ 10 +``` + +## Constraints +- The side lengths of the triangle are positive integers. \ No newline at end of file diff --git a/Week-07/Day-45_Subtract-The-Swapped-Bits-Without-Temp-Storage/README.md b/Week-07/Day-45_Subtract-The-Swapped-Bits-Without-Temp-Storage/README.md new file mode 100644 index 0000000..dc0f715 --- /dev/null +++ b/Week-07/Day-45_Subtract-The-Swapped-Bits-Without-Temp-Storage/README.md @@ -0,0 +1,26 @@ +# Subtract the swapped bits without temp storage + +This is more informational than a challenge. You can actually switch 2 variables with the XOR operation ^. XOR works with two arguments. It turns both arguments in their binary representation, and for each bit, returns 1 if they are different, 0 otherwise. + +Create a function to swap int variables *X* and *Y* _without the use of an additional temporary storage variable_ using _only_ [*XOR bitwise operations*][1]. + +## Output +- Return the *SUBTRACTION of swapped numbers* by [*XOR bitwise operations*][1]. + +_Example_ + +```text +XOR(10, 41) ➞ 31 +XOR(69, 420) ➞ 351 +XOR(12345, 890412) ➞ 878067 +XOR(2, 1) ➞ -1 +``` + +## Notes +- The swap operation needs to be done _without the use of an additional temporary storage variable_, using _only_ [*XOR bitwise operations*][1]. + +## Constraints +- The input numbers *X* and *Y* are positive integers. +- The input numbers *X* and *Y* are different from each other. + +[1]: https://en.wikipedia.org/wiki/Bitwise_operation#XOR \ No newline at end of file diff --git a/Week-07/Day-46_Hot-Pics-Of-Danny-Devito/README.md b/Week-07/Day-46_Hot-Pics-Of-Danny-Devito/README.md new file mode 100644 index 0000000..39cc835 --- /dev/null +++ b/Week-07/Day-46_Hot-Pics-Of-Danny-Devito/README.md @@ -0,0 +1,21 @@ +# Hot Pics of Danny DeVito! + +I'm trying to watch some lectures to study for my next exam but I keep getting distracted by meme compilations, vine compilations, anime, and more on my favorite video platform. + +Your job is to help me create a function that takes a string and checks to see if it contains the following words or phrases: + +- "anime" +- "meme" +- "vines" +- "roasts" +- "Danny DeVito" + +## Output +- If it does, return "NO!". Otherwise, return "Safe watching!". + +## Example +```text +preventDistractions("vines that butter my eggroll") ➞ "NO!" +preventDistractions("Hot pictures of Danny DeVito") ➞ "NO!" +preventDistractions("How to ace BC Calculus in 5 Easy Steps") ➞ "Safe watching!" +``` \ No newline at end of file diff --git a/Week-07/Day-47_Zip-It/README.md b/Week-07/Day-47_Zip-It/README.md new file mode 100644 index 0000000..da63bf9 --- /dev/null +++ b/Week-07/Day-47_Zip-It/README.md @@ -0,0 +1,23 @@ +# Zip It! + +Most data compression algorithms are pretty complex. + +But they all have in common that they are taking data that is repeating and only store it once and have a system of knowing how to uncompress them (putting the repeated segments back in place). + +## Objective +Design your own data **compress** and **uncompress** techniques. Create these two functions. + +**compress** function signature: +- input parameter _sourceFilename_ with the source filename to compress +- input parameter _targetFilename_ with the target filename compressed + +The **compress** function should generate a _targetFilename_ file, compressed. + +**uncompress** function signature: +- input parameter _sourceFilename_ with the compressed source filename +- input parameter _targetFilename_ with the target filename uncompressed + +The **compress** function should generate a _targetFilename_ file, uncompressed. + +## Notes +- It is OK if not every type of input data is capable of compression, but on the tests, it is important to garantee the generated compressed file is smaller than the original and also garantee the uncompress process, from a compressed file to its uncompressed, original version. \ No newline at end of file diff --git a/Week-07/Day-48_Christmas-Tree/README.md b/Week-07/Day-48_Christmas-Tree/README.md new file mode 100644 index 0000000..723dd5f --- /dev/null +++ b/Week-07/Day-48_Christmas-Tree/README.md @@ -0,0 +1,25 @@ +# Christmas Tree + +Write a function to create a Christmas tree based on height **h**. + +## Examples +```text +tree(1) ➞ [ + "#" +] + +tree(2) ➞ [ + " # ", + "###" +] + +tree(5) ➞ [ + " # ", + " ### ", + " ##### ", + " ####### ", + "#########" +] + +tree(0) ➞ [] +``` \ No newline at end of file diff --git a/Week-07/Day-49_Swimming-Pool/README.md b/Week-07/Day-49_Swimming-Pool/README.md new file mode 100644 index 0000000..db7f986 --- /dev/null +++ b/Week-07/Day-49_Swimming-Pool/README.md @@ -0,0 +1,49 @@ +# Swimming Pool + +Suppose a swimming pool blueprint can be represented as a 2D array, where **1**s represent the pool and **0**s represent the rest of the backyard. + +```text +[[0, 0, 0, 0, 0, 0, 0, 0], +[0, 1, 1, 1, 1, 1, 0, 0], +[0, 1, 1, 1, 1, 1, 0, 0], +[0, 1, 1, 0, 0, 0, 0, 0], +[0, 0, 0, 0, 0, 0, 0, 0]] +// Legitimate +``` + +Suppose a pool is considered legitimate if it does not touch any of the four borders in this 2D array. + +```text +[[1, 1, 0, 0, 0, 0, 0, 0], +[1, 1, 1, 1, 1, 1, 0, 0], +[0, 1, 1, 1, 1, 1, 0, 0], +[0, 0, 0, 0, 0, 0, 0, 0]] +// Illegitimate! +// The 1s are touching both the left "fence" and the upper "fence". +``` + +Create a function that returns true if the pool plan is legitimate, and false otherwise. + +## Examples +```text +isLegitimate([ + [0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 1, 1, 0, 0, 0], + [0, 1, 1, 1, 1, 1, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0] +]) ➞ true + +isLegitimate([ + [0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 1, 1, 0, 0, 0], + [0, 1, 1, 1, 1, 1, 0, 0], + [0, 0, 1, 1, 1, 0, 0, 0] +]) ➞ false + +isLegitimate([ + [0, 0, 0, 0, 0], + [0, 1, 1, 1, 0], + [0, 1, 1, 1, 0], + [0, 0, 0, 0, 0] +]) ➞ true +``` \ No newline at end of file diff --git a/Week-08/Day-50_Tic-Tac-Toe/README.md b/Week-08/Day-50_Tic-Tac-Toe/README.md new file mode 100644 index 0000000..d89d5a3 --- /dev/null +++ b/Week-08/Day-50_Tic-Tac-Toe/README.md @@ -0,0 +1,24 @@ +# Tic Tac Toe + +Create a function that takes an array of char inputs from a _Tic Tac Toe_ game. Inputs will be taken from player1 as **"X"**, player2 as **"O"**, and empty spaces as **"#"**. The program will return the winner or tie results. + +## Examples +```text +ticTacToe([ + ["X", "O", "O"], + ["O", "X", "O"], + ["O", "#", "X"] +]) ➞ "Player 1 wins" + +ticTacToe([ + ["X", "O", "O"], + ["O", "X", "O"], + ["X", "#", "O"] +]) ➞ "Player 2 wins" + +ticTacToe([ + ["X", "X", "O"], + ["O", "X", "O"], + ["X", "O", "#"] +]) ➞ "It's a Tie" +``` \ No newline at end of file diff --git a/Week-08/Day-51_Asteroid-Collision/README.md b/Week-08/Day-51_Asteroid-Collision/README.md new file mode 100644 index 0000000..db8c5cb --- /dev/null +++ b/Week-08/Day-51_Asteroid-Collision/README.md @@ -0,0 +1,31 @@ +# Asteroid Collision + +You are given an array **asteroids** of integers representing asteroids in a row. + +For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed. + +Find out the state of the **asteroids** after all collisions. If two **asteroids** meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet. + +## Examples +```text +Input: asteroids = [5,10,-5] +Output: [5,10] +Explanation: The 10 and -5 collide resulting in 10. The 5 and 10 never collide. + +Input: asteroids = [8,-8] +Output: [] +Explanation: The 8 and -8 collide exploding each other. + +Input: asteroids = [10,2,-5] +Output: [10] +Explanation: The 2 and -5 collide resulting in -5. The 10 and -5 collide resulting in 10. + +Input: asteroids = [-2,-1,1,2] +Output: [-2,-1,1,2] +Explanation: The -2 and -1 are moving left, while the 1 and 2 are moving right. Asteroids moving the same direction never meet, so no asteroids will meet each other. +``` + +## Constraints +- 1 <= asteroids <= 104 +- -1000 <= asteroids[i] <= 1000 +- asteroids[i] != 0 diff --git a/Week-08/Day-52_Switch-On-The-Gravity/README.md b/Week-08/Day-52_Switch-On-The-Gravity/README.md new file mode 100644 index 0000000..3646061 --- /dev/null +++ b/Week-08/Day-52_Switch-On-The-Gravity/README.md @@ -0,0 +1,40 @@ +# Switch on the Gravity + +Given a 2D array of some suspended blocks (represented as hastags), return another 2D array which shows the end result once gravity is switched on. + +## Examples +```text +switchGravityOn([ + ["-", "#", "#", "-"], + ["-", "-", "-", "-"], + ["-", "-", "-", "-"], + ["-", "-", "-", "-"] +]) ➞ [ + ["-", "-", "-", "-"], + ["-", "-", "-", "-"], + ["-", "-", "-", "-"], + ["-", "#", "#", "-"] +] + +switchGravityOn([ + ["-", "#", "#", "-"], + ["-", "-", "#", "-"], + ["-", "-", "-", "-"], +]) ➞ [ + ["-", "-", "-", "-"], + ["-", "-", "#", "-"], + ["-", "#", "#", "-"] +] + +switchGravityOn([ + ["-", "#", "#", "#", "#", "-"], + ["#", "-", "-", "#", "#", "-"], + ["-", "#", "-", "-", "-", "-"], + ["-", "-", "-", "-", "-", "-"] +]) ➞ [ + ["-", "-", "-", "-", "-", "-"], + ["-", "-", "-", "-", "-", "-"], + ["-", "#", "-", "#", "#", "-"], + ["#", "#", "#", "#", "#", "-"] +] +``` \ No newline at end of file diff --git a/Week-08/Day-53_Javelin-Parabolic-Throw/README.md b/Week-08/Day-53_Javelin-Parabolic-Throw/README.md new file mode 100644 index 0000000..bced478 --- /dev/null +++ b/Week-08/Day-53_Javelin-Parabolic-Throw/README.md @@ -0,0 +1,17 @@ +# Javelin Parabolic Throw + +Write a function that takes initial speed (**v** in m/s) and throw angle (**a** in degrees) and returns the maximum height and maximum range reached by javelin as a string. + +## Examples +```text +javelinThrow(36.7, 45) ➞ "Ymax=34m, Xmax=137m" + +javelinThrow(51.3, 20) ➞ "Ymax=16m, Xmax=172m" + +javelinThrow(100.1, 89) ➞ "Ymax=511m, Xmax=36m" +``` + +## Notes +- Javelin starts moving at h=0m. +- Gravitational acceleration is **g=9.81 m/s^2**. +- All results should be rounded to the nearest whole number. \ No newline at end of file diff --git a/Week-08/Day-54_RGB-To-Hex-Color-Converter/README.md b/Week-08/Day-54_RGB-To-Hex-Color-Converter/README.md new file mode 100644 index 0000000..19e86c2 --- /dev/null +++ b/Week-08/Day-54_RGB-To-Hex-Color-Converter/README.md @@ -0,0 +1,15 @@ +# RGB to Hex Color Converter + +Create a function that converts color in RGB format to Hex format. + +## Examples +```text +rgbToHex("rgb(0, 128, 192)") ➞ "#0080c0" + +rgbToHex("rgb(45, 255, 192)") ➞ "#2dffc0" + +rgbToHex("rgb(0, 0, 0)") ➞ "#000000" +``` + +## Notes +- The Hex format should be displayed in lowercase. \ No newline at end of file diff --git a/Week-08/Day-55_Filter_Repeating-Character-Strings/README.md b/Week-08/Day-55_Filter_Repeating-Character-Strings/README.md new file mode 100644 index 0000000..c74a9eb --- /dev/null +++ b/Week-08/Day-55_Filter_Repeating-Character-Strings/README.md @@ -0,0 +1,19 @@ +# Filter Repeating Character Strings + +Create a function that keeps only strings with repeating identical characters (in other words, it has a set size of 1). + +## Examples +```text +identicalFilter(["aaaaaa", "bc", "d", "eeee", "xyz"]) +➞ ["aaaaaa", "d", "eeee"] + +identicalFilter(["88", "999", "22", "545", "133"]) +➞ ["88", "999", "22"] + +identicalFilter(["xxxxo", "oxo", "xox", "ooxxoo", "oxo"]) +➞ [] +``` + +## Notes +- A string with a single character is trivially counted as a string with repeating identical characters. +- If there are no strings with repeating identical characters, return an empty array (see example #3). \ No newline at end of file diff --git a/Week-08/Day-56_Convert-To-Hex/README.md b/Week-08/Day-56_Convert-To-Hex/README.md new file mode 100644 index 0000000..10b6f23 --- /dev/null +++ b/Week-08/Day-56_Convert-To-Hex/README.md @@ -0,0 +1,16 @@ +# Convert to Hex + +Create a function that takes a strings characters as ASCII and returns each characters hexadecimal value as a string. + +## Examples +```text +toHex("hello world") ➞ "68 65 6c 6c 6f 20 77 6f 72 6c 64" + +toHex("Big Boi") ➞ "42 69 67 20 42 6f 69" + +toHex("Marty Poppinson") ➞ "4d 61 72 74 79 20 50 6f 70 70 69 6e 73 6f 6e" +``` + +## Notes +- Each byte must be seperated by a space. +- All alpha hex characters must be lowercase. \ No newline at end of file