for layer in layers:
for a, b in layer:
if l[a] > l[b]: l[a], l[b] = l[b], l[a]
I'm also pretty sure that a brute force "unrolling" of bubble sort would have resulted in fewer lines. There shouldn't be more than 21 comparisons needed for 7 elements.
pestatije 240 days ago [-]
[flagged]
Rendered at 13:04:50 GMT+0000 (Coordinated Universal Time) with Vercel.
In Python, you can use parallel assignments which let you express it easily with something like:
That'd be 16 lines + 1 for the function definition + 1 for the return.You could even just generate the code or run the network using the representation from that site:
If that's in a data structure called layers: I'm also pretty sure that a brute force "unrolling" of bubble sort would have resulted in fewer lines. There shouldn't be more than 21 comparisons needed for 7 elements.