Skip to content

Instantly share code, notes, and snippets.

@maltzsama
Last active April 27, 2022 13:44
Show Gist options
  • Save maltzsama/7519830fa0a032a66c145a9557153608 to your computer and use it in GitHub Desktop.
Save maltzsama/7519830fa0a032a66c145a9557153608 to your computer and use it in GitHub Desktop.
querying number
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def min_time(string):
count = 0
position = 0
string = string.lower()
for element in range(len(string)):
unicode_value = ord(string[element]) - 97
first_distance = abs(position - unicode_value)
second_distance = 26 - abs(position - unicode_value)
count += min(first_distance, second_distance)
position = ord(string[element]) - 97
return count
if __name__ == '__main__':
word = "AZGB"
result = min_time(word)
print(result)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def check_index(v, i):
try:
return v[i - 1] + 1
except IndexError:
return -1
def solve(number, arr, query_values):
idx = [i for i, x in enumerate(arr) if x == number]
a = [check_index(idx, x) for i, x in enumerate(query_values)]
return a
if __name__ == '__main__':
# 8[1, 2, 20, 8, 8, 1, 2, 5, 8, 0][100, 2, 1, 3, 4]
favorite = 8
vec = [1, 2, 20, 8, 8, 1, 2, 5, 8, 0]
query_val = [100, 2, 1, 3, 4]
print(solve(favorite, vec, query_val))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment