Simple Programming
30 points Easy

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

Flag
Rating 4.41
5
4
3
2
1

Discussion

it took me three months to count it all....

1

it took me three months to count it all....

0

it took me three months to count it all....

0

it took me three months to count it all....

0

it took me three months to count it all....

0

it took me three months to count it all....

0

it took me three months to count it all....

0
Protected
1

Open the file

with open("data.dat", 'r') as file: # Read all lines from the file lines = file.readlines()

Initialize a counter for lines meeting the conditions

count = 0

Iterate through each line in the list of lines

for line in lines: # Strip whitespace from the line and check if it's not empty if line.strip(): # Count the occurrences of '0' and '1' in the line count_0 = line.count('0') count_1 = line.count('1')

    # Check if the count of 0's is a multiple of 3 or the count of 1's is a multiple of 2
    if count_0 % 3 == 0 or count_1 % 2 == 0:
        # Increment the counter if the condition is met
        count += 1

Print the count of lines meeting the conditions

print(count)

1

Remember OR is important, this will impact the logic of ur code, ez challenge

1

Actually I want to report a bug in the question. In the 10000 lines of 0 and 1, there are: 6660 lines being mixture of 0 and 1 (or only 0 and 1) that fulfill the condition, 3338 lines being mixture of 0 and 1 that DOES NOT fulfill the condition, and 2 lines being "0000000000" (that is 10 zeros). These 2 lines does not fulfill the condition but apparently have to be counted as part of the answer.

These 2 lines probably passed because they do not contain any 1, so if u count the number of ones and mod 0 it u get 0 which still pass in certain codes.

Hopefully this get patched by either removing those 2 lines or changing the answer to 6660 :)

12
Protected
1

line 537 & 6296

1

TRUEEE

0
Protected
6