Sunday 17 April 2022

IVLabs Entry Challenge

Hello Readers,

This post gives a detailed explanation of the code used in the problem and my thought process. 

Link for Question Paper 

First Answer: Mode of code - C++

Link for the code of the First Answer

My thoughts for the beginning of the code were regarding how to create a random variable. At the time of solving the problem, I didn't know that there existed a random variable. So I created my own. In chaos theory, a gravitational system of more than 3 bodies is called a random system or it is totally unpredictable unless we know its initial stage. So I applied the same theory here. The function Hidestone1 calculates the position of the hidden stone on the basis of which number turn it is right now. Hidestone2 takes this to a new level and creates a totally chaotic and non-predictable state of hiding the stone behind a specific door.

Next, the code for giving the hint is implemented. This code helps just gives the only other alternative with respect to Harry's earlier chosen door and the Hidden door from the function Verify and Hint. In case Harry's New chosen door is the same as the Hidden door, a specific door is opened based on which number the door is chosen. Next, the hint is given and the new choice is asked. With this choice, we verify if the new choice is the same as the Hidden Door. If yes a positive message is popped out. 

For testing the stay or switch strategy, we ask the user how many more turns he wishes to continue the game. Then the same code is run for that number of times. Just one important factor here is that the score of each strategy gets updated only if the user finds the correct door, and not if one strategy fails the other gets the point. This is achieved by using the function loop. loop just calculates if the point is achieved with which strategy.

Note: All the above-mentioned functions are user-defined, and are not available in the standard libraries. Also, error statements for repetitive or non-acceptable answers are also added to the code. This problem could be so efficiently solved if I had used a Hierarchy of functions and OOPs. Looking forward to any one of you making a SEPARATE branch on GitHub using OOPs. 

Second Answer: Mode of code - Python

This code was created by a friend of mine. Her LinkedIn is given below. Link for the code of the Second Answer.

The objective of the code is to create a matrix of User-defined size. And then find the required 3 character line in array horizontally, vertically or diagonally. 

The basic information required for the code is obtained from the user. Then using the pandas and NumPy library, the user-defined matrix/array is generated. Now the important part comes in when the number of inputs/ number of elements in the matrix is odd or even. Based on this, the same code is printed twice. This is important as we need to fix the number of entries by a participant, as he might change an entry any time he wants if this code is not implemented and render the code useless.

Then the code for getting the entry and the character the user wants is taken. The error codes here play an important role in making the code useful as without these, the characters might get entered wrong along with the already filled positions. Then the code for calculating the score is quite simple and the result is displayed at the end. 

The beauty of this code is that it compensates for all the mistakes users might make while giving input. A sample game is also played at the bottom of the code.

Third Answer: Mode of code - C++

Link for the Third Answer.

The single most important detail in the third code is forming a user-defined size square matrix in C++. C++ doesn't allow the size of the array to be a variable. Hence the code for doing this is made by fooling the system into believing we are using the size as constant/compile-time constants using pointers and dynamic allocations. The array essentially stores the location of 1 dimension and the value of the other dimension. While calling the array, it returns values stored inside. 

Then the array is initialized to the character 'o'. The user is asked for the inputs of the matrix. Then the code for scanning the internal matrices for 4 same corners is implemented. The interesting thing about this part of the code is that it first solves for 2X2 matrices, then for 3X3 matrices and so on till nXn matrix. The end values for the for loop play a very important role in this code as we can't exceed the number of rows and columns for the sake of scanning and the end values must be within the limit eg, if we have a 5X5 matrix and the current search is for 3X3 matrix, hence the code can't search for [5,6] element as it doesn't exist. Then if and break statements are used to avoid further calculation and just tell whether the matrix is allowed or not. 

Fourth Answer: Not being able to solve till date. 

If anyone gets the answer for this, please create a SEPARATE branch and post the code there.

Fifth Answer: Mode of code - Python

Link for the Fifth Answer.

Simple NumPy and cv codes for resizing, cropping, rotating and merging the images are implemented. I don't think there will be a problem regarding this code. If there is, please leave a message in the comments.

Sixth Answer: Mode of code - Python

Link for the Sixth Problem.

The image is resized, cropped and concatenated as a puzzle. The hardest part was how to take the image as an input for the system. I have little knowledge of CV programs and hence didn't know how to do so (I tried the code for several hours). So I tricked the system by saving the individually cropped images as files in the cloud system itself and then using them as the input. Then the files were saved in accordance with the jumbled final image so as not to give any problem to the user and hence solving the 9 tile puzzle.

An easier way would be to create 2 separate canvases and put the images over them, but as I said, I have little experience in CV and hence couldn't do it. If anyone gets the answer for this, please create a SEPARATE branch and post the code there.

Thank you for reading this post.

My links...

My GithubMy LinkedInMy Twitter and My Instagram

My Friends LinkedIn

No comments:

Post a Comment

New Learnings Part 1

Hello Readers, So this post will be about the new things/ old concepts that I learned yesterday.  1) Pointers and references. I haven't ...