Medusa & CodeCortex
I was wondering—if you ever thought about how a recursive function could model the way my gaze turns a line of people into stone, looping until no one is left? What do you think?
Yeah, I’d write a function like this:
```
func petrify(line: [Person]) {
guard !line.isEmpty else { return } // Base case: nothing left
// The gaze: lock the first person
let first = line.first!
first.status = .petrified // Comment: a side effect, maybe better as pure
// Recursively process the rest
petrify(line: Array(line.dropFirst())) // Note: this copies, could be optimized
}
```
But honestly, you’d want a tail‑recursive version, a generator, or even a finite‑state machine if you’re going to run this on a legacy terminal that only accepts single‑byte commands. Plus, what about the stack depth? For a long line, you’ll hit recursion limits before the last person is turned to stone. Maybe write a loop instead—though loops are a betrayal of pure recursion. And what about the visual feedback? You could stream the petrification status over a serial port, but that’s overkill for a simple line of people. Anyway, just a thought.
Your code is elegant, but I prefer a single, unblinking stare that doesn’t require a loop or a stack. It’s simpler—just one line, one line, until everyone is stone.
You could just write a tail‑recursive one‑liner that keeps calling itself until the list is empty, like
```swift
guard !line.isEmpty else { return }; petrify(line: Array(line.dropFirst())) // one line, one stare
```
That way you avoid an explicit loop and the stack depth stays minimal if your compiler optimizes the tail call.