How to think like a Computer Scientist: 课后习题第七章 11-13

#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      penglaixy
#
# Created:     27/07/2013
# Copyright:   (c) penglaixy 2013
# Licence:     <your licence>
#-------------------------------------------------------------------------------
import sys
import turtle
import time

def adjust_window(t):
        t.penup()
        t.right(90)
        t.forward(100)
        t.left(90)
        t.pendown()

def test(did_pass):
    '''
    print the result of a test
    '''
    linenum = sys._getframe(1).f_lineno
    if did_pass:
        msg = 'Test at line {0} ok'.format(linenum)
    else:
        msg = 'Test at line {0} failed'.format(linenum)
    print msg

def draw_shape(angle_list):
    tess = turtle.Turtle()
    wn = turtle.Screen()
    adjust_window(tess)
    wn.bgcolor('lightgreen')
    tess.color('navy blue')
    tess.pensize(10)

    for (angle, step) in angle_list:
        tess.left(angle)
        tess.forward(step)
    time.sleep(8)
    wn.bye()

def draw_drunk_priate():
    angle_list = [(160, 200),(-43, 100), (270, 80), (-43, 120)]
    draw_shape(angle_list)

def draw_house():
    angle_list = [(90,150),(30,150),(120,150),(120,150),(225,216),(225,150),(225,216),(225,150)]
    draw_shape(angle_list)

def test_suite():
    '''
    Run the suite of tests for code in this module
    '''
    draw_drunk_priate()
    #draw_house()

def main():
    test_suite()

if __name__ == '__main__':
    main()

下面这段话是从维基百科中搜索到的:
http://en.wikipedia.org/wiki/Eulian_path
In graph theory, an Eulerian trail (or Eulerian path) is a trail in a graph which visits every edge exactly once. Similarly, an Eulerian circuit or Eulerian cycleis an Eulerian trail which starts and ends on the same vertex. 
Euler proved that a necessary condition for the existence of Eulerian circuits is that all vertices in the graph have an even degree,(每个顶点都有偶数个角度) and stated without proof that connected graphs with all vertices of even degree have an Eulerian circuit. 
The term Eulerian graph has two common meanings in graph theory. One meaning is a graph with an Eulerian circuit, and the other is a graph with every vertex of even degree. These definitions coincide for connected graphs.
For the existence of Eulerian trails it is necessary that no more than two vertices have an odd degree(有奇数个角度的顶点个数不大于两个); this means the K?nigsberg graph is not Eulerian. If there are no vertices of odd degree, all Eulerian trails are circuits. If there are exactly two vertices of odd degree(我们画的房子的最底下的两个顶点的角度个数都是3,说的就是这种情况), all Eulerian trails start at one of them and end at the other. A graph that has an Eulerian trail but not an Eulerian circuit is called semi-Eulerian.


第13题,除了第三个第四个图形不能画,其他的都可以,我没有试过,只是根据角度判断的,有兴趣的自己试着画吧

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值