At the end of findRotorConfiguration, the keySet is sorted in reverse order, then when the keySet.stream() is returned, it is also sorted in reverse order. It doesn't seem like the .sorted() would be needed on the returned stream() since the keySet is already sorted.
FYI: On my M1 Mac mini with 8 cores, the optimized version runs in about 4.3 seconds.
At the end of findRotorConfiguration, the keySet is sorted in reverse order, then when the keySet.stream() is returned, it is also sorted in reverse order. It doesn't seem like the .sorted() would be needed on the returned stream() since the keySet is already sorted.
FYI: On my M1 Mac mini with 8 cores, the optimized version runs in about 4.3 seconds.