Created
July 25, 2018 15:58
-
-
Save jkotra/386049ff1b6ae071e9476ca993f441c8 to your computer and use it in GitHub Desktop.
mockvita-2-inversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numpy import base_repr | |
def sum_of_digits(array): | |
digit_sum = [] | |
for i in range(len(array)): | |
x = [int(x) for x in str(array[i])] | |
digit_sum.append(sum(x)) | |
return digit_sum | |
def getInvCount(arr, n): | |
inv_count = 0 | |
for i in range(n): | |
for j in range(i + 1, n): | |
if (arr[i] > arr[j]): | |
inv_count += 1 | |
def toStr(n, base): | |
convertString = "0123456789ABCDEF" | |
if n < base: | |
return convertString[n] | |
else: | |
return toStr(n // base, base) + convertString[n % base] | |
return inv_count | |
n = int(input()) | |
array = list(input().split(',')) | |
base_six_array = [] | |
for i in range(n): | |
base_six_array.append(toStr(int(array[i]),6)) | |
digits = sum_of_digits(base_six_array) | |
print(getInvCount(digits,n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment