Dcoder icon

Circle of Numbers @ Dcoder

By Lochard | As a newbie programmer | 13 Mar 2023


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

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.