# Lecture question from lecture 1 (cs50AI)

In lecture 1(knowledge), Brian gives an example from Harry Potter and concludes that it did not rain that day. My question is that it's never mentioned in the example that rain causes Harry to not visit Hagrid, and if we consider it as a mathematical if-then statement wouldn't it lead to no conclusion on whether it rained that day or not? How is then the conclusion justified?

1. If it didn’t rain, Harry visited Hagrid today.
2. Harry visited Hagrid or Dumbledor today, but not both.
3. Harry visited Dumbledor today.
4. Harry did not visit Hagrid today.

Deduction: It rained today.

From point 3, we know that Harry visited Dumbledor today. From point 2, we know that Harry visited Hagrid or Dumbledor today but not both. Based on points 2 and 3, we know that Harry did NOT visit Hagrid today. From point 1, we know that Harry only visits Hagrid when it does not rain.
Since Harry did not visit Hagrid today, it DID rain.

So, Here is the deduction:

1. If it didn’t rain, Harry visited Hagrid today.
2. Harry visited Hagrid or Dumbledor today, but not both.
3. Harry visited Dumbledor today.
4. Harry did not visit Hagrid today.

Using sentence 3, we know that Harry visited Dumbledor.

Using sentence 2, we know Harry did not visit both Hagrid and Dumbledor. so it must not have visited Hagrid because of sentence 3. So we deduce sentence 4

Now for the sentence 1 to be true, as the consequent of implication is false, the antecedent should also be false.

And so we deduce that It rained today.

The first statement says that if it didn't rain, harry visited Hagrid today, based on that statement we can conclude that harry will visit hagrid if it didn't rain, so if it does rain harry will not visit hagrid

``````if (rain == true)
{
harry.visit(hagrid)
}
else
{
harry.stay(home)
}
``````