Implementing a Hilbert map of the Internet

后端 未结 3 659
难免孤独
难免孤独 2021-01-30 09:47

In the XKCD comic 195 a design for a map of the Internet address space is suggested using a Hilbert curve so that items from a similar IP adresses will be clustered together.

3条回答
  •  一生所求
    2021-01-30 10:28

    I expect that based on the wikipedia code for a Hilbert curve you could keep track of your current position (as an (x, y) coordinate) and return that position after n cells had been visited. Then the position scaled onto [0..1] would depend on how high and wide the Hilbert curve was going to be at completion.

    from turtle import left, right, forward
    
    size = 10
    
    def hilbert(level, angle):
        if level:
            right(angle)
            hilbert(level - 1, -angle)
            forward(size)
            left(angle)
            hilbert(level - 1, angle)
            forward(size)
            hilbert(level - 1, angle)
            left(angle)
            forward(size)
            hilbert(level - 1, -angle)
            right(angle)
    

    Admittedly, this would be a brute force solution rather than a closed form solution.

提交回复
热议问题