def test_observability(): # print() coords = ims.parse([ ".#..#", ".....", "#####", "....#", "...##", ]) space_map = ims.Map(coords=coords) """ .7..7 ..... 67775 ....7 ...87 """ # p = Point(1, 0) observe_expect = { (1, 0): 7, (4, 0): 7, (0, 2): 6, (1, 2): 7, (2, 2): 7, (3, 2): 7, (4, 2): 5, (4, 3): 7, (3, 4): 8, (4, 4): 7, } got = space_map.observerability() # print("Got :", got) # print("Expect:", observe_expect) assert observe_expect == got
def test_find_best_observer_case5(): # print() coords = ims.parse([ ".#..##.###...#######", "##.############..##.", ".#.######.########.#", ".###.#######.####.#.", "#####.##.#.##.###.##", "..#####..#.#########", "####################", "#.####....###.#.#.##", "##.#################", "#####.##.###..####..", "..######..##.#######", "####.##.####...##..#", ".#####..#.######.###", "##...#.##########...", "#.##########.#######", ".####.#.###.###.#.##", "....##.##.###..#####", ".#.#.###########.###", "#.#.#.#####.####.###", "###.##.####.##.#..##", ]) space_map = ims.Map(coords=coords) value, coord = space_map.best_observer() # print(value, coord) assert 210 == value assert (11, 13) == coord
def test_rotate_1(): print() map_data = [ #01234567890123456 ".#....#####...#..", # 0 "##...##.#####..##", # 1 "##...#...#.#####.", # 2 "..#.....X...###..", # 3 X=(8,3) "..#.#.....#....##", # 4 ] coords = ims.parse(map_data) m = ims.Map(coords=coords) X = (8,3) expect_loop1 = [ (8, 1), (9, 0), (9, 1), (10, 0), (9, 2), (11, 1), (12, 1), (11, 2), (15, 1), (12, 2), (13, 2), (14, 2), (15, 2), (12, 3), (16, 4), (15, 4), (10, 4), (4, 4), (2, 4), (2, 3), (0, 2), (1, 2), (0, 1), (1, 1), (5, 2), (1, 0), (5, 1), (6, 1), (6, 0), (7, 0), ] loop1 = [p for p in m.loop_scan(X)] assert expect_loop1 == loop1 print("INITIAL STATE") print(m) for p in m.loop_scan(X): m.vaporize(p) print("AFTER 1st LOOP VAPORATION") print(m)
def test_find_best_observer_case0(): # print() coords = ims.parse([ #0123456 "#.....#", #0 ".......", #1 "...#...", #2 ".......", #3 "#.....#", #4 ]) space_map = ims.Map(coords=coords) assert False == space_map.check_if_visible((0, 0), (6, 4)) assert True == space_map.check_if_visible((0, 0), (6, 0))
def test_find_best_observer_case2(): # print() coords = ims.parse([ #0123456789 "......#.#.", #0 A+2 = 2 "#..#.#....", #1 A+3 = 5 "..#######.", #2 A+7 = 12 ".#.#.###..", #3 A+5 = 17 ".#..#.....", #4 A+2 = 19 "..#....#.#", #5 A+3 = 22 "#..#....#.", #6 A+3 = 25 ".##.#..###", #7 A+6 = 31 "##...#..#.", #8 A+4 = 35 ".#....####", #9 A+5 = 40 ]) space_map = ims.Map(coords=coords) asteroids = space_map.asteroids() assert 40 == len(asteroids) value, coord = space_map.best_observer()
import ims def vaporize_until(m: ims.Map, base: ims.Point, n: int = 200) -> ims.Point: i = 0 while m.asteroids(): for p in m.loop_scan(base_coord): m.vaporize(p) i += 1 if i == 200: return p return None if __name__ == "__main__": amplifiers = [] coords = ims.read_file('map.txt') m = ims.Map(coords=coords) value, base_coord = m.best_observer() p = vaporize_until(m, base_coord, 200) print("200th Point:", p) print("x*100 + y =", p[0] * 100 + p[1])