Difference between revisions of "CompSciWeek2"
From Predictive Chemistry
Line 1: | Line 1: | ||
(Wed. only) |
(Wed. only) |
||
⚫ | |||
+ | == Reading Assignment == |
||
− | |||
* Beginning Python, Chapter 5 |
* Beginning Python, Chapter 5 |
||
* Algorithms, Chapters 1-3 |
* Algorithms, Chapters 1-3 |
||
+ | |||
+ | |||
⚫ | |||
** ignore python 'Class' for now |
** ignore python 'Class' for now |
||
* Complexity notation, O(n), etc. |
* Complexity notation, O(n), etc. |
||
Line 12: | Line 14: | ||
* The KISS, DRY, and incremental principles |
* The KISS, DRY, and incremental principles |
||
* Loading python modules |
* Loading python modules |
||
+ | |||
+ | == Poorly Designed Euclid's Algo. == |
||
+ | <source lang="python"> |
||
+ | a = 1547 |
||
+ | b = 224 |
||
+ | |||
+ | while(1): |
||
+ | if a < b: |
||
+ | c = a |
||
+ | a = b |
||
+ | b = c |
||
+ | a = a % b |
||
+ | if a < b: |
||
+ | c = a |
||
+ | a = b |
||
+ | b = c |
||
+ | if a == 0: |
||
+ | break |
||
+ | print "%d, %d"%(a,b) |
||
+ | |||
+ | print "The GCD of %d and %d is %d"%(a,b,b) |
||
+ | </source> |
Revision as of 10:49, 1 September 2014
(Wed. only)
Reading Assignment
- Beginning Python, Chapter 5
- Algorithms, Chapters 1-3
Algorithms, Continued
- ignore python 'Class' for now
- Complexity notation, O(n), etc.
- Loop Complexity
- First algorithms (Horner, Euclid, Babylonian)
- Code walk-through for a poorly designed Euclids algo.
- The KISS, DRY, and incremental principles
- Loading python modules
Poorly Designed Euclid's Algo.
<source lang="python"> a = 1547 b = 224
while(1):
if a < b: c = a a = b b = c a = a % b if a < b: c = a a = b b = c if a == 0: break print "%d, %d"%(a,b)
print "The GCD of %d and %d is %d"%(a,b,b) </source>