Josephus problem Python
PROGRAM FOR JOSEPHUS PROBLEM
OUTPUT
13
def josephus(n, k): if (n == 1): return 1 else: # The position returned by # josephus(n - 1, k) is adjusted # because the recursive call # josephus(n - 1, k) considers # the original position # k%n + 1 as position 1 return (josephus(n - 1, k) + k-1) % n + 1 # Driver Program to test above function n = 14k = 2 print("The chosen place is ", josephus(n, k))
13
Comments
Post a Comment