2.7 How to solve problem
Make sure to understand question
computational problem
3. Work out examples
人類是怎麼想的?
拿出月曆算
遇上年就不好算
假設psuedo code(不管細節,寫的對不對),判斷能不能用
不要太複雜
https://www.udacity.com/course/viewer#!/c-nd000/l-4184188665/e-108281762/m-108325396
有什麼還沒處理的
https://www.udacity.com/course/viewer#!/c-nd000/l-4184188665/e-108281762/m-108325397
提出另一個簡單的方法,一個一個算
https://www.udacity.com/course/viewer#!/c-nd000/l-4184188665/m-108325398
再問一個問題,這個方法對電腦來說花費的時間?
1 billion instruction per sec = 1 nano second per instruction
https://www.udacity.com/course/viewer#!/c-nd000/l-4184188665/e-108281763/m-108325401
到底要先解決哪一個問題?
先做 nextDay(),把下一天的方程式寫出來
繼續來思考 daysBetweenDates
要解決這個複雜的問題,要分成幾個步驟:
Solution in Three Parts
Well done for getting this far! The solution to this problem is broken down into three parts:
1)Step One Pseudocode
2)Step Two Helper Function
生出第一個 dateIsBefore
3)Step Three daysBetweenDates
使用 assert 處理前面的input 如果比較大怎麼辦
如果結果不是 assert 的這樣,結果就 GG
接著解決一個月不是30天的設定
寫一個程式daysInMonth去戳他,先修正nextDay,測試一下nextDay
寫 isLeapyear,找出Leapyear的規則,調整入daysInMonth 測試Leapyear方程式
然後就可以來測daysBetweenDates