Josephus Permutation
Здравейте колеги, някой дали е решил задачата да бутне едно рамо?
Условие:
You are now to create a program that prints a Josephus permutation, receiving two lines of code (the list itself (string with elements separated by a single space) and a number k) as if they were in a circle and counted out every k places until none remained.
Моето решение което дава 60/100, а пък резултатите са ми верни
circle = input().split(' ') kill_count = int(input()) result = [] circle_int = [] counter = 0 # making str circle into int for i in circle: circle_int.append(int(i)) while len(circle_int) >= 1: # adding killed man to result list for i in circle_int: counter += 1 if counter % kill_count == 0: result.append(i) # removing killed man from the circle for i in result: if i in circle_int: circle_int.remove(i) print(str(result).replace(' ', ''))
Благодаря !
Здравейте MartinBG, можете ли да обясните последния ред какво точно се случва?
Виждам че като се опитам да
Не разбирам защо се получава но когато напиша последния ред като вас се получава
Може ли да обясните защо?