As a newbie programmer

Circle of Numbers @ Dcoder

Dcoder icon

Problem: All numbers in NumberLand are standing in a circle for a dancing ceremony. Every number needs a dancing partner. Dancing partner of any number is the number which is standing radially opposite to it in the circle. The numbers are from 0 to N-1. A certain number X wants to know who will be its dancing partner. Please help X.

Input: Two positive integers denoting the value of N and X.

Output: Print the number radially opposite to X in a circle of N numbers.

Constraints: 4 ≤ N ≤ 20

0 ≤ X < N

Sample Input: 8 2

Sample Output: 

6

n, x = map(int, input().split())
print((n // 2 + x) % n)

How do you rate this article?

0


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Publish0x Publish0x

Reward the author with $0.01 in crypto, and earn yourself as you read!

20% to author / 80% to me.
Rewards are FREE. Publish0x pays them, not you.

Page not displaying correctly?