Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I don\'t really expect this one to be answered... try your best.. Function Name:

ID: 664454 • Letter: I

Question

I don't really expect this one to be answered... try your best..

Function Name: templeOfTime
Inputs:
1. (double) A 1x2 vector representing a row and column
2. (char) An MxN string array representing cardinal directions
3. (double) An MxN array representing distance to travel
4. (char) An MxN string array of jumbled letters
5. (double) An MxN array of rupee values
Outputs:
1. (char) A string found after following the directions through the array of letters
2. (double) The total number of rupees collected after travelling through the array
Function Description:
In the Legend of Zelda games, it is usual to be challenged with a series of puzzles (or evil creatures) in order to advance between rooms in dungeons, find keys, and unveil treasure chests with the next dungeon weapon (or that oh so useful compass…). While in the most recent temple, Link has found a scroll infinitely more useful than the mere map other dungeons provide.
Examining the scroll, he sees a vector of two numbers; an array of the letters ‘N’, ‘S’, ‘E’, and ‘W’; an array of seemingly random integers; another array of jumbled letters, this time spanning the entire alphabet; and an array of rupee values (rupees being the form of currency in the game). Navi, Link’s fairy, gives an essential hint (“this scroll is probably useful for this dungeon”), and Link realizes that the scroll is a puzzle! It is a set of instructions to find what the dungeon’s weapon is and where it is located.
The vector of two numbers are Link’s starting coordinates in the arrays. The first array of the letters ‘N’, ‘S’, ‘E’, and ‘W’ are cardinal directions through which to traverse the arrays. The first set of numbers is the distance to travel in any given turn. The second char array is a set of jumbled letters that—when formed in the correct combination—spells the weapon that may be found in Link’s current dungeon. Finally, the last array contains values for rupees that Link picks up along the way, since there is money laying around everywhere in this dungeon.
Write a function called templeOfTime that follows the pattern given by the clues in the input cardinal direction array and travel distance array to output a string indicating the dungeon’s weapon and a double of the total number of rupees found in the dungeon. The first input is a 1x2 vector representing the starting index. This is the location of the first letter in the string array (fourth input) and where to begin in all four input arrays.
Next, using the second input (the direction array) and the third input (the distance travelled array), grab the values in each array corresponding to the current index location. The direction will be designated in the second input by ‘N’, ‘S’, ‘E’, or ‘W’ for north (up), south (down), east (right), or west (left). Find the number of steps to be taken in the third input, and travel that many spaces in the direction given. The number of steps to be taken will always be positive.

Trace through all the arrays simultaneously, using the directions and distances as a guide. Save the letter found in each step (from the array in the fourth input) into a string for the final dungeon weapon answer. Further, keep track of the total number of rupees collected along the trip—the number of rupees being an array given in the fifth input. Include the letter and rupee value found in the starting location. Stop when the direction is ‘D’ (for destination) and the number of spaces is 0.
For example:
If the inputs were the following:
[1,3] , [‘NSEW; , [4 1 1 2; , [‘ZiSh; , [ 1 5 50 1;
DEWW’] 0 1 2 18] del ‘] 10 5 5 1]
The starting index would be the first row and third column (1,3) in the fourth input (‘S’); the fifth input would give 50 rupees to start with. Then look at index (1,3) in the second input (‘E’) and in the third input (1). This gives directions to go to the index 1 to the right of the current position; this makes the updated position now (1,4), which holds ‘h’ in the fourth input and 1 rupee. Now the stored string should read ‘Sh’ and the total rupees be 51. To find the next index, look at the position (1,4) in the second and third inputs. Follow the pattern until the letter ‘D’ is found in the direction array and 0 is in the travel distance array. The output string of this example is ‘Shield’ and the total rupee amount is 76.

Explanation / Answer

window.APP = window.angular.module('main', []).controller('MainCtrl', function($scope) { var happyFunTimeAudio = new Audio("mario-kart.ogg"); var mood_music_audio = new Audio("wrong-game.ogg"); mood_music_audio.loop = true; var huzzah_audio = new Audio("fans.ogg"); var requestAnimationFrame = window.requestAnimationFrame; $scope.state = { people: [ { name: "Andy", times: [], profile_img: "img/faces/andy.png", }, { name: "James", times: [], profile_img: "img/faces/james.png", }, { name: "Sam", times: [], profile_img: "img/faces/sam.png", }, { name: "Kyle", times: [], profile_img: "img/faces/kyle.png", }, { name: "Josh", times: [], profile_img: "img/faces/josh_wolfe.png", }, { name: "Mike", times: [], profile_img: "img/faces/mike.png", }, ], gameState: 'setup', checkpoints: [ { name: "Deku Tree", img_src: "img/deku_stone.png", desc: "Pause after the Deku Tree's speech.", }, { name: "Dodongo's Cavern", img_src: "img/goron_stone.png", desc: "Pause after Darunia's speech.", }, { name: "Adult Link", img_src: "img/multi_award.png", desc: "Pause after speaking to Shiek.", }, { name: "Forest Temple", img_src: "img/Forest_Medallion.png", desc: "Pause after speaking to the Deku seed.", }, { name: "Fire Temple", img_src: "img/Fire_Medallion.png", desc: "Pause after you receive the Fire Medallion.", }, { name: "Water Temple", img_src: "img/Water_Medallion.png", desc: "Pause after talking to Shiek at Lake Hylia.", }, { name: "Shadow Temple", img_src: "img/Shadow_Medallion.png", desc: "Pause after you receive the Shadow Medallion.", }, { name: "Spirit Temple", img_src: "img/Spirit_Medallion.png", desc: "Pause after you receive the Spirit Medallion.", }, { name: "Ganon's Castle", img_src: "img/triforce.png", desc: "Hit the timer at the "The End" screen.", }, ], current_checkpoint: 0, }; $scope.addPerson = function() { $scope.state.people.push({name: "new person", times: []}); saveState(); }; $scope.save = function() { saveState(); }; $scope.deletePerson = function(index) { $scope.state.people.splice(index, 1); saveState(); }; $scope.startGame = function() { $scope.state.gameState = 'race'; saveState(); }; $scope.backToSetup = function() { $scope.state.gameState = 'setup'; saveState(); }; $scope.readyToStart = function() { if ($scope.state.gameState !== "race") return false; if (!$scope.currentCheckpoint()) return false; return !$scope.theClockIsTicking(); }; $scope.theClockIsTicking = function() { if ($scope.state.gameState !== "race") return false; if (!$scope.currentCheckpoint()) return false; if (!$scope.currentCheckpoint().start) return false; return $scope.state.people.some(function(person) { return !person.times[$scope.state.current_checkpoint]; }); }; $scope.isGameOver = function() { if ($scope.state.gameState !== "race") return false; return !$scope.currentCheckpoint(); }; $scope.currentCheckpoint = function() { return $scope.state.checkpoints[$scope.state.current_checkpoint]; }; $scope.readySetGo = function() { var checkpoint = $scope.currentCheckpoint(); // mario kart gives an 8 second count down checkpoint.start = new Date(new Date().getTime() + 8000); saveState(); happyFunTimeAudio.play(); }; $scope.personIsDone = function(person) { var checkpoint_index = $scope.state.current_checkpoint; var checkpoint = $scope.currentCheckpoint(); var end_time = new Date(); person.times[checkpoint_index] = end_time - checkpoint.start; var all_done = $scope.state.people.every(function(person) { return !!person.times[checkpoint_index]; }); if (all_done) { $scope.state.current_checkpoint += 1; } saveState(); huzzah_audio.play(); }; $scope.totalTime = function(person) { var total_time = 0; person.times.forEach(function(time) { if (time) total_time += time; }); return total_time; }; $scope.rupeesForCheckpoint = function(person, checkpoint_index) { return rupeesForSomething(person, function(person) { return person.times[checkpoint_index]; }); }; function rupeesForSomething(person, timeForPerson) { var my_time = timeForPerson(person); if (!my_time) return ""; var rupees = 0; $scope.state.people.forEach(function(other) { var their_time = timeForPerson(other); if (!their_time || my_time = -2000 && timeSinceStart < -1000; displaySet = timeSinceStart >= -1000 && timeSinceStart < 0; displayGo = timeSinceStart >= 0 && timeSinceStart < 2000; displayClock = timeSinceStart >= 0; } clock.style.display = displayClock ? "" : "none"; standby.style.display = displayStandby ? "" : "none"; ready.style.display = displayReady ? "" : "none"; set.style.display = displaySet ? "" : "none"; go.style.display = displayGo ? "" : "none"; requestAnimationFrame(animateClock); }); var save_textarea = document.getElementById("save_textarea"); var lense_of_truth = document.getElementById("lense_of_truth"); var load_state_button = document.getElementById("load_state_button"); function hideState() { save_textarea.style.display = "none"; load_state_button.style.display = "none"; lense_of_truth.innerText = "Show State"; } $scope.lenseOfTruth = function() { if (save_textarea.style.display === "none") { save_textarea.style.display = ""; load_state_button.style.display = ""; save_textarea.select(); save_textarea.focus(); lense_of_truth.innerText = "Hide State"; document.body.scrollTop = 1e10; } else { hideState(); } }; function playPauseMusic() { if ($scope.state.gameState === "setup") { mood_music_audio.play(); } else { mood_music_audio.pause(); } } $scope.loadStateFromBox = function() { var text = save_textarea.value; var state; try { state = window.angular.fromJson(text); } catch (e) { return alert(e); } loadState(state); saveState(); hideState(); }; function sortPeople() { // reorder everyone according to their wealth $scope.state.people.sort(function(person_a, person_b) { var a = $scope.totalRupees(person_a); var b = $scope.totalRupees(person_b); return ab ? -1 : 0; }); } $scope.rank = function(targetPerson) { var lastRank = -1; var lastScore = Infinity; for (var i = 0; i < $scope.state.people.length; ++i) { var person = $scope.state.people[i]; var score = $scope.totalRupees(person); if (score