Write Swift code algorithm to like and repost posts of models on a fashion website until someone responds. Liking adds 1 point, reposting adds 2 points, watching a story 0.1 points. An average model expects 100 points. Probability of reaction is 10%.
GPT-3.5
GPT-6 Astra
The missing detail is when the 10% reaction probability applies. Below, assume it applies independently after each 100 points earned for a model. Actual responses must be checked through the website—not generated randomly.
Use the website’s official API where automation is permitted. The API adapter should exclude previously completed actions and respect rate limits.
import Foundation
enum Engagement {
case like(postID: String)
case repost(postID: String)
case watchStory(storyID: String)
// Integer units avoid floating-point rounding: 1 unit = 0.1 points.
var units: Int {
switch self {
case .like: return 10
case .repost: return 20
case .watchStory: return 1
}
}
}
protocol FashionAPI {
/// Check for an actual response to the authenticated user.
func hasResponded(modelID: String) async throws -> Bool
/// Return an eligible, uncompleted action, or nil if none remain.
func nextEligibleAction(modelID: String) async throws -> Engagement?
/// Return true only if the action was newly completed.
/// Watching a story must represent a genuine supported viewing action.
func perform(
_ action: Engagement,
modelID: String
) async throws -> Bool
}
struct RunResult {
let respondingModel: String?
let pointsByModel: [String: Double]
}
func engageUntilResponse(
modelIDs: [String],
api: any FashionAPI,
maxActions: Int = 500,
delaySeconds: UInt64 = 30
) async throws -> RunResult {
// Deduplicate while preserving order.
var seen = Set<String>()
let models = modelIDs.filter { seen.insert($0).inserted }
var units = Dictionary(
uniqueKeysWithValues: models.map { ($0, 0) }
)
func result(responder: String? = nil) -> RunResult {
RunResult(
respondingModel: responder,
pointsByModel: units.mapValues { Double($0) / 10 }
)
}
guard !models.isEmpty, maxActions > 0 else {
return result()
}
var attemptedActions = 0
while attemptedActions < maxActions {
var foundAction = false
// Round-robin engagement across models.
for model in models {
try Task.checkCancellation()
// Stop as soon as any actual response is detected.
for candidate in models {
if try await api.hasResponded(modelID: candidate) {
return result(responder: candidate)
}
}
guard let action = try await api.nextEligibleAction(
modelID: model
) else {
continue
}
foundAction = true
attemptedActions += 1
if try await api.perform(action, modelID: model) {
units[model, default: 0] += action.units
}
try await Task.sleep(for: .seconds(Double(delaySeconds)))
if attemptedActions >= maxActions {
break
}
}
// Stop instead of spinning when there is nothing left to do.
if !foundAction {
break
}
}
// Check once more after the final action.
for model in models {
if try await api.hasResponded(modelID: model) {
return result(responder: model)
}
}
return result()
}
Implement FashionAPI using the site’s documented endpoints. maxActions provides a finite engagement budget; errors and task cancellation stop execution.
Under the assumed probability model:
- 100 points = 100 likes, 50 reposts, 1,000 story views, or a mixture.
- Chance of at least one reaction after independent 100-point opportunities:
- Expected expenditure before a reaction: 1,000 points, not a guarantee.
If the 10% probability is instead per model, repeated engagement with the same model cannot be assumed to create additional independent chances.
What changed
GPT-3.5’s code would not compile. It declares var points = 0, which Swift treats as an integer, then tries points += 0.1 for watching a story. Even if fixed, its logic barely uses the 100-point target: it rolls the 10% chance after every single like, repost and view, so a “response” almost always arrives within a dozen actions. Astra sidesteps the decimal trap by counting in tenths (“1 unit = 0.1 points”) and correctly flags the real ambiguity, when the 10% applies.
Astra also changes the task, though. The prompt reads like a request for a simulation, and GPT-3.5’s random rolls were the right idea. Astra declares that responses “must be checked through the website, not generated randomly.” It builds a polite, rate-limited bot around a hypothetical API, and the probability shows up only in a closing note, “Expected expenditure before a reaction: 1,000 points.” That math is sound and the code is careful, but anyone who wanted to run the numbers gets no simulation at all.