https://en.wikipedia.org/wiki/Josephus_problem This is a struct-based solution for Josephus problem.
(cl *Cyclic[int], k int)
| 118 | // https://en.wikipedia.org/wiki/Josephus_problem |
| 119 | // This is a struct-based solution for Josephus problem. |
| 120 | func JosephusProblem(cl *Cyclic[int], k int) int { |
| 121 | for cl.Size > 1 { |
| 122 | cl.Rotate(k) |
| 123 | cl.Delete() |
| 124 | cl.Rotate(-1) |
| 125 | } |
| 126 | retval := cl.Head.Val |
| 127 | cl.Destroy() |
| 128 | return retval |
| 129 | } |