Description
Trouble Sort
Design a hardware module that implements Trouble Sort: repeatedly swap adjacent elements if they are in wrong order and have the same parity (both odd or both even). Determine if the array can be fully sorted using only these constrained swaps.
Example: For [5,6,8,4,3], can swap (6,8), (6,4), (8,4) since even, and no odd pairs adjacent. Check if final array can be sorted.
Source: Google Code Jam 2018 Qualification Round - Problem B: Trouble Sort
Input
v
Stream of 16-bit Unsigned IntegerArray to sort with parity constraints.
Output
1-bit Unsigned Integer
1 if sortable with Trouble Sort, 0 otherwise.