Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Auto Painting by Kurush
import math
def checkio(capacity, number):
lst = []
for i in range(number): lst.append(i)
for i in range(number): lst.append(i)
real_capacity = min(capacity, len(lst) // 2)
operations = [lst[i * real_capacity: (i + 1) * real_capacity] for i in range(math.ceil(len(lst) / real_capacity))]
str_operations = []
for row in operations:
str_operations.append("".join([str(operation) for operation in row]))
res_operations = ",".join(str_operations)
return res_operations
if __name__ == '__main__':
#This part is using only for self-checking and not necessary for auto-testing
def check_solution(func, k, n, max_steps):
result = func(k, n)
actions = result.split(",")
if len(actions) > max_steps:
print("It can be shorter.")
return False
details = [0] * n
for act in actions:
if len(act) > k:
print("The system can contain {0} detail(s).".format(k))
return False
if len(set(act)) < len(act):
print("You can not place one detail twice in one load")
return False
for ch in act:
details[int(ch)] += 1
if any(d < 2 for d in details):
print("I see no painted details.")
return False
if any(d > 2 for d in details):
print("I see over painted details.")
return False
return True
assert check_solution(checkio, 2, 3, 3), "1st Example"
assert check_solution(checkio, 6, 3, 2), "2nd Example"
assert check_solution(checkio, 3, 6, 4), "3rd Example"
assert check_solution(checkio, 1, 4, 8), "4th Example"
assert check_solution(checkio, 2, 5, 5), "5th Example"
assert check_solution(checkio, 3, 4, 3), "6th Example"
Feb. 18, 2019