Skip to content

Latest commit

 

History

History
31 lines (28 loc) · 818 Bytes

09.simple_programming.md

File metadata and controls

31 lines (28 loc) · 818 Bytes

CTFLearn 09 - Simple Programming

Problem Statement

Can you help me? I need to know how many lines there are where the number of 0’s is a multiple of 3 or the numbers of 1s is a multiple of 2. Please! Here is the file: https://mega.nz/#!7aoVEKhK!BAohJ0tfnP7bISIkbADK3qe1yNEkzjHXLKoJoKmqLys

Solution

Pretty Straightforward.

#!/usr/bin/python3
# usage: python3 app.py <filename>

import sys
filename = sys.argv[1]
file = open(filename, "r")
if file.mode != "r":
    exit()
data = file.read()
file.close()
count = 0
for line in data.split('\n'):
    zeros = 0
    line = line.strip()
    if len(line) == 0:
        continue
    for char in line:
        if char == '0':
            zeros += 1
    if (len(line) - zeros) % 2 == 0 or (zeros > 0 and zeros % 3 == 0):
        count += 1
print(count)