def cuboid_routes(m): total = 0 maxhp = sqrt(1 + (5 * (m**2))) for p in pytriple_gen(maxhp): trip = Vuple(p) while trip[0] <= m: cubs = set() for i in range(1, trip[0]): c = tuple(sorted([i, trip[0] - i, trip[1]])) if max(c) <= m: cubs.add(c) if trip[1] - trip[0] <= trip[0]: for i in range(trip[1] - trip[0], (trip[1] // 2) + 2): cubs.add(tuple(sorted([trip[0], trip[1] - i, i]))) total += len(cubs) trip += Vuple(p) return total
def highway_dragon(max_order=50, steps=10**16): dirs = { 0: Vuple((0, 1)), 1: Vuple((1, 0)), 2: Vuple((0, -1)), 3: Vuple((-1, 0)) } def clockwise(heading): if heading == 3: return 0 else: return heading + 1 def counterclockwise(heading): if heading == 0: return 3 else: return heading - 1 def dee(cur_order, highway, pos=Vuple((0, 0)), heading=0, step=0): for h in highway: # print(h) if h == 'F': pos += dirs[heading] step += 1 print(step, pos, heading) # if step == steps: if h == 'L': heading = counterclockwise(heading) if h == 'R': heading = clockwise(heading) if cur_order < max_order: if h == 'a': pos, step, heading = dee(cur_order + 1, 'aRbFR', pos, heading, step) if h == 'b': pos, step, heading = dee(cur_order + 1, 'LFaLb', pos, heading, step) return pos, step, heading curlevel = 0 start = 'Fa' d = '' dee(0, start)
def dee(cur_order, highway, pos=Vuple((0, 0)), heading=0, step=0): for h in highway: # print(h) if h == 'F': pos += dirs[heading] step += 1 print(step, pos, heading) # if step == steps: if h == 'L': heading = counterclockwise(heading) if h == 'R': heading = clockwise(heading) if cur_order < max_order: if h == 'a': pos, step, heading = dee(cur_order + 1, 'aRbFR', pos, heading, step) if h == 'b': pos, step, heading = dee(cur_order + 1, 'LFaLb', pos, heading, step) return pos, step, heading
def test_gt(self): a = Vuple((12, 3)) b = Vuple((7, 5)) assert a > b
def test_angle_degrees(self): v1 = Vuple((10, 10)) v2 = Vuple((1, 0)) assert 45 == round(Vuple.angle(v1, v2, radians=False))
def test_angle_radians(self): v1 = Vuple((10, 10)) v2 = Vuple((1, 0)) assert 3.1415926535897936 == (4 * Vuple.angle(v1, v2))
def test_unit_vuple(self): v = Vuple((3, 4)) assert (0.6, 0.8) == Vuple.unit_vuple(v) v = Vuple((3, 4)) assert (0.6, 0.8) == v.normalize()
def test_idiv_scalar(self): v = Vuple((6, 8)) v /= 2 assert (3, 4) == v
def test_imul_scalar(self): v = Vuple((3, 4)) v *= 2 assert (6, 8) == v
def test_mul_scalar(self): v = Vuple((3, 4)) v = (v * 2) assert (6, 8) == v
def test_mag(self): assert 5.0 == Vuple.mag((3, 4)) assert 5 == Vuple((3, 4)).get_mag()
def test_sub(self): a = Vuple((12, 3)) b = Vuple((7, 5)) assert Vuple((5, -2)) == a - b assert Vuple((-5, 2)) == b - a
def test_add(self): a = Vuple((12, 3)) b = Vuple((7, 5)) assert Vuple((19, 8)) == a + b
def test_origin_not_in_triangle(self): tri = Trigon((-175, 41), (-421, -714), (574, -645)) assert Vuple((0, 0)) not in tri assert tri.contains_origin() == False
def test_div_scalar(self): v = Vuple((6, 8)) / 2 assert (3, 4) == v
def point_prob(x, y): v1 = (xz - x, y) v2 = (x, yz - y) return Vuple.angle(v2, v1, radians=False)
def __init__(self, toop): self.min_xyz = Vuple(toop[:3]) self.dxyz = Vuple(toop[3:]) self.max_xyz = self.min_xyz + Vuple(toop[3:]) self.vol = list_product(self.dxyz)