Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.7 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69f8c998d78ad3171a0713b9 Challenge 286: Open Issues 29 challenge-286

--description--

Given an array of issue numbers and another array of pull request (PR) numbers, return an array of issues that remain open after all PRs have been merged.

  • A PR closes an issue if their digits are a rotation of each other. For example, issue 123 would be closed by PR 231 or 312.
  • A PR does not close an issue with the exact same number. For example, PR 123 does not close issue 123. So an issue with all the same number can't get closed.
  • Either number may have leading zeros stripped. For example, PR 201 would close issue 12 (012, a rotation of 201). Similarily, issue 201 would be closed by PR 12.

Return the remaining open issues in the order they were given.

--hints--

get_open_issues([123, 234], [231]) should return [234].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_open_issues([123, 234], [231]), [234])`)
}})

get_open_issues([123, 345, 16], [345, 231]) should return [345, 16].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_open_issues([123, 345, 16], [345, 231]), [345, 16])`)
}})

get_open_issues([456, 332, 12, 15], [201, 945, 180]) should return [456, 332, 15].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_open_issues([456, 332, 12, 15], [201, 945, 180]), [456, 332, 15])`)
}})

get_open_issues([12, 115, 296, 170, 24], [17, 18, 19, 20, 21]) should return [115, 296, 24].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_open_issues([12, 115, 296, 170, 24], [17, 18, 19, 20, 21]), [115, 296, 24])`)
}})

get_open_issues([19, 95, 422, 395, 754, 102, 296, 709, 237, 4400, 1802], [395, 440, 9001, 95, 242, 21, 287, 169, 14]) should return [95, 395, 754, 296, 709, 237, 1802].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_open_issues([19, 95, 422, 395, 754, 102, 296, 709, 237, 4400, 1802], [395, 440, 9001, 95, 242, 21, 287, 169, 14]), [95, 395, 754, 296, 709, 237, 1802])`)
}})

--seed--

--seed-contents--

def get_open_issues(issues, prs):

    return issues

--solutions--

def get_open_issues(issues, prs):
    def get_rotations(n):
        s = str(n)
        rotations = set()
        for i in range(len(s)):
            rotated = s[i:] + s[:i]
            rotations.add(int(rotated))
        return rotations

    def are_rotations(a, b):
        if a == b:
            return False
        return b in get_rotations(a)

    return [issue for issue in issues if not any(are_rotations(pr, issue) or are_rotations(issue, pr) for pr in prs)]