Commit 5a32966
committed
fix(collatz): correct step cache corruption in Collatz Conjecture
The memoization cache (steps_cache) was corrupting values due to
including the terminal element (n=1 or a cached value) in the
cache-update loop. This caused double-counting and incorrect step
counts on successive runs.
Fix: use path[:-1] in the cache update loop to exclude the
last path element, which is either 1 (already at cache[1]=0) or
a previously cached value. This keeps cache entries correct.
Fixes: steam-bell-92#8351 parent ecb99c8 commit 5a32966
1 file changed
Lines changed: 69 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
10 | 63 | | |
11 | 64 | | |
12 | 65 | | |
| |||
22 | 75 | | |
23 | 76 | | |
24 | 77 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | 78 | | |
29 | 79 | | |
30 | 80 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
39 | 94 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
| 95 | + | |
| 96 | + | |
46 | 97 | | |
47 | 98 | | |
48 | 99 | | |
| |||
65 | 116 | | |
66 | 117 | | |
67 | 118 | | |
68 | | - | |
| 119 | + | |
69 | 120 | | |
70 | 121 | | |
71 | 122 | | |
| |||
0 commit comments