Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

二色ボードをトリミングするやつを実装する #1

Open
log5r opened this issue Jun 24, 2023 · 1 comment
Open

二色ボードをトリミングするやつを実装する #1

log5r opened this issue Jun 24, 2023 · 1 comment

Comments

@log5r
Copy link
Owner

log5r commented Jun 24, 2023

こういうの

func trim(_ board: [[Bool]]) -> [[Bool]] {
    let h = board.count, w = board[0].count
    var left = w, right = -1, top = h, bottom = -1
    for r in 0..<h {
        for c in 0..<w where board[r][c] {
            top = min(top, r)
            bottom = max(bottom, r)
            left = min(left, c)
            right = max(right, c)
        }
    }
    var res = [[Bool]]()
    for r in top ... bottom {
        var buf = [Bool]()
        for c in left ... right {
            buf.append(board[r][c])
        }
        res.append(buf)
    }
    return res
}
@log5r
Copy link
Owner Author

log5r commented Oct 2, 2023

Array2D側に実装したほうがいい気がする

めっちゃ大変そうだけども

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant