- Joined
- Sep 20, 2022
- Messages
- 271
- Reaction score
- 40
I needed to compute a maximum subarray. It would help me solve a larger problem.
I found an algorithm on wikipedia that was close to what I needed and made some changes to it. My program was ugly. It fell out of the ugly tree, and hit every branch on the way down.
After the problem was solved, and I didn't need the routine anymore, I found Kadane's algorithm.
It does exactly what I needed, with only 6 lines, and one of those was just a return statement.
A sublime piece of code, that I wish I had found first.
I found an algorithm on wikipedia that was close to what I needed and made some changes to it. My program was ugly. It fell out of the ugly tree, and hit every branch on the way down.
After the problem was solved, and I didn't need the routine anymore, I found Kadane's algorithm.
It does exactly what I needed, with only 6 lines, and one of those was just a return statement.
A sublime piece of code, that I wish I had found first.