Python Logic for Sequences and Base Conversions
Tile Sequence Validation Logic
The following function determines if a sequence of tiles is valid by checking their compatibility and adjusting their orientation if necessary.
def is_valid_sequence(seq: list[Tile]) -> bool:
if len(seq) < 2:
res = True
else:
if not are_compatible(seq[0], seq[1]):
seq[0] = seq[0][1], seq[0][0]
i = 1
while i < len(seq) and are_compatible(seq[i - 1], seq[i]):
if seq[i - 1][1] != seq[i][0]:
seq[i] = seq[i][1], seq[i][0]
i += 1
res = i == len(seq)
return resSquare-Free Number Verification
This function checks if a positive integer is square-free, meaning no prime factor has an exponent greater than one.
def...