Skip to content

Instantly share code, notes, and snippets.

@flyck
Created February 12, 2020 12:32
Show Gist options
  • Save flyck/cdcc4fb1c21da66d91f1b9d1342c5d58 to your computer and use it in GitHub Desktop.
Save flyck/cdcc4fb1c21da66d91f1b9d1342c5d58 to your computer and use it in GitHub Desktop.
Coding Task
def determine_taskname(T):
"""
Find the string that is contained in every testcase
"""
i = 1
exists_everywhere = True
while True:
min_taskname = T[0][0:i]
for task in T:
if min_taskname not in task:
exists_everywhere = False
if not exists_everywhere:
break
else:
i += 1
return T[0][0:i-1]
def determine_groups(task_name, T, R):
groups = {}
T_trimmed = [t.replace(task_name, "") for t in T]
N = len(T)
i = 0
while i < N:
t = T_trimmed[i]
is_number = False
try:
int(t)
is_number = True
except ValueError:
pass
if is_number:
groups[t] = {
"results": [R[i]]
}
else:
group_name = t[:-1]
if group_name in groups:
groups[group_name]["results"] += [R[i]]
else:
groups[group_name] = {
"results": [R[i]]
}
i += 1
return groups
def compute_score(groups):
passed_groups = 0
for group, info in groups.items():
only_ok = True
for result in info["results"]:
if result != "OK":
only_ok = False
if only_ok == True:
passed_groups += 1
total_groups = len(groups.keys())
score = int(passed_groups * 100 / total_groups)
return score
def solution(T, R):
task_name = determine_taskname(T)
groups = determine_groups(task_name, T, R)
score = compute_score(groups)
print(score)
return score
# Task
# Calculate the test result score based on 2 array T and R
# They both have size N
# All testresults start with the same name
# One testgroup is grouped together by numbers. There may be subitems, nominated through a character
# Only if all items in a group ar "OK", the group is considered as "passed"
# score is then passed groups * 100 / total groups as integer
# make it so solution(T,R) returns the score
T = ["codility1", "codility3c", "codility2", "codility3a", "codility3b"]
R = ["BAD", "OK", "OK", "OK", "OK"]
solution(T,R)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment