Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use batches to understand Joseph's ring application problems

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to use criticism to understand the application of Joseph ring, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article. Let's take a look at it!

Title:

There are twenty-nine girls (called by 1mur29 respectively) in a circle to play the counting game. The rule is like this: count from 1, when the person who counts to 3 quits the game, and the person behind her then counts from 1. So until the last person left, now know that the game started from the 13th girl, ask what number of girl will be the last one left?

Request:

1 answer with batch processing

2 the code is concise and efficient

3 the code is universal and does not generate temporary files

Principle of bonus points:

Give priority to the idea (if the train of thought is unique, please briefly explain)

If you fully meet the requirements, add 10 points.

There are already two solutions, see the code of the moderators of more on the 3rd floor and ieutk on the 6th floor, but I personally think that neither of these solutions is perfect (see my follow-up comments).

Wait for the emergence of the perfect plan, everyone cheer!

Note: Joseph problem

The Joseph problem is a famous problem: n individuals form a circle, counting from the first, the M will be killed, the last one will be left, and the rest will be killed. For example, the serial number of the person who was killed is 5meme4, 6pr 2p3, for example. Finally, number one is left.

More:

The 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 12 3 4 5 6 7 8 9 10 11 12"

: again

For / f "tokens=1,2,4*" an in ("str%") do (

If not "% c" = = "(set" str=%%c% d% a% b "& goto: again) else (echo%% b&pause&exit)

)

Ieutk:

The code is as follows:

@ echo off

Setlocal enabledelayedexpansion

For / l an in (12-11) do set "str= a! str!"

For / l an in (29-1 13) do set "str= a! str!"

: main

Set "ie=0"

For an in (str%) do set / an ie+=1

If ie% neq 1 (

For an in (str%) do (

Set / a num+=1

If! num! Equ 3 (

Set "num=0"

Set "stringed buildings:% a =!

)

)

Goto main

)

Echo str%

Pause

Batman:

The code is as follows:

@ echo off&setlocal enabledelayedexpansion

For / l% an in (13meme 1je 29) do set "stringing trainers! #% a #"

For / l% an in (1meme 1je 12) do set "stringent fustr! #% a #"

: lp

For an in (! str!) Do (

Set / a naughty 1

If! n! Equ 3 set "stringent roomstr:% aura!" & set / a nasty 0

)

For / f "tokens=2" an in ("str%") do if "a" neq "" goto lp

The last thing left of echo is% str:#=% number & pause > nul.

The above is all the content of the article "how to use the batch to understand the Joseph Ring Application problem". Thank you for your reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report