2015 Programming Contest Packet University of Evansville Problem 1: Tellurian Not many survived the end of the world. Those that did needed an efficient way to communicate over long distances. A single world language called Tellurian was developed, designed to be shorter to write in order to conserve ink and paper (all electronic communication was wiped out). Because ink and paper are such valuable resources, they can’t afford to screw up and scratch words out. Your job is to write a program that can help them write messages correctly the first time. Fortunately for you, this language is a modified version of English. The rules of Tellurian are as follows: 1. All vowels are taken out to save space. 2. The letter ‘y’ is considered a vowel and is taken out­­ except in words like ‘you,’ which otherwise contain only vowels, in which case it is left in. 3. Words that contain all vowels keep their first letter. (This means that words like ‘ I ’ and ‘a’ are left alone.) 4. All letters are made lowercase. 5. Punctuation is preserved. You may assume every sentence ends with some type of punctuation. This program must loop continuously, asking for ‘y’ or ‘Y’ to continue. (Any other input should exit the program.) Sample input/output (user input in bold ): Welcome to the Tellurian Translator! Enter a sentence to translate: We are being overrun! w r bng vrrn! Do you wish to continue? (y/n): y Enter a sentence to translate: an eye for an eye... and a tooth for a tooth. n y fr n y... nd a tth fr a tth. Do you wish to continue? (y/n): Y Enter a sentence to translate: I don’t know how long I can survive… i dn’t knw hw lng i cn srvv… Do you wish to continue? (y/n): n Problem 2 – Zombie­Human­Snake In a post­apocalyptic world, the game we know as rock­paper­scissors has become zombie­human­snake. The rules are simple; the human smashes the zombie’s brains, the snake poisons the human, and the zombie eats the snake. For this problem you must create a zombie­human­snake game so that survivors of the apocalypse will have a new game that is more fitting for the state of the world. 1. The game is to be played by a user and the computer in rounds. The computer should alternate choosing zombie­human­snake in that order for each round. 2. At the end of each round your program should print a scoreboard and prompt the user to play again. Sample Input/Output: Run 1: Welcome to Zombie­Human­Snake! User, enter your choice (Z, H, S): H Computer chooses: z User Wins!! Scoreboard: ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ User: 1 Computer: 0 Ties: 0 Do you wish to play again (Y/N)? y User, enter your choice (Z, H, S): S Computer chooses: h User Wins!! Scoreboard: ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ User: 2 Computer: 0 Ties: 0 Do you wish to play again (Y/N)? Y User, enter your choice (Z, H, S): y Invalid input, try again: Z Computer chooses: s User Wins!! Scoreboard: ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ User: 3 Computer: 0 Ties: 0 Do you wish to play again (Y/N)? r Goodbye!! Run 2: Welcome to Zombie­Human­Snake! User, enter your choice (Z, H, S): z Computer chooses: z Tie, no one wins!! Scoreboard: ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ User: 0 Computer: 0 Ties: 1 Do you wish to play again (Y/N)? y User, enter your choice (Z, H, S): S Computer chooses: h User Wins!! Scoreboard: ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ User: 1 Computer: 0 Ties: 1 Do you wish to play again (Y/N)? y User, enter your choice (Z, H, S): h Computer chooses: s Computer Wins!! Scoreboard: ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ User: 1 Computer: 1 Ties: 1 Do you wish to play again (Y/N)? Y Goodbye!! User, enter your choice (Z, H, S): h Computer chooses: z User Wins!! Scoreboard: ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ User: 2 Computer: 1 Ties: 1 Do you wish to play again (Y/N)? N Goodbye!! Problem 3 ­ Code to stop the End A country has threatened the world with destruction by using its nuclear weapons. You have been tasked with stopping the launch from happening. It has been discovered that the designer of the launching mechanism had a poor memory so he left hints for himself to remember all of the launch cancellation codes. The hints are just numbers, and the code can be determined by breaking the numbers down into the prime numbers that multiply together to get them (also known as prime factorization). Your task is to implement a program that will help crack his hints and prevent the world from being destroyed. The input will always be a positive integer and not be greater than 32767. Display each factor separately, even if it appears multiple times. The program will end when a 0 is entered. Example Runs (user input in bold): Enter the hint for the cancellation code: 16384 2*2*2*2*2*2*2*2*2*2*2*2*2*2 Enter the hint for the cancellation code: 35694 2*3*3*3*661 Enter the hint for the cancellation code: 2233 7*11*29 Enter the hint for the cancellation code: 0 Problem 4: Survival cannon. Hello survivors, You are the last programmers left on this team and as you know we recently completed the design of the air cannon for taking out the enemy. However, a flaw was discovered in the cannon, it can only fire at a speed of 200 feet per second. Fortunately, the cannon can be adjusted to any angle vertically and horizontally by the computer. Your task is to write a program for the targeting computer that will aim it at the target. For now, just output the angles in degrees to the console for debugging. Here is some stuff you should know to help you for this task: The targets will be listed as coordinate on a cartesian plane with the air cannon being at the origin. East and west corresponding to the x on this plane, and North and South corresponding to the y. Be aware, our foes can come from all sides. The horizontal angle is the angle against the x axis of the Cartesian plane. In our case, the cannon focuses on the East at angle zero. That angle can be between ­180 and 180 degrees. With respect to the vertical angle, I am referring to the angle with respect to the cannon base the cannon is firing. That angle can only be between 0 and 90 degrees. The horizontal angle can be determined using the definition of sine and cosine. That is the sine of an angle is equal to the Northerly component divided by the distance from the origin, and the cosine is the Eastern or Western component divided by the distance from the origin. Remember, while every angle will have only one sine and cosine, every value of sine and every value of cosine have multiple angles they can correspond to, so you might need both to get the actual angle. The two in equation forms sin(v)=y/d cos(v)=x/d where y is the vertical component (in this case how far northerly the target is from us), and x is the horizontal component (in this case how far easterly the target is from us), and d is the distance from the target the cannon is. In case you forgot, you can use the distance formula to calculate the distance. √ d= (Δx)2 + (Δy)2 where d is the distance Δx is the change in x, and Δy is the change in y (since the distance is from the origin, the equation simplifies to have it be simply be x and y) Your programming toolkit has inverse sine and cosine functions usually under the math library and usually in radians rather than degrees. Also, the functions are often called asin or acos. If your toolkit uses radians, you will have to convert the measurements. To do the conversion, multiply by 180 and divide by pi. d=180*r/π Where d is the angle in degrees and r is the angle in radians. The distance a projectile will go once launched out of the cannon is determined by this equation. (If you remember this equation from a physics course, the projectile has no air resistance for optimal destruction of our foes, and the cannon is hidden underground with the firing mechanism always at ground level.) 2 d=v (sin(2h))/(2*g) where d is the distance between the points of launch and landing, v is the speed it is being launched at (200 feet per second), h is the angle it is being launched at, and g is the acceleration due to gravity (32.2 feet per second squared) Note: there are usually two valid angles. We would prefer the higher one as that tends to stun our foes more. The other valid angle that will return the same distance is the one that will add with it to get 90 degrees or π/2. In equation form: a+b=π/2 or 90° Where a and b are the angles that return the correct distance. If either angle cannot be calculated, print out an error. Diagrams for visualizing the problem A simplified representation of the horizontal angle firing with the curved line representing the angle. The axes are represented by the thick lines. The origin (and the cannon) are represented using the thick dot. A target at 200,200 is represented (the gridelines are a hundred feet apart), and the horizontal angle in this case is 45 Representation of vertical angle firing system. Targeting program, put your coordinate in 0,40000 Target is too far away. Targeting program, put your coordinate in 200,200 Vertical Angle: 76.455410647552 Horizontal Angle: 45.0000000000 Targeting program, put your coordinate in 400,400 Vertical Angle: 57.195153531234 Horizontal Angle: 45.0000000000 Targeting program, put your coordinate in 0,0 Are you crazy?! Problem 5: Supplies Map After a tsunami wiped out your city, the levees broke and the entire metropolis remains underwater. Since there’s no hope of ever bailing the city out, the survivors have constructed a series of makeshift bridges between the emergent skyscrapers. These bridges are precarious at best, but they must be crossed in order to navigate between shelter and the storehouses where you must barter for supplies. In order to navigate the bridges, you have come up with a program that will help you keep track of where you need to go to get supplies. You want to be sure of your directions before you head out, because sometimes a rickety bridge will collapse after you cross it! Luckily, the closest storehouse is no more than 6 blocks from a shelter, so you will only need a 6x6 grid to represent a map. You decide to represent your starting point, a shelter, with an ‘S’; water with a dash (‘­’); safe bridges with a ‘B’; weak bridges with a ‘W’; skyscraper roofs with an asterisk (‘*’); and your goal, a storehouse, with an ‘X’. You will need to enter in a string of these characters at the beginning of the simulation to represent your map, then print out what your map looks like, with one space between each character. After determining your map, you will need to enter the path you want to take. This path will be a string of characters representing a series of ups, downs, lefts, and rights (symbolized by ‘u’ ‘d’ ‘l’ and ‘r’ respectively). Starting at the shelter, you should test a path so you’ll know if you can make it to the storehouse safely. You may assume that you’ll never try to go off the edge of the map. If you ever land on a space containing a ‘­’, this path will cause you to fall into the water and drown, so you should print out a message telling you not to take that path. After crossing a weak bridge, it collapses, so the space should become water. Remember, you are only testing paths, not actually taking them, so when you test another path, the weak bridges should be restored for each test. If you make it to the storehouse, it means that is a safe route to take to get the supplies, and the program should let you know. Otherwise, the path is not a route to the storehouse, and you’ll end up running low on supplies if you don’t find another path. The program should loop so you can test several possible paths. If you want to navigate to a different storehouse with a new map, you should quit (by entering “q”) and restart the program. Example runs (user input in bold): Enter a grid from left to right, top to bottom, in one line: SB*­­­­­W­­*­­*­­­X­*B*­B­­­W­*B*B*­ Here is your map: S B * ­ ­ ­ ­ ­ W ­ ­ * ­ ­ * ­ ­ ­ X ­ * B * ­ B ­ ­ ­ W ­ * B * B * ­ Enter a route to try: rrr Danger! Don’t take that path, or you’ll drown. Enter a route to try: rrdd You didn’t find the storehouse. Try another path before you run out of supplies. Enter a route to try: rrddu Danger! Don’t take that path, or you’ll drown. Enter a route to try: rrdddrrddlllluu You’re able to stock up on supplies! Now to find some shelter… Enter a route to try: q Problem 6 Doomsday Clock In 1947 a group of atomic scientists introduced the Doomsday Clock as a way to measure how close humanity is to nuclear annihilation. The clock is periodically updated to reflect the current state of the world. The scientists are getting too busy with their research to keep resetting the clock. Your job is to write a program that will reset the clock for them. To help you out they developed an algorithm to set the clock. Because humanity is so close to destruction, all times will be between 11 pm and midnight so hours may be excluded. This formula will calculate only the minutes. New Time = Current Time + (Change in nuclear powers % (60 ­ current time) Inputs will have the following format: CurrentTime ChangeInNuclearPowers An input of 0 0 should stop the program. Sample input/output Welcome to the Doomsday Clock Calculator! Please input the current time and change in nuclear powers. 56 5 New Time: 57 Please input the current time and change in nuclear powers. 48 10 New Time: 58 Please input the current time and change in nuclear powers. 58 1 New Time: 59 Please input the current time and change in nuclear powers. 53 7 New Time: 53 Please input the current time and change in nuclear powers. 50 25 New Time: 55 Please input the current time and change in nuclear powers. 43 4 New Time: 47 Please input the current time and change in nuclear powers. 46 15 New Time: 47 Please input the current time and change in nuclear powers. 52 5 New Time: 57 Please input the current time and change in nuclear powers. 0 0 Goodbye! Practice Problem: Zombies Never Die BREAKING NEWS ­ Fibonacci Zombies Take Over the World EVANSVILLE – At exactly midnight on the day of Halloween, reality surpassed the boldest of fantasies to lead to the end of the world as we know it. A phenomenal conflagration of lightning over Vanderburgh County brought back to life the corpse of recently deceased Frank Bonacci, a former breeder of rabbits in Southern Indiana. Exactly one hour later, the bemusement turned into horror when late Mr. Bonacci attacked and massacred Fox News reporter Barry Longnose, who had rushed in to cover the story. At 2am, while Bonacci murdered another passerby (Chinese tourist R. Tian), Longnose stirred back to life amidst the bewildered paramedics. Sure enough, at 3am Bonacci and Longnose each perpetrated another murder, and Mr. Tian rose from the dead. Are we facing an unstoppable epidemic? “An exemplary Fibonacci pattern post­life cycle” commented Professor Don Morse, a zombieologist at UE. “Fibonacci zombies kill one man every hour, on the hour, with incredible precision. A Fibonacci zombie victim awakens after one hour as a Fibonacci zombie itself, and after another hour begins its murderous activity. Zombies are immortal and unstoppable, so humanity is doomed”. The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. Your task is to write a customized Fibonacci Series generator which first prompts users to input any two integers as their first two terms. Then, the generator prints out the first 10 terms of the series. Inputs: First number, second number, and the number of terms that is showing up Output: The first 10 terms of the series Example Run (user input in bold): Custom Fibonacci Series. Enter the first number: 2 Enter the second number: 3 Your custom Fibonacci series: 2 3 5 8 13 21 34 55 89 144