Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
guns & balls solution in Clear category for Rotate Hole by Olpag
def rotate(guns, balls):
guns = ''.join([str(i) for i in guns])
balls = ''.join(['1' if i in balls else '0' for i in range(len(guns))])
combo = [guns[-n:] + guns[:-n] for n in range(len(guns))]
return [i for i in range(len(combo)) if int(combo[i], 2) & int(balls, 2) == int(balls, 2)]
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert rotate([1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1], [0, 1]) == [1, 8], "Example"
assert rotate([1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1], [0, 1, 2]) == [], "Mission impossible"
assert rotate([1, 0, 0, 0, 1, 1, 0, 1], [0, 4, 5]) == [0], "Don't touch it"
assert rotate([1, 0, 0, 0, 1, 1, 0, 1], [5, 4, 5]) == [0, 5], "Two cannonballs in the same pipe"
Jan. 25, 2019