حلول ذكية منقولة
الحل الأول:
Function Survivor(pCount As Integer) As Variant
Dim Res As String
Survivor = "#NUM!"
If pCount < 1 Or pCount > 511 Then Exit Function
Res = WorksheetFunction.Dec2Bin(pCount)
Res = Mid(Res, 2) & Left(Res, 1)
Survivor = WorksheetFunction.Bin2Dec(Res)
End Function
الحل الثاني:
Function Survivor(pCount As Integer) As Integer
Dim Prisoners As String
Dim k As Integer, v As Integer
Prisoners = String(pCount, "1")
Do While Replace(Prisoners, "0", "") <> "1"
k = InStr(v + 1, Prisoners, "1"): If k = 0 Then k = InStr(1, Prisoners, "1")
v = InStr(k + 1, Prisoners, "1"): If v = 0 Then v = InStr(1, Prisoners, "1")
Prisoners = Left(Prisoners, v - 1) & "0" & Mid(Prisoners, v + 1)
Loop
Survivor = InStr(1, Prisoners, "1")
End Function
آمل من المشرفين الكرام إقفال هذا الموضوع
فقد وئد في يومه الأول.
شكرا للجميع.