Last active
June 4, 2018 10:46
-
-
Save javiergarval/6aa626a577c36ef216f62b3443e2dc73 to your computer and use it in GitHub Desktop.
Tuenti Challenge 7 | Challenge 1 - Pizza love
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
# Tuenti Challenge 2017 | Challenge 1 - Pizza love | |
# https://contest.tuenti.net/resources/2017/Question_1.html | |
import math | |
class SliceCounter: | |
def open_input_file(self, input_path): | |
return open(input_path, 'r') | |
def open_output_file(self, output_path): | |
return open(output_path, 'w') | |
def count_slices(self, input_file, output_file): | |
lines = input_file.readlines() | |
count = 0 | |
for i in range(1, len(lines), 2): | |
slices = lines[i + 1] | |
slice_array = map(int, slices.split()) | |
slices_sum = 0 | |
count += 1 | |
for slice in slice_array: | |
slices_sum += slice | |
output_file.write('Case #' + repr(count) + ': ' + repr(math.ceil(slices_sum / 8)) + "\n") | |
def close_files(self, input_file, output_file): | |
input_file.close() | |
output_file.close() | |
def run(self): | |
input_file=self.open_input_file("input.txt") | |
output_file=self.open_output_file("output.txt") | |
self.count_slices(input_file, output_file) | |
self.close_files(input_file, output_file) | |
slice_counter=SliceCounter() | |
slice_counter.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment