foobar_carrotland.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:foobar 作者: j314erre 项目源码 文件源码
def line_lattice_points(vertices):
    """ Return number of points on boundary line not including vertices
    """
    assert len(vertices)==2, "not a line: %s" % vertices
    xspan = abs(vertices[0][0] - vertices[1][0])
    yspan = abs(vertices[0][1] - vertices[1][1])
    ret = 0
    if xspan == 0 and yspan == 0:
        ret = 0
    elif xspan == 0:
        ret = yspan - 1
    elif yspan == 0:
        ret = xspan - 1
    elif xspan == yspan:
        ret = xspan - 1
    elif yspan > xspan:
        ret = gcd(yspan, xspan) - 1
    elif xspan > yspan:
        ret = gcd(xspan, yspan) - 1

    print "line_lattice_points %s=%d" % (vertices, ret)    
    return ret
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号