I have a list of rules such as
listofrules = {{1, 1, 2, 5, 14} -> 1, {1, 1, 2, 7, 12} -> 1, {137, 1, 2, 6, 16} ->
1, {137, 1, 2, 8, 13} -> 1, {273, 1, 2, 3, 5} ->
1, {273, 1, 2, 3, 7} -> 2, {273, 1, 2, 9, 12} ->
1, {273, 1, 2, 9, 14} -> -2, {409, 1, 2, 3, 6} ->
1, {409, 1, 2, 3, 8} ->
2, {409, 1, 2, 9, 13} -> -1, {409, 1, 2, 9, 16} ->
2, {545, 1, 2, 4, 5} -> 1, {577,1,1,1,1} -> -3 ...... , {9520, 16, 16, 13, 16} -> 2, {9520, 16, 16, 1, 1} ->
2, {9520, 16, 16, 2, 2} -> -2, {9520, 16, 16, 5, 5} -> -4, {9520,
16, 16, 6, 6} ->
3, {9520, 16, 16, 7, 7} -> -12, {9520, 16, 16, 8, 8} -> -1, {9520,
16, 16, 10, 10} -> -1, {9520, 16, 16, 12, 12} -> -4, {9520, 16, 16,
13, 13} ->
3, {9520, 16, 16, 14, 14} -> -12, {9520, 16, 16, 15, 15} ->
4, {9520, 16, 16, 16, 16} -> -1}
I want to sort it, ordering the last four elements of the LHS in growing order, irrespective of the first element.
For example, I want all the rules {#,1,1,1,1} -> #
first, then all the rules {#,1,1,1,2} -> #
etc...
How can I do that in an efficient way?