progchan

Textboard BBS.

  • No spam, doxxing, or illegal content.
  • Code blocks via [code]lang ... [/code].
  • For monospace just leave the language blank.
  • Tripcodes via name#secret.
  • Quote links with >>123.
Rules · 規則

/aglos/ thread (3 posts)

323 Name: progchan !05fbr-b_ : 2026-04-18 12:52:20

You never know when a good algorithm will come in handy, so its probably a good idea to start collecting them. Any Algorithm. Any language.

324 Name: progchan !05fbr-b_ : 2026-04-18 12:53:22

>Python Union Find
def findGroups(isConnected: List[List[int]]) -> int:
    count = len(isConnected)
    parent = list(range(count))
    rank = [1] * count
    def find(i):
        if parent[i] != i:
            parent[i] = find(parent[i])
        return parent[i]
    def union(i,j):
        nonlocal count
        pi = find(i)
        pj = find(j)
        if pi == pj:
            return
        count -= 1
        if rank[pi] > rank[pj]:
            parent[pj] = pi
            rank[pi] += rank[pj]
        else:
            parent[pi] = pj
            rank[pj] += rank[pi]
    for i in range(n):
        for j in range(n):
            if isConnected[i][j]:
                union(i,j)
    return count

325 Name: progchan !05fbr-b_ : 2026-04-18 13:17:06

>Python Shoelace
def polygon_area(points: List[List[int]]) -> int:
    n = len(points)
    area = 0
    for i in range(n):
        x1, y1 = points[i]
        x2, y2 = points[(i + 1) % n]  # wrap around
        area += x1 * y2 - x2 * y1
    return abs(area) / 2
Name: