Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

As we discussed in the class, here is the classical programming puzzle though it came from ancient times when there are no computers at all.

As we discussed in the class, here is the classical programming puzzle though it came from ancient times when there are no computers at all. We can see that practicing math and logic can sometimes save one's life! About 2000 years ago there was some war, and during one of its battles defendants were blocked by attackers in the cave. To avoid capture, they decided to stand in a circle and kill every third person until only one person remains - who was supposed to commit suicide - though he eventually preferred to surrender to enemies. Write a program to determine for given number of people N and constant step K the position of a person who remains the last - i.e. the safe position. See example below for N=10, and K = 3

coding needs to be c++, int N and K may be changed so please account if they choose different values! needs to have comments on how the code works so i have a better understanding, thank you so much for your help 1st round: 1 2 (3) 4 5 (6) 7 8 (9) 10

2nd round: 1 (2) 4 5 (7) 8 10

3rd round: (1) 4 5 (8) 10

4th round: 4 (5) 10

5th round: 4 (10)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Employ effective vocal cues Employ effective visual cues

Answered: 1 week ago

Question

13-6 How will MIS help my career?

Answered: 1 week ago

Question

13-4 What are alternative methods for building information systems?

Answered: 1 week ago