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

took 20 sec's with chatgpt

-2
Protected
0

Fiz Pro termux PY

Caminho para o arquivo data.dat no Termux

filename = '/data/data/com.termux/files/home/storage/downloads/data.dat'

Contador para linhas válidas

count_valid_lines = 0

Abrir o arquivo e ler linha por linha

with open(filename, 'r') as file: for line in file: # Contar o número de '0' e '1' na linha count_0 = line.count('0') count_1 = line.count('1')

    # Verificar se o número de '0' é múltiplo de 3 ou se o número de '1' é múltiplo de 2
    if count_0 % 3 == 0 or count_1 % 2 == 0:
        count_valid_lines += 1

Exibir o resultado

print(f"Número de linhas válidas no arquivo '{filename}': {count_valid_lines}")

-1

Fun, I ended up completing this using AWK and creating a one-liner on command line.

0
Protected
0

Used python

1

Used python

0

Created C# Simple code using Regex.Matches Function, Super Easy.

0

Great Challenge! solved this using python:

Lines = 0 with open('data.txt', 'r') as file: for line in file: count_zeros = line.count("0") count_ones = line.count("1") if count_ones % 2 == 0 or count_zeros % 3 == 0: Lines += 1 print(Lines)

just need to reformat the file into .txt ( might work with .dat too but didnt try)

0

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

5

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 :)

11
Protected
1

line 537 & 6296

1

TRUEEE

0
Protected
5