After overwhelming responses from previous years, we present you with a new collection of algorithms to implement this December.
Each Day, Each Algorithm ;)
Finish them all to get a certificate :)
Send a pull request only after completing all 31 algorithms.
Please submit all PRs on or before January 15th 11:59 PM IST.
We have a small collection of algorithms, one for every day of the month. Scroll down to take a look at them.
All you need to do is fork this repository, implement all 31 algorithms and send a pull request over to us.
Check out our FAQ for more information.
- December 1 - William Butcher's Mission
- December 2 - The Secret Language
- December 3 - Minesweeper
- December 4 - Industry
- December 5 - Donât let Mason misspend!
- December 6 - Swapped
- December 7 - Word Map
- December 8 - Aptitude Check!
- December 9 - Kochouseph Konundrum!
- FAQ
The mission of William Butcher and his crew is to free the US from the control of Supes. The Supes are seeking to destabilize the country by infiltrating the military in an effort to influence the administration.
A refugee in the United States from Asia, a Supe, was able to get away from the concentration camps. A crew member who was originally from Spain had an unplanned encounter with them and sought to make up with her despite having trouble understanding her when she tried to speak with the crew.
After careful analysis, MM discovered that she had employed a string of Hexadecimal characters and digits.
Design an algorithm to help the crew fully comprehend her hints.
Input:
1
{ 56, 6F, 75, 67, 68, 74}
Output: Vought
Input:
2
{ 49, 6E, 76, 61, 64, 65}
{4D, 69, 6C, 69, 74, 61, 72, 79}
Output:
Invade
Military
The first line of input will specify the number of words (n). The subsequent 'n' lines will specify the word to be translated.
Leonard and Sheldon are the best of friends. They know each other so well that they even developed their own language to exchange secret messages. However, they have recently made a new friend, Raj, who has difficulty understanding the two when they communicate in their language.
Leonard and Sheldonâs language is similar to Pig Latin. Their unique language consists of usual English words transformed by shifting the first two letters in a word to the end and adding a suffix 'ae'.
Help Raj translate and decode his friends' secret messages.
Input: kipediawiae
Output: wikipedia
Input: ammargrae
Output: grammar
- References
Consider a minefield made up of # and -, where each hash (#) represents a mine and each dash (-) represents a mine-free spot. Display the minefield where each dash is replaced by the number of mines immediately adjacent to the spot (horizontally, vertically, and diagonally).
Input:
5
["-", "-", "-", "-", "-"],
["-", "-", "-", "-", "-"],
["-", "-", "#", "-", "-"],
["-", "-", "-", "-", "-"],
["-", "-", "-", "-", "-"]
Output:
["0", "0", "0", "0", "0"],
["0", "1", "1", "1", "0"],
["0", "1", "#", "1", "0"],
["0", "1", "1", "1", "0"],
["0", "0", "0", "0", "0"],
Input:
5
["-", "#", "-", "-", "#"],
["-", "-", "-", "-", "-"],
["-", "-", "#", "-", "-"],
["-", "#", "-", "-", "#"],
["-", "#", "-", "-", "#"]
Output:
["1", "#", "1", "1", "#"],
["1", "2", "2", "2", "1"],
["1", "2", "#", "2", "1"],
["2", "#", "3", "3", "#"],
["2", "#", "2", "2", "#"]
The first line of input shows the number of rows and columns of the minefield (2D array).
The next line(s) of input show the minefield with the mines and the mine-free spots.
["0", "0", "0", "0", "0"],
["0", "1", "1", "1", "0"],
["0", "1", "#", "1", "0"],
["0", "1", "1", "1", "0"],
["0", "0", "0", "0", "0"],
The output should contain the arrays of digits showing number of mines immediately adjacent (horizontally, vertically and diagonally) to a given position in the array.
- References
Harper is a graduate at a bank called Pierpoint, the first assignment given to her by her boss, Eric, is to analyse the stock market rise and fall for a given set of stock market change values for n days. She must submit a report to Eric highlighting the period of time when the company should sell to maximise their profit, she must also mention the profit value.
Given a set of values, help Harper gather the necessary data for her report.
Input:
No. of days: 5
Given stock market change values: { 5,4,-1,7,8}
Output:
Profit Value: 23
Proposed days to sell: Day: 1 to Day: 5
Stock market Change Values: {5,4,-1,7,8}
Input:
No. of Days:19
Given stock market change values: { 5,-4,12,-2, -5, 6, -2,-3, 1, 5, -6,-11,7,-31,9,2,-3,8,-5 }
Output:
Profit Value: 16
Proposed days to sell: Day: 15 to Day: 18
Stock market Change Values: {9, 2, -3, 8}
The first line of input is the number of days Harper is going to consider for her analysis.
The second line of input is the stock market change values for those given days.
In order to find the best period of time to sell in order to maximise profit,
Harper must find the maximum sum of all the stock change values in every possible subset of days from the given set.
In the given sample input, it is found that out of all the subsets obtained, the one having the maximum sum was the entire set as a whole.
And thus, the company will be able to make maximum profit if they sell on all the days in that given period of time.
MASON is a motoring enthusiast and he owns a sports bike . With the price of petrol going up and down in a pattern , MASON is worried whether his salary would be sufficient to meet his needs apart from fueling his bike . So he decides to calculate how much he spends on fueling his bike per month. Help MASON calculate his fuel expenditure. If he spends more than 10 PERCENTAGE of his INCOME give him a warning message reading âEXPENDITURE EXCEEDING LIMITâ
-
MASON fuels his bike twice a day .
-
The PRICE of the fuel is x/l initially.
-
Every third day the price goes up by 3 rupees .
-
Every fifth day the price goes down by 2 rupees .
-
On the other days the price of the fuel remains x/l.
-
Help him to calculate his expense for a period of one month (31DAYS) .
-
Check whether the expenditure is more than 10 percent of his income .
-
His income is 50,000 rupees per month.
Input:
fuel_price=75
Output:
Expenditure=4686
âEXPENDITURE WITHIN LIMITâ
Input:
fuel_price=97
Output:
Expenditure=6050
âEXPENDITURE EXCEEDING LIMITâ
The input is the rate of the fuel in the beginning of the month.
The output is the amount he must spend on fueling his bike.
If the expenditure exceeds 10% of the income (i.e greater than 5000), then an alert message must be displayed.
Bob and Tanika are best friends. They were bored so they decided to play a game. The game they chose to play involved a set of ânâ positive numbers. The player who goes first must choose a position âpâ and their turn ends with that. In the subsequent turns, the player must first subtract the value in the first position by 1 and swap it with the value in position âpâ. The players will take alternate turns and the game goes on till the value in the first position becomes 0. The player whose turn it is loses the game when the value in the first position becomes 0. Determine the winner of the game if both players play optimally and display the winner's name.
Input:
Position=3
Set of numbers: 5 4 4
Player going first: Tanika
Output:
Tanika wins the game!
Bob loses the game!
1) 5 4 4 (initial)
Tanika chooses position 3
2) 4 4 4 (bob)
5-1, swapping (5-1) with value in position 3 (4)
3) 4 4 3 (tanika)
4) 3 4 3 (bob)
5) 3 4 2 (tanika)
6) 2 4 2 (bob)
7) 2 4 1 (tanika)
8) 1 4 1 (bob)
9) 1 4 0 (tanika)
10) 0 4 0 (bob)
Since, on bob's turn the initial value at the first position is 0, he loses the game.
- References
You are given a grid made up of random characters. Given a word, your task is to determine whether the word can be constructed from the given grid.
The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once.
Input:
COMMUNICATION
Output:
Found
Input:
DOCUMENT
Output:
Not Found
Input:
MEDIATION
Output:
Found
You are required to construct the given grid in the form of a 2D array of characters.
All the characters must be either in uppercase.
The dimensions of the grid are 15x15.
The input is a single word.
The output is "Found" if the input word is found in the grid else it is "Not Found".
- References
Arshith is a pre-final year student preparing for his aptitude, technical and interview rounds as part of his placement training.
He has come across a mind-boggling problem statement that integrates a coding problem with a logical question as specified below:
In a specific language, âDEMOCRACYâ is coded as âEDOMRCCAY".
Help Arshith develop a way to translate any given word to that particular language. Compute it using any approach of programming.
Input: UNCOPYRIGHTABLE
Output: NUOCYPIRHGATLBE
Input: SPEEDRUNNER
Output: PSEERDNUENR
- References
Kochouseph Chittilappilly went to Dhruv Zplanet , a gaming space, with his friends and played a game called âGuess the Wordâ.
Rules of the game are â
Computer displays some strings on the screen and the player should pick one string / word if this word matches with the random word that the computer picks then the player is declared as Winner.
Kochouseph Chittilappillyâs friends played the game and no one won the game. This is Kochouseph Chittilappillyâs turn to play and he decided to win the game. What he observed from his friendâs game is that the computer is picking up the first string whose length is odd and is of maximum length.
Due to system failures computers sometimes cannot generate odd length words. In such cases you will lose the game irrespective of whether you guess the right word or not and it displays âbetter luck next timeâ.
Write a program to help Kochouseph win the game.
Input:
5
Hello Good Morning Welcome You
Output :
Morning
Input:
3
Go to hell
Output :
Better luck next time
The first line of input is the number of words in the given string.
The second line of input is the string of words.
The output is the word chosen by the computer.
- References
Anyone who is passionate about coding and can dedicate a little time a day for the challenge for the next 31 days.
You don't need to submit it everyday. Just submit it once you're done with all 31 algorithms.
Not a problem. While coding every day is nice, we understand that other commitments might interfere with it.
Plus its holiday season. So you don't have to solve one problem every day.
Go at your own pace. One per day or 7 a week or even all 30 in a day.
Anything! New to GoLang? Best way to practice it.
Wanna find out what all this hype about Python is? Use it!
Any and all languages are welcome.
Maybe you could try using a different language for every problem as a mini-challenge?
If you are new to Git or GitHub, check out this out GitHub
Our code ninjas are hard at work preparing the rest of the problems. Don't worry, they'll be up soon.
We have a folder for each day of the month. Simply complete your code and move the file into that folder.
Be sure to rename your file to the following format: language_username
or language_username_problemname
Some examples:
python3_exampleUser.py
c_exampleUser.c
Please do not modify any existing files in the repository.
I forked the repository but some problems were added only after that. How do I access those problems?
Not to worry! Open your nearest terminal or command prompt and navigate over to your forked repository.
Enter these commands:
git remote add upstream https://github.com/SVCE-ACM/A-December-of-Algorithms-2021.git
git fetch upstream
git merge upstream/main
If you're curious, the commands simply add a new remote called upstream that is linked to this repository. Then it 'fetches' or retrieves the contents of the repository and attempts to merge it with your progress. Note that if you've already added the upstream repository, you don't need to re-add it in the future while fetching the newer questions.
This shouldn't happen unless you modify an existing file in the repository. There's a lot of potential troubleshooting that might be needed, but the simplest thing to do is to make a copy of your code outside the repository and then clone it once again. Now repeat the steps from the answer above. Merge it and then add your code. Now proceed as usual. :)
Open up an issue on this repository and we'll do our best to help you out.