So, I have this assessment where I’m required to solve a bunch of programming questions which will be marked automatically.
I have found a way to solve this question, but other people have found a different method. For example,
Define a function that takes 2 arguments, a location (as a tuple of x and y coordinates) and an instruction (north, south, west, east) as a string. Given the provided location, it should return the new location (as a tuple of x and y coordinates) when following the specified instruction:
North moves one step in the positive y direction
South moves one step in the negative y direction
West moves one step in the negative x direction
East moves one step in the positive x direction
If in the instruction is invalid, the old location should be returned. Use the function to determine the final position when starting from the point (-3, -5) and following the following instructions:
directions = [‘south’, ‘north’, ‘east’, ‘east’]
Assign this final position to the variable final_point.
So I am not asking for help answering the question, as I already have the solution but I would like some insight into how it would be marked.
My function calculates the final position all in 1 go given the parameter ‘directions’ instead of 1 by 1 like some other solutions do. I’m assuming if I assign the correct answer to ‘final_position’ then the computer will mark it correct regardless of my method? Assuming this is marked like in Hackerrank and Leetcode.
Thanks
I’m expecting that the computer marks the answers based on the output (comparing it to the expected output) instead of the method used in getting to the output.
>Solution :
The sites have a bunch of testcases and will run your function against them if it provides the expected answer.
If you knew the testcases in advance, you could in principle cheat by making your ‘solution’ purely a lookup table input/output.
Analyzing the method you used to arrive at the result is not done. It is in fact not doable (see also https://en.wikipedia.org/wiki/Halting_problem ).
The sites may impose other restrictions on your program like a time or memory limit.