Our hoary culture had several great persons since time immemorial and king Vikramaditya’s Nava Ratnas (nine gems) belongs to this ilk. They are named in the following shloka:
धनवंतरी क्षषणकाडमरसिंह राड़ चेठालमदू धटकर्परः कर्मिदाक
ख्यति कराहमिहिरि नृम््ते समाभ्य्म रत्नति वै कस्मस्मिनति तिम्द्म्
Among these, Varahamihira was an astrologer of eminence, and his book Brihat Jataka is recokoned as the ultimate authority in astrology.
He was once talking with Amarasimha, another gem among the Nava Ratnas and the author of Sanskrit thesaurus, Amarakosha.
Amarasimha wanted to know the final position of a person, who starts from the origin 0 0 and travels per the following scheme.
Scheme
- He first turns and travels 10 units of distance
- His second turn is upward for 20 units
- Third turn is to the left for 30 units
- Fourth turn is the downward for 40 units
- Fifth turn is to the right(again) for 50 units
… And thus he travels, every time increasing the travel distance by 10 units.
Test Cases
Case 1
- Input: 3
- Expected Output:-20 20
Case 2
- Input: 4
- Expected Output: -20 -20
Case 3
- Input: 5
- Expected Output: 30 -20
Case 4
- Input: 7
- Expected Output: 90 -20
n = int(input())
c = 'R'
dis = 10
x,y=0,0
for i in range(n):
if c=='R':
x=x+dis
c='U'
dis=dis+10
elif c=='U':
y=y+dis
c='L'
dis=dis+10
elif c=='L':
x=x-dis
c='D'
dis=dis+10
elif c=='D':
y=y-dis
c='A'
dis=dis+10
elif c=='A':
x=x+dis
c='R'
dis=dis+10
print(x,y)
#include<stdio.h>
int main()
{
int num;
scanf("%d",&num);
int x=0,y=0,inc=0;
for(int i=0; num; i++)
{
//right coordinate(1st Quadrant)
if(num)
{
inc += 10;
x += inc;
num--;
}
//top coordinate(2nd Quadrant)
if(num)
{
inc += 10;
y += inc;
num--;
}
//left coordinate(3rd Quadrant)
if(num)
{
inc += 10;
x -= inc;
num--;
}
//down coordinate(4th Quadrant)
if(num)
{
inc += 10;
y -= inc;
num--;
}
}
printf("%d %dn",x,y);
return 0;
}