Tuesday 19 April 2022

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 been able to understand this topic much. 

Pointers are datatypes that store the location of the variable/ entity rather than the value stored inside it. The key takeaways were how to declare a pointer and its values, how to change its values, its uses in arrays, basic mathematical operations on pointers, etc.

But as I haven't coded much with pointers, I haven't understood its full potential, need to work over there.

References are datatypes like pointers that store memory location rather than the value itself but differ with respect to their operations. The key difference is that when we perform any operation in pointers, the location of the variable gets changed and not the internal value itself, whereas, in references, the internal value, along with any past declarations with links to that variable gets changed together.

2) OOPs

This is one thing whose importance is realized every time I code in C++. The idea of such code reusability to such an extent is revolutionary. 

The key takeaways from my yesterday's learnings were - Getting to know basic OOPs structure, Basic terms such as encapsulation, abstraction, sub-classes, etc, how to form classes and their member functions, how to call its functions and create a new object & how to declare variables and the return type of the functions.

I wrote the following program just to have a bit of practice while learning.

Link to the code  

The idea here was to create a menu-driven program to do functions such as calculate factorials, find out if it is a prime number, etc using functions defined in a class. The major realization was that when I normally code using just the user-defined functions, I always keep some return type other than that void. Here I realized that we should use any other return type when we have to store the value in some variable or use that same value as an input in another function. We could calculate/carry out our needs just by using void. Also, I found one new thing. If variables are declared in public in class, we do not have to declare them again in main(). 

One more thing, we end the class declaration with a semicolon. I think so because when we declare a class, no memory as such is allocated like in the case of a user-defined function. So the compiler takes it as a really big statement. The better explanation which I found on StackOverflow is linked below.

StackOverflow Answer

3) Range Claus Switch Statement

Our teacher gave a practice problem that we have to make a code for giving output as grades with respect to the marks we obtain as input. So these grades had a marks range like 75-100 will get A and so on. The conditions were that we had to use less than 10 switch statements and completely avoid if-else statements.

So in the dilemma of how to write a logic/algorithm which will take input as marks and return a single integer for a range, I wrote the following program.

Link to the program

The thought process behind the logic is - We need just an output change in our range of inputs. For eg., We just need the output change from x at 75 marks to y at 76 marks. We can have as many outputs in the range itself. So for doing this I implemented that we need to shorten our number line by the exact amount the divisions are made and then assign a number to the input based on the shortened number line. So the bigger numbers like eg 100 would have a greater "points" available to itself as compared to any other number like 56. So my first division was [1,35];[36,55];[56,75];[76,100]. I ran the first 3 parts of the code on for loop for verifying my technique and looking at what output we are getting next. The technique was to first reduce the number line by 35%, i.e. reducing every number by 35%. Then for assigning points, I divided the number by 1/10th of the original number line. The same logic was applied for the next 20% and the further 20% reduction of the number line. The code would have run more efficiently if I had used double instead of int and then converted the double to int data type along with dividing the new number line by 1/10th of the previous number line. 

The only problem I further encountered was that I was getting 15 different outputs and I couldn't use more than 10 switch cases. Hence I used the same logic again, this time for range [0,15] by getting divisions [0,4];[5,7];[8,11];[12,15] for my grades. I further encountered a problem that the output wasn't changing at 8 but rather at 9. This error might be due to the real to int conversion. Hence I used a nested switch case and the problem was complete.


Thank you for reading this post.!

My GitHubMy LinkedInMy Instagram & My Twitter.

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

Saturday 16 April 2022

My first post!!

Hey readers,

So this is my very first post. I have no idea how to write a blog, haven't read one to my knowledge and to change this, this blog is created.

So lemme introduce myself. I am Atharav Jadhav. I live in Pune, India. Am currently 18 years old and am enrolled in the first year of my college. My college is Visvesvaraya National Institute of Technology or in preferable terms VNIT. The degree that I am going to achieve is B.Tech in Computer Science. The rest of the details you can get through my LinkedIn.

The purpose of this blog is to maintain a journal I guess, to record my progress in measurable terms in how close I have come to achieving recognizable success in Computer Science.

So this is my past experience till now --

1) I know basic OOPs structures and their uses in C++ and Python, but I haven't tried any fancy codes yet. Yes, I am on Leetcode and all those sites, but am currently just revising my concepts. 2 weeks for that from now.

2) I know how to code in JAVA, I mean I am currently reading a book, but I don't yet know how to code in JAVA yet.

3) I know how to code in C.

4) I know how to make a basic website in HTML.

5) I know how to code in the Hexadecimal language of the processors 8085 and 8086.

6) I know how to enter basic data in Mongo DB.

My other achievements till now are on LinkedIn. The achievements from starting college till now (about 6 months) are -

1) Trying to get into the robotics club (IVLabs) of our college. The opening rounds question paper and their code will be in my next post itself. 

2) I have won a competition called Chamber of Commerce organized by our college's Entrepreneurship club (ECell). In that competition, we were given a successful company and we had to pitch it to the judges as if it is a startup in today's date. I got Nvidia as the company and won the first prize.

3) I play chess (rapid rating 1002) and basketball (district level) and love cycling.

4) I love astronomy, reading books and listening to music and a bit of politics. I don't sing or dance or cook, but can criticize and appreciate all the above 3 skills.

And to prove that I am a human - I still don't know how to type with 10 fingers, I still don't know how to cut my own nails and I care way too much about Nature.

My laptop specifications are - Dell Inspirion 14 2in1, 16 Gb Ram, 512 Gb SSD, intel i7 11th Gen processor and Intel Iris Xe Graphics.

So this was my basic introduction. Looking forward to sharing with you all my coding adventures as promised. Till then Peace Out!!


 My LinkedInMy GitHubMy Instagram.

PS - I have two internship offers now from a friend.

1) Developing a website for catalogues of tools and machines.

2) Building an AI for equity trading (Yes, I study that too along with FX Trading).

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 ...