input -
2
output -
10 20
Pattern -
0 0 | 10 0 | 10 20 | -20 20 | -20 -20 | 30 -20 | 30 40 | -40 40 | -40 -40 | 50 -40 | …
input -
2
output -
10 20
Pattern -
0 0 | 10 0 | 10 20 | -20 20 | -20 -20 | 30 -20 | 30 40 | -40 40 | -40 -40 | 50 -40 | …
see 1st number:
0 10 10 -20 -20 30 30 -40 -40 50 50…
now see the 2nd number:
0 0 20 20 -20 -20 40 40 -40 -40 60 60…
l1=[0 for i in range(1111)]
l2=[0 for i in range(1111)]
l1[0]=0
l2[0]=0
l1[1]=10
l2[1]=0
l1[2]=10
l2[2]=20
l1[3]=-20
l2[3]=20
l1[4]=-20
l2[4]=-20
l1[5]=30
l2[5]=-20
for i in range(6,1111):
if(l1[i-4]>0):
l1[i]=l1[i-4]+20
if(l1[i-4]<0):
l1[i]=l1[i-4]-20
if(l2[i-4]>0):
l2[i]=l2[i-4]+20
if(l2[i-4]<0):
l2[i]=l2[i-4]-20
n=int(input())
print(l1[n],l2[n])
I observed the pattern very well. Here’s a link - if you might want to review and add to what I have achieved so far - https://codepen.io/xajinkya/pen/jgabym
I see you have hard-coded the values of first six cases, which I didn’t think of as an approach before. Although, can you please share your thought process – about how you went around the problem? Here’s what I tried https://codepen.io/xajinkya/pen/jgabym
Bad at understanding other’s code
But yeah, my thought process was i drew the pattern on a page.
It was repeating every 4 times with a difference of 20…that was all.
You can hard-code without the list as well!
I was supposed to solve this question in 30 minutes and the IDE didn’t even had syntax highlighting. For someone who hasn’t been in competitive coding for long, it has been tough for me. Also, I was unable to find compile option in the IDE provided, but so couldn’t the “IT Manager” at the exam center. Btw, how did you get the pattern? I wrote the coordinates upto 10 to figure out pattern. (which I failed at)
I tried inspired by your solution - patterns - Replit
Pattern was pretty easy to notice tbh.
Yeah, i admit the IDE was terrible, i barely got it to work and submitted my solution in last moment.
I don’t know why they had such archaic console with outdated compilers and stuffs…
Draw a graph with the coordinates,
it gets very easy to notice then!
second thing,
use ideone to share solutions like these…
I apologise that i previously didn’t adhere to this…
I posted it in a rush