I finally cracked Mario.c // CS50x 2016

Last month, I announced that I was going to take CS50x again and complete it this time.

I quickly watched the materials for Week 0 and Week 1. Problem Set 0 was a breeze like last time, so that took no time at all. Problem Set 1 was where I had got stuck last time, so this was where the challenge began.

pset1 had/has three parts or problems to solve:
  • Smart Water
  • Itsa Mario
  • Time for Change

The first part was a new problem which wasn't there last time but was fairly simple and took me only a few minutes.

The second problem was where the fun began. It was time to meet my old friend Mario. At first, Mario seems like a very simple program that can be easily solved using strings and for loops, but once you dive into the problem, you understand it's much more complicated than it looks.

You have to remember that C isn't great with strings and you can not solve the problem as easily as you can in JavaScript. After banging my against the keyboard and screaming didn't work, I tried breaking apart the problem.

There were two steps:
  • Get the height in the given range
  • Generate the pyramid based on the height

The first one was again simple with just a little loop magic, I got it to work. The second part was where the frustrating part began. Several times I got very close to the solution only to find my solution failing at one or two checks via check50.

School was also keeping me busy and between School and other work, I hardly got any time to crack this. 3 weekends passed and I had gotten nowhere, partly due to my exams.

Today, after getting home from my final paper and a celebration lunch, I sat down to finally end this, but first thing first, I posted a story on Snapchat about it. After only half-an-hour, my second Snapchat stroy came - "Finally cracked it".

Now I have to move on to the next problem, i.e. Greedy.c!

For those of you who are still stuck on mario, my tip is to first be consistent(unlike me). Secondly, think in loops - You'll need three, one for each task - spaces, hashes and new lines. Draw the pyramid on a paper for different heights and find a pattern. Solve this in steps. Just worry about the spaces first, then the hashes and then finally the new lines. You'll crack it soon enough.

Now if you'll excuse me, I have a problem to crack!

Hey there, I'm Ammar!

Share This Post


    Blogger Comment


Post a Comment