# CS50 week0 2020/10/26
**What is computer science?**
* **problem-solving**
* the process of taking some **input** (details about our problem) and generate some **output** (the solution to our problem).

**Binary(二進位)**
A computer, at the lowest level, stores data in binary, a numeral system in which there are just two digits, 0 and 1.
For example:
In binary, with just two digits, we have powers of two for each place value:
4 2 1
0 0 0
This would still be equal to 0.
Now if we change the binary value to, say, 0 1 1, the decimal value would be 3.
4 2 1
0 1 1
If we wanted to represent 8, we would need another digit:
8 4 2 1
1 0 0 0
# Representing data(資料呈現)
Some humans, many years ago, collectively decided on a standard mapping called ASCII.
A”, for example, is the number 65, and “B” is 66, and so on.
> ASCII是基於拉丁字母的一套電腦編碼系統。它主要用於顯示現代英語,而其擴展版本延伸美國標準資訊交換碼則可以部分支援其他西歐語言,並等同於國際標準ISO/IEC 646。 美國資訊交換標準代碼是這套編碼系統的傳統命名,網際網路號碼分配局現在更傾向於使用它的新名字US-ASCII
An image, too, is comprised of many smaller square dots, or pixels, each of which can be represented in binary with a system called RGB, with values for red, green, and blue light in each pixel. By mixing together different amounts of each color, we can represent millions of colors:

# Algorithms(演算法)

這邊他用找一個人的名字在電話簿裡來解釋演算法
* 逐頁翻找人名直到發現為止(紅線)
* 一次翻兩頁找(但可能漏掉)(黃線)
* 更有效的方法是直接把書本從中間剖半,從其中的半分找因為書本的排列是A到Z所以很明顯從後半段找比較方便(綠色)
* 下圖可以做一個很好的說明

# Pseudocode
We can write pseudocode, an informal syntax that is just a more specific version of English (or other human language) that represents our algorithm:
1 Pick up phone book
2 Open to middle of phone book
3 Look at page
4 If Smith is on page
5 Call Mike
6 Else if Smith is earlier in book
7 Open to middle of left half of book
8 Go back to line 3
9 Else if Smith is later in book
10 Open to middle of right half of book
11 Go back to line 3
12 Else
13 Quit
* Some of these lines start with **verbs, or actions**. We’ll start calling these functions: Pick, Open, Look....
* We also have branches that lead to different paths, like forks in the road, which we’ll call conditions: If, Else...
* And the questions that decide where we go are called **Boolean expressions**, which eventually result to a value of true or false(0或1): Smith **is** later in book, Smith **is** on page
* Finally, we have words that lead to cycles, where we can repeat parts of our program, called loops: **Go back** to line 3
# Scratch
> Graphical programming language called **Scratch**, where we’ll drag and drop blocks that contain instructions.
powerful features:
* variables
the ability to store values and change them
* threads
the ability for our program to do multiple things at once
* events
the ability to respond to changes in our program or inputs

上圖左側有很多框框代表功能(function)或是變數(variables)可以拉到中間做串接使右邊的貓咪做出動作

像是讓貓咪說Hello!
The “say” block itself is like an algorithm, where we provided an input of “hello, world” and it produced the output of Scratch (the cat) “saying” that phrase:

接下來用了比較多的操作讓貓咪移動走路或是發出聲音在各種條件下面。
詳細可以參閱網站
https://cs50.harvard.edu/x/2020/notes/0/#:~:text=We%20have%20a%20variable,%20muted,%20that%E2%80%99s%20false%20by%20default.%20And%20our%20program%20will%20constantly%20check%20if%20the%20space%20bar%20is%20pressed,%20and%20set%20muted%20to%20false%20if%20it%E2%80%99s%20true,%20or%20true%20if%20not.%20This%20way,%20we%20can%20toggle%20whether%20the%20sound%20plays%20or%20not,%20since%20our%20other%20set%20of%20blocks%20for%20the%20sea%20lion%20check%20the%20muted%20variable: