diff --git a/discoverer/la_stage1.py b/discoverer/la_stage1.py index 1f93945..1ad7418 100755 --- a/discoverer/la_stage1.py +++ b/discoverer/la_stage1.py @@ -7,39 +7,38 @@ def output_words(words): print(words) def main(): - with open(sys.argv[1], 'r') as file: - reader = csv.reader(file) + reader = csv.reader(sys.stdin) - # Skip the header... - next(reader) + # Skip the header... + next(reader) - previous_data_available = None - previous_receiver_active = None + previous_data_available = None + previous_receiver_active = None - words = [] + words = [] - for line in reader: - data_available = bool(int(line[11])) - receiver_active = bool(int(line[12])) + for line in reader: + data_available = bool(int(line[11])) + receiver_active = bool(int(line[12])) - if receiver_active and not previous_receiver_active: - if words: - output_words(words) + if receiver_active and not previous_receiver_active: + if words: + output_words(words) - words = [] + words = [] - if data_available and not previous_data_available: - bits = [int(column) for column in line[1:11]] + if data_available and not previous_data_available: + bits = [int(column) for column in line[1:11]] - word = (bits[9] << 9) | (bits[8] << 8) | (bits[7] << 7) | (bits[6] << 6) | (bits[5] << 5) | (bits[4] << 4) | (bits[3] << 3) | (bits[2] << 2) | (bits[1] << 1) | bits[0] + word = (bits[9] << 9) | (bits[8] << 8) | (bits[7] << 7) | (bits[6] << 6) | (bits[5] << 5) | (bits[4] << 4) | (bits[3] << 3) | (bits[2] << 2) | (bits[1] << 1) | bits[0] - words.append(word) + words.append(word) - previous_data_available = data_available - previous_receiver_active = receiver_active + previous_data_available = data_available + previous_receiver_active = receiver_active - if words: - output_words(words) + if words: + output_words(words) if __name__ == '__main__': main() diff --git a/discoverer/la_stage2.py b/discoverer/la_stage2.py index ea4ac5c..8ce3014 100755 --- a/discoverer/la_stage2.py +++ b/discoverer/la_stage2.py @@ -58,7 +58,7 @@ def main(): print('?? ' + format_data(data, command)) else: # Strange mix of commands and data... - pass + print('!! ' + str(words)) if __name__ == '__main__': main()