I wrote a spreadsheet to help me with Killer Sudoku. The spreadsheet has nine rows which are used to input the numbers seen in (up to) nine cells and a cell for the total value. The VBA macro starts by reading everything in - the numbers are read into the two-dimensional array vals, where the first index is the row number, the second index is the nth value in the row, and the array cnt holds the number of numbers in the row. The values are added and if the sum equals the total value, the numbers in the cells are stored. Following is the 'complex' code that does this:
The program works without issue, but it can become excruciating slow. I just did this experiment to quantify the problem. I started with two rows of values and worked my way up. Each row had all nine numbers and the total was 5*number of rows. I then timed how long it took the macros to complete. Here are the results:- 2 cells, sum 10: < 1 sec
- 3 cells, sum 15: < 1 sec
- 4 cells, sum 20: 1 sec
- 5 cells, sum 25: 2 sec
- 6 cells, sum 30: 45 sec
I didn't bother going to 7 rows because I would still be waiting for things to complete. Why on earth is this taking so long? I can attach the actual spreadsheet is anyone cares.
Bookmarks