Challenge: Strange Grid Again
Subdomeniu: Fundamentals (fundamentals)
Scor cont: 20.0 / 20
Submission status: Accepted
Submission score: 1.0
Submission ID: 464723375
Limbaj: python3
Link challenge: https://www.hackerrank.com/challenges/strange-grid/problem
Cerinta
A strange grid has been recovered from an old book. It has $5$ columns and infinite number of rows. The bottom row is considered as the first row. First few rows of the grid are like this:
..............
..............
20 22 24 26 28
11 13 15 17 19
10 12 14 16 18
1 3 5 7 9
0 2 4 6 8
The grid grows upwards forever!
Your task is to find the integer in $c$<sup>th</sup> column in $r$<sup>th</sup> row of the grid.
Input Format
There will be two integers r and c separated by a single space.
**Constraints**
* $ 1 \le r \le 2 * 10^9$
* $1 \le c \le 5$
Rows are indexed from bottom to top and columns are indexed from left to right.
Output Format
Output the answer in a single line.
Cod sursa
#!/bin/python3
import math
import os
import random
import re
import sys
def strangeGrid(r, c):
if r%2 !=0:
temp1 = 0
x = int((abs(r-1)*5))
for i in range(1,c):
temp1 += 2
return(x+temp1)
else:
temp = 0
y = int((abs(r-2)*5)+1)
for i in range(1,c):
temp += 2
return(y+temp)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
first_multiple_input = input().rstrip().split()
r = int(first_multiple_input[0])
c = int(first_multiple_input[1])
result = strangeGrid(r, c)
fptr.write(str(result) + '\n')
fptr.close()
HackerRank Fundamentals – Strange Grid Again
