Saturday, December 31, 2016

The Maze

There's only one corner of the universe you can be certain 
of improving, and that's your own self.
Aldous Huxley, Time Must Have a Stop (1944)

The closing lesson of the the first module consist in a LAB, that basically is a sequence of minigames in which you use principles of programming in order to execute the tasks.

It was very familiar to me because it reminded me a game that I used to play during my childhood - "The lost mind of Dr. Brain." In this game you can find several puzzles and one of then "motor programming" has the same principle.

 

On the left you can see a screenshot from Dr. Brain's Motor programming. On the right you can see the Mooc's course lab. The similarity is striking. 

When the game started to get complex it was introduced the concept of "loop"



After several similar exercises, it was introduced the concept of "branching".



The next examples were very similar but with an increasing difficult level.

What can I say about this activity?
I jsut loved! It was very ludic and useful. It was a way introduce the concept of "loop" and "branching" in a very interesting way.


What's next? I don't know what to expect, but I am very anxious for the following lessons.

I don't really know for how long I will still be able to understand the content of this course, but I don't care...

Challange accepted!!!

Até a próxima! ;)




Wednesday, December 28, 2016

Getting complex

A solution which does not prepare 
for the next round with some 
increased insight is hardly a
 solution at all.
(Richard Hamming)


The fourth module, Conditional Expressions and Statements,was a bit complex. Actually it is related to the fact that the conditional expressions were very tricky. But once I understood the logic behind the statements, things got more natural. What does not means that it was completely natural.

Firstly, was introduced the Ternary Operator, that in simple terms is a simplification of the previous chapter. The basic structure of the statements is the following sentence:

b?e1:e2

The terms of the expression are:

b, the bolean value;
e1, the expression in the case of the bolean value be TRUE, and;
e2, the expression to be used in the FALSE case.


See below an example of how do this statement works.

int n=-1 
int x= ?

n<0 ? x=-n:x=n;

The goal of the statment in the given example is to give the ablsolute values of the numbers. so if the number is negative the result would be the positive equivalent value while if the value of n is positive, the value assigned for x will be the proper number.

In the example the result is 1


The second part of the lesson presents how the conditionals works in compairson with the conditionals presented on the previous lesson. I.e.:

Observe the statement:

if (b) {x=m;}
else {x=n;}

Note that it is equivalent to the following conditional expression:

x=
  (b) ? m:n


Then, there was the exercises.


The first exercise consisted in the simplification of the expressions.



Later, you were supposed to determine the equivalent boolean function according to the statements:




The next exercise was very tricky. Since each blank space only had 2 possible answers, true or false, it took a while to understand the reason why the correct answers were correct. Precisely it took 2 lines.




Finally, there were the exercises in the programming environment. The first one consisted in guess the result of the code and the second in make modifications on the code in order to make it work properly. The code is supposed to deliver the number of days of each month considering the leap year. The activity was not that hard and apparently there were several ways to solve it.




How do I feel after this unity?
Tired and a bit afraid about what's next!

Até a próxima!!

Monday, December 26, 2016

Creating alternatives!

'Would you tell me, please, which way I ought to go from here?'
'That depends a good deal on where you want to get to,' said the Cat.
'I don't much care where —' said Alice.
'Then it doesn't matter which way you go,' said the Ca
t
(Alice's Adventures in Wonderland by Lewis Carroll)



The next lesson “Decisions” introduced the conditional operations. In other words, how the computer behaves when you give it alternatives. It introduces the command line “if”.
Basically it works as the example below:

int x = -1;
if (x<0)
{
   x=-x;
}

From the expression above we can infer that if the value of x is inferior to 0, the computer should assign a negative value for x. In the case, x equals -1. Therefore, -x will be 1.
The first exercise to check if the codification of the conditionals was properly understood was complete a code based on the given table of BMI (Body Mass Index).



For me, this exercise was not that difficult if you have payed attention to the previous lessons.

The next step was to see how the codification works in a real environment.This activity was more exploratory, the result of the code was not required to be correctly gessed, but it was encouraged.

As can be seen, you should play with the results of a game and accorging to the score the program would show a different sentence regardint the result of the match.

After the presentation of the basic condition, it was presented the alternative code "else", in which you can give another path considering a different condition. Take a look at the basic example.

int n =
if(n<0)
​{
​   x=-n;
​}else{
​   x=n;
​}

The first condition above is if n is a value under 0, the computer should assign the negative value of n. While the second condition means that in any other case the result of the code should be the same. In practical terms, of course.

The following exercise was a bit tricky, but not hard at all. The task was guess the results of the codes.

The folowing 2 exercises, were variations of the past ones.

I would say that this unit was a bit easier compared to the previous two. Maybe it is because I'm becaming familiarized with this new language.

I'm so happy with my progress...
Até a próxima!