def solution(num: int) -> int:
num = list(range(1, num + 1))
flag = 1
while len(num) != 1:
num = num[flag + 1::2] if len(num) % 2 == 1 and flag == 0 else num[flag::2]
flag = 1 if flag == 0 else 0
return int(num[0])
def solution(num:int):
num = [str(i) for i in range(1,num+1)]
x = 1
while len(num) >1:
if x % 2 != 0:
for i in range(len(num)):
if i % 2 == 0:
del num[0]
else:
num.append(num[0])
del num[0]
x+=1
else:
for i in range(len(num)):
if i % 2 == 0:
del num[-1]
else:
num.insert(0,num[-1])
del num[-1]
x+=1
return int(num[0])
# daily_20220429
def solution(num: int)-> int:
# your code here
num_list = [str(x+1) for x in range(num)]
round = 1
while len(num_list) > 1:
if round % 2 == 0:
del_num = [e for i, e in enumerate(num_list[::-1]) if i % 2 == 0]
for i in del_num:
num_list.remove(i)
round += 1
else:
del_num = [e for i, e in enumerate(num_list) if i % 2 == 0]
for i in del_num:
num_list.remove(i)
round += 1
return int(num_list[0])
def solution(num: int)-> int:
# your code here
num_list = [i for i in range(1,num+1)]
while len(num_list) > 1:
for item in num_list[::2]:
if len(num_list) == 1:
break
num_list.remove(item)
for item in num_list[::-2]:
if len(num_list) == 1:
break
num_list.remove(item)
return num_list[0]
assert solution(9) == 6
assert solution(100) == 54
assert solution(1000) == 510
def solution(num:int) -> int:
num = [i for i in range(1,num+1)]
x = 1
while len(num) >1:
if x % 2 ==0:
num = num[-2::-2]
num.reverse()
x+=1
else:
num = num[1::2]
x+=1
return int(num[0])
def solution(num: int)-> int:
# your code here
l = [i for i in range(1, num + 1)]
c = 1
while len(l) > 1:
if c % 2 != 0:
l = [i for i in l if l.index(i) % 2 != 0 ]
else:
l.reverse()
l = [i for i in l if l.index(i) % 2 != 0]
l.reverse()
c += 1
return l[0]
assert solution(1) == 1
assert solution(9) == 6
assert solution(100) == 54
assert solution(1000) == 510
def solution(num: int) -> int:
list_num = [i for i in range(1, num + 1)]
k = 0
begin = 0
end = len(list_num)
step = 2
while True:
list_num_new = [list_num[i] for i in range(begin, end, step)]
for i in list_num_new:
list_num.remove(i)
k = k + 1
if k % 2 == 0:
begin = 0
end = len(list_num)
step = 2
else:
begin = len(list_num) - 1
end = -1
step = -2
if len(list_num) == 1:
return list_num[0]
assert solution(9) == 6
assert solution(100) == 54
assert solution(1000) == 510
def solution(num: int)->int:
list = [i for i in range(1,num+1)]
list_new = []
while len(list) > 1:
for i in range(0,len(list)):
if i%2 !=0:
list_new.append(list[i])
if len(list_new) != 1:
list_new.reverse()
list,list_new = list_new,[]
else:
return list_new[0]
assert solution(9) == 6
assert solution(100) == 54
assert solution(1000) == 510
def solution(num):
list_1 = [i for i in range(1,num+1)]
flag = 1
while len(list_1)>1:
if flag % 2 != 0:
list_1 = list_1[1::2]
#print(list_1)
else :
list_1 = list_1[-2::-2]
list_1.reverse()
#print(list_1)
flag +=1
print(list_1)
solution(9)
solution(100)
solution(1000)
def solution(num: int) -> int:
li = [i for i in range(1, num + 1)]
while len(li) > 1:
li = [li[i] for i in range(1, len(li), 2)]
li.reverse()
return li[0]
def test_solution():
assert solution(9) == 6
assert solution(100) == 54
assert solution(1000) == 510