# Code of solving Joseph Ring problem in batch

Time：2020-7-29

Title:
There are 29 girls (called 1-29 respectively) in a circle to play the counting game. The rules are as follows: start counting from 1, the person counting to 3 will quit the game, and the person behind her will count from 1… So until the last one left, now know that the game started from girl No. 13. What number of girl will be left in the end?
requirement:
1 answer with batch processing
The code is concise and efficient
3 code is universal and does not generate temporary files
Bonus principle:
Focus on thinking (if the idea is unique, please briefly explain)
10 points will be added if the requirements are fully met

There are two sets of solutions, see the code of more on the 3rd floor and ieutk on the 6th floor, but I think they are not perfect (see my comments)
Wait for the appearance of perfect scheme, everybody refuels!!!

Note: Joseph’s question
Joseph’s problem is a well-known problem: n people form a circle and count from the first, the m will be killed, the last one will be killed, and the rest will be killed. For example, n = 6, M = 5, the serial number of the person killed is 5, 4, 6, 2, 3. There’s one left.
more：

Copy codeThe code is as follows:
@echo off
set “str=13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 1 2 3 4 5 6 7 8 9 10 11 12”
:again
for /f “tokens=1,2,4*” %%a in (“%str%”) do (
if not “%%c”==”” (set “str=%%c %%d %%a %%b”&goto :again) else (echo %%b&pause&exit)
)

ieutk：

Copy codeThe code is as follows:
@echo off
setlocal enabledelayedexpansion
for /l %%a in (12 -1 1) do set “str= %%a !str!”
for /l %%a in (29 -1 13) do set “str= %%a !str!”

:main
set “ie=0”
for %%a in (%str%) do set /a ie+=1
if %ie% neq 1 (
for %%a in (%str%) do (
set /a num+=1
if !num! equ 3 (
set “num=0”
set “str=!str: %%a =!
)
)
goto main
)
echo %str%
pause

batman：

Copy codeThe code is as follows:
@echo off&setlocal enabledelayedexpansion
for /l %%a in (13,1,29) do set “str=!str! #%%a#”
for /l %%a in (1,1,12) do set “str=!str! #%%a#”
:lp
for %%a in (!str!) do (
set /a n+=1
if !n! equ 3 set “str=!str: %%a=!”&set /a n=0
)
for /f “tokens=2” %%a in (“%str%”) do if “%%a” neq “” goto lp
The last remaining echo is% STR: ා =% sign & pause > nul

## PHP uses redis to solve the problem of oversold

preface In the event of the second killing of goods, for example, the inventory of goods is only 100, but in the rush purchase activity, 200 people may rush to buy at the same time, so there is concurrency. If the order of 100 goods is completed and the inventory is 0, it may continue […]